cancel
Showing results for 
Search instead for 
Did you mean: 

Overwrite Hardfault_Handler with a custom assembly implementation in STM32CubeIDE generated code

newbie_stm32
Associate III

Hi Community,

 

I am trying to define a custom Hardfault_Handler definition in the assembly to overwrite the default template given in the stm32xxxx_it.c in the STM32CubeIDE generated code. When the definition is put under custom.s and added to the assembly include path in the IDE it compiles without any warning or error but when in a debug session it is found that it jumps to the default Hardfault_Handler implementation instead of the custom. The default one is suppressed by defining __weak attribute to use the custom definition.

 

What might go wrong? Any hints to solve this will be helpful.

4 REPLIES 4
Danish1
Lead II

A good way to test if your hardfault handler is set to be executed rather than the default version would be to look at the vector table in the elf or hex file generated by your project. That way you don't have to trigger a hardfault to see if you are making progress.

 

I will also add that that your IDE might automatically break execution at the point the processor detects a hard-fault. At that instant you can't tell if your code will be executed or the default handler.

TDK
Guru

In the typical setup, it is defined as weak in startup_*.s. It is *not* defined as weak in stm32_*_it.c.

It can't be defined as weak in two places so either you have some weird custom configuration or something else is not right.

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

Hi, @Danish1 thanks for guiding me with the correct approach.

Hi, @TDK thanks for pointing it out I removed the weak definition in the startup file and moved the hard fault implementation from the custom.s to the startup file now I can see it is branching to the hard fault implementation defined in the startup file.

 

I am still working on how to get this in custom.s without disturbing the startup file