variable at fixed memory address

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User9076
Level 1
Level 1
Hello,
how can I tell the compiler / linker that a variable (here int16_t iAverageValues [16]) is always at the same address? I need it for the XCP-Protocol. I don't want to update the addressmapping after building a new softwareversion.
I've tried following thinks, but with no success:
int16_t iAverageValues [16] __attribute__((at(0x2000FFC0)));
or
int16_t iAverageValues [16] __attribute__ ((section (XCP_DATA)));
an modify the linker script with something like this
XCP_Data(!RX) : ORIGIN = 0x200FFC0, LENGTH = 0x20

Thanks
Markus
0 Likes
2 Replies
chismo
Employee
Employee
First like received
Hello Markus,

From the linker script file, the address 0x2000FFC0 is reserved:

/* .no_init section */
.no_init 0x2000FFC0 (NOLOAD) :
{
Heap_Bank1_End = .;
* (.no_init);
} > DSRAM_1_system


In any case, it should be possible to define a dedicated data section on the available DSRAM area.

For example, I added the following "my_data" section before the "bss" section in the linker script file:

/* Dedicated data section */
.my_data 0x20000100 :
{
KEEP(*(.my_data))
} > DSRAM_1_system


And I added the "attribute" keyword accordingly to the variable in the main.c file,

int16_t iAverageValues[16] __attribute__ ((section (".my_data")));


This appears to work fine.

Regards,
Min Wei
0 Likes
User12537
Level 1
Level 1
Hello Min Wei,

I have tested your suggestion and it works as far as I am in debug mode. If I switch to Release it doesn’t work any more. I found out the reason: Debug Setting -> Optimization Level: None, Release Setting -> Optimization Level: Optimize for size. If I change this in Release mode it works well again. But I have bigger code-size. I thought the KEEP instruction in the linker script would prevent this? Or am I doing something wrong?
Regards, Dirk
0 Likes