2021-04-23 07:41 AM
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.
2021-04-23 11:21 AM
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.
2021-04-23 07:05 PM
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.
2021-04-23 09:43 PM
CubeIDE has a very handy Hard fault analyzer, exactly to help you understand the reason of HardFaults. It's free, just use it.
2023-10-09 08:26 AM
Make your board boot option is corectly connected