Advanced STM32 Peripherals Design
This document describes the architectural approach for supporting complex STM32 systems in LabWired, focusing on DMA, EXTI, and AFIO.
Direct Memory Access (DMA)
LabWired implements DMA using a two-phase request/execute model to maintain architectural modularity and comply with Rust's ownership rules.
Design Principles
- Decoupling: The DMA controller is a standard
Peripheral. It doesn't have direct access to theSystemBusto avoid circular dependencies. - Request-Based Mastering: During its
tick(), a peripheral (like DMA) returns a list ofDmaRequestobjects. - Bus Execution: The
SystemBusexecutes these requests after the peripheral tick phase, effectively acting as the "arbiter".
Execution Flow
- Phase 1: Tick:
SystemBuscallstick()on all peripherals. - Phase 2: Collect:
SystemBusaggregates allDmaRequests returned by peripherals. - Phase 3: Execute:
SystemBusperforms the memory operations (Read/Write) requested by the DMA.
sequenceDiagram
participant B as SystemBus
participant D as DMA Peripheral
participant R as RAM / Peripheral
B->>D: tick()
D-->>B: Vec<DmaRequest>
loop Each Request
B->>R: read_u8/write_u8
end
External Interrupts (EXTI) & AFIO
EXTI and AFIO work together to map GPIO signals to processor interrupts.
EXTI Mapping
EXTI handles 16 lines corresponding to GPIO pins 0-15. - Line 0: GPIOA pin 0, GPIOB pin 0, etc. (selected via AFIO) - Lines 16-19: Specific events (PVD, RTC, USB, etc.)
Implementation Strategy
- Signal Propagation: Peripherals can now emit signals or trigger other peripherals via a
SignalBus(future enhancement) or direct wiring inSystemBus. - Configurable Mapping: AFIO registers define which GPIO port maps to which EXTI line.
Current Support Status
| Feature | Status | Notes |
|---|---|---|
| DMA Mastering | [x] Implemented | Two-phase execution in SystemBus. |
| EXTI Controller | [ ] Planned | Standard STM32F103 mapping. |
| AFIO Remapping | [ ] Planned | Basic pin mapping support. |