fix(linker): correct RAM size to 96K for STM32G474 projects - #57
Conversation
All STM32G474xx GCC linker scripts (STM32CubeIDE *.ld) define the contiguous RAM region at 0x20000000 as 128K: RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K but STM32G474xx only has 96KB of contiguous SRAM (SRAM1+SRAM2) at that address; the remaining 32KB of the chip's 128KB total SRAM is the separate CCM SRAM at 0x10000000 (already correctly declared as 32K in the same files). An application whose .data/.bss actually grows past 96KB will silently overrun into unmapped memory instead of failing to link, since the linker is told 128K is available. This is the same defect class previously confirmed and fixed by ST for other G4 parts (G491 in v1.4.0 per issue STMicroelectronics#19, referenced again in issue STMicroelectronics#29 for NUCLEO-G491RE), which were not corrected for G474. Cross-checked against the IAR (EWARM) *.icf linker files for the same parts: 366 out of 372 already correctly define the RAM region as 0x20000000-0x20017FFF (96K); the remaining 6 EWARM files under B-G474E-DPOW1 have the same 128K (0x2001FFFF) mistake and are fixed here too, along with the doc-comment header lines in the .ld files that also claimed "128Kbytes RAM". Fix generated with a script (sed) after manually verifying the change on one file, then confirming the exact same line appears byte-for-byte identical across every affected file (grep before/after counts, no other content touched). Fixes STMicroelectronics#55 Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com>
|
Hello @94xhn, Thank you for this analysis and fix proposal, as well as the others. Actually, the RAM size specified in the linker files for the STM32G474xE devices is correct, although it may not seem so at first glance. Indeed, paragraph 3.5 Embedded SRAM of DS12288, rev. 6, says about the CCM SRAM:
Similarly, paragraph 2.4 Embedded SRAM of RM0440, rev. 9, says:
The STM32G474xE being category 3 devices as indicated in Table 1. STM32G4 series memory density of RM0440, this means that:
I hope this removes the confusion. Please do not hesitate should you have questions about this. With regards, |
|
Thank you for the correction. I missed the CCM SRAM alias at 0x20018000 and incorrectly treated the 0x10000000 mapping as the only usable address. The separate EWARM regions were also not a valid cross-check against the contiguous GCC view. You are right that 0x20000000-0x2001FFFF is valid for STM32G474xE. Closing this PR. |
|
You're welcome. |
Relates to #55 (closed as not_planned because the reporter didn't reply with a board name - the underlying value is still wrong for every G474 project in the repo, not just the one #55 reported).
Problem
Every STM32G474xx GCC linker script (
STM32CubeIDE/*.ld) in this repo defines the contiguous RAM region at0x20000000as 128K:STM32G474xx has 128KB of total SRAM, but it's split as 96KB contiguous SRAM1+SRAM2 at 0x20000000 plus a separate 32KB CCM SRAM at 0x10000000 (already correctly declared in the same file). The
RAMregion above should be 96K, not 128K - as currently written, an application whose.data/.bssgrows past 96KB links successfully instead of failing, and then overruns into unmapped memory at runtime.This is the same defect class ST already confirmed and fixed for other G4 parts:
...but G474 was apparently missed in both passes.
Verification
I cross-checked the correct value against the EWARM (IAR)
*.icflinker files for the same parts, which mostly already get this right: 366 out of 372 already correctly define the RAM region as0x20000000-0x20017FFF(96K). The remaining 6 (all underB-G474E-DPOW1) have the exact same 128K (0x2001FFFF) mistake and are fixed here too.Scope of this PR
This touches 377 files (371
.ld+ 6.icf), because the same wrong constant (and matching wrong doc-comment "128Kbytes RAM" header line) is copied identically into every G474-based board/example/application project directory in the repo. I verified this is a pure, single-value, mechanical correction:.ldline is byte-for-byte identical across all 371 files before the fix (RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K).sed(verified manually on one file first), then re-verified withgrepthat exactly 377 files now have the corrected value and 0 remain with the old value.git diff --stat: 377 files changed, 748 insertions(+), 748 deletions(-) - i.e. exactly 2 lines touched per.ldfile (MEMORY region + doc comment) and 1 line per.icffile, nothing else.Happy to split this into smaller per-board-family PRs if that's easier to review - let me know and I'll do it.
Disclosure
Generative AI (Claude) was used to help investigate this issue, verify the correct value via cross-checking, and script the fix. All changes were reviewed by me before submission.