domain-embedded
Embedded and no_std Rust development constraints, patterns, and critical safety rules for microcontroller firmware.
- Enforces no dynamic allocation (heap-free design using heapless collections), no_std compilation, and static memory buffers for deterministic resource usage on resource-constrained devices
- Covers interrupt safety through critical sections and Mutex<RefCell> patterns to prevent race conditions when shared state is accessed from ISRs
- Provides hardware ownership patterns (singleton peripherals, HAL-based access) to prevent conflicting peripheral access and unsafe register manipulation
- Includes framework guidance for RTIC (priority-based), Embassy (async), and bare-metal approaches, plus key crates (cortex-m-rt, heapless, embedded-hal, defmt, probe-run)
- Documents common mistakes (Vec instead of heapless::Vec, missing critical sections, blocking in ISRs) with fixes tied to design patterns
This skill contains shell command directives (!`command`) that may execute system commands. Review carefully before installing.
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 |
More from zhanghandong/rust-skills
m15-anti-pattern
Use when reviewing code for anti-patterns. Keywords: anti-pattern, common mistake, pitfall, code smell, bad practice, code review, is this an anti-pattern, better way to do this, common mistake to avoid, why is this bad, idiomatic way, beginner mistake, fighting borrow checker, clone everywhere, unwrap in production, should I refactor, 反模式, 常见错误, 代码异味, 最佳实践, 地道写法
5.4Kcoding-guidelines
Use when asking about Rust code style or best practices. Keywords: naming, formatting, comment, clippy, rustfmt, lint, code style, best practice, P.NAM, G.FMT, code review, naming convention, variable naming, function naming, type naming, 命名规范, 代码风格, 格式化, 最佳实践, 代码审查, 怎么命名
1.1Km10-performance
CRITICAL: Use for performance optimization. Triggers: performance, optimization, benchmark, profiling, flamegraph, criterion, slow, fast, allocation, cache, SIMD, make it faster, 性能优化, 基准测试
803m07-concurrency
CRITICAL: Use for concurrency/async. Triggers: E0277 Send Sync, cannot be sent between threads, thread, spawn, channel, mpsc, Mutex, RwLock, Atomic, async, await, Future, tokio, deadlock, race condition, 并发, 线程, 异步, 死锁
744m06-error-handling
CRITICAL: Use for error handling. Triggers: Result, Option, Error, ?, unwrap, expect, panic, anyhow, thiserror, when to panic vs return Result, custom error, error propagation, 错误处理, Result 用法, 什么时候用 panic
734rust-refactor-helper
Safe Rust refactoring with LSP analysis. Triggers on: /refactor, rename symbol, move function, extract, 重构, 重命名, 提取函数, 安全重构
721