Showing results for 
Search instead for 
Did you mean: 

How to solve HardFault_Handler problem at debugging?

Associate II

Hi Everyone,

I am newbie in embedded software field, Just graduated from college.
I am trying to connect a SD card and read&write data. I did same things to my STM32F429 but when I tried them on STM32F030C8, I am facing with Debug Current Instruction Point at HardFault_Handler() function in stm32f0xx_it.c file.

I use external crystal, FATFS, SPI and just a GPIO in output mode as chipselect for SPI.

How can I fix this problem? 

Thank you in advance!




Generally, look at the call stack to understand where it entered the hard fault. Look at the code around that point and fix it. Step through code, set breakpoints, see if you can pinpoint exactly where it happens.

If you feel a post has answered your question, please click "Accept as Solution".

Don't they teach this in college?

Have your Hard Fault Handler output actionable data to identify the code causing the fault. A while() provides no useful information.

On the Cortex-M0 watch for unaligned pointers, as well as pointers to memory that doesn't exist.

The registers, and the faulting instructions, and those immediately preceding, are usually a good indication of why the processor is unhappy.

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

If you don't see the call stack deep enough - this can be because the compiler over-optimized HardFault_Handler (and other such handlers there). It sees the while(1), figures out that the function never returns, so there's no need to put the return address on stack. If this is the case - a simple trick can beat the compiler and let you see the stack of HardFault_Handler.