3
votes

I am working on an embedded C project using GCC for ARM V4.8.3. What I am trying to achieve is to place a structure into the FLASH (ROM) memory of the MCU. Since my previous post I was thinking that each object identifier qualified as a constant (const) is to be placed into the .rodata section, which in my case (according to the liker script) is nested by .text which in other hand resides within the FLASH memory region.

I tend to think so because I checked one of my object definitions, which was a constant pointer:

const char * const project_stringInvalidCharacter = "Invalid Character! \n";

The pointer was situated within FLASH if qualified as a constant.

But, when I defined a constant object of type int (const uint_8 myObj;), I saw that its address represented a number that belong to the RAM or .bss region.

In other words const works for the pointer, but didn't for integer type. By works I mean it does what I expect, reasoning from my previous post, namely to "place" the identifier into the FLASH (ROM).

1
I swear no reported warnings at all. - Hairi
@Olaf I am using eclipse IDE. Preferences->C/C++->Code Analysis only two warning boxes are currently unchecked Format String Vulnerabilities and Return with parenthesis. I don't see warning that has something to do with unassigned read-only data objects. Or something like that. If you are familiar with Eclipse IDE 3.8.1, could you please help me to enable them? - Hairi
Hmm.. I just checked and you really are right (how embarassing;-) for a global variable. Sorry, I just remembered I got this message once (long time ago), but this is only for non-static variables, as they are not guaranteed to be initialised. Makes sense - somehow. That's why askers are required to provide a minimal reproducible example. (Yet, an automatic local would likely not be placed into rodata anyway). Only solution is to always initialise static const variables. - too honest for this site
I had to dummy-edit to remove the DV. - too honest for this site

1 Answers

5
votes

Maybe the compiler is a bit confused as you don't assign a value to your constant. Try:

const uint_8 myValue=42;

and see where it will be located.