From 4ede407c2a6e74a836ac659783caae8915b8a83e Mon Sep 17 00:00:00 2001
From: 94xhn <87560781+94xhn@users.noreply.github.com>
Date: Sat, 11 Jul 2026 13:54:21 +0800
Subject: [PATCH] fix(linker): correct several cross-toolchain memory map
inconsistencies
Found by cross-checking each example's GCC (STM32CubeIDE)/IAR (EWARM)/
Keil (MDK-ARM) linker scripts against each other and against known-good
Templates sibling projects, following the same audit already done for
STM32CubeG4/WB/WL/U5/F7 in this repo family.
1. FreeRTOS_MPU (STM324xG_EVAL, STM32F412G-Discovery,
STM32F413H-Discovery, STM32F413ZH-Nucleo): Keil's scatter file
hardcodes `LR_APP 0x08000000 0x00200000` (2MB) on all four boards,
but none of them have 2MB flash - confirmed via each board's own
GCC .ld (STM324xG_EVAL/STM32F412G-Discovery: 1MB;
STM32F413H-Discovery/STM32F413ZH-Nucleo: 1.5MB). Keil believes it
has up to 1MB more flash available than physically exists. Fixed
LR_APP's size to match each board's real flash.
2. IAP_binary_template (STM32446E_EVAL, STM32469I_EVAL,
STM324x9I_EVAL): Keil's `.uvprojx` correctly offsets the app's
start address to leave room for the bootloader, but never shrinks
the length to match - it still uses the full remaining flash as if
starting from 0, overrunning the chip's actual end of flash by
exactly the size of the reserved bootloader region. IAR/GCC in the
same projects both correctly shrink the length. Fixed Keil's
OCR_RVCT4 Size to match (STM32446E_EVAL: 512K -> 496K;
STM32469I_EVAL/STM324x9I_EVAL: 2048K -> 2016K).
3. FSMC_SRAM_DataMemory (STM324xG_EVAL, STM32F407IGH6, 1MB flash):
both GCC and IAR declare the internal ROM region as 2048K, double
the chip's real 1MB - only Keil (via its `.uvprojx`) correctly uses
1MB. This is a "2-of-3-toolchains-wrong" case; a naive majority
vote here would pick the wrong answer. Fixed GCC's `.ld` and IAR's
`.icf` (plus the GCC file's doc-comment header, which also claimed
2048K) to 1024K.
4. FreeRTOS_MPU (STM32446E_EVAL, STM32F446ZE, 512K flash): IAR's
`.icf` declares ROM_end as 0x08080000 - one byte past the end of
the chip's 512K flash (0x0807FFFF) - while GCC/Keil in the same
project and the board's own Templates icf both correctly stop at
0x0807FFFF. Fixed the off-by-one.
No local ARM toolchain (arm-none-eabi-gcc/IAR/Keil) available to
compile/link-test these changes; verification relied on
address-arithmetic cross-referencing against multiple independent
references per finding (sibling toolchain files of the same project,
Templates gold standards, and the board's real flash size).
Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com>
---
.../FreeRTOS/FreeRTOS_MPU/EWARM/stm32f446xx_flash.icf | 2 +-
.../IAP/IAP_binary_template/MDK-ARM/Project.uvprojx | 2 +-
.../IAP/IAP_binary_template/MDK-ARM/Project.uvprojx | 2 +-
.../IAP/IAP_binary_template/MDK-ARM/Project.uvprojx | 2 +-
.../FreeRTOS_MPU/MDK-ARM/STM324xG_EVAL/Exe/Project.sct | 2 +-
.../FSMC/FSMC_SRAM_DataMemory/EWARM/stm32f407xx_extsram.icf | 2 +-
.../FSMC_SRAM_DataMemory/STM32CubeIDE/STM32F407IGHX_FLASH.ld | 4 ++--
.../FreeRTOS_MPU/MDK-ARM/STM32412G_DISCOVERY/Exe/Project.sct | 2 +-
.../FreeRTOS_MPU/MDK-ARM/STM32F413H_DISCOVERY/Exe/Project.sct | 2 +-
.../FreeRTOS_MPU/MDK-ARM/STM32F413ZH_Nucleo/Exe/Project.sct | 2 +-
10 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/Projects/STM32446E_EVAL/Applications/FreeRTOS/FreeRTOS_MPU/EWARM/stm32f446xx_flash.icf b/Projects/STM32446E_EVAL/Applications/FreeRTOS/FreeRTOS_MPU/EWARM/stm32f446xx_flash.icf
index ae79b0a5ac..f2bef3e807 100644
--- a/Projects/STM32446E_EVAL/Applications/FreeRTOS/FreeRTOS_MPU/EWARM/stm32f446xx_flash.icf
+++ b/Projects/STM32446E_EVAL/Applications/FreeRTOS/FreeRTOS_MPU/EWARM/stm32f446xx_flash.icf
@@ -5,7 +5,7 @@
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
-define symbol __ICFEDIT_region_ROM_end__ = 0x08080000;
+define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF;
/*-Sizes-*/
diff --git a/Projects/STM32446E_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx b/Projects/STM32446E_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx
index 6d76cb07ff..94a0c85b1c 100644
--- a/Projects/STM32446E_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx
+++ b/Projects/STM32446E_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx
@@ -314,7 +314,7 @@
1
0x8004000
- 0x80000
+ 0x7C000
1
diff --git a/Projects/STM32469I_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx b/Projects/STM32469I_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx
index 896bd13856..0d6c8a8425 100644
--- a/Projects/STM32469I_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx
+++ b/Projects/STM32469I_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx
@@ -314,7 +314,7 @@
1
0x8008000
- 0x200000
+ 0x1F8000
1
diff --git a/Projects/STM324x9I_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx b/Projects/STM324x9I_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx
index 4a14729068..24cf78bc84 100644
--- a/Projects/STM324x9I_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx
+++ b/Projects/STM324x9I_EVAL/Applications/IAP/IAP_binary_template/MDK-ARM/Project.uvprojx
@@ -314,7 +314,7 @@
1
0x8008000
- 0x200000
+ 0x1F8000
1
diff --git a/Projects/STM324xG_EVAL/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM324xG_EVAL/Exe/Project.sct b/Projects/STM324xG_EVAL/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM324xG_EVAL/Exe/Project.sct
index 8f2aa08014..02921639a2 100644
--- a/Projects/STM324xG_EVAL/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM324xG_EVAL/Exe/Project.sct
+++ b/Projects/STM324xG_EVAL/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM324xG_EVAL/Exe/Project.sct
@@ -18,7 +18,7 @@
; | Unprivileged Data |
; ---------------------
-LR_APP 0x08000000 0x00200000 ; load region size_region
+LR_APP 0x08000000 0x00100000 ; load region size_region
{
ER_IROM_PRIVILEGED 0x08000000
{
diff --git a/Projects/STM324xG_EVAL/Examples/FSMC/FSMC_SRAM_DataMemory/EWARM/stm32f407xx_extsram.icf b/Projects/STM324xG_EVAL/Examples/FSMC/FSMC_SRAM_DataMemory/EWARM/stm32f407xx_extsram.icf
index d2706d6cc6..affe4afc28 100644
--- a/Projects/STM324xG_EVAL/Examples/FSMC/FSMC_SRAM_DataMemory/EWARM/stm32f407xx_extsram.icf
+++ b/Projects/STM324xG_EVAL/Examples/FSMC/FSMC_SRAM_DataMemory/EWARM/stm32f407xx_extsram.icf
@@ -5,7 +5,7 @@
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
-define symbol __ICFEDIT_region_ROM_end__ = 0x081FFFFF;
+define symbol __ICFEDIT_region_ROM_end__ = 0x080FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x64000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x640FFFFF;
define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000;
diff --git a/Projects/STM324xG_EVAL/Examples/FSMC/FSMC_SRAM_DataMemory/STM32CubeIDE/STM32F407IGHX_FLASH.ld b/Projects/STM324xG_EVAL/Examples/FSMC/FSMC_SRAM_DataMemory/STM32CubeIDE/STM32F407IGHX_FLASH.ld
index 1c22bf7695..c5c757f46b 100644
--- a/Projects/STM324xG_EVAL/Examples/FSMC/FSMC_SRAM_DataMemory/STM32CubeIDE/STM32F407IGHX_FLASH.ld
+++ b/Projects/STM324xG_EVAL/Examples/FSMC/FSMC_SRAM_DataMemory/STM32CubeIDE/STM32F407IGHX_FLASH.ld
@@ -6,7 +6,7 @@
** @author : Auto-generated by STM32CubeIDE
**
** @brief : Linker script for STM32F407IGHx Device from STM32F4 series
-** 2048Kbytes ROM
+** 1024Kbytes ROM
** 64Kbytes CCMRAM
** 1024Kbytes RAM
**
@@ -47,7 +47,7 @@ MEMORY
{
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x64000000, LENGTH = 1024K
- ROM (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
+ ROM (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
}
/* Sections */
diff --git a/Projects/STM32F412G-Discovery/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32412G_DISCOVERY/Exe/Project.sct b/Projects/STM32F412G-Discovery/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32412G_DISCOVERY/Exe/Project.sct
index 8f2aa08014..02921639a2 100644
--- a/Projects/STM32F412G-Discovery/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32412G_DISCOVERY/Exe/Project.sct
+++ b/Projects/STM32F412G-Discovery/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32412G_DISCOVERY/Exe/Project.sct
@@ -18,7 +18,7 @@
; | Unprivileged Data |
; ---------------------
-LR_APP 0x08000000 0x00200000 ; load region size_region
+LR_APP 0x08000000 0x00100000 ; load region size_region
{
ER_IROM_PRIVILEGED 0x08000000
{
diff --git a/Projects/STM32F413H-Discovery/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32F413H_DISCOVERY/Exe/Project.sct b/Projects/STM32F413H-Discovery/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32F413H_DISCOVERY/Exe/Project.sct
index 8f2aa08014..abdd8509ad 100644
--- a/Projects/STM32F413H-Discovery/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32F413H_DISCOVERY/Exe/Project.sct
+++ b/Projects/STM32F413H-Discovery/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32F413H_DISCOVERY/Exe/Project.sct
@@ -18,7 +18,7 @@
; | Unprivileged Data |
; ---------------------
-LR_APP 0x08000000 0x00200000 ; load region size_region
+LR_APP 0x08000000 0x00180000 ; load region size_region
{
ER_IROM_PRIVILEGED 0x08000000
{
diff --git a/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32F413ZH_Nucleo/Exe/Project.sct b/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32F413ZH_Nucleo/Exe/Project.sct
index 100b34e18f..925c70f001 100644
--- a/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32F413ZH_Nucleo/Exe/Project.sct
+++ b/Projects/STM32F413ZH-Nucleo/Applications/FreeRTOS/FreeRTOS_MPU/MDK-ARM/STM32F413ZH_Nucleo/Exe/Project.sct
@@ -18,7 +18,7 @@
; | Unprivileged Data |
; ---------------------
-LR_APP 0x08000000 0x00200000 ; load region size_region
+LR_APP 0x08000000 0x00180000 ; load region size_region
{
ER_IROM_PRIVILEGED 0x08000000
{