I am attempting to store an event log in the FlexNVM memory of the MK20DX128VLH5 which is partitioned for half data flash and half EEPROM backup (16K each).
I did the development using the top part of the program flash and everything is working well. Events are stored as expected and can be retrieved without any flash programming errors.
My understanding is that the only difference in storing to program flash or data flash is the address being used in the FTFL_FCCOB registers. In program flash I am using 0x1F000 up to 0x1FFFF (top of the 128K device). For the FlexNVM, as I have it partitioned (DEPART= 2), I understand that the lower address area is used for data flash and the upper area is used for EEPROM backup records. So the address I am using for the data flash is 0x10000000-0x10003FFF. Before any write I confirm that the area being written is currently erased (0xFFFFFFFF).
When I write to an aligned address in the FlexNVM range I get back the MGSTAT0 flag which says that there was an error during the verify operation. Also, once the MGSTAT0 flag is set I can not write to the EEPROM anymore. This would indicate that something is messed up in the entire FlexNVM block. A reset or a write to the program flash will clear the MGSTAT0 flag and I can write to EEPROM again...until I try a write to the data flash.
NOTE: The final step in the Program Long Word command...clearing the CCIF bit...is done in a RAM located function called after the FCCOB registers are all setup in the Flash programming routine.
Debugging activity is shown below.
Does anyone have any ideas as to why the data is not being written to the FlexNVM and why the MGSTAT0 flag is being set?
Here are some debug requests and their related output.
- TEST command shows the current status of FTFL_FSTAT.
- TEST2 command attempts to write two long words to the FlexNVM memory
- TEST3 command writes two long words to the program flash memory
- MEMDUMP will show a range of memory
TEST2 and TEST3 commands are making calls to the exact same Flash programming routine...just the address is different. If FTFL_FSTAT is non-zero (other than the set CCIF flag) after programming it is shown in the debug output.
FTFL_FSTAT: 0x80 <-- Response to 'TEST' request (MGSTAT0 is not set...just CCIF)
0x0001FF00 0xFFFFFFFF <-- Target address and data at address before write (erased)
FLASH write (1) returned 0x10 <-- Non-0 return so value is shown (MGSTAT0 set)
FLASH write (2) returned 0x10
FTFL_FSTAT: 0x90 <-- MGSTAT0 set
10000000: FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF : ................ :
0001FF00: 83 34 00 00 01 00 00 00-FF FF FF FF FF FF FF FF : .4.............. :
FTFL_FSTAT: 0x80 <-- MGSTAT0 now clear
MEMDUMP 1FF00 1FF0F <-- Dump portion of program flash...old data and new.
0001FF00: 83 34 00 00 01 00 00 00-9D 38 00 00 01 00 00 00 : .4.......8...... :