store data when mcu is off

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

store data when mcu is off

7,307 Views
shiloh
Contributor I
I have a project where I need to store some data in the flash memory of the HCS08GT60.  My project has a hardware calibration routine that stores calibration data into variables.  Then I copy the variables into variables that I have assigned addresses to in flash memory.  All of my code is in C using CodeWarrior.  My code compiles and appears to work, but the variables in flash memory get reset when I cycle the power to the MCU.  I am not sure why these variables get reset.  I want the flash variables to survive a power reset.
 
Here is some of my C code:
#pragma DATA_SEG NON_INITIALISED
unsigned short FlashThrottleMin;
unsigned short FlashThrottleNeutral;
unsigned short FlashThrottleMax;
#pragma DATA_SEG DEFAULT
 
That code is immediately after all of the include lines but before any other variable declarations.  I also have code that sanity checks those values to see if they were set already by the hardware calibration routine and code that copies those varialbes into RAM variables during startup.
 
Here is the code in P&E_ICD_linker.prm and monitor_linker.prm, but not P&E_FCS_linker.prm.
 
/* This is a linker parameter file for the GT60 */
NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */
SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
     FlashThrottleMin       =  NO_INIT      0x1EFF TO 0x1F00;
     FlashThrottleNeutral   =  NO_INIT      0x1F01 TO 0x1F02;
     FlashThrottleMax       =  NO_INIT      0x1F03 TO 0x1F04;
     //ROM                    =  READ_ONLY    0x182C TO 0xFFAF;
     Z_RAM                  =  READ_WRITE   0x0080 TO 0x00FF;
     RAM                    =  READ_WRITE   0x0100 TO 0x107F;
     ROM1                   =  READ_ONLY    0x1080 TO 0x17FF;
     ROM2                   =  READ_ONLY    0xFFC0 TO 0xFFCB;
END
PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */  
     NON_INITIALISED                   INTO  FlashThrottleMin;
     NON_INITIALISED                   INTO  FlashThrottleNeutral;
     NON_INITIALISED                   INTO  FlashThrottleMax;
     DEFAULT_RAM                       INTO  RAM;
     _DATA_ZEROPAGE, MY_ZEROPAGE       INTO  Z_RAM;
     DEFAULT_ROM, ROM_VAR, STRINGS     INTO  ROM; /*,ROM1,ROM2*/ /* in case you want to use ROM1,ROM2 here as well, add option -OnB=b to the compiler. */
END
STACKSIZE 0x50
VECTOR 0 _Startup /* Reset vector: this is the default entry point for a C/C++ application. */
//VECTOR 0 Entry  /* Reset vector: this is the default entry point for an Assembly application. */
//INIT Entry      /* For assembly applications: that this is as well the initialization entry point */
 
Does anybody have any ideas as to why this is not working as expected?  Thanks.
Labels (1)
0 Kudos
Reply
7 Replies

812 Views
Technoman64
Contributor III

You will have to write a FLASH programming routine to Erase and Store your variables before the power down. The tricky part is that you can not Erase and Program the FLASH while running code from it. You will need to copy a small programming routine into RAM then call this the RAM Function. Once the variables are writen you can do a Return and go back to running code out of the FLASH array.

You should be able to find application notes regarding this.

0 Kudos
Reply

812 Views
Alban
Senior Contributor II

Hiya,

Indeed Technoman !
You have software drivers which handle Flash Programming.

HCS08SGFNVMSSD
Standard Software Driver for HCS08 SGF Flash
Program/erase software driver for SGF NVM (flash and EEPROM) in HCS08.

I also need to pinpoint that you CANNOT execute/read from a Flash block you are programming to.
However, the S08GT60 includes several blocks to get the total size. Therefore you can execute from one flash block your code whilst you are storing your variables in another one.

Also, when a MCU has E²PROM or emulated E²PROM, it is preferable to use it rather than Flash to store variables. Because it's usually easier to handle !

Please have a look at the Flash/E²PROM drivers included and tell us how you get on !!!

Cheers,
Alban.

 

0 Kudos
Reply

812 Views
peg
Senior Contributor IV


Alban wrote:

However, the S08GT60 includes several blocks to get the total size. Therefore you can execute from one flash block your code whilst you are storing your variables in another one.



Does it?

Not that I can find any reference to, please explain.

Regards Peg


 

0 Kudos
Reply

812 Views
Alban
Senior Contributor II
I'll check on Monday with the engineer who told me that...
As you mention, there is only one set of Flash registers.
However, I know it's not only one array physically.
I need to comfirm with him if these arrays are separated High Voltage wise and also know their number to have their boundaries.
 
To Be Continued
0 Kudos
Reply

812 Views
peg
Senior Contributor IV

Hi Alban,


 


Alban wrote:
I'll check on Monday with the engineer who told me that...
As you mention, there is only one set of Flash registers.
However, I know it's not only one array physically.
I need to comfirm with him if these arrays are separated High Voltage wise and also know their number to have their boundaries.
 
To Be Continued



Any word yet?

Regards Peg

 

0 Kudos
Reply

812 Views
Alban
Senior Contributor II
Nope, not yet...
0 Kudos
Reply

812 Views
Alban
Senior Contributor II

Finally...
I misunderstood my colleague.
There's only one charge pump for a whole 60KB array. You do need to execute Flash Programming Routines from RAM!

Alban.

0 Kudos
Reply