Find corruption on internal Flash MK22FX512VLH12

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

Find corruption on internal Flash MK22FX512VLH12

Jump to solution
917 Views
ralf1694
Contributor III

Hi community.

I must write data on the internal flash, without disable the interrupts.

But I found this:

         Interruption of an erase or program command can lead to corruption of the flash contents. Interruptions could include

         reset, loss of power, or a conflict with code running on processor.

My problem is, when I read the corrupt data from internal flash, I get a Bus Error.

Is there a way to find corrupt data on the internal flash or a way that no corruption accures?

0 Kudos
Reply
1 Solution
755 Views
mjbcswitzerland
Specialist V

Hi

Corrupted flash (this tends to be valid for second generation parts but not for all) causes a fault exception to be generated when read. It is necessary to erase the sector (or possibly the complete flash) to recover the Flash operation.

To detect the corruption you can use the fault exception itself - read all locations of Flash to see whether it is generated or not and stop further checking once an exception occurs.

Regards

Mark

View solution in original post

0 Kudos
Reply
3 Replies
755 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Oliver Schmid:

Just like Mark suggested, you can use the fault to detect a corrupted flash. There is also the option of using the Program Check command to compare your expected data vs actual stored data.

To avoid flash corruption, it is actually recommended to disable interrupts. You could also copy interrupt vectors to RAM and relocate the interrupt handler codes to a different flash block (not the one being written/erased) or to RAM memory, for all of those interrupts that are likely to trigger while the flash operation is performed.

I hope this helps!

Best regards,

Jorge Gonzalez

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

0 Kudos
Reply
755 Views
ralf1694
Contributor III

Thanks for your help:)

I implement the Bus Fault ISR and when I read the corrupt data I am in the ISR :smileyhappy:

But I have another question. When my Bus Fault ISR is empty, then I jump back to the read flash command which caused the fault. Then I read the same flash address and jump in the ISR again and after ISR back to the read command. After the 4th or 5th read from the corrupt data, I can read the data from flash and no Bus Fault occurs. Why?

Is there a way to execute the next line of the routine after the Bus Fault ISR jump back?

     -read corrupt data

     - isr

     -jump back to routine

     -next line to execute is the line after read command which caused the fault

0 Kudos
Reply
756 Views
mjbcswitzerland
Specialist V

Hi

Corrupted flash (this tends to be valid for second generation parts but not for all) causes a fault exception to be generated when read. It is necessary to erase the sector (or possibly the complete flash) to recover the Flash operation.

To detect the corruption you can use the fault exception itself - read all locations of Flash to see whether it is generated or not and stop further checking once an exception occurs.

Regards

Mark

0 Kudos
Reply