Adding memory sections in linker script file?

Discuss how to use the features of Atollic TrueSTUDIO, including the editor, assembler, C/C++ compiler, linker, debugger, static code analysis and team collaboration tools.

Moderators: Markus Girdland, Mattias Norlander

mihooper
Posts: 12
Joined: Fri Jul 07, 2017 8:48 pm

Adding memory sections in linker script file?

Postby mihooper » Fri Sep 08, 2017 3:02 pm

I am trying to store program configuration variables in flash on my STM32F765 custom board. I want to place them in the top of flash memory so that I can erase and rewrite this sector when the variables change (Sector 11 0x081C 0000 - 0x081F FFFF). However, I can't seem to get the linker to place these values at this address location. Here's what I am doing:

Added memory location "CONFIG".
MEMORY
{
/* FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K */
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1792K
CONFIG (rx) : ORIGIN = 0x081C0000, LENGTH = 256K
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
SRAM1 (xrw) : ORIGIN = 0x20020000, LENGTH = 368K
SRAM2 (xrw) : ORIGIN = 0x2007C000, LENGTH = 16K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}

The I add the following in the linker file:
.flash_config :
{
*(.flash_config*);
} >CONFIG

Then in my main.c program I add:
__attribute__((section(".flash_config.TEST_VARIABLE"))) int test_variable = 1;

After building and linking, then entering debug mode, I would expect to read this value in memory location 0x081C0000.
But it does not appear to be properly loaded. In my memory browser I see this:

0x081C0000 FFFFFFFF FFFFFFFF FFFFFFFF

Can someone see what i am doing wrong?

Thanks,

MikeH
Thanks,
Mike H

Supertony
Posts: 1
Joined: Tue Jan 23, 2018 7:20 am

Re: Adding memory sections in linker script file?

Postby Supertony » Tue Jan 23, 2018 7:39 am

HI , i have the same problem with last release of Truestudio for STM32, seems impossible to placing const data at my specific address.
Why? How to fix it?
Antonio.

bartes
Posts: 1
Joined: Thu Dec 01, 2016 4:10 pm

Re: Adding memory sections in linker script file?

Postby bartes » Tue Jan 23, 2018 4:21 pm

Not sure what's wrong with your code, but I have a few suggestions for debugging the problem.

In General, to see / check where the linker has placed your variables you can set it to generate a map file and then look through it. Go to Project Properties, C/C++ Build->Settings->Tool Settings->Other->Reports and check 'Create Map File'.

TrueSTUDIO also has a much nicer interface for viewing the map file in it's 'Build Analyzer'.

GoofBall
Posts: 4
Joined: Fri Nov 24, 2017 8:09 pm

Re: Adding memory sections in linker script file?

Postby GoofBall » Thu May 14, 2020 4:53 pm

Try slapping "volatile" in front of your declaration:

Code: Select all

volatile __attribute__((section(".flash_config.TEST_VARIABLE"))) int test_variable = 1;

frank_ee
Posts: 117
Joined: Wed Apr 05, 2017 5:08 pm
Location: USA

Re: Adding memory sections in linker script file?

Postby frank_ee » Thu May 14, 2020 8:45 pm

Hello,

Did you get it to work?

mihooper
Posts: 12
Joined: Fri Jul 07, 2017 8:48 pm

Re: Adding memory sections in linker script file?

Postby mihooper » Thu May 14, 2020 8:53 pm

No. I gave up on using flash to store the config info since I needed to change config info on the fly, which is to slow for my time-sensitive application. I now us a FRAM (bus speed read-writes) device. Works well.
Thanks,
Mike H

frank_ee
Posts: 117
Joined: Wed Apr 05, 2017 5:08 pm
Location: USA

Re: Adding memory sections in linker script file?

Postby frank_ee » Thu May 14, 2020 10:28 pm

The following Atollic blog http://blog.atollic.com/using-gnu-gcc-on-arm-cortex-devices-placing-code-and-data-on-special-memory-addresses-using-the-gnu-ld-linker describes the steps.

I can provide data I placed into the linker script file I used. Although your data is in RAM, you can use ST HAL libraries to reprogram flash sections in case you go back to the original.

You can also allocate sections in RAM for buffers using the linker script.


Return to “Atollic TrueSTUDIO tool discussions”

Who is online

Users browsing this forum: No registered users and 8 guests