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.

CCS/TM4C129ENCPDT: Embedded C++ in CCS

Part Number: TM4C129ENCPDT

Tool/software: Code Composer Studio

I am trying my first code in embedded C++. I have some requirement to use Exceptions and Classes. So I have to shift from embedded C to C++
I wrote the following c++ code in ccs7. It is just to blink the on board led on the TI Evaluation board. The program compiled with no error. But when upleaded into the board, it gets uploaded and starts running automatically.
Usually when written in embedded C and when I upload the code in ccs, it gets uploaded into the board and waits for the resume button to be pressed. Only when I press the resume button the code starts running.
But in this c++ code, as soon I upload the code, it shows that the code is running. But no output is seen in the board. I doubt that the code itself is not uploaded or not getting started.

Do I need to change any settings in the file properties to run the c++ code specifically?

I created an empty project in from File-->New-->CCSProject.
Then added a Souce file in the project. Choosed the template as "Default C++ Source template". This is the only place where I mentioned that the code I am going to write is going to be in c++.
Then I started with including the the header file "iostream" just to verify whether the c++ template is working or not.

I have some my own driver files written in embedded C for some ICs. If I switch to embedded C++ and start working with Classes and Objects, Will I still be able to use those driver files?

Thank You for your time.



#include <iostream> #include <stdbool.h> #include <stdint.h> #include <stdlib.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/flash.h" #include "driverlib/interrupt.h" #include "driverlib/gpio.h" #include "driverlib/rom_map.h" #include "driverlib/sysctl.h" #include "driverlib/systick.h" #include "drivers/pinout.h" #include "driverlib/debug.h" #include "driverlib/pin_map.h" #include "driverlib/rom.h" #include "driverlib/ssi.h" #include "driverlib/eeprom.h" #include "driverlib/uart.h" #include "string.h" #include "utils/ustdlib.h" #include "utils/uartstdio.h" using namespace std; int g_ui32SysClock; void main() { // Run from the PLL at 120 MHz. g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); SysCtlPeripheralReset(SYSCTL_PERIPH_GPION); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)) {} GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); SysCtlDelay(40000*10); while(1) { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1); SysCtlDelay(40000*500); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x00); SysCtlDelay(40000*500); } }

  • RAGHUL N M said:
    I created an empty project in from File-->New-->CCSProject.
    Then added a Souce file in the project. Choosed the template as "Default C++ Source template". This is the only place where I mentioned that the code I am going to write is going to be in c++.
    Then I started with including the the header file "iostream" just to verify whether the c++ template is working or not.

    I went through the same steps for a TM4C1294 device (as I only have the TM4C1294XL Launchpad handy) and used just the bit of source code you attached above. I built and loaded the code to the target and it halted at main, as expected. Clicking the Resume button started the LED blink. I did not have to do anything specific in the settings other than ensuring that the compiler and linker paths to include files and driverlib.lib were properly set up to point to the TivaWare directories.

    For some general information on working with C++ please refer to this page: http://processors.wiki.ti.com/index.php/C%2B%2B_Support_in_TI_Compilers 
    The Compiler Users Guide also has some detail on this subject: http://www.ti.com/lit/spnu151

    RAGHUL N M said:
    I have some my own driver files written in embedded C for some ICs. If I switch to embedded C++ and start working with Classes and Objects, Will I still be able to use those driver files?

    I believe that should work as long as you follow all conventions for mixing C and C++ code, and rebuild your libraries with options to match any specific C++ options that your application uses.