Project

General

Profile

Linux Application Development Using Code Composer Studio with a C/C++ Project

Goal

This page describes how to build and debug a sample Hello World program using Code Composer Studio and a C/C++ Project.

Assumptions

The following are assumed:

  • The Linux Development environment has been installed as described in Code_Composer_Installation.
  • The multi-architecture version of gdb has been installed as described in Gdb_Multiarch_Installation.
  • The target has an IP address which can be reached from your development host. These notes will use 10.0.103.50 as an example address. Substitute your address as needed.

Building the Program

  • Start Code Composer Studio
  • Select a new workspace. e.g. ~/helloworld. Click the Launch Button
  • Close the Getting Started Window. You may need to click the Restore Icon in the upper right to get a normal display.
  • Create a new project
    • File->New->Project->C/C++-> C/C++ Project. Click on Next
    • Pick C++ Managed Build. Click on Next.
    • Enter a Project Name: e.g. Hello.
    • Executable with an Empty Project
    • Toolchain should be Cross GCC. Click on Next
    • Select Configurations: Debug and Release should both be checked. Click on Next
    • Cross GCC Command:
      • Cross compiler prefix:
        arm-linux-gnueabihf-
        
      • Cross compiler Path: substitute your user name or browse to the path
        /home/<user-name>/ti-processor-sdk-linux-am57xx-evm-06.03.00.106/linux-devkit/sysroots/x86_64-arago-linux/usr
        
      • Click on Finish
  • Create a source file.
    • File->New->Source File
      • Source File: hello.cpp
      • Click on Finish.
    • Add the following to the source file hello.cpp:
        
      #include <stdio.h>
      
      int main (int argc, char**argv)
      {
          printf ("Hello from code composer C/C++ project\n");
          fflush (stdout);
      }
      
  • Build the project: One of the following:
    • Project->Build
    • Project->Build All
    • ctrl-b

Running the Program

In a terminal window do the following:

  • Copy the executable to the target:
    cd ~/helloworld/Hello/Debug
    export IPADDR=10.0.103.50
    rsync Hello root@${IPADDR}:
    
  • Execute the program
    ssh root@${IPADDR} ./Hello
    

You should see the following printed:

Hello from code composer C/C++ project

Debugging the Program

To debug the project you need to do the following:

  • Start the gdbserver program on the target. The gdbserver program will wait until the host makes a connection and will provide access to the desired application on behalf of the debugger running on the host.
  • Start the gdb-multiarch program on the host from within Code Composer to run and control the target program.

The exact steps needed are as follows:

  • Start gdbserver on the target.
    • In a terminal window on the host
      export IPADDR=10.0.103.50
      ssh root@${IPADDR} gdbserver :10000 ./Hello
      

      From the target, you should see text like the following:
      Process ./Hello created; pid = 1987
      Listening on port 10000
      
  • Start debugging in Code Composer
    • Create a debug configuration. Run->Debug Configurations
      • Select C/C++ Remote Application.
      • Click on the New Configuration button (upper left)
        • Main tab
          • Project: Hello
          • C/C++Application: Debug/Hello
          • At bottom of tab next to Using GDB (DSF) Automatic Remote Debugging Launcher. Click on Select other...
          • Select Preferred Launcher
            • Check Use configuration specific settings
            • Select GDB (DSF) Manual Remote Debugging Launcher
            • Click on OK
        • Debugger Tab
          • Main Tab under Debugger Options:
            • GDB Debugger: Instead of gdb, replace with: gdb-multiarch
          • Connection Tab under Debugger Options:
            • Type: TCP
            • Host name or IP: your_target_ip (use ip address on target to see)
            • Port: 10000 (must match what was given to gdbserver)
        • Click on the Debug button (lower right)

After pressing the Debug button, the following should happen:

  • A build will be done (but no changes). If there had been changes, you would need to copy the new executable to the target and start gdbserver over.
  • Code Composer should connect to the gdbserver on the target and stop at the printf line. There should be an arrow to the left of the printf line.

To verify that you have control of the target, try the following:

  • Step over the printf line. Run->Step Over or press the Step Over icon in the tool bar.
  • Step over the fflush line. Should see the output of the program in the terminal where gdbserver was started.
  • Terminate the debug session. Run->Terminate or use the Terminate icon in the tool bar.

Breakpoints can be set/cleared by clicking in the gutter to the left of the line numbers in the source view.

Conclusion

The steps above have demonstrated how to do the following in Code Composer Studio:

  • Create a C/C++ Project
  • Add a source file and code for a simple hello world program
  • Build the program
  • Copy the executable to the target
  • Start gdbserver on the target
  • Start a debug session in Code Composer Studio
  • Step through the simple program
  • Terminate the debug session

A real application would be more complicated since the program being debugged would be more complex, but the same basic steps would be used.

Go to top
Add picture from clipboard (Maximum size: 1 GB)