2022-11-30 01:59 AM
The hardfault exception often occurs during system operation.
The R14(LR) is 0xFFFFFFF9 in the exception handler(bit2 = 0).
So the main stack(MSP) is used, and that value is 0x20003778 like the follwing picture.
The following picture is the memory value from 0x20003778(MSP).
The LR is 0x4001000c, and this location is SYSCFG external interrupt configuration register 2 at the STM32L0x2.
Why does the hardfault exception occur at this point?
What should I do check to debug this problem?
Thanks
2022-11-30 02:18 AM
Look at the call stack window/tab - you will see the routine call hierarchy which led to the problem.
2022-11-30 05:18 AM
> The LR is 0x4001000c
No, that's value of R12. Stacked LR is 0x0800840D and stacked PC is 0x02010000. So, you should look at code *before* 0x0800840C (at 0x0800840C is the instruction into which the call returns) and figure out, why was there a jump/call to 0x02010000 (maybe call through incorrectly set function pointer).
JW
2022-11-30 05:55 AM
Usually better to automate the reporting in a human readable manner.
Check you're not doing unaligned access of 16 or 32-bit values via a pointer.
Look at the offending code in the context of the registers, walk back a little if "imprecise" due to write buffering.