Copy Values from ROM to RAM at startup

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy Values from ROM to RAM at startup

2,221 Views
Donal
Contributor II
Hello All,
I have a problem where I need to copy calibrations from ROM to RAM upon startup, but I wish to keep the same variable name throughout the application code.

For example, a calibration variable initialization is as follows:

#pragma CONST_SEG EEPROM_CALS
extern const U32 Sb10_Constant8 = 0x0023;

Now, this variable is used throughout the application. And there are certain situations when I will want to modify this value, to test the behaviour of the application to this new value. I may also want to flash this new value back into EEPROM.

There can't be a second RAM variable for this, as part of the application is auto generated.
So the following simple solution would not suffice:
Sb10_Constant8_RAM = Sb10_Constant8_ROM;

Is there any method to allow the variable initialization to occur but upon start-up the value is copied into RAM with the variable name Sb10_Constant8 always residing in RAM?


Cheers,
Donal
0 Kudos
4 Replies

762 Views
CrasyCat
Specialist III
Hello
 
I assume you are using CodeWarrior for HC08 or HC12 as development software. Am I right?
 
If this is the case, the standard Startup code we are delivering is copying initialization value from ROM to RAM at startup. Just make sure you are using ANSI C startup and not minimal startup code when creating your application.
 
If you have already created your project, make sure to remove the option -D__ONLY_INIT_SP from the compiler command line and rebuild your application.
 
CrasyCat
0 Kudos

762 Views
Donal
Contributor II
Hi Mac : The names of the calibration variables are global, but we can't change them as they are autogenerated along with a large proportion of the code. If we were to have different names then it would involve a lot or rework each time the autogenerated code is updated.


CrasyCat: I am using Codewarrior for the HCS12. So I have to modify this startup code so that it will copy my calibrations from ROM to RAM. Will the varibale names also point to the RAM copies rather than ROM?

Cheers,
Donal
0 Kudos

762 Views
Lundin
Senior Contributor IV
What you wish to do is to allocate a variable at two locations. That isn't possible, since it doesn't make sense. But if you must, you could simulate that behaviour with macros. Lets assume that MY_VAR is the holy name that you use all over the code which cannot be changed:


#define MY_VAR (*address)

#pragma CONST_SEG GLOBAL_ROM
const volatile int myVarROM = something;

#pragma DATA_SEG GLOBAL_RAM
volatile int myVarRAM = myVarROM;

volatile int* address = &myVarROM

...

int main()
{
...
myVarRAM = changedToSomething;
address = &myVarRAM;
0 Kudos

762 Views
bigmac
Specialist III
Hello Donal,
 
I do not quite understand why the variables at the two different locations cannot have different names.  I assume that the RAM locations could be global variables, and explicitly assigned an initial value corresponding to the required constant value.
 
Or have I missed something obvious?
 
Regards,
Mac
 
0 Kudos