liveBook · Manning

Arm Cortex-M

As explained in Embedded Software with Rust

Arm Cortex-M is a family of energy-efficient processor cores designed primarily for microcontrollers and embedded systems.

Arm Cortex-M is a family of 32-bit processor cores designed for microcontrollers, emphasizing low power, small size, and real-time performance. Chip vendors combine these cores with flash, SRAM, and peripherals to make complete microcontrollers. section 1.5.1

The family ranges from small cores such as the Cortex-M0+ to higher-performance variants such as the Cortex-M85. Sleep modes and fast wake-up suit battery-powered devices. The Nested Vectored Interrupt Controller (NVIC) supports predictable interrupt handling, with hardware assistance for context entry and exit. section 1.5.1

On reset, a Cortex-M core consults a vector table at the start of its memory map. The first entry supplies the initial main stack pointer; the second gives the reset handler address. Other entries identify exception and interrupt handlers. A microcontroller can alias physical flash to address 0x00000000 so the core finds the table there. section 4.2.1

STM32 flash aliasing

On many STM32 devices, physical flash starts at 0x08000000. Boot configuration can map it to 0x00000000, where the core expects to find the vector table. section 4.2.1

Cortex-M firmware controls hardware through memory-mapped registers. Many core facilities, including SysTick, NVIC, the memory protection unit, and debug logic, have architecturally defined addresses. Device peripherals such as GPIO and timers also expose registers, but their details depend on the microcontroller. section 5.1.2

// SysTick Reload Value Register
const SYST_RVR: *mut u32 = 0xE000_E014 as *mut u32;

// SysTick Current Value Register
const SYST_CVR: *mut u32 = 0xE000_E018 as *mut u32;

unsafe {
    core::ptr::write_volatile(SYST_RVR, 0x00FF_FFFF); // Set reload value
    let current = core::ptr::read_volatile(SYST_CVR);  // Read current countdown value
}

This Rust listing uses volatile access to write the SysTick reload register and read its current value. The pointer operations require unsafe code. section 5.2.3

Volatile access is not a substitute for memory ordering. When ordering or completion matters, the cortex-m crate exposes barrier instructions: DMB orders memory accesses, DSB additionally waits for outstanding operations to complete, and ISB synchronizes subsequent instruction fetching. section 5.2.3

For bare-metal Rust, cortex-m exposes processor facilities and registers; cortex-m-rt supplies startup routines, memory initialization, and entry and exception macros. Panic crates choose the behavior on failure: panic-halt stops execution, while panic-semihosting can provide debugging output during development. section 3.5.1

How Embedded Software with Rust covers it

How deep it goes
Explains core features, reset and vector-table behavior, memory-mapped I/O, and Rust runtime support, including manual and runtime-crate startup approaches.
Examples
Illustrates flash aliasing on STM32 devices and volatile access to SysTick registers.
What it assumes
Assumes familiarity with embedded programming while introducing Rust techniques for firmware.
What you can do after
Apply it via cortex-m and cortex-m-rt to access processor features and set up bare-metal Rust startup.
How it connects
Connects Cortex-M to interrupt handling, memory-mapped I/O, memory barriers, linker scripts, and bare-metal startup.

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.