liveBook · Manning

PRIMASK

As explained in Embedded Software with Rust

PRIMASK is a Cortex-M processor register that controls whether most configurable interrupts are permitted.

PRIMASK controls whether maskable interrupts are permitted. Setting it disables them globally, unlike NVIC controls for individual interrupts. This can protect critical work, but is not the favored way to create critical sections. section 4.5.5 section 5.5.3

use core::arch::asm;

// asm!(): Writes 1 to PRIMASK via MSR, which masks all exceptions except NMI
// and HardFault.
#[inline(always)]
fn disable_interrupts() {
    unsafe {
        core::arch::asm!(
            "msr PRIMASK, {reg}",
            reg = in(reg) 1u32,
            options(nomem, nostack),
        );
    }
}

This Rust inline-assembly example writes 1 to PRIMASK with MSR; the comment notes that NMI and HardFault remain unmasked. section 5.5.3

How Embedded Software with Rust covers it

How deep it goes
Shows interrupt-control calls and a raw assembly write, while deferring a fuller critical-section treatment.
Examples
Uses cortex_m interrupt-control calls and an asm! block that writes PRIMASK with MSR.
What you can do after
Operate interrupt masking with cortex_m calls or write PRIMASK using Rust inline assembly.
How it connects
Connects to the Nested Vectored Interrupt Controller, critical sections, and inline assembly.

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.