# DMA：传输对齐错误，源缓冲区未对齐到4字节边界

- **ID:** `embedded/dma-transfer-alignment-error`
- **领域:** embedded
- **类别:** config_error
- **错误码:** `0x40020010`
- **验证级别:** ai_generated
- **修复率:** 87%

## 根因

DMA控制器要求源地址与传输大小对齐（例如，字传输为4字节），但输入缓冲区因编译器打包或堆栈分配而未对齐。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| STM32F767 HAL 1.16.0 | active | — | — |
| ARM GCC 12.2.1 | active | — | — |

## 解决方案

1. ```
   Allocate source buffer with alignment attribute: uint8_t buffer[256] __attribute__((aligned(4)));
   ```
2. ```
   Use memalign or posix_memalign for heap allocation: uint8_t *buf = memalign(4, 256);
   ```

## 无效尝试

- **** — Adding __attribute__((aligned(4))) to variable declaration does not fix dynamic allocations; heap buffers may still be misaligned. (70% 失败率)
- **** — Changing DMA transfer size to byte mode works but reduces performance and may cause data corruption if hardware expects word alignment. (80% 失败率)
