
Domain Embedded
Ship bare-metal or MCU firmware in Rust without heap surprises, ISR races, or HAL ownership bugs.
Overview
domain-embedded is an agent skill for the Build phase that applies no_std and MCU domain constraints so embedded Rust stays heapless, interrupt-safe, and HAL-ownership-correct.
Install
npx skills add https://github.com/zhanghandong/rust-skills --skill domain-embeddedWhat is this skill?
- Maps six domain rules (no heap, no std, real-time, resource limits, hardware safety, interrupt safety) to Rust design ch
- Enforces heapless buffers and static allocation patterns instead of Box/Vec on MCUs
- Documents ISR-safe shared state with Mutex<RefCell<T>> and critical sections
- Auto-injects target config from .cargo/config.toml at skill load
- Covers GPIO, SPI, I2C, UART, DMA, Embassy, RTIC, cortex-m, ESP32, STM32, nRF vocabulary
- 6 domain rules mapped to design constraints
- Auto-reads .cargo/config.toml when present
Adoption & trust: 581 installs on skills.sh; 1.2k GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your agent writes desktop-style Rust with heap allocation and blocking ISRs that will not compile or will fail on a resource-limited microcontroller.
Who is it for?
Indie hardware or IoT builders using Rust HAL/Embassy/RTIC on a known MCU target with an existing Cargo workspace.
Skip if: Pure host-side Rust CLI tools, WASM, or teams that already have a full BSP style guide and only need one-off refactors without domain gates.
When should I use this skill?
Developing embedded or no_std Rust when Cargo.toml or .cargo/config.toml are in scope (keywords: embedded, MCU, HAL, embassy, RTIC).
What do I get? / Deliverables
Generated firmware code and reviews follow embedded domain rules—static buffers, #![no_std], and safe peripheral ownership—matching your .cargo/config.toml target.
- Constraint-aligned embedded Rust snippets
- ISR and peripheral access reviews
Recommended Skills
Journey fit
Firmware and HAL work sit in Build when you are implementing the product on real hardware. Embedded logic, drivers, interrupts, and no_std crates map to backend implementation constraints rather than UI or docs.
How it compares
Use as a domain constraint layer on top of generic Rust skills—not a substitute for vendor SDK examples or hardware bring-up checklists.
Common Questions / FAQ
Who is domain-embedded for?
Solo and indie builders shipping firmware in Rust on MCUs who want the coding agent to honor no_std, heapless, and interrupt-safety rules automatically.
When should I use domain-embedded?
During Build backend work when editing embedded crates, HAL drivers, or ISR handlers—especially after changing .cargo/config.toml or adding Embassy/RTIC tasks.
Is domain-embedded safe to install?
It is procedural guidance only; review the Security Audits panel on this Prism page before trusting any third-party skill in your repo.
SKILL.md
READMESKILL.md - Domain Embedded
## Project Context (Auto-Injected) **Target configuration:** !`cat .cargo/config.toml 2>/dev/null || echo "No .cargo/config.toml found"` --- # Embedded Domain > **Layer 3: Domain Constraints** ## Domain Constraints → Design Implications | Domain Rule | Design Constraint | Rust Implication | |-------------|-------------------|------------------| | No heap | Stack allocation | heapless, no Box/Vec | | No std | Core only | #![no_std] | | Real-time | Predictable timing | No dynamic alloc | | Resource limited | Minimal memory | Static buffers | | Hardware safety | Safe peripheral access | HAL + ownership | | Interrupt safe | No blocking in ISR | Atomic, critical sections | --- ## Critical Constraints ### No Dynamic Allocation ``` RULE: Cannot use heap (no allocator) WHY: Deterministic memory, no OOM RUST: heapless::Vec<T, N>, arrays ``` ### Interrupt Safety ``` RULE: Shared state must be interrupt-safe WHY: ISR can preempt at any time RUST: Mutex<RefCell<T>> + critical section ``` ### Hardware Ownership ``` RULE: Peripherals must have clear ownership WHY: Prevent conflicting access RUST: HAL takes ownership, singletons ``` --- ## Trace Down ↓ From constraints to design (Layer 2): ``` "Need no_std compatible data structures" ↓ m02-resource: heapless collections ↓ Static sizing: heapless::Vec<T, N> "Need interrupt-safe state" ↓ m03-mutability: Mutex<RefCell<Option<T>>> ↓ m07-concurrency: Critical sections "Need peripheral ownership" ↓ m01-ownership: Singleton pattern ↓ m12-lifecycle: RAII for hardware ``` --- ## Layer Stack | Layer | Examples | Purpose | |-------|----------|---------| | PAC | stm32f4, esp32c3 | Register access | | HAL | stm32f4xx-hal | Hardware abstraction | | Framework | RTIC, Embassy | Concurrency | | Traits | embedded-hal | Portable drivers | ## Framework Comparison | Framework | Style | Best For | |-----------|-------|----------| | RTIC | Priority-based | Interrupt-driven apps | | Embassy | Async | Complex state machines | | Bare metal | Manual | Simple apps | ## Key Crates | Purpose | Crate | |---------|-------| | Runtime (ARM) | cortex-m-rt | | Panic handler | panic-halt, panic-probe | | Collections | heapless | | HAL traits | embedded-hal | | Logging | defmt | | Flash/debug | probe-run | ## Design Patterns | Pattern | Purpose | Implementation | |---------|---------|----------------| | no_std setup | Bare metal | `#![no_std]` + `#![no_main]` | | Entry point | Startup | `#[entry]` or embassy | | Static state | ISR access | `Mutex<RefCell<Option<T>>>` | | Fixed buffers | No heap | `heapless::Vec<T, N>` | ## Code Pattern: Static Peripheral ```rust #![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 | Mistake | Domain Violation | Fix | |---------|-----------------|-----| | Using Vec | Heap allocation | heapless::Vec | | No critical section | Race with ISR | Mutex + interrupt::free | | Blocking in ISR | Missed interrupts | Defer to main loop | | Unsafe peripheral | Hardware conflict | HAL ownership | --- ## Trace to Layer 1 | Constraint | Layer 2 Pattern | Layer 1 Implementation | |-------