2.5.2.4 Software Ordering of Memory Accesses

The order of instructions in the program flow does not always guarantee the order of the corresponding memory transactions. This is because:

  • the processor can reorder some memory accesses to improve efficiency, providing this does not affect the behavior of the instruction sequence.
  • the processor has multiple bus interfaces
  • memory or devices in the memory map have different wait states
  • some memory accesses are buffered or speculative.

2.5.2.2 Memory System Ordering of Memory Accesses describes the cases where the memory system guarantees the order of memory accesses. Otherwise, if the order of memory accesses is critical, software must include memory barrier instructions to force that ordering. The processor provides the following memory barrier instructions:

DMB: The Data Memory Barrier (DMB) instruction ensures that outstanding memory transactions complete before subsequent memory transactions. See 2.6.10.3 DMB.

DSB: The Data Synchronization Barrier (DSB) instruction ensures that outstanding memory transactions complete before subsequent instructions execute. See 2.6.10.4 DSB.

ISB: The Instruction Synchronization Barrier (ISB) ensures that the effect of all completed memory transactions is recognizable by subsequent instructions. See 2.6.10.5 ISB.

MPU programming

Use a DSB followed by an ISB instruction or exception return to ensure that the new MPU configuration is used by subsequent instructions.