cancel
Showing results for 
Search instead for 
Did you mean: 

Place constant at end of used flash - not specific address

LCE
Principal II

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!

1 ACCEPTED SOLUTION

Accepted Solutions
mfgkw
Associate III

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.

View solution in original post

17 REPLIES 17
Andrew Neil
Super User

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

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

mfgkw
Associate III

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
Principal II

@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
Senior III

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
Principal II

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.

Radosław
Senior III

Show your linker script, 

Do You have any orphane sections?

mfgkw
Associate III

Maybe you see debug info after all others?

LCE
Principal II

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