cancel
Showing results for 
Search instead for 
Did you mean: 

Hardfault exception on Cortex M0

Kim.Andy
Associate III

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.

0693W00000WJqZ9QAL.pngThe following picture is the memory value from 0x20003778(MSP).

0693W00000WJqbKQAT.pngThe 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

3 REPLIES 3
gbm
Lead III

Look at the call stack window/tab - you will see the routine call hierarchy which led to the problem.

> 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

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..