Skip to main content
Graduate II
September 2, 2025
Solved

Place constant at end of used flash - not specific address

  • September 2, 2025
  • 23 replies
  • 1047 views

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!

    This topic has been closed for replies.
    Best answer by mfgkw

    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.

    23 replies

    Super User
    September 2, 2025

    @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 ...

    LCEAuthor
    Graduate II
    September 2, 2025

    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...

    mfgkwAnswer
    Graduate II
    September 2, 2025

    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.

    LCEAuthor
    Graduate II
    September 2, 2025

    @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, ...

    Visitor II
    September 2, 2025

    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.

    LCEAuthor
    Graduate II
    September 2, 2025

    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.

    Graduate II
    September 2, 2025

    Maybe you see debug info after all others?

    Visitor II
    September 2, 2025

    Show your linker script, 

    Do You have any orphane sections?

    LCEAuthor
    Graduate II
    September 2, 2025

    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

    Visitor II
    September 2, 2025

    *.map file will show you what was places after your section. 

    I'm wondering why you do this?  

    Graduate II
    September 2, 2025

    An alignment of 4 would be sufficient :)

    LCEAuthor
    Graduate II
    September 2, 2025

    I'm wondering why you do this?  

    Part of file check for bootloader / application update

    Visitor II
    September 2, 2025

    That i'm gessing, but still, not exacly understand why this method,

     

    I'm juster after creating my bootleader for many decives  (end of flash was that last thing to bothering),