Learn / Under the hood · guide 8 of 10

Where your code and data live

You can read the memory map, say which RAM suits which job, explain why a big program has to run from the external Quad-SPI flash, and read a linker script and a cache-coherence problem without panic.

Intermediate≈ 40 minBefore this:Clocks: from 64 MHz to 480 MHz

The STM32H750 has only 128 KB of internal flash but about 1 MB of RAM in five blocks, and the board adds 8 MB of usable SDRAM and two 64 MB Quad-SPI flash chips. This guide is the map: what sits at which address, who can reach it, and what that means for your linker script, your buffers and your caches.

You will learn
You need
  • STM32H750B-DK and a USB cable to CN14 (the ST-LINK connector)
  • STM32CubeIDE with the STM32CubeH7 firmware package (for ST’s BSP and examples)

On this board

Pulled from the datasheet tables and the board schematic. Click a pin for everything the finder knows about it.

PinBallBoard netUsed here asAFOpen
PH6T11SDRAM_SDNE1SDRAM chip select (bank 2): FMC_SDNE1AF12 FMC_SDNE1
PH7U13SDRAM_SDCKE1SDRAM clock enable (bank 2): FMC_SDCKE1AF12 FMC_SDCKE1
PG8F15SDRAM_SDCLKSDRAM clock: FMC_SDCLKAF12 FMC_SDCLK
PF10L3QSPI_CLKQuad-SPI clock, shared by both flash chipsAF9 QUADSPI_CLK
PD11R15QSPI_BK1_IO0Quad-SPI data line IO0 of the first flash (bank 1)AF9 QUADSPI_BK1_IO0
1

The whole map on one page

The Cortex-M7 sees one 4 GB address space. Code, RAM, peripherals and external memories are all just addresses. This is the part of it that matters for the STM32H750 on this board:

  • 0x00000000, 64 KB: ITCM RAM (fast code RAM)
  • 0x08000000 to 0x0801FFFF, 128 KB: internal flash (the reference manual notes that bank 1 is limited to this range on the STM32H750xB)
  • 0x20000000, 128 KB: DTCM RAM
  • 0x24000000 to 0x2407FFFF, 512 KB: AXI SRAM
  • 0x30000000 SRAM1 (128 KB), 0x30020000 SRAM2 (128 KB), 0x30040000 SRAM3 (32 KB)
  • 0x38000000, 64 KB: SRAM4, and 0x38800000, 4 KB: backup SRAM
  • 0x40000000 to 0x5FFFFFFF: peripherals (the addresses of GPIO ports, RCC and every register you have used)
  • 0x90000000 to 0x9FFFFFFF: Quad-SPI window
  • 0xC0000000 (bank 1) and 0xD0000000 (bank 2): SDRAM windows of the FMC

Add the RAMs up and you get 1056 KB: 192 KB of TCM, 864 KB of "user" SRAM. The datasheet and the user manual call this "1 Mbyte of RAM".

You met the same idea in the LED guide: GPIOJ->BSRR is a pointer into the peripheral region. Reading a register and reading a variable are the same kind of access, just to different addresses.

2

Which RAM for what

Five RAM blocks look wasteful until you see that each sits somewhere different in the chip, with different neighbours:

  • ITCM and DTCM are wired straight to the CPU. No wait states and the same timing every time. Only the CPU and the MDMA can reach them: the LTDC, DMA2D and ordinary DMAs cannot. Use DTCM for the stack and hot variables, ITCM for interrupt handlers and time-critical code.
  • AXI SRAM (512 KB) is the roomy general-purpose block on the main AXI bus. Most masters can use it, including the LTDC and DMA2D. The reference manual says it can be used for graphic objects such as frame buffers. In a CubeIDE project the linker script puts your normal variables here by default.
  • SRAM1, SRAM2, SRAM3 sit in another power domain. They are meant for DMA buffers of peripherals in that domain. SRAM3 is the one the manual points to for Ethernet and USB buffers.
  • SRAM4 (64 KB) is in the third domain and is the home of the BDMA's buffers. It can also keep data when the other domains sleep.
  • Backup SRAM (4 KB) survives Standby when a battery is on VBAT.

