A simple and reliable EEPROM emulation library written in C for STM32 (HAL-based).
This library allows you to store and retrieve non-volatile data using the STM32's internal Flash memory β ideal for devices that do not include dedicated EEPROM.
It provides a lightweight API for initialization, read, write, format, and capacity management, making it easy to integrate into any STM32 project.
It supports all STM32 series.
- π§© Fully blocking, synchronous operation
- πΎ Uses internal Flash for data storage
- π§± Configurable page/sector size and memory layout (Auto and Manual)
- π§ Supports data structure mapping for easy use
- βοΈ Works with both single-bank and dual-bank Flash configurations
- π Safe write mechanism to protect existing data
- π Clean, modular, and portable API
You can add the library to your STM32 project in two ways:
Add these files to your project:
- ee.h
- ee.c
- ee_config.h
Include them in your application source files and compile.
Future support will be available via the official STM32 pack repository.
Defines page/sector sizes and optional manual Flash configuration or Use Auto Selection (define EE_MANUAL_CONFIG = 0).
/* USER CODE BEGIN EE_CONFIGURATION */
#define EE_MANUAL_CONFIG                  0
#if (EE_MANUAL_CONFIG == 1)
#define EE_SELECTED_PAGE_SECTOR_NUMBER    16
#define EE_SELECTED_PAGE_SECTOR_SIZE      EE_PAGE_SECTOR_SIZE_1K
#define EE_SELECTED_BANK                  FLASH_BANK_1
#define EE_SELECTED_ADDRESS               0x08000000
#endif
/* USER CODE END EE_CONFIGURATION */| Function | Description | 
|---|---|
| ee_init() | Initialize EEPROM emulation module with a data buffer | 
| ee_capacity() | Get total emulated EEPROM capacity (in bytes) | 
| ee_format() | Erase and format the EEPROM area in Flash memory | 
| ee_read() | Load data from Flash into RAM buffer | 
| ee_write() | Save (write) the RAM buffer back to Flash memory | 
Use your data structure like this:
#include "ee.h"
typedef struct
{
 uint32_t val1;
 int16_t val2;
 int8_t val3;
 float val4;
} stotrage_t;
stotrage_t ee_data;
int main(void)
{
  // HAL / system init ...
  // ...
  ee_init(&ee_data, sizeof(stotrage_t));
  ee_read();
  ee_data.val1 = 10000;
  ee_data.val2 = -202;
  ee_data.val3 = -3;
  ee_data.val4 = 4.5f;
  ee_write();
  while (1)
  {
    // main loop...
  }
}- Flash erase/write cycles are limited β avoid frequent writes.
- For some series should enable 'EE_MANUAL_CONFIG'.
If this project helped you, please β star the repo and consider supporting:
Licensed under the terms in the LICENSE.