Hi, I am working with Qorivva Power Arctechture and CodeWarrior. In my program I have declared some fixed constants, like calibrations constants. I have used "const int" to allocate it in flash memory with some non-volatile value. After recalibration process I want to change the value of this variables. My example code is:
#include <string.h>
#include "MPC5634M_MLQC80.h"
const int my_map_ROM[4]; // constant calibration map (FLAXH)
volatile int my_map_RAM[4] = {2,1,0,0}; // volatile calibration map (RAM)
int main(void)
{
int count=0;
volatile char desvio = 0; // change manualy to call different tasks
volatile int a=1, b=0, x; // change manually for debug
int y = ~0; // see result
while(1)
{
switch(desvio)
{
case 1: // Load data Flash2RAM in the begining
memcpy( (void *)my_map_RAM[0], (const void *)my_map_ROM[0], 4*sizeof(int) );
desvio = 0;
break;
case 2: // Load RAM data to local variables
a = my_map_RAM[0];
b = my_map_RAM[1];
desvio = 0;
break;
case 3: // Change RAM values for other tasks
my_map_RAM[0] = a;
my_map_RAM[1] = b;
desvio = 0;
break;
case 4: // Save data RAM2Flash for energy fault
memcpy( (void *)my_map_ROM[0], (const void *)my_map_RAM[0], 4*sizeof(int) );
desvio = 0;
break;
default:
y = a*x +b;
}
count++;
}
}
"case 2" and "case 3" are OK, but "case 1" and "case 4" does not work properly.
Original Attachment has been moved to: Project_VarConst.zip
Original Attachment has been moved to: Installed-Plugins.TXT.txt.zip
Solved! Go to Solution.
Hello Carlos,
There is probably an user error: memcpy() parameters are missing address "&" operators. So actually do not copy the array from Rom to Ram but rather copy from addresses stored at position 0 of your array.
I'd suggest you to change the line from:
memcpy( (void *)my_map_RAM[0], (const void *)my_map_ROM[0], 4*sizeof(int) );
to:
memcpy( (void *)&my_map_RAM[0], (const void *)&my_map_ROM[0], sizeof(my_map_ROM) );
or
memcpy( (void *)my_map_RAM, (const void *)my_map_ROM, sizeof(my_map_ROM) );
Note:
You cannot program Flash (case 4: // Save data RAM2Flash for energy fault) just by memcpy(). It requires some additional steps (erase memory, program memory). The ROM data should be placed to a specific Flash block that you can erase/program without interference to the executed code.
I'd suggest you to check Freescale C90FL Software driver for more details. (http://cache.freescale.com/files/microcontrollers/software/app_software/C90FL_JDP_EEE_v104.exe?fsrch...)
Hope it helps.
regards,
Stanislav
What's the CodeWarrior version you are using?
For Classic CodeWarrior, please:
1)Start the IDE and click on Help | About Freescale(Metrowerks) CodeWarrior.
2)Click on Installed Products
3)Provide us all info displayed. Or you can save them in a txt file.
For Eclipse CodeWarrior, please:
1)Start the IDE and click on Help | About CodeWarrior Development Studio.
2) Provide us the info displayed.
Any suggestion ?
Hello Carlos,
There is probably an user error: memcpy() parameters are missing address "&" operators. So actually do not copy the array from Rom to Ram but rather copy from addresses stored at position 0 of your array.
I'd suggest you to change the line from:
memcpy( (void *)my_map_RAM[0], (const void *)my_map_ROM[0], 4*sizeof(int) );
to:
memcpy( (void *)&my_map_RAM[0], (const void *)&my_map_ROM[0], sizeof(my_map_ROM) );
or
memcpy( (void *)my_map_RAM, (const void *)my_map_ROM, sizeof(my_map_ROM) );
Note:
You cannot program Flash (case 4: // Save data RAM2Flash for energy fault) just by memcpy(). It requires some additional steps (erase memory, program memory). The ROM data should be placed to a specific Flash block that you can erase/program without interference to the executed code.
I'd suggest you to check Freescale C90FL Software driver for more details. (http://cache.freescale.com/files/microcontrollers/software/app_software/C90FL_JDP_EEE_v104.exe?fsrch...)
Hope it helps.
regards,
Stanislav
OK, but link is broken. Try Freescale Search .
Thank you.
It is attached.