Rule of thumb: ordinary variables in AXI SRAM or DTCM, anything the LTDC or DMA2D touches in AXI SRAM (or SDRAM), a DMA buffer in the SRAM block of the peripheral's own domain. Whichever block you pick, check that the master that needs the memory can actually reach it.

3

The linker script: how code and data get an address

The compiler turns your C into pieces: .text (code), .rodata (constants), .data (initialised variables), .bss (zeroed variables). A linker script tells the linker which memory each piece goes to. Its first part, the MEMORY block, simply restates the memory map for your chip.

This is the MEMORY block CubeIDE generates for an STM32H750 project (the numbers match the map above):

MEMORY
{
  FLASH   (rx)  : ORIGIN = 0x08000000, LENGTH = 128K   /* internal flash */
  DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
  RAM_D1  (xrw) : ORIGIN = 0x24000000, LENGTH = 512K   /* AXI SRAM */
  RAM_D2  (xrw) : ORIGIN = 0x30000000, LENGTH = 288K   /* SRAM1 + SRAM2 + SRAM3 */
  RAM_D3  (xrw) : ORIGIN = 0x38000000, LENGTH = 64K    /* SRAM4 */
  ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
}

Tip. The build output ends with a "Memory region" table: how much of FLASH and each RAM you use. Open the generated .map file to see the address of every variable. When something is "in the wrong RAM", the map file is where you find out.

4

External memory 1: the SDRAM, 8 MB at 0xD0000000

The board carries a 128-Mbit SDRAM chip (MT48LC4M32B2) on the FMC. The FMC has two SDRAM banks and each one has its own chip-select and clock-enable pin. The schematic wires this chip to SDNE1 (PH6) and SDCKE1 (PH7): that is SDRAM bank 2, which the memory map puts at 0xD0000000.

A chip of 128 Mbit is 16 MB, but only half of it is usable here. The schematic connects data lines SDRAM_D0 to SDRAM_D15 and the byte-mask lines NBL0 and NBL1: a 16-bit data bus, although the chip has 32 data pins. With 12 row address lines, 8 column lines and 4 internal banks the reachable size is 4 × 4096 × 256 × 2 bytes = 8 MB. ST's own examples configure it that way (16-bit bus, 12 rows, 8 columns, bank 2), and ST's linker script for external SDRAM declares 8192 KB.

SDRAM is not usable straight after reset. The FMC has to be told the chip's geometry and timings, and the chip needs a start-up command sequence (clock on, precharge, refresh, mode register). That is a page of code, so most people use ST's BSP, which does it in one call. After that it is plain memory: a pointer to 0xD0000000 works like any array. A frame buffer fits easily: 480 × 272 pixels at 16 bits is 255 KB, so eight megabytes hold dozens of them.

The price is speed. SDRAM sits outside the chip, behind a 16-bit bus, and every access is slower than AXI SRAM. It is a good home for frame buffers and big images, a poor one for variables your loops hammer.

#include "stm32h750b_discovery_sdram.h"   /* from the STM32CubeH7 package (BSP) */

#define SDRAM_BASE   0xD0000000U            /* FMC SDRAM bank 2 */
#define SDRAM_BYTES  (8U * 1024U * 1024U)   /* 16-bit data bus: 8 MB reachable */

void sdram_test(void)
{
    if (BSP_SDRAM_Init(0) != BSP_ERROR_NONE) Error_Handler();   /* FMC setup + start-up sequence */

    volatile uint32_t *p = (volatile uint32_t *)SDRAM_BASE;
    uint32_t words = SDRAM_BYTES / 4U;

    for (uint32_t i = 0; i < words; i += 1024U) p[i] = 0xA5000000U ^ i;        /* write a pattern */
    for (uint32_t i = 0; i < words; i += 1024U) {                              /* read it back */
        if (p[i] != (0xA5000000U ^ i)) Error_Handler();
    }
}
5

