An4894 How to Use Eeprom Emulation on Stm32 Mcus Stmicroelectronics En
An4894 How to Use Eeprom Emulation on Stm32 Mcus Stmicroelectronics En
Application note
Introduction
EEPROMs (electrically erasable programmable read-only memories) are used for nonvolatile storage of updatable application
data, or to retain small amounts of data in the event of power failure in complex systems. To reduce cost, an external EEPROM
can be replaced by on-chip flash memory, provided that a specific software algorithm is used.
This application note describes the software solution (X-CUBE-EEPROM) for substituting a standalone EEPROM by emulating
the EEPROM mechanism using the on-chip flash memory available on the STM32 series products listed in Table 1.
X‑CUBE‑EEPROM also provides a firmware package including examples showing how to exploit this EEPROM emulation driver
(see Section 5: API and application examples).
For STM32WB series products only, an example that maintains a Bluetooth® LE connection and communication while
performing EEPROM operations is provided.
For STM32H5 series products, an example using the high-cycle data area for the EEPROM operations is provided.
The emulation method uses at least two flash memory pages, between which the EEPROM emulation code swaps data as they
become filled. This is transparent to the user. The EEPROM emulation driver supplied with this application note has the
following features:
• Lightweight implementation and reduced footprint.
• A simple API consisting of a few functions to format, initialize, read and write data, and clean up flash memory pages.
• At least two flash memory pages to be used for internal data management.
• Clean-up simplified for the user (background page erase).
• Wear-leveling algorithm to increase emulated EEPROM cycling capability.
• Robust against asynchronous resets and power failures.
• Optional protection implementation for flash memory sharing between cores in multicore STM32 devices (for example
STM32WB series).
• Maintenance of cache coherency.
The EEPROM size to be emulated is flexible and only limited by the flash memory size allocated to that purpose.
Type Series
STM32C0 series, STM32G0 series, STM32G4 series, STM32H5 series, STM32L4 series, STM32L4+ series,
Microcontrollers
STM32L5 series, STM32U0 series, STM32U3 series, STM32U5 series, STM32WB series, STM32WL series
1 General information
This document scopes STM32 microcontrollers that are based on an Arm® core.
Note: Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
Reference documents
EEPROM emulation solutions and application notes are available for other STM32 series as listed below.
[1] Application note STM32F0 series EEPROM emulation in STM32F0xx microcontrollers (AN4061)
[2] Application note STM32F1 series EEPROM emulation in STM32F10x microcontrollers (AN2594)
[3] Application note STM32F2 series EEPROM emulation in STM32F2xx microcontrollers (AN3390)
[4] Application note STM32F3 series EEPROM emulation in STM32F30x/STM32F31x STM32F37x/STM32F38x
microcontrollers (AN4056)
[5] Application note STM32F4 series EEPROM emulation in STM32F40x/STM32F41x microcontrollers (AN3969)
[6] Application note Building wireless applications with STM32WB series microcontrollers (AN5289)
[7] Reference manual STM32H563/H573 and STM32H562 Arm®-based 32-bit MCUs (RM0481)
EEPROM is a key component of many embedded applications that require nonvolatile storage of data updated
with byte, half-word, or word granularity during runtime. However, microcontrollers used in these systems are very
often based on embedded flash memory. To eliminate components, save PCB space and reduce system costs,
the STM32 flash memory may be used instead of the external EEPROM to store not only code, but also data.
Special software management is required to store data in embedded flash memory. The EEPROM emulation
software scheme depends on many factors, including the required EEPROM reliability, the architecture of the
flash memory used, and the final product requirements, among other parameters.
The main differences between embedded flash memory and external serial EEPROM are the same for any
microcontroller that uses flash memory technology (they are not specific to STM32 series microcontrollers).
One difference is that EEPROMs do not require an erase operation to free up space before data can be written
again. Other major differences are summarized in Table 2.
External EEPROM
Feature (for example, M24C64: I2C serial access Emulated EEPROM using on-chip flash memory
EEPROM)
• 4 million cycles at 25°C 10 kcycles per page at 105°C(2). Using multiple on‑chip
flash memory pages is equivalent to increasing the number
Endurance • 1.2 million cycles at 85°C
of write cycles. See Section 4.4: Cycling capability:
• 600 kilocycles at 125°C EEPROM endurance improvement.
• 7 years at 125°C
• 50 years at 125°C
Retention(2) • 15 years at 105°C
• 100 years at 25°C
• 30 years at 85°C
3.1 Principle
EEPROM emulation can be performed in various ways, considering the flash memory characteristics and final
product requirements. The approach detailed below requires two sets of flash memory pages allocated to
nonvolatile data.
The first set of pages is initially erased and used to store new data and flash memory programming operations are
done sequentially in increasing order of flash memory addresses. Once the first set of pages is full of data, it
needs to be garbage-collected.
The second set of pages collects only the valid data from the first set of pages and the remaining area can be
used to store new data. Once the transfer of valid data to the second set of pages is completed, the first set of
pages can be erased.
Each set of pages can be made up of one or several flash memory pages. For most STM32 series covered by
this document, a header field that occupies the first four 64-bit words (32 bytes) of each page indicates its status,
the exception being the STM32U5 series, where the header occupies the first four 128-bit words (64 bytes).
Each page has five possible states:
• ERASED: the page is empty (initial state).
• RECEIVE: the page used during data transfer to receive data from other full pages.
• ACTIVE: the page is used to store new data.
• VALID: the page is full. This state does not change until all valid data is completely transferred to the
receiving page.
• ERASING: valid data in this page has been transferred. The page is ready to be erased.
Figure 1 shows the page status evolution in the case where each set of pages is made of two pages.
FORMAT
EEPROM
Transfer DATA
ERASED
Write DATA
DT45026V1
ERASING
1. When in single bank mode, these devices operate 128 bits wide read accesses. However, the EEPROM emulation solution
is designed for 64 bits wide read accesses.
2. The high-cycle data area is available on the STM32H563/H573 and the STM32H562 MCUs.
The minimal write width in flash memory is 64 bits (128 bits for STM32U5 and STM32H5 series, or 16 bits for
STM32H5 series using high-cycle data area) due to its ECC (error correcting code) that cannot be switched off.
Only zeros (0x0000 0000 0000 0000, or 0X0000 0000 0000 0000 0000 0000 0000 0000 for STM32U5 series) can
be written to an already programmed nonnull flash memory line. As the first four words are used by the header, a
flash memory page can store up to 252 variable elements when the page size is 2 Kbytes, and up to 508 variable
elements when the page size is 4 Kbytes.
The possible states of a flash memory page are coded by writing 0xAAAA AAAA AAAA AAAA (or 0xAAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA for the STM32U5 series) into the page header. It is possible to determine
the page state using the following procedure:
• The page is in the ERASING state if its fourth line is not erased.
• The page is in the VALID state if the third line is not erased and the fourth line is erased.
• The page is in the ACTIVE state if the second line is not erased and the third and fourth lines are erased.
• The page is in the RECEIVE state if the first line is not erased and the second, third, and fourth lines are
erased.
• The page is in the ERASED state if the first four lines are erased.
This algorithm allows the coding of all states and transitions described in Section 3.2: Page status valid
transitions. Each variable element is defined by a virtual address and a data value to be stored in flash memory
for subsequent retrieval or update. In the implemented software, the virtual address is 16 bits long and the data
value is either 8 bits, 16 bits, or 32 bits long. The driver requires the virtual address values to be between 0x0001
(0x0000 corresponds to an EEPROM element invalidated by the driver), and the maximum number of EEPROM
variables required. Also, since virtual addresses are 16-bits wide, the maximum number of EEPROM variables
cannot exceed 0xFFFE (0xFFFF corresponds to an erased flash memory line). Moreover, the number of variables
is limited by the size of the product flash memory (see Section 4.6: Computing the required size of flash memory
for EEPROM emulation).
Each element also contains a 16-bit CRC that is used to check the element integrity. When data is modified, the
modified data associated with the same virtual address is stored in a new flash memory location. Data retrieval
returns the up-to-date data value.
Figure 3. Flash page and EEPROM variable format (except STM32U5 series)
Flash Page
RECEIVE
ACTIVE
Page Header 0xFFFFFFFFFFFFFFFF
(4 * 8 bytes) VALID
for ERASED page
ERASING
Variable Element
16-bit
Virtual 16-bit 8, 16 or 32-bit
Address CRC Data value
Page Data
(Number of variable
elements per page
* 8 bytes)
DT45027V2
Figure 4. STM32U5 series Flash page and EEPROM variable format
Flash Page
RECEIVE
ACTIVE
Page Header 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
(4 * 16 bytes) VALID
for ERASED page
ERASING
Variable Element
16-bit
Virtual 16-bit 96-bit
Address CRC Data value
Page Data
(Number of variable
elements per page
* 16 bytes)
DT47646V1
For this example, only two flash memory pages are necessary: Page 0 and Page 1. In Figure 5, RCRC represents
the 16-bit CRC value for this variable element (refer to Section 4.7: EEPROM emulation robustness for more
details about CRC).
Figure 5 shows only the write commands, which are done sequentially in increasing order of flash memory
addresses.
ERASED ACTIVE
ERASING ACTIVE
FFFFFFFFFFFFFFFFFFFF 7777RCRC45120000
7777RCRC32120000 7777RCRC45120000
FFFFFFFFFFFFFFFFFFFF 0100RCRCADADADAD
7777RCRC45120000 0100RCRCADADADAD
FFFFFFFFFFFFFFFFFFFF 0020RCRC67452301
0100RCRCADADADAD 0020RCRC67452301
FFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFF
7777RCRC67120000 FFFFFFFFFFFFFFFFFFFF
DT45028V2
4 Advanced features
The EEPROM emulation firmware is designed to fulfill most of the requirements for an embedded application in
terms of nonvolatile storage. This section covers these requirements in detail. Other embedded application
requirements may be needed in particular cases and are addressed in Section 6: Embedded application aspects.
Each STM32 device on-chip flash memory page can be programmed and erased reliably a limited number of
times. For write-intensive applications that need to update each variable more than this number, the wear leveling
algorithm allows the endurance of the emulated EEPROM to be increased.
Table 5 shows the limit number of reliable programming and erasing operations for devices covered by this
application note:
Knowing the requested size of emulated EEPROM and the targeted endurance, it is possible to compute the flash
memory size to be used for that purpose. The flash memory size is also a function of the data width of stored
variables.
STM32L4
1. Not applicable for STM32L4: a maximum of 512 Kbytes can be allocated to EEPROM emulation. Refer to the STM32
product datasheet for the size of each bank.
Note: To get the same information for other STM32 series, you can apply the formula presented in
Section 4.6: Computing the required size of flash memory for EEPROM emulation.
4.6 Computing the required size of flash memory for EEPROM emulation
As first approximation, the required size of flash memory is proportional to the emulated EEPROM size and to the
cycling capability. Table 6 can be used to estimate the required size of flash memory according to the data width
of stored elements for STM32L4 series and STM32L4+ series MCUs.
For a precise flash memory size requirement, whatever the STM32 series, use the formula below:
Note: Values of ‘flash memory endurance values (kcycles)’ for applicable STM32 series are listed in Table 5.
The formula is decomposed into the following steps:
1. Knowing the number of elements a flash memory page can store (refer to Table 3) compute the number of
flash memory pages needed to store the EEPROM elements. The calculated flash memory size is
independent of the element data width.
2. Multiply the number of pages by the targeted integer cycling ratio, for instance 1 for the standard 10 kcycles
endurance or 10 to achieve 100 kcycles endurance when the flash memory endurance is 10 kcycles. The
flash memory endurance of the product indicated in Table 5 must be considered.
3. Multiply the number of flash memory pages by 2 to include the data transfer mechanism.
4. Add the number of guard pages (an even number) to get the final number of flash memory pages.
5. Knowing the flash memory page size for your product (refer to Table 3), compute the flash memory size
required by the EEPROM emulation.
STM32L4 calculation example
To store 4000 individual bytes, and knowing that each page can store up to 252 elements, a set of pages must
comprise 16 flash memory pages. A second set of pages, of the same size, is required to transfer data when the
first one is full. If we assume that we use two guard pages, 34 flash memory pages are necessary.
Note: This calculation is a slightly conservative estimation.
To detect this corruption and recover from it, the EE_Init routine is implemented. It is called immediately after
power-up. This routine checks the sequence of page statuses for integrity and performs a repair if necessary. This
ensures that no data is lost. Refer to Section 5.3: EEPROM emulation timing for more details.
To avoid a possible failure scenario, erased pages are systematically erased again upon reset (in the EE_Init
routine). This ensures a safe behavior but consumes cycling capability of the emulated EEPROM. This systematic
erase can be avoided if the application is designed not to generate an asynchronous reset or power failure during
flash memory writes or erases. Refer to Section 6.3: Detecting power failures for more details.
Robustness is achieved at the expense of several checks and recovery mechanisms implemented in the
EE_Init routine. This induces a slight code size increase and longer initialization time when compared with
simpler EEPROM emulations. See Section 5.3: EEPROM emulation timing for further details.
4.8.1 Device embedding flash memory with RWW (read while write) capability
With STM32 devices embedding a dual-bank flash memory, it is recommended to put the critical routines (vector
table, critical interrupt service routines) in one bank and the area used for EEPROM emulation in the other bank.
The flash memory area in the bank used for EEPROM emulation can still be used, but with execution delays
during flash memory write and erase operations.
Note: To know whether your STM32 device supports flash memory with RWW capability, refer to the product
datasheet.
• The CRPF bit from the PWR_EXTSCR register bit (set when a critical radio operation is ongoing)
Both are available on STM32WB series MCUs.
Note: The same problematic applies to some dual-core applications other than radio.
For STM32WB series products integrating a Bluetooth® LE stack, a ‘flash access management’ mechanism,
based principally on the hardware semaphore feature, is described in document [6].
For the P-NUCLEO-WB55 Nucleo board, two examples are provided in the X-CUBE-EEPROM firmware package
(see Section 5.1.2: STM32Cube expansion software (X-CUBE-EEPROM)):
• An example that simply exploits the EEPROM emulation driver (similar to the examples for other series).
• An example that maintains a Bluetooth® LE connection and communication while processing EEPROM
operations. It follows the flash memory access timing rules in document [6], and can be used as a
reference for implementing this mechanism.
To determine the availability of the above mechanisms for other STMicroelectronics MCUs with RF stacks, refer to
their datasheets and other related documentation.
DT45030V5
A sample demonstration project using the EEPROM emulation driver is also supplied to demonstrate how to
manage 1000 nonvolatile variables. Sample projects are provided for the boards listed in Table 7. They are
located in the Projects\STM32xx\EEPROM_Emul package folders, and can easily be tailored to other boards
using the same STM32 MCU series.
One more example is provided for the P-NUCLEO-WB55.Nucleo board. It is located at Projects\STM32WB\BLE_H
eartRate_EEPROM_Emul\P-NUCLEO-WB55.Nucleo. The Nucleo board maintains a Bluetooth® LE connection and
communication in addition to processing EEPROM operations. By using the DUALCORE_FLASH_SHARING
preprocessor-defines symbol, this example follows the flash memory sharing mechanism and timing rules
described in Section 4.8.3: Dual core considerations.
• flash_interface.c: contains the functions needed to handle the STM32 flash specific features.
• main.c: this application program is an example using the described routines to configure, write to, and read
from the emulated EEPROM.
• stm32xxxx_it.c: shows an example of interrupt service file using the
EE_DeleteCorruptedFlashAddress function in the NMI handler.
For the Bluetooth® LE STM32WB series example, BLE_HeartRate_EEPROM_Emul, the code illustrating the
driver exploitation can be found in the Core/Src/app_entry.c file. In particular, the functions EEPROM_Emul_Init
and EEPROM_Emul_Operation are examples of sequencer tasks for EEPROM driver initialization and
exploitation (read and write operations).
• NB_OF_VARIABLES (default 1000, 100 for STM32C0 series(a)): Number of nonvolatile elements, each
element value being 8-, 16-, 32-or 96-bit.
• START_PAGE_ADDRESS: Address of the first flash memory page used for EEPROM emulation. For dual-
bank capable devices, the first address of the second bank is a good example value for this parameter to
benefit from this feature (see Section 4.8: Real-time considerations).
• CYCLES_NUMBER (default 1): The number of kcycles, X, for the equivalent EEPROM endurance. If
CYCLES_NUMBER equals 10, the emulated EEPROM has an equivalent endurance of 10 x X kcycles. X
is the flash memory endurance for the product used and listed in Table 5. Flash memory endurance.
• GUARD_PAGES_NUMBER (default 2): Number of guard pages used to reduce pressure on flash memory.
This number has to be even.
• CRC_POLYNOMIAL_LENGTH (default 16): No need to modify in most cases. A 16-bit CRC is optimized in
terms of computational speed and flash memory size, and offers a very good detection rate.
• CRC_POLYNOMIAL_VALUE (default 0x8005): No need to modify in most cases. This ANSI CRC is
optimized in terms of computational speed and flash memory size, and offers a very good detection rate
To activate the dual-core flash memory sharing mechanism in the context of the Bluetooth® LE stack of the
STM32WB series, DUALCORE_FLASH_SHARING must be defined as a preprocessor symbol in user software.
Erases all flash pages used for EEPROM emulation and writes an
EE_Format
ACTIVE header to the first page.
Configures the EEPROM emulation variables to their initial state and
restores the flash pages to a known good state in case of asynchronous
reset or power loss during flash memory write or erase operation.
Erases the flash pages that need to be erased (for instance pages not
fully erased in ERASE state, pages in ERASING state). The
EE_FORCE_ERASE parameter has to be used by default. If the
EE_Init
application guarantees that no asynchronous reset nor power loss can
happen during flash write or erase operations, then the
EE_CONDITIONAL_ERASE parameter can be used. Refer to
Section 4.7.2: Page header recovery.
After reset, this function needs to be systematically called prior to
accessing the emulated EEPROM.
This function updates the data value corresponding to the virtual address
passed as a parameter. Only the last stored element is read. It returns a
status equal to EE_OK unless it cannot find any data at the given virtual
EE_ReadVariableXXbits address.
Three functions are implemented to deal with all supported data sizes
(XX = 8, 16, 32 or 64).
This function updates the EEPROM at a given virtual address with the
data value passed as parameters.
If the set of pages used for EEPROM emulation is full, it triggers a flash
memory page transfer and returns a Status equal to
EE_CLEANUP_REQUIRED. In the case of the Bluetooth® LE application
EE_WriteVariableXXbits
for the NUCLEO-WB55 Nucleo board (DUALCORE_FLASH_SHARING
is defined), it can return EE_FLASH_USED when the flash memory is
used by CPU2(1)
Three functions are implemented to deal with all supported data sizes
(XX = 8, 16, 32 or 64).
Erases the set of pages in ERASING state. The application program can
call this function when real-time constraints are low. The flash cleanup is
EE_CleanUp
done in polling mode so this function does not return before one set of
flash memory pages used for EEPROM emulation is erased.
Erases the set of pages in ERASING state. The flash cleanup is started
EE_CleanUp_IT in interrupt mode so this function returns immediately and following page
erase is done by subsequent interrupt service routines.
This function can be called under NMI to delete a corrupted flash address
FI_DeleteCorruptedFlashAddress found by the flash memory ECCD in order to clear this flash interface
fault Section 4.7.1: Data recovery.
1. EE_WriteVariableXX bits can return EE_FLASH_USED only in the case of direct EEPROM variable writing and not in the
case of a page transfer, a page header update, or the initialization process. Also, when this value is returned, the driver can
activate the HSEM interrupt so that an interrupt is raised when the CPU2 releases the semaphore associated to the flash
memory device being used. The user program can then do something else while waiting for the semaphore release.
1. Based on 1000 elements (16-bit address, 16-bit CRC, and 32-bit data).
2. Example with Bluetooth® LE communication.
Table 9 does not include the flash memory size used for EEPROM emulation itself. Refer to the formula given in
Section 4.6: Computing the required size of flash memory for EEPROM emulation to calculate the corresponding
flash memory size.
Note also that the application program (main.c) implements the VarDataTab[] variable to store the
EEPROM element values. Its size is 4000 bytes for 1000 32-bit elements.
For flexibility, this variable is placed in RAM in the provided example. Moreover, VarDataTab[] can easily be
removed as most user applications do not need to have a RAM copy of the elements stored in flash memory.
1. The maximum initialization time and cleanup time depend on the number of flash memory EEPROM pages used, and the time to erase one
page. (See the section "Flash memory characteristics" in the STM32 product datasheet). The time taken to erase flash memory EEPROM
pages = number of pages * tERASE.
2. When the application ensures the EEPROM emulation cannot be interrupted by an asynchronous reset or power failure, a conditional erase
can be used. It is more efficient in terms of execution time and also in terms of EEPROM endurance (refer to Section 4.7.2: Page header
recovery for more details).
3. The typical write time is close to the minimal write time as there is no data transfer in most cases. The maximum value refers to a write
operation that generates a data transfer.
4. The minimum value refers to a read operation of the last element stored in the flash memory and the maximum value refers to a read
operation of the first element stored in the flash memory.
5. Timing measurements for the STM32L4+ series board (NUCLEO-L4R5ZI) has been done for an 80 MHz system clock so that a comparison
can be done with the STM32L4 series (NUCLEO-L476RG). However, the NUCLEO-L4R5ZI can be pushed up to 120 MHz while the
NUCLEO-L476RG is limited at 80 MHz. The measurements for the other boards are done for the maximum system clock.
6. Data taken from the example without Bluetooth® LE capabilities.
Note: These timing measurements are provided to give the reader an idea of the emulation firmware performance for
different STM32 series. They are based on 100 operations for each type of operation. Thus, they are not an
absolute reference. It is possible to find different minimums, maximums and even means (especially if the
measurement conditions are modified).
This section provides advice on how to overcome software limitations in embedded applications and how to fulfill
the needs of different applications.
7 Conclusion
The STM32 devices internal flash memory can be used advantageously in many applications to emulate an
EEPROM. Even though the memory characteristics are quite different, this application note has shown that
emulated EEPROM competes with real EEPROM in terms of:
• Memory size
• Read and write access times
• Driver usage simplicity and flexibility
• Memory endurance
• Data retention
• Robustness to asynchronous resets and power failures
• Reliability
• Cost by removing the need for an external component
Revision history
Table 11. Document revision history
Contents
1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Main differences between external and emulated EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Difference in write access time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Programming and erase operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Implementing EEPROM emulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 Page status valid transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 Page and variable format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.4 Simple use case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.5 Reading data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4 Advanced features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
4.1 Data granularity management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 Wear leveling algorithm and flash memory page allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.3 Guard pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.4 Cycling capability: EEPROM endurance improvement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.5 High-cycle data area of flash memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.6 Computing the required size of flash memory for EEPROM emulation . . . . . . . . . . . . . . . . . 12
4.7 EEPROM emulation robustness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.7.1 Data recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.7.2 Page header recovery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.8 Real-time considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.8.1 Device embedding flash memory with RWW (read while write) capability . . . . . . . . . . . . . 14
4.8.2 Running the critical processes from the internal RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.8.3 Dual core considerations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.9 Cleaning up the flash memory in interrupt or polling mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.10 Cache coherency maintenance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5 API and application examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16
5.1 EEPROM emulation software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.1.1 Key features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.1.2 STM32Cube expansion software (X-CUBE-EEPROM) . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.1.3 User defines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.1.4 User API definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.2 EEPROM emulation memory footprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.3 EEPROM emulation timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
List of tables
Table 1. Application products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Table 2. Differences between external and emulated EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Table 3. Flash memory properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Table 4. Emulated EEPROM virtual addresses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 5. Flash memory endurance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Table 6. Flash usage for a 4000-byte emulated EEPROM (STM32L4/L4+) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Table 7. Boards covered . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Table 8. API definition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Table 9. Memory footprint for EEPROM emulation mechanism. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Table 10. EEPROM emulation timings for different targets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 11. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
List of figures
Figure 1. Page status evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 2. Page status valid transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 3. Flash page and EEPROM variable format (except STM32U5 series) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 4. STM32U5 series Flash page and EEPROM variable format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 5. Data update flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 6. Directory tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16