EEPROM Emulation driver for KEA128 Demo Interpretation

Document created by Hui_Ma Employee on Oct 7, 2015
Version 1Show Document
  • View in full screen mode

[EEPROM emulation driver for KEA128 and KEA8] software used for Kinetis EA family product (without integrated EEPROM memory), which using the sector-erasable Flash memory be used to emulate the EEPROM through EEPROM emulation software.  The software could downloaded from here:


This document will interpret EEPROM emulation driver demo for KEA128 product and shows how the EEPROM emulation driver works and related API function introduction.

1> EEPROM emulation driver feature

The EEPROM emulation driver for SGF/FTM flash family implements the fix-length data record scheme. Several sectors shall be involved in emulation with a round robin scheduling scheme. The EEPROM functionalities to be emulated include initializing, de-initializing, reading, writing records.

The EEPROM emulation driver is more complicated than general Flash program data application with following features:


  • User configurable emulated EEPROM size.
  • Larger life for the flash memory used for EEPROM emulation.
  • Unique feature of Cache Table which makes data retrieval fast.
  • Support fix length record scheme only.
  • Support synchronous model which can be run from both RAM and FLASH. When running from FLASH, user needs to relocate flash launch command routine to RAM to avoid Read While Write error.
  • If any operation fails during EEPROM emulation, the driver will try to repeat that operation until successfully for several times (which is defined by user). If that operation still fails, the driver will make the related sector to DEAD to eliminate it from round robin sequence and continue other tasks without stopping driver.
  • Concurrency support via callback.
  • Release in C source code format.
  • Ready-to-use demos illustrating the usage of the driver with different compilers.


2> Demo interpretation

The demo routine located at default installation path: ..\\KEA EEPROM Emulation Driver\KEA_SGF180\Demos\build\TRK_KEAZ128\iar\Normal_demo folder.


For the demo runs in Flash memory, avoiding Read While Write error happened,

Eed_FlashLauchnCommand and g_EECallBack must be relocated to or placed in RAM when the main routine start. Then it will disable the cache and initialize Flash clock(KEA128 ICS module default clock mode is FEI, the default system/core clock is 21MHz, the Flash clock divider value set to 20 to make Flash clock to be 1MHz).


  After flash clock initialized, it will initialize EEPROM configuration start address. The status of each sector with five value, which means Blanked, Alternative, Active, Dead and Invalid.


The EE_ALLOTED_SECTORS macro will calculate the total number of sectors, which includes Active sectors and Alternative sectors.


The EE_ACTIVE_SECTORS value is 1 and EE_READY_SECTORS value is 2, so the EE_ALLOTED_SECTORS value is 3.

Then there with three allotted sector, and allocated at below address:

     eepromConfig.startSecAddr[0] = 0x1A00;

     eepromConfig.startSecAddr[1] = 0x1C00;

     eepromConfig.startSecAddr[2] = 0x1E00;


After initialize start address for EEPROM configuration, following to call Eed_DeinitEeprom() function to erase all sectors used for emulation.


Then it will initialize EEPROM emulation, includes to remove dead sector from EEPROM system and determine maximum valid index in array of start sector address after that; also includes initialize all sectors by erasing the “possible-error-sector”; and initialize and update cache table if enabled. It call Eed_InitAllSectors() function to initialize all sectors and allocate the current active sector to base sector. The Eed_ShiftIdxToBase() function will be called to shift the current index to base index of 0. After that, the EEPROM configuration startSecAddr array will change to :

     eepromConfig.startSecAddr[0] = 0x1E00;

     eepromConfig.startSecAddr[1] = 0x1A00;

     eepromConfig.startSecAddr[2] = 0x1C00;

The active sector start address at 0x1E00.

Then it will program erase cycle value to each sector start address, the erase cycle value will occupy 4 bytes with sector start address offset 0:

erase cycle value 0x1a00.png

Then make the base sector to be active and program the active indicator at sector start address offset 8. Here the base sector start address is 0x1E00, the active indicator will be programmed at 0x1E08 with active indicator value 0x55555555:

active indicator value 0x1e08.png


Then it will call Eed_SearchBlankSpace () function to find blank space of EEPROM system, in this demo, the blank space start address at 0x1e0c.

If enable the Flash cache, the cache will be cleared and updated during EEPROM emulation initialize phase.


The demo will write eight group data to EEPROM system, each group with 16 bytes data, total data number is 128 bytes. The data located at Flash start address is 0x1e0c. After each group data programming, it will following with the data ID info and program the status.


write data analyze.png


With all data was written, the all 128 bytes data was programed at 0x1e00 start EEPROM sector.

write data result.png

When the write data exceed the active EEPROM sector, the swapping will occur. The swapped EEPROM sector will record previous data and current write data. If there exist sector erase action, it will also update the erase cycle value.

The data is full and the new data written will make swap happens:

before swap 01_3rd.png

After swap happens:

swap start 01_3rd.png


At the end of demo, it will read EEPROM data back and make sure all valid record ID are written to EEPROM emulation.

3 people found this helpful