cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt service routine and C++

bernier-paul
Associate II
Posted on November 18, 2012 at 12:03

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 :)

2 REPLIES 2
Posted on November 18, 2012 at 15:23

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bernier-paul
Associate II
Posted on November 23, 2012 at 22:37

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) ^^