liveBook · Manning

DSB

As explained in Embedded Software with Rust

dsb is a Cortex-M data synchronization barrier instruction that waits for preceding memory operations to complete before subsequent instruction execution.

DSB (Data Synchronization Barrier) is a Cortex-M instruction that waits for preceding memory operations, including implicit operations, to complete before any subsequent instruction executes. It is useful when firmware must ensure that an operation has completed at the system level before continuing. section 5.1.3 section 5.2.3

Program order does not always match bus visibility: a write can remain in a buffer while a later read proceeds. DMB orders memory accesses; DSB is stricter and also holds up subsequent non-memory instructions until preceding operations complete. DSB is more costly. section 5.1.3 section 5.5.2

STR  r0, [r1]          ; Store to a bufferable address
DSB                    ; Data Synchronization Barrier: ensures ALL pending memory
                       ; operations (explicit and implicit, including cache line
                       ; fills) complete before any subsequent instruction executes
ADD  r2, r3, r4        ; Non-memory instruction: cannot execute until the DSB
                       ; has fully completed, unlike with DMB
LDR  r5, [r6]          ; Load: guaranteed to occur after all prior memory
                       ; operations have fully completed

The store must complete before the DSB allows the addition or subsequent load to execute. section 5.1.3

Volatile reads and writes control how the compiler treats an access; they do not by themselves ensure system-wide ordering or completion of buffered writes. Volatile access also does not perform cache maintenance. Use a barrier when hardware-visible ordering or completion is required. section 5.2.3

In Rust, prefer cortex_m::asm::dsb() to emit the barrier. Inline assembly via core::arch::asm! is an alternative when available intrinsics are insufficient. section 5.2.3 section 5.6

unsafe {
    // MPU_CTRL register: 0xE000_ED94
    // Alternatively accessible via cortex_m::peripheral::MPU
    core::ptr::write_volatile(0xE000_ED94 as *mut u32, 0x0); // Disable MPU
    asm::dsb();

    // Configure MPU regions here...

    core::ptr::write_volatile(0xE000_ED94 as *mut u32, 0x1); // Enable MPU
    asm::dsb(); // Ensure enable write completes before ISB
    asm::isb(); // Flush pipeline: subsequent instructions use new MPU config
}

When reconfiguring the MPU, the second DSB completes the enable write before ISB flushes the pipeline so subsequent instructions use the new configuration. section 5.5.2

How Embedded Software with Rust covers it

How deep it goes
Explains completion semantics and barrier contrasts with assembly and MPU examples, while referring detailed synchronization requirements to Arm Application Note AN321.
Examples
Illustrates a buffered store followed by DSB and an addition, and an MPU reconfiguration sequence using DSB and ISB.
What you can do after
Apply it via cortex_m::asm::dsb() when preceding memory operations must complete before execution continues.
How it connects
Connects DSB to DMB, ISB, volatile access, memory-mapped I/O, and MPU configuration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.