Jason Yeh

Tips for QG8 flash EEPROM emulation

Discussion created by Jason Yeh on Feb 6, 2008
Latest reply on Feb 7, 2008 by Jason Yeh
Recently, I decide to use qg8 to replace silab's 8051 mcu. The first problem I meet is the EEPROM emulation . In the 8051, it simply use movx instruction to access the flash memory as EEPROM, but it seems difficult in HCS08 family.

I had go through many documents, most of them are not clearly told the detail information about using flash to emulate EEPROM. Finally I download the source code in c from this forum, the link is http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=8708&query.id=480164#M8708.

but unfortunelly, there is no document memtion about the details, so I want to share what I know about EEPROM emulation in QG8, maybe someone already know....

First, please download the QG8 flash 6.zip from the link, you can directly run this project without any modifications. but if you want to merge these code into your project, you must modify the .prm file.

In this section, (I assume the EEPROM locate in 0xe000 to 0xe1ff page)

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
    Z_RAM                    =  READ_WRITE   0x0060 TO 0x00FF;
    RAM                      =  READ_WRITE   0x0100 TO 0x025F;
    ROM                      =  READ_ONLY    0xE000 TO 0xFFAD;
    ROM1                     =  READ_ONLY    0xFFC0 TO 0xFFCF;
 /* INTVECTS                 =  READ_ONLY    0xFFD0 TO 0xFFFF; Reserved for Interrupt Vectors */
END

a.) add this line
    EEPROM      = READ_ONLY 0xE000 to 0xE1FF   // reserve space to prevent overlap of code
b) modify
    ROM            = READ_ONLY 0xE200 to 0xFFAD    //
c) add
    CODE_RELOC   = READ_ONLY 0xE200 to 0xE240 RELOCATE_TO 0x0060

I'm not sure what the c). do, because the flash routines are not locate in 0xE200 to 0xE240 in my program, but it still can run.

Finally, if you want to "write" certain address, you must run the "CopyErase" first, the "CopyErase" routine will clear (or reset?) the content of the EEPROM to 0xff so that you can "write" this address again.

This is because the "write" process only set the required bits to "0", not "1". For example, if writing a value "0xa5" into address 0xE000, the process will be
1. call CopyErase
2. call CopyProgram
3. call RunProgram

then, if a new value of 0x5a should be update, the process is the same as above, if skip (1), the data in 0xE000 will be "0x00".

Outcomes