GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Vanderhell/microflash: Unified flash abstraction layer for embedded systems in C99. One partition-based API for NOR, EEPROM, FRAM, and RAM with stats, CRC32, and strict bounds checks.

BranchesTags
Open more actions menu

Latest commit

 

History

10 Commits
10 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
cmake
cmake
 
 
docs
docs
 
 
include
include
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CMakeLists.txt
CMakeLists.txt
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 

Repository files navigation

microflash

CI License: MIT C99

microflash is a small C99 flash abstraction for embedded systems.

It requires C99 or newer, does not allocate from the heap, and does not depend on an OS.

It provides:

  • caller-owned partition storage,
  • caller-owned statistics storage,
  • partition-relative read/write/erase operations,
  • CRC32 helpers,
  • per-partition operation counters,
  • explicit NOR erase/write alignment rules.

It does not provide heap allocation, global adapter state, or microconf compatibility helpers.

Contracts

  • Partition names are borrowed strings and must remain valid for the life of the partition.
  • The driver context is caller-owned and must outlive the mflash_t instance.
  • Duplicate partition names are rejected.
  • Overlapping partition ranges are rejected.
  • mflash_erase_write() only accepts full erase-unit NOR updates; partial NOR updates are rejected.
  • RAM erase fills the selected range with zeroes.
  • EEPROM, FRAM, and RAM use validated write semantics for mflash_erase_write().
  • Zero-length read/write/erase operations succeed without driver I/O.
  • Statistics count successful public read/write/erase operations and saturate at UINT32_MAX.
  • mflash_crc32(NULL, 0) is supported and returns 0.

Build

With CMake:

cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure

With the documented Makefile path:

cd tests
make

Direct C99 compile:

cc -std=c99 -Wall -Wextra -Wpedantic -Werror -Iinclude src/mflash.c tests/test_all.c -o test_all
./test_all

Install and consume with find_package:

cmake -S . -B build-install
cmake --build build-install
cmake --install build-install --prefix "$PWD/prefix"
cmake -S tests/consumer -B build-consumer -DCMAKE_PREFIX_PATH="$PWD/prefix"
cmake --build build-consumer
ctest --test-dir build-consumer --output-on-failure

ARM compile-only check:

arm-none-eabi-gcc -std=c99 -Wall -Wextra -Wpedantic -Werror -ffreestanding -mcpu=cortex-m3 -mthumb -Iinclude -c src/mflash.c -o mflash.o
arm-none-eabi-gcc -std=c99 -Wall -Wextra -Wpedantic -Werror -ffreestanding -mcpu=cortex-m3 -mthumb -Iinclude -c tests/arm_consumer.c -o arm_consumer.o

Quick Start

#include "mflash.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>

typedef struct {
    uint8_t *mem;
    uint32_t size;
} mock_ctx_t;

static int mock_read(uint32_t addr, void *buf, uint32_t len, void *ctx)
{
    mock_ctx_t *mock = (mock_ctx_t *)ctx;
    if (mock == NULL || buf == NULL || addr > mock->size || len > mock->size - addr) {
        return -1;
    }
    memcpy(buf, mock->mem + addr, len);
    return 0;
}

static int mock_write(uint32_t addr, const void *buf, uint32_t len, void *ctx)
{
    mock_ctx_t *mock = (mock_ctx_t *)ctx;
    if (mock == NULL || buf == NULL || addr > mock->size || len > mock->size - addr) {
        return -1;
    }
    memcpy(mock->mem + addr, buf, len);
    return 0;
}

int main(void)
{
    uint8_t storage[256];
    mflash_partition_t partitions[4];
    mflash_stats_t stats[4];
    mock_ctx_t ctx = { storage, sizeof(storage) };
    mflash_driver_t driver = { mock_read, mock_write, NULL, &ctx };
    mflash_t flash;
    uint8_t value = 0x42U;

    memset(storage, 0xFF, sizeof(storage));
    if (mflash_init(&flash, &driver, partitions, stats, 4U) != MFLASH_OK) {
        return 1;
    }
    if (mflash_add_partition(&flash, "config", 0U, 256U, 0U, 1U,
                             MFLASH_TYPE_RAM, false) < 0) {
        return 1;
    }
    if (mflash_write(&flash, 0U, 0U, &value, 1U) != MFLASH_OK) {
        return 1;
    }
    if (mflash_read(&flash, 0U, 0U, &value, 1U) != MFLASH_OK) {
        return 1;
    }
    return value == 0x42U ? 0 : 1;
}

Documentation

  • API Reference
  • Cookbook
  • Design
  • Porting Guide
  • Troubleshooting
  • Verification
  • Contributing
  • Security
  • Changelog

License

MIT, see LICENSE.

About

Unified flash abstraction layer for embedded systems in C99. One partition-based API for NOR, EEPROM, FRAM, and RAM with stats, CRC32, and strict bounds checks.

Topics

cc99crc32eepromembeddedfirmwareflash-memoryframhalstorage

Resources

Readme
MIT license

Contributing

Contributing

Security policy

Security policy
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.