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.

Using C++ with MSP432



Hello!

I would like to use C++ in CCS with MSP430. The target board is the MSP432
launchpad. As it works well with MSP430, I am configuring the project with
"Treat all files as C++" option. However, setting this option with an empty
project using MSP430 yields a bunch of errors as attached below.
Does anybody know how to fix this?

Thanks,

Pascal

#18 expected a ")"    msp432_startup_ccs.c    /Test432    line 63    C/C++ Problem
#339 linkage specification is incompatible with previous "__nop" (declared at line 45)    .ccsproject    /Test432    line 45, external location: /Applications/ti/ccsv6/ccs_base/arm/include/CMSIS/cmsis_ccs.h    C/C++ Problem
#339 linkage specification is incompatible with previous "__wfe" (declared at line 62)    .ccsproject    /Test432    line 62, external location: /Applications/ti/ccsv6/ccs_base/arm/include/CMSIS/cmsis_ccs.h    C/C++ Problem
#339 linkage specification is incompatible with previous "__wfi" (declared at line 56)    .ccsproject    /Test432    line 56, external location: /Applications/ti/ccsv6/ccs_base/arm/include/CMSIS/cmsis_ccs.h    C/C++ Problem
#821 badly formed pragma    msp432_startup_ccs.c    /Test432    line 64    C/C++ Problem
#1181-D #warning directive: "MSP432 software will be updated to use CMSIS-Core in March 2016. This update will allow your MSP432 software to be CMSIS compliant, but require modification to your existing MSP432 code. A beta release is available if you want to start converting your code today. Refer to http://www.ti.com/MSP432CMSIS for detailed changes, conversion guide and background information."    .ccsproject    /Test432    line 69, external location: /Applications/ti/ccsv6/ccs_base/arm/include/msp432p401r.h    C/C++ Problem
#179-D variable "interruptVectors" was declared but never referenced    msp432_startup_ccs.c    /Test432    line 65    C/C++ Problem

  • Pascal4275 said:
    However, setting this option with an empty
    project using MSP430 yields a bunch of errors as attached below.

    Try the work-around in https://e2e.ti.com/support/microcontrollers/msp430/f/166/p/420398/1497934#1497934 of adding an #if block to the ccsv6/ccs_base/arm/include/CMSIS/cmsis_ccs.h file

  • Pascal,

    If the previous response solved your problem, please verify the answer.

    Thanks,
    Michael Arriete
  • Hello Michael!

    Sorry for the delay. I resumed this work today. No, it doesn't solve the problem.
    The way to reproduce it:
    - On Mac OS, the about panel saus Code Composer Studio Version 6.1.2.0014
    - Project -> New CCS project.
        The configuration panel opens, and since I was using 432 last time, it's still
        configured for 432. Set the name. The compiler version is TI V5.2.6.
        Choose empty project with main.c
        The only code line stops the watchdog.
    - Compile and debug (press the green bug icon) -> The debugger highlights the
        only code line.
    - Stop debugger, open Project -> properties -> CCS build -> Advanced options ->
        language options. Just in case, the only selected item at that point is "enable
        sipport for GCC extensioons (DEPRECATED) (--gcc). I check the line just above,
        treat C files as C++ files (--cpp_default, -fg). Then click OK.
    - Compile (same as above).
    I get:
    "../msp432_startup_ccs.c", line 63: error #18: expected a ")"
    "../msp432_startup_ccs.c", line 64: error #821: badly formed pragma
    "../msp432_startup_ccs.c", line 65: warning #179-D: variable "interruptVectors" was
    declared but never referenced 2 errors detected in the compilation of "../msp432_startup_ccs.c".

    That's about it. Of course one workaround would be to work in C instead of C++.

    Pascal

  • Pascal4275 said:
    I check the line just above,  treat C files as C++ files (--cpp_default, -fg).

    The problem with that is that the syntax for some pragmas differs for C and C++. When "treat C files as C++ files" is selected the #pragma in the C source file msp432_startup_ccs.c generates a compile error when treated as a C++ file.

    Instead of checking "treat C files as C++ files", rename main.c to main.cpp so that only main.cpp gets compiled as C++, leaving msp432_startup_ccs.c to be compiled as C.

  • Hello!

    Thanks for your reply.
    So basically this means that in the case of MSP432, "treat C files as C++ files" should
    never be used, right? In this case, CCS should not allow to select this option for 432.
    But you say that pragmas are different, so I think the best thing to do would be
    both pragmas separated by a ifdef c++.
    What would be the proper C++ syntax for the pragma in msp432_startup_ccs.c?

    Pascal
  • Pascal4275 said:
    So basically this means that in the case of MSP432, "treat C files as C++ files" should never be used, right? In this case, CCS should not allow to select this option for 432.

    No, the "treat C files as C++ files" works as expected, but can only be used if all .c files contains code which is valid for the C++ compiler.

    Pascal4275 said:
    What would be the proper C++ syntax for the pragma in msp432_startup_ccs.c?

    The Pragma Directives section of the MSP430 Optimizing C/C++ Compiler User's Guide shows the C++ syntax for each pragma.

  • Hello Michael!

    Thanks for your reply. I have read the proper section of the compiler. Just to be sure,
    the version I have is MSP430 Optimizing C/C++ Compiler v15.12.0.LTS, downloaded just now.
    Restarting from the place where the basic program works (above message at "stop debugger..."
    which is the 4th point of the list.
    The program in C is loaded normally and the line stopping watchdog is highlighted.
    Now changing to cpp default, as said previously, I get the message:

    #18 expected a ")"    msp432_startup_ccs.c    /Test432    line 63    C/C++ Problem
    #821 badly formed pragma    msp432_startup_ccs.c    /Test432    line 64    C/C++ Problem

    Now as these 2 lines seem to be the problem:
    #pragma RETAIN (interruptVectors)
    #pragma DATA_SECTION(interruptVectors, ".intvecs")

    I have looked at the documentation for RETAIN and DATA_SECTION.

    Page 109 says that #pragma RETAIN(symbol) should be modified as #pragme RETAIN,
    and page 101 says that DATA_SECTION(symbol, "section name") should be modified as
    #pragma DATA_SECTION("section name")

    I thought that the following code could work:

    #ifdef __cplusplus
    #pragma RETAIN
    #pragma DATA_SECTION(".intvecs")
    #else
    #pragma RETAIN (interruptVectors)
    #pragma DATA_SECTION(interruptVectors, ".intvecs")
    #endif

    Result: it doesn't. At first, it seems to compile and briefly shows the code uploader.
    But a window called "0xc00ea5e" shows up in the source file tabbed editor, saying "no
    source available for 0xc00ea5e. View disassembly.
    The cosnsole message says (in red):
    CORTEX_M4_0: Can't Run Target CPU: (Error -1268 @ 0x3090001) Device is locked up in Hard
    Fault or in NMI. Reset the device, and retry the operation. If error persists, confirm
    configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower
    TCLK). (Emulation package 6.0.83.1)

    Just in case, I also tried to remove the idef __cpplusplus & add directly the 2 lines
    #pragma RETAIN (interruptVectors)
    #pragma DATA_SECTION(interruptVectors, ".intvecs")
    -> Doesn't work
    I also tried to rename the startup.c file to startup.cpp. Nothing works.

    If you have any other hint...

    Thanks,

    Pascal

  • Pascal4275 said:
    I thought that the following code could work:

    #ifdef __cplusplus
    #pragma RETAIN
    #pragma DATA_SECTION(".intvecs")
    #else
    #pragma RETAIN (interruptVectors)
    #pragma DATA_SECTION(interruptVectors, ".intvecs")
    #endif

    When I tried that change in an example project, with "Treat C files as C++ files" selected the generated program was incorrect because the InterruptVectors had not been retained. It turns out the documentation for the C++ RETAIN pragma is incorrect; see #pragma RETAIN generates Error # 18 expected a ")" . As described in that thread, for the vectors to be retained by the C++ compiler they need to be marked as extern const. i.e. change to the following (by adding extern to the line for interruptVectors):

    #ifdef __cplusplus
    #pragma RETAIN
    #pragma DATA_SECTION(".intvecs")
    #else
    #pragma RETAIN (interruptVectors)
    #pragma DATA_SECTION(interruptVectors, ".intvecs")
    #endif
    extern void (* const interruptVectors[])(void) =
    

    With this change, with  "Treat C files as C++ files" selected from looking at the linker .map file confirm that the interrupt vectors are now retained (but don't have a launchpad to test running the program at the moment).

    Pascal4275 said:
    I also tried to rename the startup.c file to startup.cpp. Nothing works.

    Unfortunately, downloading a program without the interrupt vectors retained "bricks" the MSP430 launchpad, as per https://e2e.ti.com/support/microcontrollers/msp430/f/166/p/419867/1740311#1740311. You need to un-brick the launchpad and then try the download the corrected program.

     

  • Hello!
    Thanks for your reply.
    I just tried to add "extern", and it works. Thanks a lot for the hint. I cannot say I understood it all,
    but at least if works now. I have used the same code as above with ifdef __cplusplus.
    I also verified that it still works in plain C.
    By the way, my launchpad wasn't bricked at all. It didn't work without the extern keyword. I added
    it and it just worked.
    Pascal

**Attention** This is a public forum