no_std · embedded-hal · RTIC · embassy

Rust 嵌入式开发

用内存安全、零成本抽象的 Rust 写裸机固件。
no_std 工具链、PAC、类型状态 GPIO、RTIC、async embassy、DMA 安全、defmt,12 章从原理到实战。

12 章节 Cortex-M / RISC-V / ESP32 no_std 裸机 RTIC + embassy 并发 probe-rs + defmt 调试
课程目录
Chapter 01
为何用 Rust 做嵌入式
内存安全无 GC、零成本抽象、所有权防数据竞争、vs C 的对比、embedded-hal/RTIC/embassy 生态、目标平台,写下第一个 blinky。
内存安全 零成本抽象 blinky
Chapter 02
no_std 与工具链
std vs no_std、core/alloc、rustup target add、cargo-binutils、链接脚本 memory.x、cortex-m-rt 启动、#[entry]、panic handler、cargo flash。
no_std cortex-m-rt memory.x
Chapter 03
PAC 与 svd2rust
Peripheral Access Crate、SVD 文件、寄存器类型安全访问、read/write/modify 闭包、位段 API、vs C 裸指针操作寄存器。
PAC svd2rust 寄存器
Chapter 04
embedded-hal 生态
HAL trait 抽象层、平台无关驱动、OutputPin/InputPin/DelayNs/SPI/I2C trait、驱动 crate 复用、stm32f4xx-hal 示例。
embedded-hal trait 驱动复用
Chapter 05
GPIO 与基础外设
类型状态模式 typestate、引脚模式编译期检查、点灯/按键、Delay、split() 所有权拆分,非法配置无法通过编译。
GPIO typestate 编译期检查
Chapter 06
中断与 RTIC 框架
Cortex-M 中断、cortex-m-rt 中断处理、临界区 critical-section、RTIC 框架(资源/任务/优先级)、编译期数据竞争检查。
中断 RTIC critical-section
Chapter 07
所有权在裸机中的应用
Send/Sync、静态可变全局的安全封装、Mutex<RefCell>、Peripheral 单例、move 语义在 ISR/main 间共享数据。
Send/Sync Mutex 单例
Chapter 08
异步嵌入式 embassy
async/await 在 no_std、embassy 执行器、Timer::after、async 外设、多任务 #[embassy_executor::task]、vs RTOS。
async embassy executor
Chapter 09
内存、堆栈与 alloc
无堆默认、栈布局、heapless(Vec/String/Queue 固定容量)、可选 alloc + 全局分配器、栈溢出保护 flip-link。
heapless alloc 栈溢出
Chapter 10
DMA 与并发安全
DMA 传输所有权转移、'static 生命周期约束、双缓冲、embedded-dma trait、类型系统防止 DMA 期间访问缓冲区。
DMA 双缓冲 'static
Chapter 11
调试:probe-rs 与 defmt
probe-rs 生态、cargo embed、RTT、defmt 高效日志、defmt-rtt、断点调试 GDB、panic 定位与栈回溯。
probe-rs defmt RTT
Chapter 12
实战:异步环境监测节点
综合项目:embassy 异步架构,I2C 读传感器 + 串口上报 + LED 状态,完整 Cargo.toml/代码/架构图/部署 checklist。
实战 embassy I2C 部署
⚒️ 配套开发者工具箱 · JSON / 正则 / 时间戳 / Cron 等 17 款免费在线工具