External memory 2: two Quad-SPI flash chips at 0x90000000

The second external memory is flash: two 512-Mbit Quad-SPI NOR chips, 64 MB each. Each has its own chip-select and four data lines (bank 1 and bank 2); they share the clock QSPI_CLK (PF10).

Quad-SPI normally works like a command interface: you send a read command and an address, then clock the data in. The QUADSPI peripheral also has a memory-mapped mode: once you configure it, any read from the region starting at 0x90000000 is turned into the right flash command automatically. To the CPU the flash looks like read-only RAM, and it can also fetch instructions from it.

Two chips can be used one at a time (64 MB window) or together in dual-flash mode, where the peripheral reads a byte from each chip at the same time: twice the speed and 128 MB in one window. ST's BSP and its Template projects use the dual mode for this board; their linker script for QSPI declares 131072 KB at 0x90000000.

Writing is not memory-mapped. You erase and program through QUADSPI commands, with the flash in indirect mode. Switching between the two modes is what ST's QSPI_MemoryMappedDual example shows: erase, write, then switch to memory-mapped mode and compare.

6

Why big H750 programs run from QSPI

The STM32H750 is the "value line" part of the family. It has the same CPU and peripherals as the others but only 128 KB of internal flash. A graphics program with fonts and images is easily 1 MB. So ST designed this chip to run code from external memory. That is execute in place.

The usual recipe:

  1. A small boot program stays in the internal flash at 0x08000000. It sets up the clocks, then the QUADSPI (and the SDRAM, if you use it), switches the flash to memory-mapped mode.
  2. It jumps to your real application, linked to run at 0x90000000.
  3. The application's linker script says FLASH ORIGIN = 0x90000000 and LENGTH = 128M instead of the 128 KB at 0x08000000.

