Use Cases

Read and Write Emulated EEPROM Variables (FLITF, NVM)

This use case applies to both FLITF and NVM and shows how to read and write variables using the EEPROM Emulation module. It requires:

  • Initialization of the EEPROM Emulation module.

  • Writing variables.

  • Reading back the written variables to verify correctness.

The code required to implement this use case is as follows:

/* This example assumes EEPROM Emulation has already been initialized
 * (e.g. EE_Init() has been called successfully).
 */

ee_status status;
uint16_t data_counter = 0U;
uint8_t data_write[EE_NB_OF_VARIABLES + 1U];

/* Step 1: Write all 8-bit variables */
for (uint16_t var_id = 1U; var_id <= EE_NB_OF_VARIABLES; var_id++)
{
  data_counter++;
  data_write[var_id] = (uint8_t)var_id;

  status = EE_WriteVariable8bits(var_id, data_write[var_id]);

 /* FLITF only: a cleanup may be required when pages become full. */
  if (status == EE_INFO_CLEANUP_REQUIRED)
  {
    (void)EE_CleanUp();
    status = EE_WriteVariable8bits(var_id, data_write[var_id]);
  }

  if (status != EE_OK)
  {
    /* Handle write error */
    break;
  }
}

/* Step 2: Read back and verify all variables */
for (uint16_t var_id = 1U; var_id <= EE_NB_OF_VARIABLES; var_id++)
{
  uint8_t data_read = 0U;

  status = EE_ReadVariable8bits(var_id, &data_read);
  if (status != EE_OK)
  {
    /* Handle read error */
    break;
  }

  if (data_read != data_write[var_id])
  {
    /* Handle data mismatch */
    break;
  }
}

This code snippet is a minimal reference implementation. You can adapt and extend it (error handling, variable mapping, cleanup strategy, etc.) to match your application needs.

List of EEPROM Emulation examples

The following table lists the available examples:

Example Name

Description

read_write

Demonstrates basic read and write operations using the EEPROM Emulation module. It initializes the module, writes variables, and reads them back to verify correctness.