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 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.
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 :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With