I have an embedded project containing both c files (drivers from the SDK) and c++ (.cpp) files (my own code). I'm trying to set up an interrupt service routine. I've found it works fine if the ISR is in a .c file. However, the exact same function moved into a .cpp file does not work.
In MK64F12_Vector.s;
_vectors:
...
.word PORTD_MyIRQHandler
Some related initialization code that is called once at start-up;
CLOCK_EnableClock(kCLOCK_PortD);
EnableIRQ(PORTD_IRQn);
PORT_SetPinInterruptConfig(PORTD, 0, kPORT_InterruptFallingEdge);
In .c file;
void PORTD_MyIRQHandler()
{
while (1) ; // put breakpoint here
}
The above works fine if PORTD_MyIRQHandler() is in a .c file. But if I move it to a .cpp file (where I want it!) I get the error below. Note I am just copying & pasting it without changing anything.
(.vectors+0x138): undefined reference to `PORTD_MyIRQHandler'
Is there something else I need to do to get it to work? A compiler or linker option perhaps? I've tried the following without success;
__attribute__((interrupt)) void PORTD_MyIRQHandler() {..}
#pragma interrupt
void PORTD_MyIRQHandler() {..}
I am using Segger Embedded Studio with gcc.
extern "C"in the C++ code? Name mangling could be the culprit.