This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How handle Cortex-M0 Interrupts on IAR using C++?

Note: This was originally posted on 30th August 2011 at http://forums.arm.com

[font=Times][size=2][font=arial, verdana, tahoma, sans-serif][size=2]Hello everybody,

I'm using IAR 6.21 compiler and a LPC11C14 IAR's dev board, doing my firsts test with C++.[/size][/font]
Also I'm simulating UART interrupts in the C-SPY simulator, all working great on C, so the problem is not the macros or whatever.

I search on the web how to handle interrupts in C++, and found that:
http://www.eetimes.com/design/embedded/4023817/Interrupts-in-C-

So I did this on my code:

in uart.h:
class uart
{
...
public:
    static void UART0_IRQHandler( void );
}

in uart.c:
void uart::UART0_IRQHandler( void );
{
    // breakpoint reading the UART receive register
}

And the vector is defined correctly in cstartup_m.s and in the cstartup_m.c (I've tested with either, one per time obviously)
the vector worked fine in C, so it's not the problem.

The problem is my static member is not even linked, the linker uses the default function provided in the vector definition source code.
I tried to figure out what I'm doing wrong and made some other tests also, but no way to establish a connection between the uart interrupt vector and mu static member function.
It works if I "mix" C with C++ using "extern C" definitions, but I believe that should be a "correct" way of doing this.

What I'm doing wrong?
Is this the best way of deal with interrupts in C++?


Thanks in advance buddies.
André Rairan.[/size][/font]
Parents
  • Note: This was originally posted on 5th September 2011 at http://forums.arm.com

    Thanks for answer isogen74.

    I see that a clean way is using "extern C", no magic to link the vectors with C++ functions...

    But on Cortex-M we can define the vectors in C, contacting the IAR support, they said that we can also set the vectors in C++ and they sent a example.
    I modified that and it's attached.

    I've defined all interrupt vectors on interruptDRV.h class, and link this with the startup code.
    Works fine and looks like more with C++.

    Best Regards
Reply
  • Note: This was originally posted on 5th September 2011 at http://forums.arm.com

    Thanks for answer isogen74.

    I see that a clean way is using "extern C", no magic to link the vectors with C++ functions...

    But on Cortex-M we can define the vectors in C, contacting the IAR support, they said that we can also set the vectors in C++ and they sent a example.
    I modified that and it's attached.

    I've defined all interrupt vectors on interruptDRV.h class, and link this with the startup code.
    Works fine and looks like more with C++.

    Best Regards
Children
No data