Find corruption on internal Flash MK22FX512VLH12

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Find corruption on internal Flash MK22FX512VLH12

跳至解决方案
984 次查看
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 项奖励
回复
1 解答
822 次查看
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 项奖励
回复
3 回复数
822 次查看
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 项奖励
回复
822 次查看
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 项奖励
回复
823 次查看
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 项奖励
回复