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.yaml
```

## Suite & 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: 0
```

## CI 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.yaml
```

## Troubleshooting 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. |

## Related boards & component twins

[Board: nucleo-h743zi2](https://circuittwin.ai/boards/nucleo-h743zi2) [Board: nucleo-f767zi](https://circuittwin.ai/boards/nucleo-f767zi) [Board: teensy-4-1](https://circuittwin.ai/boards/teensy-4-1) [Twin: W25Q128JV](https://circuittwin.ai/twins/w25q128jv) [Twin: ST7789](https://circuittwin.ai/twins/st7789) [Twin: LAN8720A](https://circuittwin.ai/twins/lan8720a) [STM32H7 CI guide](https://circuittwin.ai/guides/stm32h7-digital-twin-ci)

## More in Fault Injection & Debugging

[I2C NACK and stuck-bus fault injection in CI](https://circuittwin.ai/guides/i2c-nack-fault-injection) [SPI bus fault testing and chip-select verification](https://circuittwin.ai/guides/spi-bus-fault-testing) [Debugging UART baud mismatches and framing errors](https://circuittwin.ai/guides/uart-baud-mismatch-debugging) [Cortex-M HardFault triage in CI and reverse GDB](https://circuittwin.ai/guides/cortex-m-hardfault-ci-triage)

> ## Run this workflow on your own ELF
>
> Start free on CircuitTwin to run local board twins, fault matrices and CI checks with zero per-run credits.
>
> [Start now](https://app.circuittwin.ai/try) [Read the quickstart](https://circuittwin.ai/docs/quickstart) [Connect a coding agent](https://circuittwin.ai/docs/agents)
