STM32H7 DMA Buffers in DTCM: Why Transfers Fail and How to Fix the Linker Script

2026-12-02 · Davide Carrese
STM32 · STM32H7 · DMA · Linker Script · Firmware Debugging

You enable DMA on an STM32H7 and nothing arrives: the receive buffer stays empty, a UART or SPI transfer ends with HAL_DMA_ERROR_TE, or an ADC reports overruns. The same code worked on an F4. In many cases the DMA configuration is fine and the buffer simply lives in DTCM, a memory that DMA1 and DMA2 cannot reach. This article shows how to recognise it, prove it in thirty seconds, and fix it in the linker script without breaking cache coherency.

The symptom

The exact failure depends on the peripheral, which is why it takes so long to find. Typical reports on the ST Community for DMA1/DMA2 on STM32H7 are:

What they share: the project builds, the peripheral configuration looks identical to a working F4 project, and the failure is deterministic. The first thing to look at is not the DMA registers but the address of the buffer.

Root cause: DMA1/DMA2 are in D2, and DTCM is private to the core

STM32H7 (the dual-domain parts such as STM32H743/H753, RM0433) has several RAMs with different owners. ST's FAQ "DMA is not working on STM32H7 devices" summarises which DMA can reach what:

ControllerDomainCan access
DMA1, DMA2D2Almost everything except ITCM and DTCM
BDMAD3Only SRAM4 and backup SRAM
MDMAD1All memories, including ITCM and DTCM

For the STM32H743 the memory map is, per the datasheet and RM0433:

MemoryAddressSizeDMA1/DMA2
ITCM RAM0x0000000064 KBNo
DTCM RAM0x20000000128 KBNo
AXI SRAM (D1)0x24000000512 KBYes
SRAM1/2/3 (D2)0x30000000128 + 128 + 32 KBYes (preferred)
SRAM4 (D3)0x3800000064 KBBDMA's memory

The TCMs are connected directly to the Cortex-M7 core, not to the bus matrix that the D2 DMA masters use. A DMA access to 0x2000xxxx therefore is not routed to a RAM the DMA can see and ends in a bus error, which the DMA reports as a transfer error (as reported in the ST Community threads below). HAL does not check buffer addresses, so HAL_UART_Transmit_DMA() happily accepts a pointer the controller cannot use.

Other H7 variants (single-core H72x/H73x with RM0468, H7S, dual-core H745) have different memory maps and different bus-master tables. ST Community threads even point out an error in the RM0468 system architecture table, so for any part other than H743/H753 check the bus-matrix table in your reference manual rather than copying addresses from this article.

Why your buffer ends up in DTCM

You never wrote "put this in DTCM". The linker did it for you. ST's FAQ lists "memory placed in DTCM RAM" as a common cause because DTCM is often the default RAM in generated projects and examples. Check your own .ld: if .data, .bss and the heap/stack section end with >DTCMRAM (the region name in ST-generated scripts), every object below is in DTCM:

Confirm it in thirty seconds

Do not read DMA registers first. Print or watch the address.

  1. In the debugger, evaluate the buffer pointer you pass to HAL. If it starts with 0x2000 (or 0x0000), you are done.
  2. Or ask the toolchain: arm-none-eabi-nm -n firmware.elf | grep -i dma and look at the addresses of your buffers, or open the .map file.
  3. Confirm on the hardware: with the stream enabled, read DMA_SxM0AR. If it holds a 0x2000xxxx value and the transfer-error flag is set, the diagnosis is certain.

A compile-time-independent guard is a small run-time check you call in every _DMA() wrapper. This one is specific to H743-class parts and lists only the RAMs DMA1/DMA2 can use; adjust the ranges to your device:

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

/* STM32H743: AXI SRAM (D1) and SRAM1..3 (D2), per RM0433 memory map.
   DTCM (0x20000000) and ITCM (0x00000000) are deliberately excluded. */
static bool dma12_can_reach(const void *p, size_t len)
{
    uintptr_t a = (uintptr_t)p;
    uintptr_t e = a + len;               /* one past the end */
    if (len == 0U) return false;
    if (a >= 0x24000000UL && e <= 0x24080000UL) return true; /* AXI SRAM 512 KB */
    if (a >= 0x30000000UL && e <= 0x30048000UL) return true; /* SRAM1+2+3 288 KB */
    return false;
}

