STM32 gotchas
323. In Cortex-M7, interrupts may result in double read from the same FSMC/FMC address, due to instructions being abandoned/restarted

Quoting from Cortex-M7 Technical Reference Manual (TRM) chapter 2.7.1 Exception handling:

To minimize interrupt latency, the processor can abandon the majority of multicycle instructions that are executing when the interrupt is recognized. The only exception is a device or strongly-ordered load, or a shared store exclusive operation that starts on the AXI interface. All normal memory transactions are abandoned when an interrupt is recognized. The processor restarts any abandoned operation on return from the interrupt. 1

This can lead to surprising problems, if the external device attached to FMC/FSMC is not a "pure" memory, and its reading has side effects, such as in case of using a FIFO (as experienced by user rromo9).

Similarly to effects of speculative prefetch, at the cost of losing some performance, this can be mitigated by setting given FSMC/FMC area as Device (as opposed to Normal) in MPU (or using the "trick" with FSMC/FMC areas swap).


1. To reduce interrupt latency, also the "smaller" Cortex-M4 can abandon and restart instructions, but it's only the relatively lengthy division instruction, which uses only registers and never accesses external memory. The lengthy STM and LDM instructions (and their aliases, PUSH and POP) can be interrupted and continued, as processor remembers number of outstanding accesses in the EPSR register. There are exceptions to this, though, e.g. if the STM/LDM is within an IT(E) block - for the minute details see ARMv7M Architecture Reference Manual (ARM), chapter B1.5.10 Exceptions in Load Multiple and Store Multiple operations.