Hello all,
I ran into this issue over the weekend. I am using the FRDM-KE06Z dev board with KDS 3.0.
I have dedicated (4) 512-byte blocks of flash at Address 0x0000F800 for use as non-volatile data storage.
I am using the Processor-Expert-generated FLASH1_SetByteFlash( ) method to write 0s to a byte in my region.
The flash peripheral is setup using "write method" = "write" in PEx.
I apologize in advance for the length of the posting, but I want to avoid all of the typical "back-and-forth" and put out all the details at once.
Earlier code has already written the 0xfffffffd value at 0x0000F810 using the FLASH1_SetLongFlash method - which is working fine.
0x0000F800 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
I am careful to only change ones to zeros.
As I step through the following code in the debugger, I see Bytes being modified at 0x0000F801, 0x0000F802, and 0x0000F803 as well.
FLASH1_SetByteFlash( (RecordStore_TAddress)0x0000F800, 0xFE );
verylongdelay();
At this point in the Memory Browser view, I see what I expect:
(Displaying in Little Endian format)
0x0000F800 FFFFFFFE FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
But watch after this is executed...
FLASH1_SetByteFlash( (RecordStore_TAddress)0x0000F800, 0xFC );
verylongdelay();
Now things have gotten weird:
0x0000F800 FFFFFEFC FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF üþÿÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
The new value is in the correct location, but the previously-written byte has moved up!
FLASH1_SetByteFlash( (RecordStore_TAddress)0x0000F800, 0xF8 );
verylongdelay();
0x0000F800 FFFEFCF8 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF øüþÿÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
Now again, the new write is correct, but the side effects are very annoying:
The two previously-written bytes have been flashed at the two addresses above my target writeaddress:
And so it continues with this write:
FLASH1_SetByteFlash( (RecordStore_TAddress)0x0000F800, 0xF0 );
verylongdelay();
0x0000F800 FEFCF8F0 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF ðøüþÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
Again. Preview bytes are overwritten in higher-order bytes of the longword.
Now things change when we write again the 5th time.
We never go out of this specific long, but we do put the correct data at the correct target address:
FLASH1_SetByteFlash( (RecordStore_TAddress)0x0000F800, 0xE0 );
verylongdelay();
0x0000F800 FCF8F0E0 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF àðøüÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
Notice that no other bytes are affected when writing the 5th time.
But, as before, the three additional writes seem to adversely affect the other bytes in the longword:
FLASH1_SetByteFlash( (RecordStore_TAddress)0x0000F800, 0xC0 );
verylongdelay();
0x0000F800 F8F0E0C0 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF Àðøüÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
FLASH1_SetByteFlash( (RecordStore_TAddress)0x0000F800, 0x80 );
verylongdelay();
0x0000F800 F0E0C080 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF .Àðøÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
FLASH1_SetByteFlash( (RecordStore_TAddress)0x0000F800, 0x00 );
verylongdelay();
0x0000F800 E0C08000 FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF ..Ààÿÿÿÿÿÿÿÿÿÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
Obviously, at this point we have zeroed all 8 bits at location 0x0000F800, so the experiment has to end.
Can someone else please verify this operation? I am not sure whether this is a bug in the Processor Expert-generated code, or an issue with the Flash peripheral in the KE06Z part?
In order to keep moving forward with my project, I have replaced all FLASH1_SetByteFlash() calls with FLASH1_SetLongFlash(), and re-architected as necessary to use longwords instead of bytes. Hopefully I can save others some hassle in the future...
Thank you,
-Mike