How To Use

Use the EEPROM Emulation module as follows:

Selecting Files

Add the following source and header files to the project:

  • Core (mandatory): eeprom_emul_core.c, eeprom_emul_core.h

  • Algorithm (select one algorithm depending on the Flash memory type):

    • FLITF: eeprom_algo_flitf.c, eeprom_algo_flitf.h

    • NVM: eeprom_algo_nvm.c, eeprom_algo_nvm.h

  • Interfaces (the required interfaces depend on the selected algorithm):

    • FLITF requires the Flash, CRC, and TIME interfaces.

    • NVM requires the Flash, CRC, and ECC interfaces.

    • Flash:

      • FLITF EDATA: eeprom_itfflash_flitf_edata.c

      • NVM EDATA: eeprom_itfflash_nvm_edata.c

      • Template: eeprom_itfflash_template.c

      • Header: eeprom_itf_flash.h

    • CRC:

      • Ready-to-use implementation: eeprom_itfcrc_crc.c

      • Template: eeprom_itfcrc_template.c

      • Header: eeprom_itf_crc.h

    • ECC (required for NVM):

      • BCH-based ready-to-use implementation: eeprom_itfecc_bch.c

      • Template: eeprom_itfecc_template.c

      • Header: eeprom_itf_ecc.h

    • TIME (required for FLITF; used by progressive cleanup):

      • HAL tick-based ready-to-use implementation: eeprom_itftime_gettick.c

      • Template: eeprom_itftime_template.c

      • Header: eeprom_itf_time.h

  • User configuration (mandatory): eeprom_emul_conf.h

Configuration

User Configuration

The following table summarizes the main configuration items in the user configuration header eeprom_emul_conf.h (algorithm selection, capacity, and endurance):

Config Item

Description

Constraints

EE_ALGO_FLITF

Select the FLITF algorithm.

Define this macro and do not define EE_ALGO_NVM.

EE_ALGO_NVM

Select the NVM algorithm.

Define this macro and do not define EE_ALGO_FLITF.

EE_FRAME_LINE_SIZE

FLITF only. Size of one frame line in bytes.

8 or 16

EE_SECTOR_SIZE

NVM only. Size of one NVM/Flash sector in bytes.

Must match the target device.

EE_START_PAGE_ADDRESS

Start address of the emulation area (first page or sector reserved for EEPROM Emulation).

Target-specific and aligned with the reserved Flash/NVM area.

EE_FLASH_BASE_ADDRESS

FLITF only. Base Flash address used for page-number and address computations.

Must be a valid target Flash base address.

EE_FLASH_PAGE_SIZE

FLITF only. Flash page size in bytes.

Must match the target device.

EE_NB_OF_VARIABLES

Total number of emulated variables. For NVM, this is the sum of the 8-bit and 16/32-bit variable counts.

Project-dependent; variable IDs start at 1.

EE_NB_OF_8BITS_VARIABLES

NVM only. Number of 8-bit variables.

Project-dependent; may be 0.

EE_NB_OF_16_32BITS_VARIABLES

NVM only. Number of 16/32-bit variables.

Project-dependent; may be 0.

EE_CYCLES_NUMBER

Number of write cycles.

Must be at least 1; higher values increase storage requirements.

EE_GUARD_PAGES_NUMBER

FLITF only. Extra guard pages added to reduce transfer frequency.

Project-dependent; may be 0.

EE_CLEANUP_PROGRESSIVE_TIME_MS

FLITF only. Time budget in milliseconds for a single EE_CleanUpProgressive() call.

Must be greater than or equal to the configured Flash page erase time. The default is 100.

Example minimal custom header eeprom_emul_conf.h for FLITF:

#ifndef EEPROM_EMUL_CONF_H
#define EEPROM_EMUL_CONF_H

/* Select algorithm */
#define EE_ALGO_FLITF              (1)

/* FLITF frame layout */
#define EE_FRAME_LINE_SIZE         (8)

/* Emulation area mapping (adapt to the linker script) */
#define EE_START_PAGE_ADDRESS      (FLASH_EDATA_BASE + FLASH_EDATA_BANK_SIZE)
#define EE_FLASH_BASE_ADDRESS      FLASH_EDATA_BASE
#define EE_FLASH_PAGE_SIZE         FLASH_EDATA_PAGE_SIZE

/* Capacity and endurance */
#define EE_NB_OF_VARIABLES         (1000U)
#define EE_CYCLES_NUMBER           (1U)
#define EE_GUARD_PAGES_NUMBER      (1U)

/* Time budget granted to a single EE_CleanUpProgressive() call */
#define EE_CLEANUP_PROGRESSIVE_TIME_MS (100UL)

#endif /* EEPROM_EMUL_CONF_H */

Example minimal custom header eeprom_emul_conf.h for NVM:

#ifndef EEPROM_EMUL_CONF_H
#define EEPROM_EMUL_CONF_H

/* Select algorithm */
#define EE_ALGO_NVM               (1)

/* Emulation area mapping (adapt to the linker script) */
#define EE_START_PAGE_ADDRESS      (NVM_EDATA_BASE)
#define EE_SECTOR_SIZE             (8U*1024U)

/* Capacity / endurance */
#define EE_NB_OF_VARIABLES         (1000U)
#define EE_NB_OF_8BITS_VARIABLES   (500U)
#define EE_NB_OF_16_32BITS_VARIABLES (500U)
#define EE_CYCLES_NUMBER           (1U)

#endif /* EEPROM_EMUL_CONF_H */

EEPROM Emulation Initialization

Initialize the hardware peripherals first, then fill the ee_object_t handles and call EE_Init(). The Flash and CRC handles are required by both algorithms. The HAL tick TIME implementation does not require a handle, so its time_object can be NULL; a custom TIME implementation may use that field. The generated accessors below are target-specific and can be replaced by the handles used by the application.

For FLITF, erase_type controls how pages requiring an erase are handled. NVM does not use this parameter during EE_Init().

ee_object_t ee_obj = {
  .f_object = EEPROM_EMULATION_FLASH_HANDLE(),
  .crc_object = EEPROM_EMULATION_CRC_HANDLE(),
  .time_object = NULL
};

ee_status status = EE_Init(&ee_obj, EE_CONDITIONAL_ERASE);
if (status != EE_OK)
{
  /* Handle initialization error. */
}

EEPROM Emulation Usage

After file selection, interface configuration, and initialization, the EEPROM Emulation module is ready to use. The core API provides functions to read and write variables of different sizes and to perform maintenance tasks.