This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
I have selected the compiler version GNU v8.3.1.25 (Mitto Systems Limited) with the linker command file of msp430f5438a.
Now I want to set variables in the memory of (linker file example):
RAM: ORIGIN = 0x1C00, LENGTH = 0x4000 /* END=0x5BFF, size 16384 */ ROM (rx) : ORIGIN = 0x5C00, LENGTH = 0xA380 /* END=0xFF7F, size 41856 */ HIROM (rx) : ORIGIN = 0x00010000, LENGTH = 0x00035BFF
How can is set variables to a specific address in the memory e.g. 0x001c00 (RAM) or 0x005c00 (FLASH)? With #pragma LOCATiON(...) , I already tried , but it seems that does not work with GCC. And I do not want to create extra sections in the linker file; is that possible?
Marco Steinborn said:I do not want to create extra sections in the linker file; is that possible?
I'm not aware of any way to do that. The only way I know is to use the section variable attribute to put the variable in a section which you name. In the linker script, allocate that section to the desired address.
Thanks and regards,
-George
This is not currently possible to do entirely from C/C++. This year we are actually adding the functionality to be able to use a "location" attribute on functions and data to place them at a specific address.
As George mentioned, you need to use the "section" attribute with associated linker script updates.
A brief example:
int __attribute__((section(".qdata.2000"))) var_at_0x2000 = 1; int __attribute__((section(".qdata.2100"))) var_at_0x2100 = 2;
Then in the linker script (0x1C00 is the start address of RAM):
.data : { ..................... . = 0x2000 - 0x1c00; *(.qdata.2000) . = 0x2100 - 0x1c00; *(.qdata.2100) .................... } > RAM AT> ROM
Now in the linked output executable:
$ nm a.out | grep var_at 00002000 D var_at_0x2000 00002100 D var_at_0x2100
There's plenty of useful documentation on linker script placement here: https://sourceware.org/binutils/docs/ld/Location-Counter.html#Location-Counter