ROM not getting the set value

I am working on developing a car software stack based on the Renesas RL78 controller. Getting started, variables declared as const (ROM variables) don't get initialized to the given value.

Ex: const uint8 var_test = 1;

On the other hand, global static variables are initialized.

Is this a startup code issue? kindly suggest ...

+3


source to share


4 answers


Usually const is not enough for a definition to allow variables to move around in ROM (you can always drop it). Usually you need to mark the variable with some particular compiler to indicate what you want, or perhaps a compiler flag to indicate your intent. I believe the IAR compiler uses the @ symbol so that you can specify the location for the variable. I would check his manual :-)



+1


source


Like the other answers suggested, your constant variable probably doesn't fit in the ROM section.

You need to tell the compiler / linker where to put it.

With the IAR toolchain it is possible something like



#pragma SET_CONST_PAGE(ConstArea)

const int myVariable1=42;
const int myVariable2=4711;

#pragma SET_DEFAULT_CONST_PAGE

      

But your debugger is not showing the correct value, this is another problem, it is possible that the variable is optimized.
To see what's going on, look in the map file and see (with a debugger) at the assembly level what is done.

+1


source


Non-static variables const

are not "persistent enough" to go to ROM, usually. If you test a function using variables like this, you will probably see that the function preamble has code to initialize variables on the local stack.

Of course, the startup code cannot fix this, since it (by definition) cannot write values โ€‹โ€‹to ROM.

0


source


Const objects are not required for the language to be located in ROM, but simply read only after initialization, and for performance reasons on some targets, for example, the compiler could avoid this.

Reference Manual for IAR RL78 C / C ++ Compiler :

"Static and global objects declared const and located in large memory are allocated in ROM. Const declared that saddr objects are allocated in RAM and initialized by the system runtime at startup. Const declared next to objects are allocated according to the --near_const_location option ...

In C ++, objects that require runtime initialization cannot be put into ROM.

Refer to the directive #pragma location

or @

in the manual, this allows you to place them at absolute addresses or in named memory segments.

0


source







All Articles