AN2594
Application note
EEPROM emulation
in STM32F10x microcontrollers
Introduction
Many applications require EEPROM (electrically erasable programmable read-only
memory) for non-volatile data storage. For low-cost purposes, the STM32F10x devices do
not use EEPROM. Instead, they implement EEPROM emulation using the embedded Flash
memory.
This application note explains the differences between external EEPROM and embedded
Flash memory, and it describes a software method for emulating EEPROM using the onchip Flash memory of the STM32F10x devices.
This document also focuses on some embedded aspects in emulated EEPROM data
storage, that the reader is assumed to know.
Glossary
Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers
where the Flash memory density ranges between 16 and 32 Kbytes.
Medium-density devices are STM32F10x and STM32F103xx microcontrollers where the
Flash memory density ranges between 32 and 128 Kbytes.
High-density devices are STM32F10x and STM32F103xx microcontrollers where the Flash
memory density ranges between 256 and 512 Kbytes.
Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
August 2009 Doc ID 13718 Rev 3 1/10
www.st.com
Contents AN2594
Contents
1 Embedded Flash memory versus EEPROM: main differences . . . . . . . 5
1.1 Difference in write access time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Difference in writing method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Difference in erase time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Implementing EEPROM emulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.1 Application example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1.2 EEPROM software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Embedded application aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1 Data granularity management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1.1 Programming on a word-by-word basis . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1.2 Programming on a byte-by-byte basis . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Wear leveling: Flash memory endurance improvement . . . . . . . . . . . . . . 11
3.2.1 Wear-leveling implementation example . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3 Page header recovery in case of power loss . . . . . . . . . . . . . . . . . . . . . . 12
3.4 Cycling capability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2/16 Doc ID 13718 Rev 3
AN2594 List of tables
List of tables
Table 1. Differences between embedded Flash memory and EEPROM . . . . . . . . . . . . . . . . . . . . . . 5
Table 2. Status combinations and actions to be taken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Table 3. Maximum number of variables stored in emulated EEPROM (with 10 000 cycles) . . . . . . 14
Table 4. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Doc ID 13718 Rev 3 3/16
List of figures AN2594
List of figures
Figure 1. Header status switching between page0 and page1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 2. EEPROM variable format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 3. Data update flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 4. WriteVariable flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 5. Page swap scheme with four pages (wear leveling). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4/16 Doc ID 13718 Rev 3
AN2594 Embedded Flash memory versus EEPROM: main differences
1 Embedded Flash memory versus EEPROM: main
differences
Electrically erasable programmable read-only memory (EEPROM) is a key component of
many embedded applications that require non-volatile storage of data updated with a byte or
word granularity during run time.
On the other hand, the microcontrollers used in those systems are each time more often
based on embedded Flash memory. To eliminate components, save silicon space and
reduce system cost, the STM32F10xxx Flash memory may be used instead of EEPROM for
simultaneous code and data storage.
Unlike Flash memory, however, external EEPROM does not require an erase operation to
free up space before data can be rewritten. Hence a special software management is
required to store data into embedded Flash memory.
Obviously the emulation software scheme depends on many factors, including the EEPROM
reliability, the architecture of the Flash memory used, and the product requirements.
The main differences between embedded Flash memory and external serial EEPROM are
generic to any microcontroller that use the same Flash memory technology (it is not specific
to the STM32F10xxx family products). The major differences are summarized in Tab l e 1 .
Table 1. Differences between embedded Flash memory and EEPROM
Feature External EEPROM
–a few ms
Write time
Erase time N/A Page/Mass Erase time: 20 ms
Write method
Read access
Write/Erase
cycles
– random byte: 5 to 10 ms
– page: a hundred µs per word (5 to
10 ms per page)
– once started, is not CPU-dependent
– only needs proper supply.
– serial: a hundred µs
– random word: 92 µs
– page: 22.5 µs per byte
– from 10 kilocycles to 1 000
kilocycles
1.1 Difference in write access time
As Flash memories have a shorter write access time, critical parameters can be stored
faster in the emulated EEPROM than in an external serial EEPROM, thereby improving data
storage.
Emulated EEPROM using on-chip Flash
memory
Word program time: 20 µs
once started, is CPU-dependent: a CPU
reset will stop the write process even if the
supplied power stays within specifications.
– parallel: a hundred ns
– very few CPU cycles per word.
– Access time: 35 ns
– from 10 kilocycles to 100 kilocycles (the
use of many on-chip Flash memory pages
is equivalent to increasing the number of
write cycles) see Section 3.4: Cycling
capability
Doc ID 13718 Rev 3 5/10