Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ROM variable not getting the defined value

Tags:

c

embedded

I'm working on developing a software stack for automotives based on a Renesas RL78 controller. Getting straight into the problem, variables declared const(ROM variables) are not getting initialized with the defined value.

Ex : const uint8 var_test = 1;

On the other hand, global,static variables are getting initialized.

Is this the problem with the startup code? kindly suggest...

like image 348
vickysat Avatar asked Jun 16 '26 23:06

vickysat


2 Answers

Like the other answers, probably your const variable isn't placed into a ROM section.

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

With an IAR toolchain it's probably something like

#pragma SET_CONST_PAGE(ConstArea)

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

#pragma SET_DEFAULT_CONST_PAGE

But that your debugger doesn't show the correct value is another problem, it's possible that the variable is optimized.
To be sure what happens look into the map file and look (with the debugger) at assembly level what is done.

like image 182
jeb Avatar answered Jun 21 '26 04:06

jeb


Usually const isn't enough of a qualifier to allow variables to go in ROM (you could always cast it away). Usually you need to mark the variable with something compiler specific to indicate what you want, or perhaps a compiler flag to indicate your intention. I believe the IAR compiler uses the @ symbol to allow you to specify a location for a variable. I'd check its manual :-)

like image 23
Joe Avatar answered Jun 21 '26 06:06

Joe