static const - placement in flash or RAM (ARM gcc Question)
I have some hideously obfuscated code I am trying to port from Codewarrior to Crossworks. Unfortunately I am finding it crashes in Crossworks and it all boils down to a some particular structures (within structures) being placed in flash yet others being placed in RAM. In Codewarrior, the relevant structures *do* get placed in RAM, even though they are set to a certain value in the source code. In Crossworks, all structures declared static const seem to get placed in flash (in rodata).
How on earth does Codewarrior know which static const declarations to put in RAM and which in flash and, maybe more importantly, how do I mimic this in Crossworks?!
Codewarrior also uses gcc by the way.
Thanks!
Rob
-
You need to have an attribute for your variable that says where it should be placed. For example:
const volatile char myVariable __attribute__ ((section (".data") )) = "String in RAM";
I've never worked out why you need double brackets.
See Crossworks for Arm: CrossStudio User Guide: Linking and Section Placement
and Crossworks for Arm: GNU Tools Reference: GNU C/C++ Compiler: Extensions to the C language Family: Specifying Attributes of Variables
Hope this helps,
Danish
Please sign in to leave a comment.
Comments
2 comments