domain-embedded by zhanghandong/rust-skills
npx skills add https://github.com/zhanghandong/rust-skills --skill domain-embedded包含 Shell 命令
此技能包含可能执行系统命令的 shell 命令指令(!command``)。安装前请仔细审查。
目标配置: !cat .cargo/config.toml 2>/dev/null || echo "No .cargo/config.toml found"
第 3 层:领域约束
| 领域规则 | 设计约束 | Rust 含义 |
|---|---|---|
| 无堆 | 栈分配 | heapless,无 Box/Vec |
| 无 std | 仅核心 | #![no_std] |
| 实时性 | 可预测的时序 | 无动态分配 |
| 资源受限 | 最小内存 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 静态缓冲区 |
| 硬件安全 | 安全的外设访问 | HAL + 所有权 |
| 中断安全 | 在 ISR 中无阻塞 | 原子操作,临界区 |
RULE: 不能使用堆(无分配器)
WHY: 确定性内存,无 OOM
RUST: heapless::Vec<T, N>, 数组
RULE: 共享状态必须是中断安全的
WHY: ISR 可以在任何时候抢占
RUST: Mutex<RefCell<T>> + 临界区
RULE: 外设必须有明确的所有权
WHY: 防止冲突访问
RUST: HAL 获取所有权,单例模式
从约束到设计(第 2 层):
"需要兼容 no_std 的数据结构"
↓ m02-resource: heapless 集合
↓ 静态大小: heapless::Vec<T, N>
"需要中断安全的状态"
↓ m03-mutability: Mutex<RefCell<Option<T>>>
↓ m07-concurrency: 临界区
"需要外设所有权"
↓ m01-ownership: 单例模式
↓ m12-lifecycle: 硬件的 RAII
| 层级 | 示例 | 目的 |
|---|---|---|
| PAC | stm32f4, esp32c3 | 寄存器访问 |
| HAL | stm32f4xx-hal | 硬件抽象 |
| 框架 | RTIC, Embassy | 并发 |
| 特质 | embedded-hal | 可移植驱动程序 |
| 框架 | 风格 | 最适合 |
|---|---|---|
| RTIC | 基于优先级 | 中断驱动应用 |
| Embassy | 异步 | 复杂状态机 |
| 裸机 | 手动 | 简单应用 |
| 目的 | Crate |
|---|---|
| 运行时 (ARM) | cortex-m-rt |
| Panic 处理器 | panic-halt, panic-probe |
| 集合 | heapless |
| HAL 特质 | embedded-hal |
| 日志 | defmt |
| 闪存/调试 | probe-run |
| 模式 | 目的 | 实现 |
|---|---|---|
| no_std 设置 | 裸机 | #![no_std] + #![no_main] |
| 入口点 | 启动 | #[entry] 或 embassy |
| 静态状态 | ISR 访问 | Mutex<RefCell<Option<T>>> |
| 固定缓冲区 | 无堆 | heapless::Vec<T, N> |
#![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();
}
});
}
}
| 错误 | 领域违反 | 修复 |
|---|---|---|
| 使用 Vec | 堆分配 | heapless::Vec |
| 无临界区 | 与 ISR 竞争 | Mutex + interrupt::free |
| 在 ISR 中阻塞 | 错过中断 | 推迟到主循环 |
| 不安全的外设访问 | 硬件冲突 | HAL 所有权 |
| 约束 | 第 2 层模式 | 第 1 层实现 |
|---|---|---|
| 无堆 | 静态集合 | heapless::Vec<T, N> |
| ISR 安全 | 临界区 | Mutex<RefCell> |
| 硬件所有权 | 单例 | take().unwrap() |
| no_std | 仅核心 | #![no_std], #![no_main] |
| 何时 | 查看 |
|---|---|
| 静态内存 | m02-resource |
| 内部可变性 | m03-mutability |
| 中断模式 | m07-concurrency |
| 硬件不安全操作 | unsafe-checker |
每周安装数
450
仓库
GitHub 星标数
912
首次出现
Jan 20, 2026
安全审计
安装于
opencode408
codex394
gemini-cli389
github-copilot377
amp339
kimi-cli335
Contains Shell Commands
This skill contains shell command directives (!command``) that may execute system commands. Review carefully before installing.
Target configuration: !cat .cargo/config.toml 2>/dev/null || echo "No .cargo/config.toml found"
Layer 3: Domain Constraints
| 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 |
RULE: Cannot use heap (no allocator)
WHY: Deterministic memory, no OOM
RUST: heapless::Vec<T, N>, arrays
RULE: Shared state must be interrupt-safe
WHY: ISR can preempt at any time
RUST: Mutex<RefCell<T>> + critical section
RULE: Peripherals must have clear ownership
WHY: Prevent conflicting access
RUST: HAL takes ownership, singletons
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 | Examples | Purpose |
|---|---|---|
| PAC | stm32f4, esp32c3 | Register access |
| HAL | stm32f4xx-hal | Hardware abstraction |
| Framework | RTIC, Embassy | Concurrency |
| Traits | embedded-hal | Portable drivers |
| Framework | Style | Best For |
|---|---|---|
| RTIC | Priority-based | Interrupt-driven apps |
| Embassy | Async | Complex state machines |
| Bare metal | Manual | Simple apps |
| 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 |
| 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> |
#![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();
}
});
}
}
| 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 |
| Constraint | Layer 2 Pattern | Layer 1 Implementation |
|---|---|---|
| No heap | Static collections | heapless::Vec<T, N> |
| ISR safety | Critical sections | Mutex<RefCell> |
| Hardware ownership | Singleton | take().unwrap() |
| no_std | Core-only | #![no_std], #![no_main] |
| When | See |
|---|---|
| Static memory | m02-resource |
| Interior mutability | m03-mutability |
| Interrupt patterns | m07-concurrency |
| Unsafe for hardware | unsafe-checker |
Weekly Installs
450
Repository
GitHub Stars
912
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
opencode408
codex394
gemini-cli389
github-copilot377
amp339
kimi-cli335
平台战略框架指南:24位行业领袖教你设计、执行与扩展平台业务
670 周安装