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!

17 REPLIES 17
mfgkw
Associate III

An alignment of 4 would be sufficient :)

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

I'm wondering why you do this?  

LCE
Principal II

I'm wondering why you do this?  

Part of file check for bootloader / application update

Radosław
Senior III

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),   

LCE
Principal II

Paranoia! :D

LCE
Principal II

Shoot, now the STM32CubeProg complains about the *.elf file :

Warning: File corrupted. Two or more segments defines the same memory zone

And it doesn't load the complete flash content into the programmer.

:(

And this is very bad for first time flashing in production.

mfgkw
Associate III

Showing your ld file could help helping ...

 

I tried a small project with this change in the ld file:

...

/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM

ENDOFFLASH :
{
. = ALIGN(8);
} >FLASH

/* Remove information from the compiler libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}

.ARM.attributes 0 : { *(.ARM.attributes) }
}

 

In the c file I added a variable like this:

const int __attribute__((section("ENDOFFLASH"))) lastVariable = 123;

ENDOFFLASH :
{

. = ALIGN(8);

*(ENDOFFLASH)

} >FLASH

 

Input section and output, don't mix this. Also used attribute for variable or keep for section should me used