2023-12-03 09:45 PM
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.
2023-12-04 01:13 AM
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.
2023-12-04 05:35 AM
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.
2023-12-04 11:07 PM
Hi, @Danish1 thanks for guiding me with the correct approach.
2023-12-04 11:08 PM - edited 2023-12-04 11:10 PM
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