Fault Injection & Debugging
Preventing Cortex-M7 D-Cache and DMA coherency bugs
DMA bypasses the Cortex-M7 L1 data cache. Missing cache maintenance or MPU non-cacheable regions silently corrupts packets.
Cortex-M7 devices (STM32F767, STM32H743, Teensy 4.1 i.MX RT1062) add a 32-byte-line L1 D-Cache. When you enable SCB_EnableDCache(), TX DMA sends stale SRAM values unless you clean the cache, and RX DMA writes are invisible until you invalidate.
Use MPU regions over a dedicated .dma_buffer linker section or align every DMA buffer to 32 bytes, then gate your compiled ELF in CI with deterministic DMA transfer assertions.
Cortex-M7 cache rules for DMA
| DMA direction | Required cache op | Failure if omitted |
|---|---|---|
Memory -> Peripheral (TX) | SCB_CleanDCache_by_Addr() before start | Peripheral transmits old SRAM contents |
Peripheral -> Memory (RX) | SCB_InvalidateDCache_by_Addr() after complete | CPU reads stale cache line instead of new RX bytes |
Adjacent variables | Align buffer start & size to 32 bytes | Invalidate wipes neighbor struct in same cache line |
Local CLI workflow
Shell - test Cortex-M7 DMA binary in CI
ct test run --json --recheck tests/m7-dma-coherency.suite.yamlSuite & fault configuration
tests/m7-dma-coherency.suite.yaml
version: 1
board: nucleo-h743zi2
firmware: build/h7_dma_app.elf
tests:
- name: spi-dma-rx-payload-integrity
timeout_ms: 2000
expect:
console_contains: "DMA_CRC_MATCH"
exit_code: 0CI pipeline integration
.github/workflows/m7-dma-ci.yml
name: Cortex-M7 DMA CI
on: [push, pull_request]
jobs:
m7-dma:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cmake --build build
- uses: circuittwin/action@v1
with:
suite: tests/m7-dma-coherency.suite.yamlTroubleshooting checklist
| Symptom | Fix |
|---|---|
| Neighboring globals reset to old values after RX DMA | Pad every DMA buffer with __attribute__((aligned(32))) and round buffer length up to a multiple of 32 bytes. |
| STM32H7 DMA fails to access DTCM RAM (0x20000000) | DMA1/DMA2 cannot reach DTCM on STM32H7; place DMA buffers in AXI SRAM (0x24000000) or D2 SRAM (0x30000000). |
Frequently asked questions
| Question | Answer |
|---|---|
| Why cannot STM32H7 DMA1 or DMA2 read from DTCM RAM? | DTCM (0x20000000) connects directly to the Cortex-M7 core and is not routed on the D2 AHB bus matrix used by DMA1/DMA2. Move DMA buffers to AXI SRAM or SRAM1/2/3. |