I'd like to know if there's a simple way to reference from C the end of the "occupied" flash (e.g. a linker defined label like etext). The current linker scripts are pretty flexible, but I don't want to hard-wire things. My reason is that I want to use any available flash for data logging.
Geoffrey
linker symbols for stm32 Topic is solved
-
- Posts: 87
- Joined: Thu May 07, 2015 9:47 pm
- Has thanked: 3 times
- Been thanked: 15 times
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: linker symbols for stm32
Hi,
Good point, actually that is missing, it would be nice to add a symbol to mark the end of flash0...flash7 like it is done for ram0...ram7.
Something like:
Moving this in change request, will look into this.
Giovanni
Good point, actually that is missing, it would be nice to add a symbol to mark the end of flash0...flash7 like it is done for ram0...ram7.
Something like:
Code: Select all
.flash0 : ALIGN(4)
{
__flash0_free__ = .;
} > flash0
Moving this in change request, will look into this.
Giovanni
Re: linker symbols for stm32
It's worth noting that its less important to know where your code ends in flash but rather where the next block after the end of your code starts.
Because you can only erase a whole block of flash at a time, you can't safely occupy the space after your program but before the start of the next flash block (unless your data logging is write-only - as in you never plan to erase the data without also reflashing the chip) without also erasing some of your program when you want to erase the data.
In one of my projects we have to do exactly this (store data after our program in flash which could be rewritten at runtime) - we accomplished it by making a local copy of the device's ld file (https://github.com/ChibiOS/ChibiOS/blob ... 2F407xG.ld for example) and decreasing the size of flash0.
You then have compile time guarantees that your program won't exceed the expected size, and you can hard code the starting location for your data based on that. If your program no longer fits, it won't compile - and you can increase the size of flash0 to the next block boundary.
Because all flash blocks are not the same size on the STM32 parts, its not a trivial case of rounding up in order to calculate the start of the next block.
Its not a super complex calculation, just something to keep in mind.
Because you can only erase a whole block of flash at a time, you can't safely occupy the space after your program but before the start of the next flash block (unless your data logging is write-only - as in you never plan to erase the data without also reflashing the chip) without also erasing some of your program when you want to erase the data.
In one of my projects we have to do exactly this (store data after our program in flash which could be rewritten at runtime) - we accomplished it by making a local copy of the device's ld file (https://github.com/ChibiOS/ChibiOS/blob ... 2F407xG.ld for example) and decreasing the size of flash0.
You then have compile time guarantees that your program won't exceed the expected size, and you can hard code the starting location for your data based on that. If your program no longer fits, it won't compile - and you can increase the size of flash0 to the next block boundary.
Because all flash blocks are not the same size on the STM32 parts, its not a trivial case of rounding up in order to calculate the start of the next block.
Its not a super complex calculation, just something to keep in mind.
-
- Posts: 87
- Joined: Thu May 07, 2015 9:47 pm
- Has thanked: 3 times
- Been thanked: 15 times
Re: linker symbols for stm32
Here's what I've done in the short term (before a more general solution emerges). I copied the processor specific linker script (e.g. STM32XXX.ld) and added a section to the end (after INCLUDE rules.d)
/* Generic rules inclusion.*/
INCLUDE rules.ld
/* added part */
SECTIONS
{
.lastsection (NOLOAD):
{
. = ALIGN(2048);
_DATA_START = .;
} > flash0
}
This wouldn't be necessary if each of the flashn sections had a default end label.
/* Generic rules inclusion.*/
INCLUDE rules.ld
/* added part */
SECTIONS
{
.lastsection (NOLOAD):
{
. = ALIGN(2048);
_DATA_START = .;
} > flash0
}
This wouldn't be necessary if each of the flashn sections had a default end label.
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: linker symbols for stm32
Hi,
I added extra rules for loading data in flash areas and to mark start..end. It is in trunk.
Giovanni
I added extra rules for loading data in flash areas and to mark start..end. It is in trunk.
Giovanni
-
- Posts: 87
- Joined: Thu May 07, 2015 9:47 pm
- Has thanked: 3 times
- Been thanked: 15 times
Return to “Small Change Requests”
Who is online
Users browsing this forum: No registered users and 9 guests