2015-06-12 04:49 AM
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?
2015-06-12 05:43 AM
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. JW2015-06-12 05:50 AM
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¤tviews=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=52Covered this in a couple of other threads for GNU/GCC and Keil.2015-06-12 06:27 AM
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.