2024-01-16 06:54 AM
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!
Volkan
2024-01-16 07:51 AM
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.
2024-01-16 09:21 AM - edited 2024-01-16 09:22 AM
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.
https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c
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.
2024-01-16 09:57 AM
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.