cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create a ''gap'' at a specific address in flash memory?

arnold_w
Senior
Posted on June 12, 2015 at 13:49

I am working with the STM32F407 microcontroller and building using Eclipse/GNU and my project is using a standard linker script (can be found in, for example, the Discovery Demonstration Board ''Blink LED''-example). I would like to create a gap at a specific address in flash memory:

FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 16K
MY_GAP (rx) : ORIGIN = 0x08004000, LENGTH = 16K
FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 992K

The above does not work well, it simply puts the stuff that should reside in FLASH at address0x08008000, so the first sector is wasted. The below is not a solution either because I want the tools to have the freedom to pick FLASH_BEGINNING or FLASH_END, I don't want to have to make that decision in the linker script:

FLASH_BEGINNING (rx) : ORIGIN = 0x08000000, LENGTH = 16K
MY_GAP (rx) : ORIGIN = 0x08004000, LENGTH = 16K
FLASH_END (rx) : ORIGIN = 0x08008000, LENGTH = 992K

I basically want the code to be packed so no memory is wasted and I shouldn't have to make changes to the linker script if the code size increases. Can someone please help me?

3 REPLIES 3
Posted on June 12, 2015 at 14:43

There is no way to coax the GNU tools into creating a discontinuous memory area (and, honestly it would be a task not worth solving at all). The best thing you can do is to place the default .text in the largest continuous piece, and hand-pick smaller pieces of code or constant data into the smaller piece (through explicit assigning them into a section using __attribute__((section(''sectionname''))).

I would advice you to give up on this plan. If you explain us what do you want to accomplish, we may come up with better solution.

JW
Posted on June 12, 2015 at 14:50

I basically want the code to be packed so no memory is wasted and I shouldn't have to make changes to the linker script if the code size increases.

Ok, then you'll have to put your programming pants on and rewrite the linker, GNU/LD doesn't work that way. Alternatively you could do multiple linker passes, process the .MAP file with a script, and generate a custom .LD which better placement of specific functions/objects to more optimally use the space.

You need to give the sections different names, and make sure the vectors get in the front section. You can also direct other sections and objects into the area.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F2%20linker%20script%20to%20emulate%20EEPROM&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=52]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32F2%20linker%20script%20to%20emulate%20EEPROM&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=52

Covered this in a couple of other threads for GNU/GCC and Keil.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arnold_w
Senior
Posted on June 12, 2015 at 15:27

I want to place a bootloader in the second sector, that's why I don't want to use it in the application. I previously worked with a different brand of microcontrollers and there it was extremely easy to accomplish this in C-code, I simply placed an array where I wanted the gap:

unsigned char MY_GAP[16 * 1024] __attribute__ ((space(psv), aligned(1024), noload, address(0x08004000)));

However, I've googled a bit and it doesn't seem like something like this is possible with the tools I'm using, it seems I must do it in the linker script.