STM32CubeMX generates incorrect linker script for BKPRAM (backup RAM) via Memory Management Tool
STM32CubeMX generates incorrect linker script for BKPRAM (Backup RAM) via Memory Management Tool
Environment
- STM32CubeMX: v6.17.0, see "Memory Management" (Tools > Memory Management)
- MCU: STM32H523RETx
- Toolchain: STM32CubeIDE - GNU Tools for STM32 (14.3.rel1)
Applied Memory Setup (screenshot):

STM32CubeMX generates 3 linker scripts (STM32H523RETX_FLASH.ld, STM32H523RETX_FLASH_MMT_TEMPLATE.ld, STM32H523RETX_RAM.ld). The STM32H523RETX_FLASH_MMT_TEMPLATE.ld is used in the generated STM32CubeIDE project output.
Issue 1: BKPRAM memory region has incorrect x (execute) permission
Generated linker script contains:
BKPRAM (xrw) : ORIGIN = 0x40036400, LENGTH = 2K
The x (executable) flag is incorrect. BKPSRAM is a data-only backup memory — it is not executable. According to RM0481 sec. 2.3, BKPSRAM is accessible only via the system bus (S-AHB), not the code bus (C-AHB). Marking it executable is misleading and may cause incorrect MPU configuration.
Expected:
BKPRAM (rw) : ORIGIN = 0x40036400, LENGTH = 2K
Issue 2: .BKPRAM section is missing the (NOLOAD) keyword
Generated linker script contains:
.BKPRAM :
{
. = ALIGN(4);
KEEP (*(.BKPRAM))
. = ALIGN(4);
} >BKPRAM
The (NOLOAD) keyword is missing. Without it, the GCC linker creates a load memory address (LMA) in flash and the startup code attempts to copy BKPRAM contents from flash to address 0x40036400 at boot. This fails because:
- BKPSRAM at 0x40036400 is a peripheral-bus-mapped memory — it cannot be accessed via the C-AHB code bus used during the startup copy
- The DBP bit (PWR_DBPCR) and BKPRAM clock (RCC) are not yet enabled at the time of the startup copy
- BKPSRAM is intended to retain data across resets — overwriting it at startup defeats its purpose
Expected:
.BKPRAM (NOLOAD) :
{
. = ALIGN(4);
KEEP (*(.BKPRAM))
. = ALIGN(4);
} >BKPRAM
NOLOAD is the correct GCC linker keyword to mark a section as not initialized from flash.
Impact
Both issues affect the generated file STM32H523RETX_FLASH_MMT_TEMPLATE.ld. Using the generated linker script without manual correction results in a HardFault or a failed debug session when BKPRAM variables are declared with __attribute__((section(".BKPRAM"))).
Could you please advise whether there is a way to configure STM32CubeMX to generate the correct linker script content? If not, please report these these two issues as a bug.
Thank you in advance.
Regards, Vit
