2025-09-02 4:32 AM - edited 2025-09-02 4:42 AM
Heyho,
how can I put a constant at the end of the STM32's used flash? (using: STM32CubeIDE)
Not at a specific address (that's not a problem), but I'd like to have a constant always at the end of the used internal flash, independent of any other source code changes.
I just find that there's some ASCII characters = "ASCII" (twice) and lots of 0x00 at the end of my H7 and F7 bin files - that from my sources or placed by CubeIDE?
Thanks!
Solved! Go to Solution.
2025-09-02 4:56 AM - edited 2025-09-02 5:14 AM
In the linker script (*.ld) you can define a new section (e.g. "EOF") and place it behind FLASH place it as last entry in FLASH.
When you declare your const variable with __attribute__((section("EOF"))) you should be done.
2025-09-02 4:40 AM
@LCE wrote:Not at a specific address (that's not a problem), but I'd like to have a constant always at the end of the internal flash!
Surely, "the end of internal flash" is a specific address?
Are you just asking how to determine what that address is?
The device header file might have something...
Or do you mean the end of the used Flash space?
Check out symbols provided by the Linker script for that ...
2025-09-02 4:45 AM
Thanks, Andrew.
I changed my question: I mean the end of the used flash.
I'll check the linker script stuff for that.
Darn, 2 years ago that I worked on that, and I'm really too good at forgetting...
2025-09-02 4:56 AM - edited 2025-09-02 5:14 AM
In the linker script (*.ld) you can define a new section (e.g. "EOF") and place it behind FLASH place it as last entry in FLASH.
When you declare your const variable with __attribute__((section("EOF"))) you should be done.
2025-09-02 5:36 AM
@mfgkw until now I have placed sections (many!) at specific addresses, how can I place a section at the end of the used flash?
What I mean is: I have 512 kB flash, program code takes 312 kB, EOF should be after 312 kB.
After next source code change, program ends at 444 kB, EOF should start after 444 kB, ...
2025-09-02 5:48 AM
Sections are placed in order of appirance in linkerscript, Just create new section after actually last.
So this section simply must be last (in corresponding MEMORY region) in linker script, nothing else.
2025-09-02 6:02 AM
Hmm, almost.
I added this to the SECTIONS after all other sections using "FLBOOT":
.FlashBootEOF :
{
KEEP(*(.FlashBootEOF)) ;
} >FLBOOT
Put a string there in source code, and the string is close to the end, but some other constant strings (without any section attributes) are placed after these.
2025-09-02 6:05 AM
Show your linker script,
Do You have any orphane sections?
2025-09-02 6:13 AM
Maybe you see debug info after all others?
2025-09-02 6:14 AM - edited 2025-09-02 6:17 AM
Craaazy!
I just moved this section definition to the end of the linker script, not just the end where FLBOOT sections are defined.
Now it's at the end of used flash.
Thanks to all!
Edit: and with align 16 it's at an address which is easier to check with a bin file viewer :D