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.
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.
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.
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