From 5b6ca399e895017373fefa297cbbfad8e6746bbe Mon Sep 17 00:00:00 2001 From: 94xhn <87560781+94xhn@users.noreply.github.com> Date: Sat, 11 Jul 2026 17:45:40 +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 in this repo family. 1. Examples/TIM/TIM_TimeBase (STM3210C_EVAL, STM32F107RC, 256K flash / 64K RAM): GCC's .ld and IAR's .icf both use a memory map for a different, larger STM32F107 variant (1024K flash / 96K RAM, confirmed by the .ld's own doc-comment header claiming "1024KByte FLASH" for a "STM32F107RCIx" device - inconsistent with its own ORIGIN/filename, which are for the RC/256K part). Keil's STM32F107VC and IROM(0x8000000-0x803FFFF) correctly use 256K, matching this board's Templates project. This is a "2-of-3-toolchains-wrong" case - a naive majority vote here would have picked the wrong answer. Fixed GCC/IAR to 256K flash / 64K RAM, matching Keil and Templates. 2. Applications/IAP/IAP_Binary_Template (STM3210C_EVAL and STM3210E_EVAL): Keil's .uvprojx correctly offsets the app's flash start address (0x8004000) to leave room for the bootloader, but never shrinks the length to compensate - OCR_RVCT4 still declares the region as if it started from 0x8000000, running past 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 (240K for STM3210C_EVAL, 1008K for STM3210E_EVAL). Fixed Keil's OCR_RVCT4 Size to match on both boards. 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 / tags which name the actual target chip). Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com> --- .../IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx | 2 +- .../Examples/TIM/TIM_TimeBase/EWARM/stm32f107xc_flash.icf | 4 ++-- .../SW4STM32/STM3210C_EVAL/STM32F107RCTx_FLASH.ld | 8 ++++---- .../IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Projects/STM3210C_EVAL/Applications/IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx b/Projects/STM3210C_EVAL/Applications/IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx index a4c35baff..00d2b03fe 100644 --- a/Projects/STM3210C_EVAL/Applications/IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx +++ b/Projects/STM3210C_EVAL/Applications/IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx @@ -314,7 +314,7 @@ 1 0x8004000 - 0x40000 + 0x3C000 1 diff --git a/Projects/STM3210C_EVAL/Examples/TIM/TIM_TimeBase/EWARM/stm32f107xc_flash.icf b/Projects/STM3210C_EVAL/Examples/TIM/TIM_TimeBase/EWARM/stm32f107xc_flash.icf index acb665195..471d4d488 100644 --- a/Projects/STM3210C_EVAL/Examples/TIM/TIM_TimeBase/EWARM/stm32f107xc_flash.icf +++ b/Projects/STM3210C_EVAL/Examples/TIM/TIM_TimeBase/EWARM/stm32f107xc_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__ = 0x080FFFFF; +define symbol __ICFEDIT_region_ROM_end__ = 0x0803FFFF; define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; -define symbol __ICFEDIT_region_RAM_end__ = 0x20017FFF; +define symbol __ICFEDIT_region_RAM_end__ = 0x2000FFFF; /*-Sizes-*/ define symbol __ICFEDIT_size_cstack__ = 0x400; define symbol __ICFEDIT_size_heap__ = 0x200; diff --git a/Projects/STM3210C_EVAL/Examples/TIM/TIM_TimeBase/SW4STM32/STM3210C_EVAL/STM32F107RCTx_FLASH.ld b/Projects/STM3210C_EVAL/Examples/TIM/TIM_TimeBase/SW4STM32/STM3210C_EVAL/STM32F107RCTx_FLASH.ld index fc651a943..7da970cec 100644 --- a/Projects/STM3210C_EVAL/Examples/TIM/TIM_TimeBase/SW4STM32/STM3210C_EVAL/STM32F107RCTx_FLASH.ld +++ b/Projects/STM3210C_EVAL/Examples/TIM/TIM_TimeBase/SW4STM32/STM3210C_EVAL/STM32F107RCTx_FLASH.ld @@ -3,8 +3,8 @@ ** ** File : LinkerScript.ld ** -** Abstract : Linker script for STM32F107RCIx Device with -** 1024KByte FLASH, 96KByte RAM +** Abstract : Linker script for STM32F107RCTx Device with +** 256KByte FLASH, 64KByte RAM ** ** Set heap size, stack size and stack location according ** to application requirements. @@ -35,8 +35,8 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Specify the memory areas */ MEMORY { -FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K +FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K +RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K } /* Define output sections */ diff --git a/Projects/STM3210E_EVAL/Applications/IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx b/Projects/STM3210E_EVAL/Applications/IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx index 219587f28..9aa39eb04 100644 --- a/Projects/STM3210E_EVAL/Applications/IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx +++ b/Projects/STM3210E_EVAL/Applications/IAP/IAP_Binary_Template/MDK-ARM/Project.uvprojx @@ -314,7 +314,7 @@ 1 0x8004000 - 0x100000 + 0xFC000 1