Overview

Purpose

The EEPROM Emulation module provides an abstraction layer to emulate EEPROM functionality on STM32 Flash memory. It lets applications store and retrieve data persistently without requiring dedicated EEPROM hardware.

Key Features

The main features of EEPROM Emulation are:

  • Configurable emulation capacity: Number of variables and write cycles.

  • Algorithm selection: FLITF or NVM aligned with device constraints and performance.

  • Power-failure recovery: Restores a consistent state after reset, even if power is lost during a write.

  • Data integrity options: CRC for corruption detection and BCH-based ECC for bit error correction.

  • Pluggable interfaces: Ready-to-use and template drivers for Flash, CRC, and ECC.

  • Typed variable access: Persistent variables with fixed sizes (for example 8-bit, 16-bit, 32-bit).

  • Maintenance modes: Cleanup and wear-leveling can run in polling or interrupt-driven workflows.

Architecture

The following diagram illustrates the software components of the EEPROM Emulation utility and their interactions across the application, core, algorithms (FLITF/NVM), interfaces (Flash/CRC/ECC), STM32 HAL libraries, and hardware.

@startuml
skinparam componentStyle rectangle

title EEPROM Emulation Architecture Overview

' =========================
' Application
' =========================
package "Application" {
  component APP as "User Application\n(firmware code)"
}

' =========================
' EEPROM Emulation
' =========================
package "EEPROM Emulation" {

  ' -------------------------
  ' CORE MODULE
  ' -------------------------
  package "CORE_MODULE" {
    component CORE as "core"

    package "ALGO" {
      component ALGO_FLITF as "Algo_FLITF"
      component ALGO_NVM   as "Algo_NVM"
    }

    CORE --> ALGO_FLITF : selects / calls
    CORE --> ALGO_NVM   : selects / calls
  }

  ' -------------------------
  ' INTERFACES (Flash / CRC / ECC only)
  ' -------------------------
  package "interface" {
    component ITF_FLASH as "Flash interface"
    component ITF_CRC   as "CRC interface"
    component ITF_ECC   as "ECC interface"
  }

  ' Liaisons ALGO -> interface
  ALGO_FLITF --> ITF_FLASH : read / write
  ALGO_NVM   --> ITF_FLASH : read / write

  ALGO_FLITF --> ITF_CRC : integrity check

  ALGO_FLITF --> ITF_ECC : error correction
}

' =========================
' System (HAL + HW)
' =========================
package "System" {
  component HAL as "STM32 HAL\n(FLASH/CRC/NVM)"
  component HW  as "STM32_HW"

  HAL --> HW : register access
}

' =========================
' Connections
' =========================
APP --> CORE : API calls

ITF_FLASH --> HAL : driver calls
ITF_CRC   --> HAL : driver calls
ITF_ECC   --> HAL : driver calls

@enduml

Component Structure

Core ( eeprom_emul_core.c / eeprom_emul_core.h): Provides the main APIs for initialization, variable read/write, and maintenance. It manages the overall state and coordinates interactions between algorithms and interfaces.

Algorithms ( eeprom_algo_flitf.c / eeprom_algo_nvm.c): Implement the EEPROM Emulation algorithms, handling initialization, data read/write, and memory cleanup according to the selected method (FLITF or NVM).

User configuration ( eeprom_emul_conf.h): Defines the main parameters for EEPROM Emulation, including Flash layout, number and size of variables, endurance options (number of write cycles), and enabled features (algorithms, CRC, ECC, maintenance mode).

Interfaces : Provide both ready-to-use implementations and customizable templates for Flash access, CRC calculation, and ECC encoding/decoding. The appropriate implementation can be selected or adapted to the target hardware and application needs.

Modules and Files

The following diagram illustrates the EEPROM Emulation module and its associated files.

@startuml
top to bottom direction
skinparam linetype ortho
<style>
componentDiagram {
   arrow {
      FontSize 8
   }
}
</style>

title EEPROM Emulation Modules Overview

package "Application" {
  component APP as "User Application"
}

package "EEPROM Emulation" {

  package "Interfaces" as ITF_P {
    together {
      package "Flash" {
        component ITF_FLASH_H as "eeprom_itf_flash.h"
        component ITF_FLITF_EDATA as "eeprom_itfflash_flitf_edata.c" #DAE8FC
        component ITF_NVM_EDATA as "eeprom_itfflash_nvm_edata.c" #DAE8FC
        component ITF_FLASH_TPL as "eeprom_itfflash_template.c" #DAE8FC
      }
      package "CRC" {
        component ITF_CRC_H as "eeprom_itf_crc.h"
        component ITF_CRC as "eeprom_itfcrc_crc.c" #DAE8FC
        component ITF_CRC_TPL as "eeprom_itfcrc_template.c" #DAE8FC
      }
      package "ECC" {
        component ITF_ECC_H as "eeprom_itf_ecc.h"
        component ITF_ECC as "eeprom_itfecc_bch.c" #DAE8FC
        component ITF_ECC_TPL as "eeprom_itfecc_template.c" #DAE8FC
      }
    }
  }

  package "Algorithms" as ALGO_P {
    component ALGO_FLITF_C as "eeprom_algo_flitf.c"
    component ALGO_FLITF_H as "eeprom_algo_flitf.h"
    component ALGO_NVM_C   as "eeprom_algo_nvm.c"
    component ALGO_NVM_H   as "eeprom_algo_nvm.h"
  }

  package "Core" as CORE_P {
    component CORE_C    as "eeprom_emul_core.c"
    component CORE_H    as "eeprom_emul_core.h"
    component CORE_CONF as "eeprom_emul_conf.h" #DAE8FC
  }

}


APP --> CORE_C
CORE_C ..> CORE_H : include
CORE_H ..> CORE_CONF : include
ALGO_FLITF_C ..> ALGO_FLITF_H : include
ALGO_NVM_C ..> ALGO_NVM_H : include
ITF_FLITF_EDATA ..> ITF_FLASH_H : include
ITF_NVM_EDATA ..> ITF_FLASH_H : include
ITF_FLASH_TPL ..> ITF_FLASH_H : include
ITF_CRC ..> ITF_CRC_H : include
ITF_CRC_TPL ..> ITF_CRC_H : include
ITF_ECC ..> ITF_ECC_H : include
ITF_ECC_TPL ..> ITF_ECC_H : include

CORE_C ..> ALGO_FLITF_H : include
CORE_C ..> ALGO_NVM_H : include
CORE_C ..> ITF_FLASH_H : include
CORE_C ..> ITF_CRC_H : include
CORE_C ..> ITF_ECC_H : include


@enduml