cancel
Showing results for 
Search instead for 
Did you mean: 

What's cause of HardFault_handler () ?

GPaiv.1
Associate III

Hi,

During debugging in my code, I enter in the function HardFault_handler (), I know then this error is about the registers but I don't know how interpreter this registers. 

0693W00000AMNcWQAX.png

4 REPLIES 4

The PROCESSOR registers, not the PERIPHERAL ones. ie R0, R1, R2, LR, PC, etc and the values pushed to the stack. Perhaps one of Joseph Yiu's books on the Cortex-Mx part would be easier than the ARM Technical Reference Manuals.

See the example handlers I've post dozens of times.

Look at the disassembly of the code that faults.

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

Yeah, you would have a better idea looking at the stack contents right before the HardFault_Handler() was invoked, also analyzing the call stack (series of function calls that lead up to that point) should give you more clues. STM32CubeIDE Debug perspective has the "widgets" to show all that.

Most likely the HardFault is being triggered due to some "illegal"instruction attempting to execute or some invalid memory address being read or written to. Sometimes the cause can be a simple typo in a register address, for example specifying 0x400220000 instead of 0x40022000.

Pavel A.
Evangelist III

CubeIDE has a very handy Hard fault analyzer, exactly to help you understand the reason of HardFaults. It's free, just use it.

thannara123
Senior

Make your board boot option is corectly  connected