Question

I want the variables in a specific .c file should be stored in a particular RAM location,how can I achieve this. I am using IAR IDE for ARM.

The reason I want to do so is when compiler stores variables in bit-band SRAM region of ARM core they cannot be read correctly.If I comment some section of code then compiler stores them in non-bitband SRAM region and then correct result is observed.

Was it helpful?

Solution

With EWARM, you can place variables with a few methods. You can place at a specific address using @. From IAR's support site:

const char RELEASEDATE[16] @ 0x0000FF10 = __DATE__ ;
const char RELEASETIME[16] @ 0x0000FF20 = __TIME__ ;

Alternatively, you can locate variables in a section (which sounds like what you want) using the location pragma. From the same source:

#pragma location = "ConstSection1"
__root const char RELEASEDATE[16] = __DATE__ ;
#pragma location = "ConstSection2"
__root const char RELEASETIME[16] = __TIME__ ;

And in your linker file (.icf) you would have:

place at address mem: 0x0000FF10    { readonly section ConstSection1 };
place at address mem: 0x0000FF20    { readonly section ConstSection2 };

I prefer the #pragma as the @ operator looks out of place. Additionally, someone reading the code expects #pragma to be something compiler specific, while @ hides itself in the code and doesn't stand out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top