# SPI DMA：缓冲区地址0x2000FF01未对齐，数据传输中止

- **ID:** `embedded/spi-dma-misaligned-buffer`
- **领域:** embedded
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

DMA缓冲区地址未对齐到DMA控制器要求的边界（通常为4或16字节），导致传输错误或总线故障。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| STM32H743 | active | — | — |
| ARM Cortex-M7 r1p1 | active | — | — |
| HAL_DMA v2.2.0 | active | — | — |

## 解决方案

1. ```
   Allocate DMA buffers using aligned memory macros. For GCC, use __attribute__((aligned(16))). For CMSIS, use DMA_BUFFER_ALIGNED.
   ```
2. ```
   Use dynamic memory allocation from a dedicated aligned heap, e.g., pvPortMallocAligned from FreeRTOS or memalign.
   ```

## 无效尝试

- **Use memcpy to copy data to a temporary buffer before DMA transfer** — Adds latency and memory overhead; if the temporary buffer is also not aligned due to compiler padding, the error persists. (50% 失败率)
- **Disable DMA and use polling SPI instead** — Reduces throughput significantly and may cause CPU starvation in high-speed applications. (80% 失败率)
- **Change DMA FIFO threshold to bypass alignment check** — FIFO threshold does not affect address alignment requirements; misalignment still causes AHB bus error. (95% 失败率)
