Flash One-Time Initialization

Showing results for 
Search instead for 
Did you mean: 

Flash One-Time Initialization

Contributor II

I'm using the 56F807 and would like a way to know whether the chip has been powered on/the code has been run before.

Basically, I'm storing a bunch of parameters in the data flash and I would like to know in my C code if the parameter addresses in flash are valid (having been initialized by being run once before) or if I need to initialize them programmatically, because they are uninitialized.

I know of two ways to solve this problem, that if possible I'd like to avoid:

1) Custom write some addresses in the flash to say they haven't been initialized, ie., writing 0xdead 0xbeef to a couple words at a specified location and then on the first time power up (and every powered up), check those addresses and write them to be 0x0 if they aren't. The problem with this is, as I understand it, I would have to re-code the s-rec download program to custom write those addresses, and I would like to avoid doing this if possible.

2) Specify the addresses of my parameters, by default in the code, and then, I believe, when I change those, I would also need to change the constants in flash program memory. This solution, as I understand it, just scares me.

I would appreciate any suggestions or thoughts!

Labels (1)
0 Kudos
2 Replies

Contributor II

Wow, that was easy.

I totally overlooked the obvious that the flash is initialized with 0xffs.  (I for some reason thought it was undefined.)  Took your advice and allocated a space in flash (0x2000) to be an initialized word and just read and rewrote that with an "initialed" value if it hadn't been initialized... and obviously did my parament initialization if it wasn't already initialized the first time.

Thanks for the advice!

0 Kudos

Contributor IV

I'd put a 'dummy' variable in flash.  Once things are initialized, 'zero' the dummy variable by just writting a 00h pattern over it.  Once that happens, the only way to 'unzero' it would be to reprogram the part.

If you're talking about something that could move...  Put a BLOCK of addresses, with each pointer being valid for a possible block.  Then you can have a loader just drop data into locations.  If it has to 'move', then zero the pointer.  If your program has to 'find' the blocks, just have it start a walk and ignore 00 entries.

Depending on complexity, you might be able to just put 'no data' as FF, Data as a value (with a known value structure) and 00 as 'voided data', then have your program walk till it finds valid data. 

One caveat is to make sure you don't put a data type that could possibly have a 00 value as the head of the block.  If that can happen, then you'll have to make sure you add at least one byte to your structure that can be FF (no data), 00 (erased data), any other value (data block follows). 



Message Edited by mke_et on 03-02-200603:03 PM

0 Kudos