linker symbols for stm32 Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
geoffrey.brown
Posts: 87
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 15 times

linker symbols for stm32  Topic is solved

Postby geoffrey.brown » Thu May 31, 2018 4:54 pm

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

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: linker symbols for stm32

Postby Giovanni » Thu May 31, 2018 6:17 pm

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:

Code: Select all

    .flash0 : ALIGN(4)
    {
        __flash0_free__ = .;
    } > flash0


Moving this in change request, will look into this.

Giovanni

apmorton
Posts: 36
Joined: Fri Sep 29, 2017 10:26 am
Been thanked: 16 times

Re: linker symbols for stm32

Postby apmorton » Thu May 31, 2018 8:30 pm

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.

geoffrey.brown
Posts: 87
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 15 times

Re: linker symbols for stm32

Postby geoffrey.brown » Fri Jun 01, 2018 12:59 pm

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.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: linker symbols for stm32

Postby Giovanni » Sat Jun 02, 2018 2:09 pm

Hi,

I added extra rules for loading data in flash areas and to mark start..end. It is in trunk.

Giovanni

geoffrey.brown
Posts: 87
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 15 times

Re: linker symbols for stm32

Postby geoffrey.brown » Sun Jun 03, 2018 6:40 pm

Thanks !
Geoffrey


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 8 guests