Agent Skill
2/7/2026

rust-embedded

Use when developing embedded, no_std, or bare-metal Rust for microcontrollers (ARM, RISC-V, ESP32, STM32, nRF). Covers HAL, PAC, probe-rs, defmt logging, panic-halt, alloc, static mut, volatile access, DMA, interrupt handler, real-time constraints, no_std setup, heapless collections, interrupt-safe state with Mutex RefCell, peripheral ownership, RTIC, Embassy, and cortex-m patterns.

P
peixotorms
0GitHub Stars
1Views
npx skills add peixotorms/odinlayer-skills

SKILL.md

Namerust-embedded
DescriptionUse when developing embedded, no_std, or bare-metal Rust for microcontrollers (ARM, RISC-V, ESP32, STM32, nRF). Covers HAL, PAC, probe-rs, defmt logging, panic-halt, alloc, static mut, volatile access, DMA, interrupt handler, real-time constraints, no_std setup, heapless collections, interrupt-safe state with Mutex RefCell, peripheral ownership, RTIC, Embassy, and cortex-m patterns.

name: rust-embedded description: Use when developing embedded, no_std, or bare-metal Rust for microcontrollers (ARM, RISC-V, ESP32, STM32, nRF). Covers HAL, PAC, probe-rs, defmt logging, panic-halt, alloc, static mut, volatile access, DMA, interrupt handler, real-time constraints, no_std setup, heapless collections, interrupt-safe state with Mutex RefCell, peripheral ownership, RTIC, Embassy, and cortex-m patterns.

Embedded Development

Domain Constraints

Domain RuleDesign ConstraintRust Implication
No heapStack allocationheapless, no Box/Vec
No stdCore only#![no_std]
Real-timePredictable timingNo dynamic alloc
Resource limitedMinimal memoryStatic buffers
Hardware safetySafe peripheral accessHAL + ownership
Interrupt safeNo blocking in ISRAtomic, critical sections

Critical Rules

  • Cannot use heap (no allocator) — use heapless::Vec<T, N> and arrays for deterministic memory.
  • Shared state must be interrupt-safe — ISR can preempt at any time. Use Mutex<RefCell<T>> + critical section.
  • Peripherals must have clear ownership — HAL takes ownership via singletons to prevent conflicting access.

Layer Stack

LayerExamplesPurpose
PACstm32f4, esp32c3Register access
HALstm32f4xx-halHardware abstraction
FrameworkRTIC, EmbassyConcurrency
Traitsembedded-halPortable drivers

Framework Comparison

FrameworkStyleBest For
RTICPriority-basedInterrupt-driven apps
EmbassyAsyncComplex state machines
Bare metalManualSimple apps

Key Crates

PurposeCrate
Runtime (ARM)cortex-m-rt
Panic handlerpanic-halt, panic-probe
Collectionsheapless
HAL traitsembedded-hal
Loggingdefmt
Flash/debugprobe-run

Static Peripheral Pattern

#![no_std]
#![no_main]

use cortex_m::interrupt::{self, Mutex};
use core::cell::RefCell;

static LED: Mutex<RefCell<Option<Led>>> = Mutex::new(RefCell::new(None));

#[entry]
fn main() -> ! {
    let dp = pac::Peripherals::take().unwrap();
    let led = Led::new(dp.GPIOA);

    interrupt::free(|cs| {
        LED.borrow(cs).replace(Some(led));
    });

    loop {
        interrupt::free(|cs| {
            if let Some(led) = LED.borrow(cs).borrow_mut().as_mut() {
                led.toggle();
            }
        });
    }
}

Common Mistakes

MistakeDomain ViolationFix
Using VecHeap allocationheapless::Vec
No critical sectionRace with ISRMutex + interrupt::free
Blocking in ISRMissed interruptsDefer to main loop
Unsafe peripheralHardware conflictHAL ownership
Skills Info
Original Name:rust-embeddedAuthor:peixotorms