??? 02/05/08 23:09 Read: times |
#150357 - flash corruption or write failure Responding to: ???'s previous message |
I recently had a problem with flash corruption on an SiLabs part.
The project is an audio switcher with some buttons to select channels and the ability to store up to 32 "scenes" or combinations of enabled channels. Each scene requires 8 bytes. The scenes are stored in a page of the flash. At power-up, the micro fetches the 32 scenes and stores them in XRAM. When the user press the "recall scene" button and chooses a scene, I don't read from the flash, I just read the scene data from the RAM and configure the switches appropriately. When the user presses "store scene" and selects which slot to save it in, the RAM copy of the scene is updated. Then the page containing all of the scenes is erased and finally the RAM is copied to the flash. And this all seemed to work. Power off, power on, it all restored, great. But if the thing was off overnight, the flash recall at power-up returned garbage. I thought it was the reset, or the clock, or a bit backwards somewhere, or I was writing to an illegal location, or that my code was just too big, but none of that was the case. After stepping through the code in the debugger, I noticed that the flash page write function was exiting early, because it thought it was supposed to write zero bytes. Of course that was not what I intended. I then checked the function call, which accepted as one of its parameters an unsigned char called BytesToWrite. I left the three clues to why this failed in my post above. Can anyone see the REAL cause of the "flash corruption" ??? -a |