2021-11-17 02:26 AM
I am using stm32f4. I have a hardfault error at sometimes, when I write new code in to the flash. So I check the Fault Registers like in below:
SerialPrint("Fault: %08x %08x %08x\n",SCB->HFSR, SCB->CFSR, SCB->BFAR);
Output results:
SCB->HFSR = 0x40000000
SCB->CFSR = 0x00008200
SCB->BFAR = 0xb1584604
It seems to Bus Fault. And it's address 0xb1584604 . How can I find, which part in this address ? How can I find the error with this address ?
2021-11-17 03:28 AM
BFAR seldom gives you usable information. The primary way to debug hardfault is to find out the PC at the moment of fault from stack, and then in disasm observe piece of code just *before* this address. I use debugger so I don't need to print out the stack, which in C may be quite challenging, e.g. https://community.st.com/s/question/0D50X0000BACfzTSQT/how-do-i-debug-a-hard-fault-on-a-stmf7
JW
2021-11-17 09:37 AM
Fishing the stacked PC and LR helps to pin-point things. Identifies where it died, and where it came from. One could perhaps walk the stack further, but this is usually sufficient to identify the code/reason for the failure, and add in sanity checking to report conditions or catch them earlier.
Here we tend to push out enough data so a failure in the field can be diagnosed/identified without having to attach a debugger or provide tools/training
https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c
The entry LR is a return-call-gate, so the one on the stack is the one of interest. Hard Faults can return if you can identify/remediate the failure.
The BFAR can help identify the register used on the memory load/store.
And IMPRECISE fault points to an earlier write operation whose write buffer just completed, might need to walk back a few instructions to identify those responsible.