#define DMA_BUF_CHECK(p, n)  do { if (!dma12_can_reach((p), (n))) { __BKPT(0); } } while (0)

The sizes add up as follows: 0x24000000 + 0x80000 (512 KB) = 0x24080000; SRAM1 + SRAM2 + SRAM3 = 128 + 128 + 32 = 288 KB = 0x48000, so the end is 0x30048000. This assumes the three D2 SRAMs are contiguous as in the H743 map.

⚠ Moving the buffer is only half of it

AXI SRAM is cacheable. As soon as the buffer is outside DTCM, the D-cache comes into play and you can swap one invisible failure for another (stale reads, lost writes). Apply the cache maintenance or MPU rules from STM32H7 D-Cache Coherency as well.

The fix: a dedicated DMA section in D2 RAM

The least invasive fix, also the one ST describes, is a separate output section mapped to a DMA-reachable region and a section attribute on the buffers that need it. In the linker script, inside SECTIONS, with the region names of the ST-generated script (RAM_D2 is SRAM1..3 at 0x30000000; check that your script defines it):

  .dma_buffer (NOLOAD) :
  {
    . = ALIGN(32);
    *(.dma_buffer)
    *(.dma_buffer*)
    . = ALIGN(32);
  } >RAM_D2

NOLOAD keeps the section out of the flash image: it is not initialised and not zeroed by the standard startup code, which only handles .data and .bss. Treat these buffers as uninitialised memory. The 32-byte alignment is the Cortex-M7 cache line size, needed for the maintenance operations below.

In C:

#define DMA_BUFFER  __attribute__((section(".dma_buffer"), aligned(32)))

DMA_BUFFER static uint8_t uart_rx[256];   /* 256 is a multiple of 32 */

void start_rx(UART_HandleTypeDef *huart)
{
    DMA_BUF_CHECK(uart_rx, sizeof uart_rx);
    HAL_UART_Receive_DMA(huart, uart_rx, sizeof uart_rx);
}

Keep the size a multiple of the cache line, otherwise a neighbouring variable shares the line with the DMA buffer and invalidation can discard its data.

Variant: move the whole RAM

If your application does not use the D-cache, or you accept the cost, you can replace DTCMRAM with RAM_D1 in the > target of .data, .bss and the heap/stack section. ST's FAQ describes this. Everything, including stack and heap, is then DMA-reachable, but you lose DTCM's zero-wait-state determinism for the stack and hot variables. If the initial stack pointer is defined by a separate _estack symbol, it has to move with the stack section. I prefer the dedicated section, because the fast memory stays where the CPU needs it.

Variant: the heap and RTOS objects

Variant: use MDMA

MDMA reaches DTCM, and it can be chained with DMA1/DMA2, but ST Community answers describe this as complicated. I would use it only when DTCM placement is a hard requirement.

Check that the destination RAM is clocked

The D2 SRAMs have their own clock enables in the RCC AHB2 enable register (RM0433, RCC section; the HAL macro names, __HAL_RCC_D2SRAM1_CLK_ENABLE() or __HAL_RCC_SRAM1_CLK_ENABLE(), depend on the HAL version, so grep your stm32h7xx_hal_rcc_ex.h). If the clock is off, accesses to the section do not behave as RAM. Enable the clocks early, before any D2 RAM is touched. Be especially careful if you also put .bss or .data in D2 RAM, because the startup code zeroes .bss before main(). I could not verify the reset state and clock requirements for every H7 part, so confirm this for your device.

Verify and guard against regression

Practical checklist

How I would approach this on a client project

On a new H7 board I look at the linker script and the map file before writing any peripheral code, and I decide on a memory plan: what goes in DTCM (stack, hot state, RTOS kernel objects), what goes in AXI SRAM (large buffers, framebuffers), what goes in D2 SRAM (DMA buffers), and which regions are non-cacheable through the MPU. I put that plan in the repository next to the linker script, so that the next engineer does not have to rediscover it. I add the address assert in the DMA wrappers from the start, since the cost is a few instructions in debug builds, and I make the CI fail when a DMA buffer symbol lands in the wrong region. If the project is already showing mysterious DMA failures, checking the buffer addresses is the first thing I do, before touching the peripheral configuration.

Sources

💬 Comments by email

Reply to this article by email — I read and respond to every message.