0x40020010 embedded config_error ai_generated true

DMA:传输对齐错误,源缓冲区未对齐到4字节边界

DMA: transfer alignment error, source buffer not aligned to 4-byte boundary

ID: embedded/dma-transfer-alignment-error

其他格式: JSON · Markdown 中文 · English
87%修复率
82%置信度
1证据数
2024-04-22首次发现

版本兼容性

版本状态引入弃用备注
STM32F767 HAL 1.16.0 active
ARM GCC 12.2.1 active

根因分析

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

English

DMA controller requires source address to be aligned to transfer size (e.g., 4 bytes for word transfer), but input buffer is misaligned due to compiler packing or stack allocation.

generic

官方文档

https://www.st.com/resource/en/reference_manual/dm00124865-stm32f7-series-reference-manual-stmicroelectronics.pdf

解决方案

  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);

无效尝试

常见但无效的做法:

  1. 70% 失败

    Adding __attribute__((aligned(4))) to variable declaration does not fix dynamic allocations; heap buffers may still be misaligned.

  2. 80% 失败

    Changing DMA transfer size to byte mode works but reduces performance and may cause data corruption if hardware expects word alignment.