3
\$\begingroup\$

I have the following flash section defined in my linker file:

keep { section .SomeConst };
place at address mem: 0x0003F800 { readonly section .SomeConst };

In my code I have the following symbols defined:

#pragma location = ".SomeConst"
__root const uint8_t _value1[16] = {...};
#pragma location = ".SomeConst"
__root const uint8_t _value2[16] = {...};
#pragma location = ".SomeConst"
__root const uint8_t _value3[16] = {...};

Is it safe to assume _value1 will always be at 0x3F800? is it safe to assume _value2 will always be at 0x3F810? etc? I assume its not.. but wanted to check with the experts.

This is using EWARM

Thanks Bret

\$\endgroup\$
4
\$\begingroup\$

Your code only tells the compiler to place variables _value1, _value2 and _value3 in the segment starting at 0x0003F800. It is not safe to assume they will always get the address in order, especially if alignment comes into play.

If you need to force the compiler to store a variable at a given address, you should say so explicitly:

#pragma location=0x3F800
__root const uint8_t _value1[16] = {...};
#pragma location=0x3F810
__root const uint8_t _value2[16] = {...};
#pragma location=0x3F820
__root const uint8_t _value3[16] = {...};

You could also put your EWRAM variables in a structure which you would then place with #pragma pack. This would guarantee the order of variables inside the structure as well as the alignment, so you could effectively rely on offsets of individual fields being constant.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ That is what I thought, thank you very much for the clarification.. IAR doesn't explicitly say either way in their documentation. \$\endgroup\$ – BAO Aug 17 '16 at 13:16
1
\$\begingroup\$

Current linker arrangement only ensures all these variables will go to targeted section. But which variable would get placed at start may depend on order of object linking if same section is used in other compiled units . If you want to be 100% sure for a variable to be mapped at some address define exclusive memory section only for that variable and and map it in separately in linker w/ expected alignment.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.