This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSPM0G3507: Code Composer Studio - modifying .c to .cpp breaks interrupts

Part Number: MSPM0G3507
Other Parts Discussed in Thread: SYSCONFIG

I started with the example:  spi_controller_echo_interrupts_LP_MSPM0G3507_nortos_ticlang

for my project I wanted to use classes, so i renamed the spi_controller_echo_interrupts.c to spi_controller_echo_interrupts.cpp

it still builds ok, but if i put a breakpoint on the interrupt service routines, the debugger says they are disabled, and the code goes to the default handler (stuck in the while(1) loop.

it seems to link to main just fine, as i can step through it just fine.  also, if i rename main() to mainx() it correctly wont build, so it seems that its using the file.

how do i make sure that the interrupt routines get linked?

  • Hi,

    It looks like a compiler issue. I am moving this thread to CCS team and check if they can help on this. 

    Best regards,

    Cash Hao

  • Hi,

    I checked with compiler team. And they do not think it is compiler issue. 

    And from my point, there is one C++ example projects in the SDK(empty_cpp). And if you want to build your project with C++, you might need to start with that C++ project.

    Best regards,

    Cash Hao

  • I would not guess its a compiler issue as well.
    I thought it would have to do with c++ name mangling.

    but the ti_msp_dl_config.h does have "extern c" declared which i think is supposed to avoid that.  i can't tell exactly if its being used, as this is a generated file so i can't modify it..  

    can someone look into this futher?  i'd prefer not to start with an empty project.  I tried, I wasn't sure what needed to be done, I started by trying to add a syscfg, but whenever i click away from it i get a "oh Snap! The last change caused an exception..."  the last time i asked how to add a syscfg to the system i was told to use a sample instead.

    the steps to recreate the issue are quite easy... if you have a launchpad lp_mspm0g3507:

    1) start with the spi_controller-echo_interrupts_LP_MSPM0G3507_nortos_ticlang

    2) set a breakpoing on Group1_IRQHandler() in spi_controller_echo_interrupts.cpp

    3) set a breakpoint on Default_Handler() in startup_mspm0g3507_ticlang.c

    4) build and run

    5) press the button on the side and the Group1_IRQHandler should be hit, this is good

    6) rename spi_controller_echo_interrupts.c to .cpp

    7) build and run

    8) press the button on the side of the board, and Default_Handler should be hit, this is bad.

  • HI,

    I just tried to modify the sysconfig configuration of the empty_cpp_LP_MSPM0G3507_nortos_ticlang. I didn't get any error reported. And in this example project, it already has sysconfig file in it. No need to add a sysconfig to the project.

    About this C++ issue.  Let me reproduce this issue by your steps first. And check what we could help you on this thread. 

    Best regards,

    Cash Hao

  • i started from empty project and added in the LED and SWITCH to GPIOs, added in the SPI, then put in the code to initialize the setup, but the behaviour is the same, can you either follow my 8 steps above and figure out what needs to be done, or point me to a c++ example with interrupts that works.

    thank you.

  • any update on this?  thanks.

  • I think you are right - C++ name mangling. Normally, this causes a failure to link but:

    Here, we see:-

    void Default_Handler (void) __attribute__((weak));

    ...

    extern void GROUP0_IRQHandler (void) __attribute__((weak, alias("Default_Handler")));
    extern void GROUP1_IRQHandler (void) __attribute__((weak, alias("Default_Handler")));

    ...

    extern void SPI0_IRQHandler (void) __attribute__((weak, alias("Default_Handler")));
    extern void SPI1_IRQHandler (void) __attribute__((weak, alias("Default_Handler")));

    These functions have weak default handlers that get called if you don't provide a different one.

    In the sample code, we see:-

    void SPI_0_INST_IRQHandler(void)
    {
    ...

    void GROUP1_IRQHandler(void)

    ...

    These 2 functions will have their names mangled by the C++ compiler, so will not be available to replace the default weak handlers.

    make them

    extern "C" void SPI_0_INST_IRQHandler(void)

    extern "C" void GROUP1_IRQHandler(void)

    and it should work (I hope).

    Jim

  • I had tried using extern "C" but the compiler was complaining, at this point i'm not sure what about because i made my own header file and put the function declarations in there.  i used the syntax from the ti_msp_dl_config.h file
    #ifdef __cplusplc
    extern "C" {
    ...

    and now it appears to be working.  so i could spend time to figure out what wasn't working, but since i have a solution, i'm moving forward.  thanks.