Using Flash as EEPROM inMC9S08QG8

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

Using Flash as EEPROM inMC9S08QG8

2,958 Views
RogerSchaefer
Contributor III

In her post Peg has explained how to use a bank of Flash in the QG8 as EEPROM and I can do that without a problem if there are only a few bytes that need to be saved as if it were in EEPROM. However, what if you need to have a fairly large amount of data, say 300 to 500 bytes, in a pseudo EEPROM area? There is not enough RAM to save a copy of the data. I suppose you could use another bank of Flash but I don’t have another 512 bytes to spare.

Does anyone have a method to solve this problem?

Roger Schaefer

www.RASmicro.com

Labels (1)
0 Kudos
Reply
7 Replies

660 Views
tonyp
Senior Contributor II
You have hit on an old design limitation.  (In my opinion all MCUs should have at least twice the RAM of the minimum Flash erase block size, either by increasing RAM or by lowering the Flash erase block size.  But, that's another story.)

Back to your problem:  Obviously, your EEPROM data aren't loaded into corresponding variables all at once, or else you shouldn't have a problem.  So, you're using that one Flash page more like a mini-disk, and I think in this case there isn't much you can do (without over-inflating code, which already must be near its limit or else you would find that extra Flash page you actually need).

It would help to know what most of your data represents, but I'll give it a shot without it.

Other than going with a bigger chip, you could try these:

Optimize the code further so you may free one Flash page for scratch pad.  Even carefully written assembly code can often be optimized down a bit several times.  If you're not using assembly in such a small chip, you could rewrite the whole thing in assembly, and the problem will disappear (you will certainly free at least one more page).

Simple compression or even variable combination based on bit-size is one option.  For example, a value up to 3 with a value up to 63 can share the same byte.

Choose most-used defaults for some variables, and not allow changes for them.  Or, allow up to so many changes in all variables collectively.  So, that one user may change any variable but not more than, say, ten variables total.  Then you only save the changed defaults to the mini-disk (but you need to index things so you can know which is which).
0 Kudos
Reply

660 Views
bigmac
Specialist III
Hello Roger,
 
I think that, whatever programming method you have adopted, if the code size should exceed 14 of the 16 available flash pages, you would be over-stretching the use of that device anyway.  There would be very little allowance for spare capacity, should future enhancement of the code be necessary.  The requirement for additional non-volatile parameter storage will only exacerbate the already critical situation.
 
It might appear that you should be using a device with at least 16k flash capacity.  This should allow the use of two flash pages for alternate writes of your non-volatile parameters.  You might even have additional RAM capacity within the larger device.
 
I would be wary of a scenario where the non-volatile parameters were transferred to RAM, one or more values were modified, and then the flash page was erased and re-programmed.  The parameters would be vulnerable to a power fail occurring during this process, with potentially total loss of all parameters.  I think the use of two flash pages would be safer.
 
Regards,
Mac
 
0 Kudos
Reply

660 Views
RogerSchaefer
Contributor III
Thanks Tony & Mac,
 
The program is in assembly.  I wrote it orginally for a MC68HC908GP32 which has more flash, ram and smaller size sectors to erase.  But the GP32 is a bigger chip & costs more.  I was hoping to slim down the program to fit into a QG8 so that I could use a pc board I designed for another use.  Can see a photo here:  http://www.rasmicro.com/DS18B20.htm
 
Roger
0 Kudos
Reply

660 Views
JimDon
Senior Contributor III
Geeeze where's your sense of humor.
That'd a nice board you have made and I can undesrtand you would to use it  before you design a new one.
Well, the only constrictive input I have is consider an I2C EEPROM in an 8 pin dip package in the prototype area. It shows the I2C pins free on the schmatic, only takes two pins. The 24LC256 has 64 byte pages, so you should be able to squeeze that in to ram

A 24LC256 can he had for a few dollars (1.70 at mouser) .







Message Edited by JimDon on 2008-07-26 06:24 PM
0 Kudos
Reply

660 Views
JimDon
Senior Contributor III
The real question is peg a she or a he.


0 Kudos
Reply

660 Views
peg
Senior Contributor IV
Or whether bigmac is really a hamburger???

BR David

0 Kudos
Reply

660 Views
bigmac
Specialist III


peg wrote:
Or whether bigmac is really a hamburger???

BR David


Actually this bigmac is vegetarian.

 
0 Kudos
Reply