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 6:19 AM
An alignment of 4 would be sufficient :)
2025-09-02 6:24 AM
*.map file will show you what was places after your section.
I'm wondering why you do this?
2025-09-02 6:58 AM
> I'm wondering why you do this?
Part of file check for bootloader / application update
2025-09-02 7:05 AM
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),
2025-09-02 8:23 AM
Paranoia! :D
2025-09-02 9:26 AM - edited 2025-09-02 9:32 AM
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.
2025-09-02 10:31 AM
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;
2025-09-02 10:39 AM - edited 2025-09-02 10:44 AM
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