Flash write error writing to Kinetis K20 FlexNVM

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

Flash write error writing to Kinetis K20 FlexNVM

Jump to solution
2,011 Views
wre
Contributor III

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?

Thanks,

Bill

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.

TEST  <-- Interactive Request
FTFL_FSTAT: 0x80  <-- Response to 'TEST' request (MGSTAT0 is not set...just CCIF)

TEST3
0x0001FF00 0xFFFFFFFF   <-- Target address and data at address before write (erased)
0x0001FF04 0xFFFFFFFF
TEST2
0x10000000 0xFFFFFFFF
FLASH write (1) returned 0x10   <-- Non-0 return so value is shown (MGSTAT0 set)
0x10000004 0xFFFFFFFF
FLASH write (2) returned 0x10
TEST
FTFL_FSTAT: 0x90  <-- MGSTAT0 set
MEMDUMP 10000000 1000000F   <-- Dump portion of Flex NVM...nothing there.
10000000: FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF : ................ :
MEMDUMP 1FF00 1FF0F   <-- Dump portion of program flash...data is there.
0001FF00: 83 34 00 00 01 00 00 00-FF FF FF FF FF FF FF FF : .4.............. :
TEST3  <-- Write two more long words to program flash
0x0001FF08 0xFFFFFFFF
0x0001FF0C 0xFFFFFFFF
TEST
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...... :
Labels (1)
1 Solution
1,823 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Bill Elliot,

  Thanks for your updated information.

  How do you identify the PFLASH or DFLASH with the same function command(0x06 (PGM4))? 

  Do you use this one?

pastedImage_1.png

I think you can write a simple project, just test your DFLASH write, read and erase without eeprom at first, when it works, then you can add the eeprom code again.

Any updated information from your side, please kindly let me know.

Have a great day,
Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
7 Replies
1,823 Views
wre
Contributor III

Question answered!  As kerryzhou‌ mentioned, the read and write addresses for the FlexNVM are different. 

When setting up a FLASH command to write to the FlexNVM, bit 23 of the address must be a '1'.  Reads of the FlexNVM are from the standard addresses for the Kinetis part. In the case of the K20DX128VLH5, with the FlexNVM partitioned for 16K of data and 16K of EEPROM backup, the 'reads' are from 0x1000_0000 to 0x1000_3FFF but the 'writes' are from 0x0080_0000 to 0x0080_3FFF.

1,823 Views
kerryzhou
NXP TechSupport
NXP TechSupport

HI  Bill Elliot,

   Please give me your detial chip partnumber, then I can help you to check more detials.

   As you know, K20 have a lot of series, 50M, 72M, 100M, ect.

   So, please give me your chip full name.

  Waiting for your updated information.

 

Have a great day,
Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply
1,823 Views
wre
Contributor III

Hello kerryzhou,

   Thank you for responding.  This is a 50M part, the MK20DX128VLH5.

Thanks,

Bill

0 Kudos
Reply
1,823 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Bill Elliot,

  Thanks for your updated information.

1. When you do the Program Longword command to Pflash, it has problems or not?

2. If you don't do the FlexNVM partition(no eeprom function), then when you do the Dflash longword program, it has problems or not?

3. After the FlexNVM partition, do you check SIM_FCFG1, whether EESIZE and DEPART is like which you have defined?

4. When you do the flash operation, please disable all the other interrupt function. Run the flash command in the RAM.

5. The program command, do you use this command:

pastedImage_2.png

Have a great day,
Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply
1,823 Views
wre
Contributor III

Hello kerryzhou,

Here are the answers to your questions:

1) Programming to PFLASH works correctly.

2) The application I am running requires EEPROM so I am unable to try this at this time.

3) SIM_FCFG1 contains the correct values.  DEPART = 0x02 and EESIZE = 0x06.

4) Interrupts are disabled when writing to the FLASH.

5) Yes, I am using the LongWord Program command as you show.

Again, the function called is the same for PFLASH or DFLASH, only the address to the call is different per my original question.

Thanks,

Bill

0 Kudos
Reply
1,824 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Bill Elliot,

  Thanks for your updated information.

  How do you identify the PFLASH or DFLASH with the same function command(0x06 (PGM4))? 

  Do you use this one?

pastedImage_1.png

I think you can write a simple project, just test your DFLASH write, read and erase without eeprom at first, when it works, then you can add the eeprom code again.

Any updated information from your side, please kindly let me know.

Have a great day,
Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply
1,823 Views
wre
Contributor III

Hello kerryzhou‌.  That was the missing piece!  As stated in my original question the address of where to write the event is passed to the programming function but the 23rd bit was not being addressed.  If the passed-in address is at or above the base address of the FlexNVM (0x10000000) I now create the 'write' address with 

ulAdd ^= 0x10800000;

This puts the write address in the correct FLASH command range for the FlexNVM...in my case between 0x800000 and 0x803FFF.

Thanks again,

Bill

0 Kudos
Reply