The only thing you want to make sure that you do this is not to damage the data that may be legitimately present in the flash memory, so if you are trying to write information in a failure situation, you need to do this carefully and with knowledge that the system can be in very poor condition, so everything you do should be done in such a way as not to get worse.
Typically, when I detect a failure condition, I try to spit out information from the serial port. The UART driver, accessible from the broken state, is usually quite simple - it just needs to be a simple polling driver that writes characters to the transmit data register when the bit is busy clear - the fault handler usually does not need good use with multitasking, so the polling is fine. And you don’t have to worry about incoming data at all; or at least you don’t have to worry about incoming data in a way that cannot be processed by polling. In fact, a failure handler usually cannot expect multitasking and interrupt handling to work because the system is confused.
I am trying to write a register file, part of the stack, and any important data structures of the OS (the current task control block or something else) that may be available and interesting. The watchdog timer is usually responsible for resetting the system in this state, so the failure handler may not be able to write everything, so first unload the most important material (do not watchdog crash handler - you do not want any error to interfere with the watchdog timer reset system).
Of course, this is most useful in setting up development, because when the device is released, it may not have anything attached to the serial port. If you want to capture these types of crash dumps after release, then they should be written somewhere suitable (for example, as a reserved flash partition, just make sure that it is not part of the normal data / file system area, make sure it is not may spoil this data). Of course, you will need to learn something in this area at boot so that it can be detected and sent somewhere useful, or it makes no sense if you can not return the units back after opening and can connect them to the debug setting, which can look at the data.
source share