cancel
Showing results for 
Search instead for 
Did you mean: 

Unclear behavior of hard fault due to function location in the code

THare.1
Associate II

I am working with stm32H743 MCU, sometimes when I add a function, its calling caused a hard fault, when I move the function to another place in the code, the fault is resolved.

What can be the reason?

3 REPLIES 3
TDK
Guru

The location of the function is not likely to be a direct cause of the hardfault, but if there are bugs in the code, it may alter how/when these bugs show up.

Stay objective. Don't focus on the location of the function. Instead, determine the cause of the hard fault by looking at SCB registers or using the fault analyzer in STM32CubeIDE. Memory issues are a common cause of hard fault. Dynamic allocation failing, or writes out of bounds, or stack overflows.

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

Thanks for your response

Thanks for your response. Well, it's clear to me that I can research this and find the cause by using the debugger, Im using KEIL environment with ST-LINK debugger and there is also a KEIL document here https://www.keil.com/appnotes/files/apnt209.pdf that shows what to look for and how to deal with hard-fault issue, I just wanted to save time, maybe someone has already encountered this and can save me The investigation, I'm sure it's something simple ... 😉