KeiSeiKit-1.0/_blocks/stack-embedded-stm32.md
Parfii-bot a4e667de10 KeiSeiKit-public — clean state
Single-commit clean baseline after security scrub of niche-tells,
project codenames, internal jargon, and contributor-email leaks.

Contents:
- 100 Rust crates (_primitives/_rust/)
- 37 agent manifests (_manifests/) + generated specs (_generated/)
- 67 user-invocable skills (skills/)
- 33 hooks (hooks/)
- Composition blocks (_blocks/)
- Documentation (docs/, README.md)
- TS adapter packages (_ts_packages/)
- Assembler (_assembler/)
- Roles (_roles/)
- Templates (_templates/)
- Forgejo CI (.forgejo/)

Author: Denis Parfionovich <info@greendragon.info>

License: see LICENSE.
2026-05-01 12:09:03 +08:00

32 lines
1.4 KiB
Markdown

# STACK — Embedded Rust STM32 (embassy / cortex-m)
Rust-first by default. STM32H743 is a common reference MCU.
**Crate skeleton:**
```rust
#![no_std]
#![no_main]
use embassy_executor::Spawner;
use embassy_stm32::bind_interrupts;
use defmt_rtt as _;
use panic_probe as _;
```
**HAL choice:** embassy (async, preferred for new work) OR cortex-m-rt + HAL crates (if you need full sync control). Pick one per project; no mixing.
**Memory budget (MANDATORY comment in `Cargo.toml`):**
```toml
# STM32H743ZI — flash 2 MiB, RAM 1 MiB. Current: flash 312 KiB / RAM 84 KiB.
```
Update on every commit that moves size by > 4 KiB.
**I/O rules:**
- DMA for any transfer > 32 bytes (UART, SPI, I2C, ADC bursts). Polling in ISRs bricks latency.
- Interrupt priorities EXPLICIT via `NVIC`. Default `0` = highest — two handlers at priority 0 deadlock.
- NO heap allocations in ISRs. `heapless::Vec` / `heapless::String` only, with compile-time capacity.
**Allocator:** default is NO allocator (`#![no_std]` bare). If you add `alloc`, document why — usually avoidable with `heapless`.
**Debug:** `defmt` + `probe-rs` for logging. NEVER `println!` (no stdout).
**Forbidden:** `alloc` without justification; `.unwrap()` outside `#[cfg(debug_assertions)]`; interrupt handlers > 30 LOC (move logic to a task); DMA without `'static` buffers (UB with stack buffers); flashing without `probe-rs erase` when changing memory map.