Skip to main content
LCE
Principal II
September 2, 2025
Solved

Place constant at end of used flash - not specific address

  • September 2, 2025
  • 23 replies
  • 1049 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!

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

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

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
LCE
LCEAuthor
Principal 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...

mfgkwBest answer
Associate 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.

LCE
LCEAuthor
Principal 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, ...

Radosław
Associate 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.

LCE
LCEAuthor
Principal 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.

Associate II
September 2, 2025

Maybe you see debug info after all others?

Radosław
Associate II
September 2, 2025

Show your linker script, 

Do You have any orphane sections?

LCE
LCEAuthor
Principal 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

Radosław
Associate II
September 2, 2025

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

I'm wondering why you do this?  

Associate II
September 2, 2025

An alignment of 4 would be sufficient :)

LCE
LCEAuthor
Principal II
September 2, 2025

I'm wondering why you do this?  

Part of file check for bootloader / application update

Radosław
Associate 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),