KE02 EEPROM Interface

The KE02 EEPROM interface is based on the internal Flash interface since erasing and writing EEPROM based data uses the same technique, although extended by the EEPROM commands:

  • FCMD_ERASE_VERIFY_EEPROM_SECTION 0x10
  • FCMD_PROGRAM_EEPROM 0x11
  • FCMD_ERASE_EEPROM_SECTOR 0x12
EEPROM content can be read memory-mapped from the address 0x10000000 and so can be read without requiring special access routines as long as it is read as individual bytes. 16 and 32 bit access are not allowed in the EEPROM memory area and an attempt to read as half- or long words results in a hardware fault.

Reading the EEPROM content can be tested by using the I/O menu of the command line interface and the "md" (memory display) command. "md 10000000 b 10" displays the first 10 bytes from its physical memory location. Modifying the content is of course not possibe with the "mm" (memory modify) command and would cause an exception.

Another way of reading the EEPROM content is by using the "sd" (storage display) command. "sd 10000 b 10" displays the first 10 bytes from its virtual memory location. This assumes a KE02 with 64k Flash where the EEPROM is tagged onto the internal Flash memory map, otherwise the address to use is the one after the end of the internal space. The µTasker memory interface (open document), as used by the storage commands, handles the EEPROM as an extension to the internal memory of the Kinetis and so enables writing and reading as well. "se" (storage erase) can therefore be used to delete EEPROM sectors and "sm" (storage modify) to write. "sf" (storage fill) allows filling an area with a value. This allows such operations to be made as if the storage medium were contiguous and so can start in internal Flash and overflow into EEPROM. It is however necessary to understand the physical rules imposed by the underlying hardware and so, on the KE02, erases in the internal Flash area will be 512 byte sector erases and in the EEPROM area they will be 2 byte erases, for example.

EEPROM Command Details

When the erase target area is an EEPROM sector the command 0x12 is used. The command deletes 2 bytes in the sector, whereby larger delete sizes cause multiple sectors to be erased.
When the write target area is in the EEPROM the command 0x11 is used. Each individual write can be between 1 and 4 bytes in length but it is important that the bytes to be programmed are previously in the erased state because cumulative programming of bits in a single EEPROM byte is not allowed.
Unlike writing to the internal Flash of the Kinetis KE, where the interface collects an aligned phrase to be programmed and it is only committed to the Flash when either full or forced to do so, writes to the EEPROM virtual area bypasses the intermediate buffer and allows individual byte writes to be performed.

Simulator

The µTasker keeps a copy of the EEPROM content (together with the Flash content) which is saved to the hard disk each time the simulator is closed normally (not when the program execution is stopped by the debugger). When the simulatro is restarted, the previous EEPROM content has thus been preserved. If software attempts to write to non-erased bytes in the EEPROM area the simulator will throw an exception since this is an illegal operation on the hardware that must be avoided. The correct usage of the interface by the SW using the EEPROM storage, or an EEPROM emulation layer, can this be verified in the simulation enviromnement with any misusage clearly shown.

Practical Test of the EEPROM Operation

The following sequences in the I/O menu allow simple tests of the EEPROM operation (assuming 64k internal Flash - adjust the address used to suit other devices):
"sd 10000 b 20" - display the first 20 bytes of Flash to see what is initially there (a new device will be all 0xf)
"se 10000 100" - optionally erase the complete EEPROM (note that the erase length is in hex - 256 bytes)
"sm 10000 b 55" - write a single byte to the first EEPROM location (repeat sd 10000 b 20 to see change)
"sm 10002 l 12345678" - write a long word starting at the third EEPROM location (repeat sd 10000 b 20 to see change)
"se 10002 1" - erase a single EEPROM sector (repeat sd 10000 b 20 to see change) - note that this is the same as "se 10002", "se 10002 0" and "se 10002 2" due to the fact that an EEPROM sector is 2 bytes aligned

Note that "md 10000000 b 20" is equivalent when displaying the memory content since it is then directly accessing the EEPROM's physical location. When working with the µTasker simulator the "sd" command should be used since the "md" command doesn't access emulated memory but instead just returns fixed data. Care must always be taken when using the memory interface on HW since incorrect inputs can cause illegal accesses to be made which result in a reset of the board. Manipulating Flash areas used by code can also lead to loss of code integrity requiring the board to be reprogrammed!

The following test is interesting to see the way that the flash interface operates as if the internal Flash and EEPROM were contiguous medium:
"sf fff8 b 55 20" - perform a fill of 20 bytes with the value 0x55. The start of the fill area is in the internal Flash (last 8 bytes), followed by the virtual EEPROM address area. The result is that 8 bytes are programmed to the final sector of internal Flash and then the rest are written to the EEPROM area.
"se fff8 0" to "se fff8 8" now erases the final internal Flash sector and so only erases the first 8 bytes that were written with the fill command. "se fff8 9" however erases the final internal Flash sector (8 bytes) plus the first EEPROM sector.

FRDM-KE02Z Boot Loader and EEPROM

It is found that each time a new program is loaded to the FRDM-KE02Z using its on-board boot loader the EEPROM content is deleted. This is presumably due to the fact that the boot loader on the board is using a command that deletes both program Flash and EEPROM (eg. ERASE ALL BLOCK, command 0x08, which "Erases all flash and EEPROM blocks"). This of course can make development difficult when parameters are lost each time code is loaded. It is possible (but not necessarily likely) that this behaviour will be improved in future boot loaders on the board. A workaround (assuming enough space in Flash) is however to install the µTasker serial loader (eg. for KBOOT operation) which then allows firmware updates without affecting the EEPROM content.

Conclusion

It is seen that software using the interface needs to be aware of the HW details since, unlike pure EEPROM that allows individual bytes to be modified, it requires small sectors to be erased/written to emulate this. Thanks to the fact that the EEPROM Flash sector size is very small it is of course very easy to allow the software to emulate a pure EEPROM device if required.

Please post question or comments to this article in the µTasker forum

Return to the Kinetis Developer's page


µTasker Kinetis support. Copyright (c) 2004..2018 M.J.Butcher Consulting