2012-11-18 03:03 AM
Hey everyone,
I'm working on the STM32F4DISCOVERY with CoIDE 1.6.0 in C++. I have an interrupt on TIMER4 overflow, and so I put the interrupt service routine (void TIM4_IRQHandler(void) {}) in the main.cpp. But if I just do that it doesn't work as I end up in theDefault_Handler. I figure out it was like the routine was not found in execution. So I put extern ''C'' around my routine
#ifdef __cplusplus
extern
''C''
{
#endif
void
TIM4_IRQHandler(
void
) {
...
}
#ifdef __cplusplus
}
#endif
And it worked. But now I can't use C++ code in this routine whereas I'd like to get the instance of a singleton in it. I'm stuck, would you have some solution or workaround ? Thank you very much :)
2012-11-18 06:23 AM
Possible options :
Put the mangled name of the C++ routine into the vector table. Use cdecl or attributes directive. Call another C++ function from the IRQ Handler.2012-11-23 01:37 PM
Thanks for you (technical) answers. I learned things, mainly about mangling.
By the way, I found a very simple way to solve it : put the definition of the IRQ_Handler in a .h and put the extern ''C'' around here (and not in the .cpp directly). It was pretty obvious (ST examples do like that) ^^