2021-08-07 05:32 PM
Have a device built around an 32f429 which appears to be hard faulting too infrequently to catch on the bench with debugger attached -- but have lab personnel running all day and getting the errors, not infrequently enough.
I can use some BKUP registers (BKUP RAM and RT Clock) to store away some info from the HardFault handler before resetting -- then dump out to a file after reset. I'm getting bits from the fault status registers and the values stacked when fault occurs (including address of a suspect instruction). All I've found about the ABI is the ARM Base ABI which says that SP and LR are callee saved. I'm using Keil tools (ARMCC ?? - not in front of the IDE at the moment) -- but so far I've evoked little hints about anything documented about where those registers are saved. I know the locations of variables will not be known (in general), but the calls preceding the fault should be extractable.
2021-08-08 01:18 AM
Read PM0214, chapter Exception model, subchapter Exception entry.
Clive (Tesla DeLorean) wrote about debugging hardfaults here many times, e.g. https://community.st.com/s/question/0D50X0000Az372YSQQ/stm32l412-hardfault-while-using-minimal-cubeide-example
JW
2021-08-08 08:06 AM
2021-08-08 09:05 AM
PC stacked at the exception entry points to instruction which is one or a few instructions after the instruction which caused the exception. Except in cases where the execution went completely awry (i.e. taking messed up function pointers or return after stack corruption), this together with content of other registers and mixed source/disasm is enough to find out the problematic line/data in the source.
JW
2021-08-08 09:29 AM
2021-08-08 09:54 AM
What's on stack is entirely up to the compiler.
DWARF contains that information so the debugger can walk back, but I don't think it's trivial nor that it can in any simple way be implemented on the target.
A "poor man's tracer" could be conceived by simply going through the stack (backwards) and consider everything in FLASH range to be a valid return address.
JW