From a080c77b29d81ebb2c0cbf5906598930f3c3f559 Mon Sep 17 00:00:00 2001 From: 94xhn <87560781+94xhn@users.noreply.github.com> Date: Sat, 11 Jul 2026 18:04:31 +0800 Subject: [PATCH] fix(linker): correct cross-toolchain memory map inconsistencies Found by cross-checking each example's GCC (SW4STM32)/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/F4/L4/H7/F1/L0 in this repo family. 1. Applications/USB_Device/DFU_Standalone/Binary/binary_template (STM32072B_EVAL, STM32F072VBTx, 128K flash): GCC's .ld and Keil's .uvprojx both correctly offset the app's flash start address to 0x08007000 to leave room for the bootloader, but neither shrinks the length to compensate - both still declare 128K as if starting from 0x08000000, running 28K past the chip's actual end of flash. IAR's .icf correctly uses 100K (0x08007000-0x0801FFFF). Fixed GCC's .ld and Keil's OCR_RVCT4 Size to 100K (0x19000), matching IAR. 2. Applications/USB_Device/DFU_Standalone/Binary/binary_template (STM32F072B-Discovery, STM32F072RBTx, 128K flash): identical bug as #1 above, same board family, same fix (128K -> 100K on GCC's .ld and Keil's OCR_RVCT4 Size). 3. Examples/IWDG/IWDG_WindowMode (STM32F070RB-Nucleo, STM32F070RB, 128K flash / 16K RAM): IAR's .icf alone declares only 64K flash and 8K RAM - half of the chip's actual capacity, and half of what GCC's .ld, Keil's OCR_RVCT4, and this board's own Templates project all agree on. Fixed IAR's .icf region end symbols to 0x0801FFFF (128K flash) and 0x20003FFF (16K RAM). 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 (Templates gold standards, sibling toolchain files of the same project, and the Keil tag naming the actual target chip). Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com> --- .../Binary/binary_template/MDK-ARM/Project.uvprojx | 2 +- .../SW4STM32/STM32072B_EVAL/STM32F072VBTx_FLASH.ld | 2 +- .../Examples/IWDG/IWDG_WindowMode/EWARM/stm32f070xb_flash.icf | 4 ++-- .../Binary/binary_template/MDK-ARM/Project.uvprojx | 2 +- .../SW4STM32/STM32F072B-Discovery/STM32F072RBTx_FLASH.ld | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Projects/STM32072B_EVAL/Applications/USB_Device/DFU_Standalone/Binary/binary_template/MDK-ARM/Project.uvprojx b/Projects/STM32072B_EVAL/Applications/USB_Device/DFU_Standalone/Binary/binary_template/MDK-ARM/Project.uvprojx index 0723b1c6..bf278209 100644 --- a/Projects/STM32072B_EVAL/Applications/USB_Device/DFU_Standalone/Binary/binary_template/MDK-ARM/Project.uvprojx +++ b/Projects/STM32072B_EVAL/Applications/USB_Device/DFU_Standalone/Binary/binary_template/MDK-ARM/Project.uvprojx @@ -273,7 +273,7 @@ 1 0x8007000 - 0x20000 + 0x19000 1 diff --git a/Projects/STM32072B_EVAL/Applications/USB_Device/DFU_Standalone/Binary/binary_template/SW4STM32/STM32072B_EVAL/STM32F072VBTx_FLASH.ld b/Projects/STM32072B_EVAL/Applications/USB_Device/DFU_Standalone/Binary/binary_template/SW4STM32/STM32072B_EVAL/STM32F072VBTx_FLASH.ld index 90feeeeb..c952592b 100644 --- a/Projects/STM32072B_EVAL/Applications/USB_Device/DFU_Standalone/Binary/binary_template/SW4STM32/STM32072B_EVAL/STM32F072VBTx_FLASH.ld +++ b/Projects/STM32072B_EVAL/Applications/USB_Device/DFU_Standalone/Binary/binary_template/SW4STM32/STM32072B_EVAL/STM32F072VBTx_FLASH.ld @@ -36,7 +36,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ MEMORY { RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 15K -FLASH (rx) : ORIGIN = 0x8007000, LENGTH = 128K +FLASH (rx) : ORIGIN = 0x8007000, LENGTH = 100K SRAM(rx) : ORIGIN = 0x20000000, LENGTH = 1K } diff --git a/Projects/STM32F070RB-Nucleo/Examples/IWDG/IWDG_WindowMode/EWARM/stm32f070xb_flash.icf b/Projects/STM32F070RB-Nucleo/Examples/IWDG/IWDG_WindowMode/EWARM/stm32f070xb_flash.icf index c7facb75..423368e0 100644 --- a/Projects/STM32F070RB-Nucleo/Examples/IWDG/IWDG_WindowMode/EWARM/stm32f070xb_flash.icf +++ b/Projects/STM32F070RB-Nucleo/Examples/IWDG/IWDG_WindowMode/EWARM/stm32f070xb_flash.icf @@ -5,9 +5,9 @@ define symbol __ICFEDIT_intvec_start__ = 0x08000000; /*-Memory Regions-*/ define symbol __ICFEDIT_region_ROM_start__ = 0x08000000; -define symbol __ICFEDIT_region_ROM_end__ = 0x0800FFFF; +define symbol __ICFEDIT_region_ROM_end__ = 0x0801FFFF; define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; -define symbol __ICFEDIT_region_RAM_end__ = 0x20001FFF; +define symbol __ICFEDIT_region_RAM_end__ = 0x20003FFF; /*-Sizes-*/ define symbol __ICFEDIT_size_cstack__ = 0x400; define symbol __ICFEDIT_size_heap__ = 0x200; diff --git a/Projects/STM32F072B-Discovery/Applications/USB_Device/DFU_Standalone/Binary/binary_template/MDK-ARM/Project.uvprojx b/Projects/STM32F072B-Discovery/Applications/USB_Device/DFU_Standalone/Binary/binary_template/MDK-ARM/Project.uvprojx index 715eb7bb..578a2d17 100644 --- a/Projects/STM32F072B-Discovery/Applications/USB_Device/DFU_Standalone/Binary/binary_template/MDK-ARM/Project.uvprojx +++ b/Projects/STM32F072B-Discovery/Applications/USB_Device/DFU_Standalone/Binary/binary_template/MDK-ARM/Project.uvprojx @@ -273,7 +273,7 @@ 1 0x8007000 - 0x20000 + 0x19000 1 diff --git a/Projects/STM32F072B-Discovery/Applications/USB_Device/DFU_Standalone/Binary/binary_template/SW4STM32/STM32F072B-Discovery/STM32F072RBTx_FLASH.ld b/Projects/STM32F072B-Discovery/Applications/USB_Device/DFU_Standalone/Binary/binary_template/SW4STM32/STM32F072B-Discovery/STM32F072RBTx_FLASH.ld index b39ef0c5..ba94dfc6 100644 --- a/Projects/STM32F072B-Discovery/Applications/USB_Device/DFU_Standalone/Binary/binary_template/SW4STM32/STM32F072B-Discovery/STM32F072RBTx_FLASH.ld +++ b/Projects/STM32F072B-Discovery/Applications/USB_Device/DFU_Standalone/Binary/binary_template/SW4STM32/STM32F072B-Discovery/STM32F072RBTx_FLASH.ld @@ -36,7 +36,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ MEMORY { RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 15K -FLASH (rx) : ORIGIN = 0x8007000, LENGTH = 128K +FLASH (rx) : ORIGIN = 0x8007000, LENGTH = 100K SRAM(rx) : ORIGIN = 0x20000000, LENGTH = 1K }