Question

I have been developing a firmware that has a heavy GUI library ported on lpc1788. I am using a 32 MB SDRAM for processing the fonts and images and a NAND flash to store the binaries of the font and bmp's, along with the device configuration data.
I have disable the Usage Fault, MemManage fault and Bus Fault. So sometimes when something goes wrong with any GUI function, the execution goes in Hard Fault. Now, the library that I have used for GUI is emWin and I have no means to know what function caused the Hard Fault. If the NAND flash is corrupted and the library tries to fetch anything to display, say a background image, then it goes in hard fault. I can handle such a situation, because I know for sure (by means of some code implementation with flags) that my NAND flash is corrupted and I need to reprogram the binaries into it, because if I don't, whenever the device is booted up, it will go in hard fault.
But, if some other routine causes the Hard Fault, then I actually should not reprogram the entire flash allover again. So, if I know what caused the Hard Fault, I would be able to modify the handler accordingly deciding on whether I need to reprogram it or simply modify some parameters and carry on with the last know configuration.

Is there a way to determine what function caused the Hard Fault, run-time? Even the address would be enough. Can this be done?

Était-ce utile?

La solution

Implement a hard fault handler that reports the stacked registers. The PC register will indicate the execution address at which the exception occurred.

An example can be found here, though the use of printf in the example is probably ill-advised; you'd want something that wrote unbuffered direct to the UART I'd suggest - the system is already broken - the less code needed to get the diagnostic out the better. The similar solution here simply copies the values to variables and requires you to set a breakpoint in your debugger to inspect them.

To see the code at the reported PC address, either consult your compiler's map and or list output files, or enter the address directly into the PC register in your debugger.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top