RTIC (Real-Time Interrupt-driven Concurrency) is a framework that gives you safe shared state between interrupt handlers on Cortex-M without a traditional RTOS.

The core idea: interrupt handlers are tasks. Shared resources are declared with a priority ceiling. The framework uses Cortex-M's BASEPRI register to mask lower-priority interrupts when a task accesses a shared resource — this is called the Stack Resource Policy (SRP) and it guarantees deadlock-free execution.

The Rust borrow checker enforces at compile time that you cannot access a shared resource without holding the correct lock token. You physically cannot write a data race in RTIC — it doesn't compile.

#[rtic::app(device = stm32f4xx_hal::stm32, peripherals = true)]
mod app {
    #[shared]
    struct Shared {
        can_tx: CanTx,
    }

    #[task(binds = CAN1_TX, shared = [can_tx])]
    fn can_tx_handler(cx: can_tx_handler::Context) {
        cx.shared.can_tx.lock(|tx| {
            tx.transmit_next();
        });
    }
}

The .lock() call raises the interrupt mask for the duration of the closure. No mutex, no spinlock — just BASEPRI manipulation and a lifetime that proves the lock is held.

Used in SpaceCAN's spacecan-firmware crate for CAN frame transmission and reception on STM32F4.