ST ships this recipe as the ExtMem_Boot template in the STM32CubeH7 package (application note AN5188 describes it, according to ST's readme). These are tools from ST, not part of the seven documents this site indexes. Programming the QSPI flash from the PC needs an external loader for the debugger or STM32CubeProgrammer: CubeProgrammer ships a file named MT25TL01G_STM32H750B-DISCO.stldr for this board. Not verified on this board: whether that loader matches its default two-chip fitting, so treat it as a pointer.

What it costs: instructions come over a four-bit bus instead of from the flash on the chip, so uncached code runs slower. The caches on the Cortex-M7 hide most of that for loops and hot code, and the first run through code is the slow one. And everything in the boot program has to be left alone afterwards: if your application reconfigures the QUADSPI that is fetching its own code, the next instruction fetch fails.

Tip. Start learning without any of this: a program under 128 KB runs from the internal flash exactly as in the LED guide. Move to QSPI when your .text outgrows the FLASH line in the build output.

7

Caches and the MPU: why a shared buffer "sometimes" shows old data

The Cortex-M7 has a 16 KB instruction cache and a 16 KB data cache. The CPU talks to the cache; the cache talks to memory. The LTDC, DMA2D and DMAs talk to memory directly, past the cache. That produces the classic H7 surprise:

  • The CPU writes a frame buffer, but the new pixels are still in the data cache. The LTDC reads the old ones from RAM. Fix: after writing, clean the cache range (SCB_CleanDCache_by_Addr).
  • DMA2D fills a buffer in RAM, but the CPU reads stale copies from its cache. Fix: invalidate the range (SCB_InvalidateDCache_by_Addr) before reading.

Buffers shared this way should start at a 32-byte boundary and have a size that is a multiple of 32, which is the cache line size. ST's readme in the ExtMem_Boot template says the same, and adds that the TCM RAMs are not cached, so they never need this.

The other fix is the MPU: mark the buffer's address range as non-cacheable and nothing needs cleaning, at the cost of slower CPU access to it. The programming manual explains cache maintenance and the MPU regions; ST's application notes AN4838 (MPU) and AN4839 (cache) are the practical guides.

If display, DMA or Ethernet data looks "almost right" but wrong in a random way, suspect the cache before anything else.

#include "stm32h7xx.h"

void caches_on(void)               /* call early in main(), after the clock setup */
{
    SCB_EnableICache();
    SCB_EnableDCache();
}

/* The CPU wrote a buffer that the LTDC / DMA2D / a DMA will read: push it out to RAM. */
void cpu_wrote_buffer(void *buf, uint32_t size)        /* buf 32-byte aligned, size multiple of 32 */
{
    SCB_CleanDCache_by_Addr((uint32_t *)buf, (int32_t)size);
}

/* Hardware wrote a buffer that the CPU will read: throw away stale cache lines. */
void hardware_wrote_buffer(void *buf, uint32_t size)
{
    SCB_InvalidateDCache_by_Addr((uint32_t *)buf, (int32_t)size);
}

Common mistakes

  • Pointing the LTDC or DMA2D at DTCM or ITCM. Those RAMs are reachable only by the CPU and the MDMA, so the transfer fails or reads nothing. Use AXI SRAM or SDRAM.
  • Believing the SDRAM is 16 MB. The chip is, but the board wires a 16-bit data bus, so ST’s examples and linker scripts use 8 MB. ST’s BSP header still defines SDRAM_DEVICE_SIZE as 16 MB: do not trust that constant for the size.
  • Using the BSP SDRAM and QSPI timings unchanged after raising the AHB clock. ST’s examples run the AHB at 200 MHz and set the SDRAM clock to half of it (100 MHz). At the 240 MHz AHB from the clocks guide that is 120 MHz, and the cycle counts in the timing registers no longer match the chip’s datasheet times. The SDRAM datasheet is not among the documents on this site; check it, or divide the FMC clock by 3.
  • Forgetting cache maintenance on a shared buffer, or aligning it badly. The symptom is data that is right most of the time. Align to 32 bytes.
  • Reconfiguring or de-initialising the QUADSPI from the application while it is the source of the running code.
  • Putting a big array in a default .bss and being surprised the program no longer fits. Check the "Memory region" table after every build.

Check yourself

Try to answer before opening. If you get stuck, the pages linked above have the answer.

The LTDC needs a 261,120-byte frame buffer (480 × 272 × 2 bytes). Name two places on this board where it can live, and one that will not work.

It fits in the 512 KB AXI SRAM at 0x24000000 and in the SDRAM at 0xD0000000. It will not work in DTCM (0x20000000): the LTDC cannot reach the TCM RAMs, and 128 KB would not be enough anyway.

Which SDRAM chip-select does the board use, and what address does that give?

The schematic wires SDRAM_SDNE1 (PH6) and SDRAM_SDCKE1 (PH7). That is the FMC SDRAM bank 2, which the memory map places at 0xD0000000. Bank 1 would be at 0xC0000000.

Your application is 600 KB. What do you change so it can be flashed and run?

It cannot fit in the 128 KB internal flash. Link it to run from the Quad-SPI region at 0x90000000 (FLASH ORIGIN in the linker script), flash it to the QSPI chips with an external loader, and keep a small boot program in internal flash that enables memory-mapped mode and jumps there (ST’s ExtMem_Boot template does this).

You enabled the D-cache and now the LTDC shows old pixels even though your drawing code ran. What is the likely cause and the fix?

The new pixels are still in the CPU’s data cache; the LTDC reads RAM. Clean the cache range of the frame buffer after drawing (SCB_CleanDCache_by_Addr), or place the buffer in a region the MPU marks non-cacheable.

Reading list

Every page this guide sent you to, by document. Reading them in order is a good revision.

RM0433RM0433 reference manual (STM32H742/743/753/750)p.130p.136p.137p.802p.859p.879
DS12556STM32H750xB datasheetp.22p.23p.24p.52
UM2488UM2488 STM32H745I/H750B-DK Discovery kit user manualp.2p.15
PM0253PM0253 Cortex-M7 programming manualp.32p.221p.240p.245
MB1381MB1381 Discovery board schematic (H750XB variant)sheet 9sheet 11

Search next

Each of these opens the finder with pins, registers, schematic hits and document pages for the term.

Where to go next