Electronic – Does the CPU of an ARM Cortex M halt during flash self-programming

armcortex-m

Most ARM Cortex M MCUs do not feature EEPROM memory. Instead, persistent data can be written to the same flash memory that also holds the program.

  • What is the state of the CPU during this erase/write process?
  • Does it halt? Does it maintain normal operation?
  • Does the behavior of the CPU depend on the specific MCU family (e.g. STM32, Kinetis L) used?

(To some people this could look like a stupid question, but Microchip's PIC16 halts the CPU for up to 40ms during flash self-programming.)

Best Answer

The behavior of the core does depend on the implementation. The Flash is not integral to the ARM core, and as such, every vendor implements it differently. Typically, during the erase/write process one would execute from RAM, and execution should not be affected.

On the STM32, I believe reads from flash stall while erase/write cycles are ongoing. This would cause the core's execution to stall until the operation completes. With some of the flash configurations, I believe you can continue to execute/read flash and it will only stall when you access the part of the flash that you are eraseing/programming.

I've used other Cortex M's where you must execute from RAM while modifying flash contents otherwise you will encounter a bus fault (and likely a system crash if your bus fault/hard fault handlers are in flash). Some micros with large amounts of flash implement it as two independent flash arrays, and these typically allow for full access to one bank while operating on the other.

You would need to refer to the documentation for your specific part to see the limitations of execution while modifying flash contents.