AN5342 · Application noteHow to use error correction code (ECC) management for internal memories protection on STM32 MCUs
Download .pdfOpen in the full document

Nonvolatile memory ECC

Nonvolatile memory ECC

For STM32H72x/3x/4x/5x lines, the nonvolatile memory word (smallest programmable amount of memory) is 256 bits, while on STM32H7Ax/Bx lines, STM32H5 series, STM32C5 series, and STM32U5 series, it is 128 bits. Table 5 Nonvolatile memory ECC coverage in STM32 devices shows the word size for STM32 devices with ECC in nonvolatile memory. This is also the portion of memory protected by the bits required to achieve error detection and correction on the nonvolatile memory word. Write access to any smaller unit of memory is only possible on read-modify-write basis, this action results in higher stress to the memory hardware. The STM32H5 series, STM32C5 series, STM32U5 series, and STM32H7Ax/Bx line also feature added robustness on the small 0.5-2 Kbyte OTP area, where every 16 bits are protected with 6 bits of ECC redundancy. There is no OTP memory area on STM32H72x/3x/4x/5x lines.

Table 5. Nonvolatile memory ECC coverage in STM32 devices
MemoryH72x/H73x

Other
H74x/H75x

H7Ax/H7BxG0

G4/L4/L5/
WB/WL/U3

H503

H563/573
C5

L0/L11

U5

U0
Bank1256b256b128b64b64b2128b128b16b128b64b
Bank2-256b128b64b364b4-128b16b4128b-
Special region--16b---16b5---

The ECC functionality is integrated into the nonvolatile memory controller and cannot be disabled. If the application is not designed to take advantage of the ECC, it can disable the associated interrupt and ignore the flag bits in the nonvolatile memory status registers.

The disadvantage of an integrated ECC solution is that programming single bits in the nonvolatile memory word is not possible without prior erase of this word. As programming without erase is sometimes used by implementations of EEPROM emulation or a monotonic counter, another algorithm must be selected for such applications on ECC enabled memories.

The flash memory controller of STM32H7 series implements also a hardware CRC integrity protection. The CRC is a complementary mechanism, not an ECC replacement. If the automated background CRC check is activated, the read access to the flash memory also implicitly checks the ECC in the whole range.

1 ECC in STM32L0 has no user interface, so it is not described in detail in this table.
2 If DBANK = 0, the access width is 128 bits, but ECC remains 2 × 8 bytes.
3 Only G0Bx/G0Cx.
4 Only on dual bank devices.
5 Area of 16 bits words is configurable.

Cache memory ECC

Cache is a memory that does not have its own address range. Its purpose is to reduce the latency of accessing the addressed memory by preserving a copy of frequently accessed contents (either code of data) or contents which are likely to be needed soon (current address+1 for example). Physically it is an SRAM with different addressing.

Only STM32H7 series have cache with ECC protection. By default, the Cortex®-M7 L1 cache is also protected by ECC by using the same SEC DED code. The word width is 256-bit as the entire line of cache is covered. The cache ECC protection can be disabled. To modify the state of the cache ECC, the code must first disable and flush the cache. Then the ECC settings can be modified and the cache re-enabled with new setting.

The CPU cache is only involved in AXIM bus accesses, the ITCM, and DTCM address range does not require cache. The tightly coupled memories are almost exclusively dedicated to the use of the Cortex®‑M7 core. The Cortex®‑M7 processor can automatically recover from any detected ECC fault in instruction cache. One-bit errors are covered by the automatic correction. For two-bit errors, the line is invalidated and the instructions are loaded again from the program memory. In the case of data cache, a two-bit error detection may result in losing the ongoing modifications while reloading old data.
Note:

The write through practice is not recommended as a countermeasure to this rare event.

The ART accelerator cache that supports the Cortex®‑M4 core on dual-core STM32H7 series microcontrollers is not protected by ECC.

As there is no interrupt notification or interface to ECC detection results of the CPU cache, the only solution to detect the rare event of two-bit data cache ECC error is to monitor the IEBR and DEBR core registers. Refer to the document AN5342_General-information.html#id_9792__entry_wpb_xtz_gwb and the Arm® Cortex® technical documentation (TRM) for more details.

It is also necessary to flush or invalidate instruction cache after two-bit ECC error interrupt from instruction memory (by flash or SRAM). Otherwise, illegal opcode may remain in cache, leading to hard fault.

ECC testing

ECC testing does not verify that the STM32 MCU is functional. It is useful to test the application firmware reaction to ECC error occurrence, therefore there is a requirement to integrate ECC testing into different aspects of general software testing. The tests can include unitary tests of ECC subsystem functions, acceptance tests, or nonregression tests. The reaction to ECC detection or correction is important, for example, for certification on safety requirements compliance.

Note:

If ECC testing is related to functional safety compliance needs, it is recommended to refer to the Safety Manual of the applicable STM32 MCU series, available on www.st.com.

Note:

On specific STM32 series, a dedicated software-based procedure to test ECC efficiency is available. The test procedure allows the application software to inject ECC errors in memory. Refer to the Reference Manual to check if the option is available and related details.

ECC testing in SRAM

Testing the ECC in SRAM is relatively simple because reading uninitialized RAM on a cold boot is usually enough to trigger an ECC error and test the reaction. The effect is random, but it is easy to produce.

Sometimes, for example on the STM32H7 series, it is possible to disable the ECC, modify the memory contents, and then reenable the ECC, which becomes desynced with the data by this action. Subsequent read from that memory location encounters an ECC error.

ECC testing in nonvolatile memory

Different methods can be used to test ECC, in addition to flash memory testing, as shown in Table 6 Methods for ECC testing in nonvolatile memory.

Table 6. Methods for ECC testing in nonvolatile memory
MethodAdvantagesDisadvantagesApplicable products
Dedicated flash word with errors planted from factory
  • Simple to use, only requires read from the dedicated address to get the ECC interrupt
  • Simple section of SEC or DED outcome
  • Address decoding test is not possible
  • Feature is only available in selected series

STM32U5 series

Data programmed to a location that was not erased before
  • Can be applied anywhere in nonvolatile memory
  • Known patterns to select SEC or DED outcome
  • Feature is only available in selected series

STM32C5 series
STM32H5 series
STM32H7 series

Disturbing the flash erase or program cycle with a reset
  • Universally applicable
  • Can be applied anywhere in memory
  • Tuning is required to provide the correctly timed reset
  • Achieving SEC is difficult
All STM32 series
Memory reconfigurationAimed at testing data area ECC protection
  • Limited to the last few sectors of nonvolatile memory
  • Not usable once the option bytes are closed
  • Achieving SEC is difficult

STM32H5
STM32C5