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?
已解决! 转到解答。
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
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!
-----------------------------------------------------------------------------------------------------------------------
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
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