From 51ef3b2d96b356908ee887697e8eb54ceb11338f Mon Sep 17 00:00:00 2001 From: 94xhn <87560781+94xhn@users.noreply.github.com> Date: Sat, 11 Jul 2026 18:44:48 +0800 Subject: [PATCH] fix(linker): correct cross-toolchain memory map inconsistencies Cross-checked GCC (STM32CubeIDE .ld), IAR (EWARM .icf) and Keil (MDK-ARM .uvprojx OCR_RVCTx) memory declarations against each other and against the true per-device Flash/RAM capacity (verified from each board's own Templates/TrustZoneDisabled project). Fixed 8 confirmed drift bugs across 6 boards: 1. STM32H5F5J-DK/Applications/OpenBootloader GCC .ld reserved 90K Flash for the bootloader while IAR .icf and the enabled Keil OCR_RVCT4 both reserve 70K (0x11800), matching the established OpenBootloader footprint convention used elsewhere in ST's Cube ecosystem (e.g. STM32CubeU5/B-U585I-IOT02A also uses 70K). Reduced GCC's declared length to 70K. 2. NUCLEO-H563ZI/Examples/FLASH/FLASH_SwapBanks GCC .ld declared the full 2048K (2MB) Flash region for a single bank image, while IAR .icf and the enabled Keil OCR_RVCT4 both correctly reserve only 1024K (one bank of the 2MB dual-bank device), matching the analogous FLASH_SwapBanks example on NUCLEO-H5E5ZJ where all three toolchains agree on half the flash per bank. Reduced GCC's ROM length to 1024K. 3. NUCLEO-H503RB/Examples/RAMCFG/RAMCFG_WriteProtection GCC .ld declared only 10K RAM while IAR .icf and Keil (enabled OCR_RVCT9) both declare the full 32K RAM available on this device. The equivalent example on sibling boards (NUCLEO-H533RE, NUCLEO-H563ZI) also declares the full per-device RAM in its GCC linker script, confirming 10K is a stray/incorrect value. Raised GCC's RAM length to 32K. 4. NUCLEO-H563ZI/Examples/RAMCFG/RAMCFG_ECC_Error_Generation Same pattern as #3: GCC .ld declared only 100K RAM while IAR/Keil declare the full 640K RAM of the device, and the same example on NUCLEO-H533RE/NUCLEO-H5E5ZJ declares full RAM in GCC too. Raised GCC's RAM length to 640K. 5. STM32H573I-DK/Applications/FileX/FX_IAP/IAP_binary_template This IAP application image is linked to start mid-flash at 0x08100000 (after a bootloader region). GCC .ld and the enabled Keil OCR_RVCT4 both declared a 2048K (2MB) length from that offset, which extends to 0x08300000 -- 1MB past the device's actual flash end at 0x08200000 (2MB total flash from 0x08000000). Only IAR .icf correctly bounds the region at 0x081FFFFF (1024K remaining). This is the classic "offset correctly shifted, length not shrunk to match" IAP bug pattern. Reduced both GCC and Keil to 1024K. 6. NUCLEO-H553ZG: 5 Keil applications (Fx_File_Edit_Standalone, Nx_UDP_Echo_Client, Nx_UDP_Echo_Server, Tx_LowPower, Tx_Thread_Creation) These .uvprojx files declare IROM/OCR_RVCT4 = 4096K Flash and IRAM/OCR_RVCT9 = 1536K RAM -- the memory profile of a different, larger H5 device (matches STM32H5E5ZJ/H5F5J exactly). The actual NUCLEO-H553ZG device has 1024K Flash / 304K RAM, confirmed by this board's own Templates/TrustZoneDisabled, Templates_Board, Templates_LL and every USBX example on the same board (all correctly use IROM=0x100000, IRAM=0x4c000), and matching GCC's own .ld for these same 5 applications. A Keil build of any of these 5 apps would link successfully against phantom Flash/RAM addresses that do not exist on the real NUCLEO-H553ZG hardware. Corrected the Cpu device-map string, IRAM/IROM defaults and OCR_RVCT4/OCR_RVCT9 to the verified 1024K/304K values. 7. STM32H573I-DK: Nx_Iperf_wifi and Nx_Network_Basics_wifi GCC .ld and IAR .icf both expose the device's full 640K RAM as one contiguous region. In these two Keil projects the equivalent OCR_RVCT6/OCR_RVCT7 entries already describe the correct continuation banks (0x20040000+64K, 0x20050000+320K, together with OCR_RVCT9's 256K completing exactly 640K) but Ra1Chk/Ra2Chk were left disabled, so Keil only linked against the first 256K bank. Every other NetXDuo example on this same board (Nx_MQTT_Client, Nx_TCP_Echo_Client/Server, Nx_WebServer) instead exposes the full 640K as a single IRAM entry and is unaffected. Enabled Ra1Chk/Ra2Chk to restore access to the full 640K RAM, matching GCC/IAR and the sibling examples. Not fixed (documented, left as-is): STM32H573I-DK/Applications/OpenBootloader: GCC .ld uses the full 2048K/640K (clearly an un-customized copy of the generic Template), while IAR (64K Flash/64K RAM) and Keil (128K Flash/64K RAM) agree on RAM but disagree with each other on the exact reserved Flash size. Left untouched: no reliable way to determine whether 64K or 128K is the intended bootloader Flash footprint without ST engineering input, and this project touches the TrustZone-adjacent secure-alias OCR entries, so an incorrect guess here carries more risk than benefit. Signed-off-by: 94xhn <94xhn1@gmail.com> Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com> --- .../STM32CubeIDE/STM32H503RBTX_FLASH.ld | 2 +- .../MDK-ARM/Fx_File_Edit_Standalone.uvprojx | 10 +++++----- .../MDK-ARM/Nx_UDP_Echo_Client.uvprojx | 10 +++++----- .../MDK-ARM/Nx_UDP_Echo_Server.uvprojx | 10 +++++----- .../ThreadX/Tx_LowPower/MDK-ARM/Tx_LowPower.uvprojx | 10 +++++----- .../MDK-ARM/Tx_Thread_Creation.uvprojx | 10 +++++----- .../STM32CubeIDE/STM32H563ZITX_FLASH.ld | 2 +- .../STM32CubeIDE/STM32H563ZITX_FLASH.ld | 2 +- .../MDK-ARM/IAP_binary_template.uvprojx | 2 +- .../STM32CubeIDE/STM32H573IIKXQ_FLASH.ld | 2 +- .../Nx_Iperf_wifi/MDK-ARM/Nx_Iperf_wifi.uvprojx | 4 ++-- .../MDK-ARM/Nx_Network_Basics_wifi.uvprojx | 4 ++-- .../STM32CubeIDE/STM32H5F5LJHXQ_FLASH.ld | 2 +- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Projects/NUCLEO-H503RB/Examples/RAMCFG/RAMCFG_WriteProtection/STM32CubeIDE/STM32H503RBTX_FLASH.ld b/Projects/NUCLEO-H503RB/Examples/RAMCFG/RAMCFG_WriteProtection/STM32CubeIDE/STM32H503RBTX_FLASH.ld index 9eb61e314..45d8a4c38 100644 --- a/Projects/NUCLEO-H503RB/Examples/RAMCFG/RAMCFG_WriteProtection/STM32CubeIDE/STM32H503RBTX_FLASH.ld +++ b/Projects/NUCLEO-H503RB/Examples/RAMCFG/RAMCFG_WriteProtection/STM32CubeIDE/STM32H503RBTX_FLASH.ld @@ -44,7 +44,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Memories definition */ MEMORY { - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 10K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K } diff --git a/Projects/NUCLEO-H553ZG/Applications/FileX/Fx_File_Edit_Standalone/MDK-ARM/Fx_File_Edit_Standalone.uvprojx b/Projects/NUCLEO-H553ZG/Applications/FileX/Fx_File_Edit_Standalone/MDK-ARM/Fx_File_Edit_Standalone.uvprojx index 391a98961..d240ba9bc 100644 --- a/Projects/NUCLEO-H553ZG/Applications/FileX/Fx_File_Edit_Standalone/MDK-ARM/Fx_File_Edit_Standalone.uvprojx +++ b/Projects/NUCLEO-H553ZG/Applications/FileX/Fx_File_Edit_Standalone/MDK-ARM/Fx_File_Edit_Standalone.uvprojx @@ -18,7 +18,7 @@ STMicroelectronics Keil.STM32H5xx_DFP.1.5.0-A02 https://www.keil.com/pack/ - IRAM(0x20000000-0x2017FFFF) IROM(0x08000000-0x83FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP + IRAM(0x20000000-0x2004BFFF) IROM(0x08000000-0x80FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP @@ -247,12 +247,12 @@ 0 0x20000000 - 0x180000 + 0x4c000 1 0x8000000 - 0x400000 + 0x100000 0 @@ -277,7 +277,7 @@ 1 0x8000000 - 0x400000 + 0x100000 1 @@ -302,7 +302,7 @@ 0 0x20000000 - 0x180000 + 0x4c000 0 diff --git a/Projects/NUCLEO-H553ZG/Applications/NetXDuo/Nx_UDP_Echo_Client/MDK-ARM/Nx_UDP_Echo_Client.uvprojx b/Projects/NUCLEO-H553ZG/Applications/NetXDuo/Nx_UDP_Echo_Client/MDK-ARM/Nx_UDP_Echo_Client.uvprojx index 61bf5f116..a79b70840 100644 --- a/Projects/NUCLEO-H553ZG/Applications/NetXDuo/Nx_UDP_Echo_Client/MDK-ARM/Nx_UDP_Echo_Client.uvprojx +++ b/Projects/NUCLEO-H553ZG/Applications/NetXDuo/Nx_UDP_Echo_Client/MDK-ARM/Nx_UDP_Echo_Client.uvprojx @@ -18,7 +18,7 @@ STMicroelectronics Keil.STM32H5xx_DFP.1.5.0-A02 https://www.keil.com/pack/ - IRAM(0x20000000-0x2017FFFF) IROM(0x08000000-0x83FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP + IRAM(0x20000000-0x2004BFFF) IROM(0x08000000-0x80FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP @@ -247,12 +247,12 @@ 0 0x20000000 - 0x180000 + 0x4c000 1 0x8000000 - 0x400000 + 0x100000 0 @@ -277,7 +277,7 @@ 1 0x8000000 - 0x400000 + 0x100000 1 @@ -302,7 +302,7 @@ 0 0x20000000 - 0x180000 + 0x4c000 0 diff --git a/Projects/NUCLEO-H553ZG/Applications/NetXDuo/Nx_UDP_Echo_Server/MDK-ARM/Nx_UDP_Echo_Server.uvprojx b/Projects/NUCLEO-H553ZG/Applications/NetXDuo/Nx_UDP_Echo_Server/MDK-ARM/Nx_UDP_Echo_Server.uvprojx index 8449ffd62..4ff036bd0 100644 --- a/Projects/NUCLEO-H553ZG/Applications/NetXDuo/Nx_UDP_Echo_Server/MDK-ARM/Nx_UDP_Echo_Server.uvprojx +++ b/Projects/NUCLEO-H553ZG/Applications/NetXDuo/Nx_UDP_Echo_Server/MDK-ARM/Nx_UDP_Echo_Server.uvprojx @@ -18,7 +18,7 @@ STMicroelectronics Keil.STM32H5xx_DFP.1.5.0-A02 https://www.keil.com/pack/ - IRAM(0x20000000-0x2017FFFF) IROM(0x08000000-0x83FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP + IRAM(0x20000000-0x2004BFFF) IROM(0x08000000-0x80FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP @@ -247,12 +247,12 @@ 0 0x20000000 - 0x180000 + 0x4c000 1 0x8000000 - 0x400000 + 0x100000 0 @@ -277,7 +277,7 @@ 1 0x8000000 - 0x400000 + 0x100000 1 @@ -302,7 +302,7 @@ 0 0x20000000 - 0x180000 + 0x4c000 0 diff --git a/Projects/NUCLEO-H553ZG/Applications/ThreadX/Tx_LowPower/MDK-ARM/Tx_LowPower.uvprojx b/Projects/NUCLEO-H553ZG/Applications/ThreadX/Tx_LowPower/MDK-ARM/Tx_LowPower.uvprojx index 02f189e4c..4502497f8 100644 --- a/Projects/NUCLEO-H553ZG/Applications/ThreadX/Tx_LowPower/MDK-ARM/Tx_LowPower.uvprojx +++ b/Projects/NUCLEO-H553ZG/Applications/ThreadX/Tx_LowPower/MDK-ARM/Tx_LowPower.uvprojx @@ -18,7 +18,7 @@ STMicroelectronics Keil.STM32H5xx_DFP.1.5.0-A02 https://www.keil.com/pack/ - IRAM(0x20000000-0x2017FFFF) IROM(0x08000000-0x83FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP + IRAM(0x20000000-0x2004BFFF) IROM(0x08000000-0x80FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP @@ -247,12 +247,12 @@ 0 0x20000000 - 0x180000 + 0x4c000 1 0x8000000 - 0x400000 + 0x100000 0 @@ -277,7 +277,7 @@ 1 0x8000000 - 0x400000 + 0x100000 1 @@ -302,7 +302,7 @@ 0 0x20000000 - 0x180000 + 0x4c000 0 diff --git a/Projects/NUCLEO-H553ZG/Applications/ThreadX/Tx_Thread_Creation/MDK-ARM/Tx_Thread_Creation.uvprojx b/Projects/NUCLEO-H553ZG/Applications/ThreadX/Tx_Thread_Creation/MDK-ARM/Tx_Thread_Creation.uvprojx index 3de588f2e..65683a7b0 100644 --- a/Projects/NUCLEO-H553ZG/Applications/ThreadX/Tx_Thread_Creation/MDK-ARM/Tx_Thread_Creation.uvprojx +++ b/Projects/NUCLEO-H553ZG/Applications/ThreadX/Tx_Thread_Creation/MDK-ARM/Tx_Thread_Creation.uvprojx @@ -18,7 +18,7 @@ STMicroelectronics Keil.STM32H5xx_DFP.1.5.0-A02 https://www.keil.com/pack/ - IRAM(0x20000000-0x2017FFFF) IROM(0x08000000-0x83FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP + IRAM(0x20000000-0x2004BFFF) IROM(0x08000000-0x80FFFFF) CLOCK(8000000) FPU3(SFPU) CPUTYPE("Cortex-M33") ELITTLE TZ DSP @@ -247,12 +247,12 @@ 0 0x20000000 - 0x180000 + 0x4c000 1 0x8000000 - 0x400000 + 0x100000 0 @@ -277,7 +277,7 @@ 1 0x8000000 - 0x400000 + 0x100000 1 @@ -302,7 +302,7 @@ 0 0x20000000 - 0x180000 + 0x4c000 0 diff --git a/Projects/NUCLEO-H563ZI/Examples/FLASH/FLASH_SwapBanks/STM32CubeIDE/STM32H563ZITX_FLASH.ld b/Projects/NUCLEO-H563ZI/Examples/FLASH/FLASH_SwapBanks/STM32CubeIDE/STM32H563ZITX_FLASH.ld index 4bd688dfb..0ee1ff8e7 100644 --- a/Projects/NUCLEO-H563ZI/Examples/FLASH/FLASH_SwapBanks/STM32CubeIDE/STM32H563ZITX_FLASH.ld +++ b/Projects/NUCLEO-H563ZI/Examples/FLASH/FLASH_SwapBanks/STM32CubeIDE/STM32H563ZITX_FLASH.ld @@ -46,7 +46,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 640K - ROM (rx) : ORIGIN = 0x08000000, LENGTH = 2048K + ROM (rx) : ORIGIN = 0x08000000, LENGTH = 1024K } /* Sections */ diff --git a/Projects/NUCLEO-H563ZI/Examples/RAMCFG/RAMCFG_ECC_Error_Generation/STM32CubeIDE/STM32H563ZITX_FLASH.ld b/Projects/NUCLEO-H563ZI/Examples/RAMCFG/RAMCFG_ECC_Error_Generation/STM32CubeIDE/STM32H563ZITX_FLASH.ld index 19c992364..cd9e04d15 100644 --- a/Projects/NUCLEO-H563ZI/Examples/RAMCFG/RAMCFG_ECC_Error_Generation/STM32CubeIDE/STM32H563ZITX_FLASH.ld +++ b/Projects/NUCLEO-H563ZI/Examples/RAMCFG/RAMCFG_ECC_Error_Generation/STM32CubeIDE/STM32H563ZITX_FLASH.ld @@ -44,7 +44,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Memories definition */ MEMORY { - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 100K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 640K FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K } diff --git a/Projects/STM32H573I-DK/Applications/FileX/FX_IAP/IAP_binary_template/MDK-ARM/IAP_binary_template.uvprojx b/Projects/STM32H573I-DK/Applications/FileX/FX_IAP/IAP_binary_template/MDK-ARM/IAP_binary_template.uvprojx index 7e6b8f688..65ca70ea2 100644 --- a/Projects/STM32H573I-DK/Applications/FileX/FX_IAP/IAP_binary_template/MDK-ARM/IAP_binary_template.uvprojx +++ b/Projects/STM32H573I-DK/Applications/FileX/FX_IAP/IAP_binary_template/MDK-ARM/IAP_binary_template.uvprojx @@ -277,7 +277,7 @@ 1 0x8100000 - 0x200000 + 0x100000 1 diff --git a/Projects/STM32H573I-DK/Applications/FileX/FX_IAP/IAP_binary_template/STM32CubeIDE/STM32H573IIKXQ_FLASH.ld b/Projects/STM32H573I-DK/Applications/FileX/FX_IAP/IAP_binary_template/STM32CubeIDE/STM32H573IIKXQ_FLASH.ld index 6b246ffba..81b6e884b 100644 --- a/Projects/STM32H573I-DK/Applications/FileX/FX_IAP/IAP_binary_template/STM32CubeIDE/STM32H573IIKXQ_FLASH.ld +++ b/Projects/STM32H573I-DK/Applications/FileX/FX_IAP/IAP_binary_template/STM32CubeIDE/STM32H573IIKXQ_FLASH.ld @@ -45,7 +45,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ MEMORY { RAM (xrw) : ORIGIN = 0x20010000, LENGTH = 576K - FLASH (rx) : ORIGIN = 0x08100000, LENGTH = 2048K + FLASH (rx) : ORIGIN = 0x08100000, LENGTH = 1024K } /* Sections */ diff --git a/Projects/STM32H573I-DK/Applications/NetXDuo/Nx_Iperf_wifi/MDK-ARM/Nx_Iperf_wifi.uvprojx b/Projects/STM32H573I-DK/Applications/NetXDuo/Nx_Iperf_wifi/MDK-ARM/Nx_Iperf_wifi.uvprojx index db116443e..63dd53079 100644 --- a/Projects/STM32H573I-DK/Applications/NetXDuo/Nx_Iperf_wifi/MDK-ARM/Nx_Iperf_wifi.uvprojx +++ b/Projects/STM32H573I-DK/Applications/NetXDuo/Nx_Iperf_wifi/MDK-ARM/Nx_Iperf_wifi.uvprojx @@ -208,8 +208,8 @@ 0 1 0 - 0 - 0 + 1 + 1 0 1 0 diff --git a/Projects/STM32H573I-DK/Applications/NetXDuo/Nx_Network_Basics_wifi/MDK-ARM/Nx_Network_Basics_wifi.uvprojx b/Projects/STM32H573I-DK/Applications/NetXDuo/Nx_Network_Basics_wifi/MDK-ARM/Nx_Network_Basics_wifi.uvprojx index b8e384709..e7bfa5c2b 100644 --- a/Projects/STM32H573I-DK/Applications/NetXDuo/Nx_Network_Basics_wifi/MDK-ARM/Nx_Network_Basics_wifi.uvprojx +++ b/Projects/STM32H573I-DK/Applications/NetXDuo/Nx_Network_Basics_wifi/MDK-ARM/Nx_Network_Basics_wifi.uvprojx @@ -208,8 +208,8 @@ 0 1 0 - 0 - 0 + 1 + 1 0 1 0 diff --git a/Projects/STM32H5F5J-DK/Applications/OpenBootloader/STM32CubeIDE/STM32H5F5LJHXQ_FLASH.ld b/Projects/STM32H5F5J-DK/Applications/OpenBootloader/STM32CubeIDE/STM32H5F5LJHXQ_FLASH.ld index 977931f56..9e4af27ae 100644 --- a/Projects/STM32H5F5J-DK/Applications/OpenBootloader/STM32CubeIDE/STM32H5F5LJHXQ_FLASH.ld +++ b/Projects/STM32H5F5J-DK/Applications/OpenBootloader/STM32CubeIDE/STM32H5F5LJHXQ_FLASH.ld @@ -46,7 +46,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 35K - FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 90K + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 70K } /* Sections */