Skip to content

nimaltd/ee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

142 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📘 EEPROM Emulation Library for STM32

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.


✨ Features

  • 🧩 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

⚙️ Installation

You can add the library to your STM32 project in two ways:

1. Copy files directly

Add these files to your project:

  • ee.h
  • ee.c
  • ee_config.h

Include them in your application source files and compile.

2. STM32Cube Pack Installer (optional)

Future support will be available via the official STM32 pack repository.


🔧 Configuration (ee_config.h)

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 */

🧰 API Overview

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

🚀 Quick Start

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... } }

💡 Notes

  • Flash erase/write cycles are limited — avoid frequent writes.
  • For some series should enable 'EE_MANUAL_CONFIG'.

Watch the Video ( Previous version ):

Video

💖 Support

If this project helped you, please ⭐ star the repo and consider supporting:

  • GitHub
  • YouTube
  • Instagram
  • LinkedIn
  • Email
  • Ko-fi

📜 License

Licensed under the terms in the LICENSE.