liveBook · Manning

Compiler intrinsic

As explained in Embedded Software with Rust

An intrinsic function is a compiler- or architecture-provided function that exposes a low-level operation with direct correspondence to machine instructions.

An intrinsic exposes a low-level operation through a function that maps directly to a machine instruction. On Cortex-M, `cortex-m::asm` provides calls for common instructions, making hardware intent clear without inline assembly. These calls can affect processor state, timing, or memory ordering, so use them with care. section 5.5.2

Common uses include:

  • Pause at a precise instruction boundary with `bkpt()` to inspect machine state under a debugger. section 5.5.2
  • Use `dmb()` to order memory accesses, or `dsb()` to wait for preceding memory operations to complete. section 5.5.2
  • Use `wfi()` or `wfe()` to suspend the core, and `sev()` to send an event to a core waiting in `wfe()`. section 5.5.2
use cortex_m::asm;

// Most cortex_m::asm functions are unsafe as they
// directly affect processor state.
unsafe {
    asm::nop();   // No-op: useful for timing padding
    asm::wfi();   // Wait for interrupt: suspend core until interrupt pending
    asm::isb();   // Instruction Synchronisation Barrier
    asm::dsb();   // Data Synchronisation Barrier
    asm::dmb();   // Data Memory Barrier
    asm::udf();   // Trigger UsageFault: used as a hard assert
    asm::bkpt();  // Breakpoint: halts core under a connected debugger
    asm::wfe();   // Wait for event: suspend core until event or interrupt
    asm::sev();   // Send event: wake a core waiting in wfe()
}

See the `cortex_m::asm` listing for these calls and additional instructions, including `nop()`, `isb()`, and `udf()`. section 5.5.2

Changing MPU configuration

After writing the MPU control register, the example uses `dsb()` to ensure the write completes and `isb()` so subsequent instructions use the new configuration. section 5.5.2

How Embedded Software with Rust covers it

How deep it goes
Explains direct instruction mappings and barrier ordering, but defers detailed Cortex-M synchronization requirements.
Examples
Uses breakpoint debugging, wait and event instructions, memory barriers, and MPU configuration.
What you can do after
Apply `cortex-m::asm` to issue common Cortex-M instructions and order hardware-facing memory operations.
How it connects
Connects to inline assembly, memory-mapped I/O, DMA descriptors, and memory barriers.

Also explained in

Compare how 2 books explain compiler intrinsic →

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.