I 'll talk a little more about what brought me here, and how I use @Mike's understanding to fix this.
I had a well-functioning project on a demo project in Eclipse SW4STM32, but the sources and headers were scattered everywhere, so I wanted the more “compact” project to be easier to set up and use as the basis for minor changes (and easier to follow in Git )
I created an empty AC6 project designed for the same board. He generated the HAL, startup_stm32.s and LinkerScript.ld . Then I copied all .c and the corresponding .h from the original project to my new project (which in itself was painful because they were scattered across the directories BSP, CMSIS, Components, Middlewares, etc.). Everything compiled and seemed to work until I started a little change.
In the debugger, it seemed that all function calls worked until the main while(1) where I ended up in the Default_Handler defined in startup_stm32.s , apparently from WWDG_IRQHandler . In fact, it was the default IRQ handler for user-defined handlers ( WWDG_IRQHandler was the first to be declared, gdb reported this as this, as @D Krüger pointed out).
Without much luck, I began to study the compiler and linker options or linker script until I realized that the only file that I did not check was startup_stm32.s , which really was different.
I blindly copied it and voila!
The explanation I could give is that STM32 calls the IRQ handlers defined in startup_stm32.s when an interrupt occurs, they all point to Default_Handler() (later overridden by the linker). Therefore, if the .c file you copied defines a handler with a slightly different name (but according to its own startup_xxx.s ), you will end up with the startup_xxx.s Default_Handler() method (which is an infinite loop) instead of the one you defined And that's it goes wrong.
See https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html for more information.
NB. I am not happy to blindly copy-paste without full understanding, but time limits and milestones usually push you into territories that you are not happy to explore ...
Matthieu
source share