Storing dynamic data in flash.. help ?

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

Storing dynamic data in flash.. help ?

3,890 Views
RChapman
Contributor I
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
 
Posted: Tue Feb 22, 2005 6:56 pm  
 
 am interested to know how I can store dynamic data in the flash of an HC08KX8. Basically I need to store non-volatile data in th KX8 wich will change during runtime! I understand there are ROM routines to write to flash, but I not sure how I would use them using C. Once the KX8 is running in the field, it will be shut off and on, and the values stored need to be remembered! Any info, links to where I can read up on this would be of great help! Thanks in advance!!!!!!
 
Posted: Tue Feb 22, 2005 7:02 pm      
 
Hi, The Application Note AN1831 is describing how to use the on-chip Flash programming routines on KX8. Got to FSL website and search for: Application Note AN1831 Posted: Tue Feb 22, 2005 7:15 pm    
 
Thanks for such a quick response! I'll check it out and get back to you!
 
Posted: Tue Feb 22, 2005 7:17 pm  
 
 
THANKS!!!!!!!!!! I will be reading these!!!!!!!!
 
Posted: Tue Feb 22, 2005 7:41 pm   
 
Seems like this will do! This site is awesome! Very quick responses!
 
Posted: Tue Feb 22, 2005 8:02 pm     
 
AN2346 gives ya an algorithm - altogether 100 bytes or so... Could be reused with some clk-speed considerations within each derivate.
 
Posted: Wed Mar 02, 2005 2:18 am    
 
Works like a charm! Thanks all!!! HC08 Rules
 
 

Message Edited by Alban on 01-26-2006 11:58 AM

Labels (1)
0 Kudos
2 Replies

369 Views
Ozelo
Contributor I
I have read all the documentation described here and have successful implemented the code using CW 5.0. BUT, for some reason I dont know yet, I still cant simulate it using the "True-Time Simulator" that says I am trying to access "unimplemented ROM bytes". Im coding for the KX8 variant and also I have correctly specified the ROM resident routines addresses.

My question is: Have anyone done this already using the simulator or it only works using the device directly? Am I doing something wrong maybe?

Here is the code:



/* ROM Resident Routines Pointer Definitions */
#define PRGRNGE 0x1009 /* Program a range of FLASH locations */
#define ERARNGE 0x1006 /* Erase a page or a whole array of FLASH */
#define RDVRRNG 0x1003 /* Reads/Verifies a range of locations in FLASH */
#define GETBYTE 0x1000 /* Gets a byte of data from comm port */
#define DELNUS 0X100C /* Generate a delay */

void FLASHProgram(void);
void FLASHErase(void);

/* RAM Data Block */
unsigned char CTRLBYT @0x0048; /* Select between mass/page erase */
unsigned char CPUSPD @0x0049; /* CPU value equals 4x Bus speed */
unsigned int LADDR @0x004A; /* Last address of FLASH to manipulate */
unsigned char DATA[4] @0x004C; /* Data to program into FLASH */

unsigned int FADDR = 0xFB43; /* First Address to store data in FLASH */
unsigned char DataSize = 4; /* Variable to calculate Last Address */


const byte FLBPR_INIT @0x0000FF7E = 0xFF; /* Initialize Flash Block Protection */

/*
* FLASHProgram: Calls ROM-Resident Routine PRGRNGE.
* Locations starting from address specified by FADDR will be
* programmed. The range size is calculated depending on LADDR
*
* Parameters: None
*
* Return : None
*/
void FLASHProgram(void){

asm(LDHX FADDR); /* Load address of RAM Data Block to H:X */
asm(JSR PRGRNGE); /* Call PRGRNGE ROM Subroutine */

}

/*
* FLASHErase: Calls ROM-Resident Routine ERARNGE.
* In the case mass bit (CTRLBYT bit 6) is set, calling ERARNGE
* will perform a mass erase. If the mass bit is cleared (0), a
* page erase will be performed. FADDR may be any address in the
* range to be erased.
*
* Parameters: None
*
* Return : None
*/
void FLASHErase(void){

asm(LDHX FADDR); /* Load to H:X address in FLASH range to be erased */
asm(JSR ERARNGE); /* Call ERARNGE ROM Subroutine */

}


And here is the call:


/* RAM DATA Initialization */
CTRLBYT = 0; /* Page erase (clear bit-6) */
CPUSPD = 40; /* 9.8304MHz * 4 = 39.3 = 40 (using external OSC) */
LADDR = FADDR + DataSize - 1; /* Last address in FLASH to program */

/* DATA Buffer Initialization */
DATA[0] = 0xAA;
DATA[1] = 0xBB;
DATA[2] = 0xCC;
DATA[3] = 0xDD;

FLASHErase(); /* Erase the page in FLASH specified by FADDR */
/*
* NOTE: FLASH locations must be blank before
* trying to write data into them.
*/
FLASHProgram(); /* Program DATA into FLASH location starting at FADDR */



Please, help. :smileyhappy: I must be missing something... TIA
Ozelo
0 Kudos

369 Views
bigmac
Specialist III

Hello Ozelo,

I would suspect that the simulator would not simulate the ROM-based routines since there is really no reason for it to do so.  So you will probably need to test EEPROM emulation using actual hardware.  For the simulator, "implemented ROM" would actually refer to flash memory.

For simulation purposes, you might replace the ROM routine calls with dummy functions that do nothing, to be used during simulation only.  This will at least allow the program to compile and link.

Regards,
Mac

 

0 Kudos