Debugging a program on the stellaris launchpad board

OpenOCD now supports TI’s stellaris launchpad. Patching it it’s no longer necessary!
The source it’s available here!

After creating a template for the Stellaris Launchpad, I wanted to debug it and my own programs as well.

So I installed openOCD and used gdb (for arm-none-eabi) to debug it and see if it works properly.

I writing here a tutorial to help someone who would like to do the same.

The first thing to do it’s obtaining a compile toolchain, I’m lazy and I use the arm-none-eabi from Codesourcey that’s already built from them and free to use as I described it here.

When you got that working the next step it’s getting the Stellarisware software, the process it’s described here too. (It’s not really needed, but if you want to do something quickly that’s the way to go because the API for it it’s well documented and easy to use).

After doing the previous steps you need to get the source code of openOCD, patch it and build it. You can find how all this born in (this forum topic).

You’ll need git, which you can get on Ubuntu just opening a terminal and typing:

sudo apt-get install git-core

You need to get the latest openOCD source code so type on the terminal:

cd ~/stellaris/
git clone git://

This will create a directory called openOCD containing all the source files of the project. then you need to install the libraries you’ll need to built it. So again type in the terminal:

sudo apt-get install libtool autoconf texinfo libusb-dev

This tutorial will just focus on the Launchpad board, you’d probably need other libraries if you need to build openOCD for other dongles.

The next step it’s to patch the sources with the latest patch from this archive (thanks Spencer Oliver). The process it’s quite easy and you can choose different methods to do it, I’ll go for the git pull to the project so type:

git pull refs/changes/22/922/10

And git will automatically patch the sources with the latest patch revision.

Then you’ll need to build openOCD, there are plenty of information on the README file, basically I just did this:

cd openocd
./configure --enable-maintainer-mode  --enable-ti-icdi

I skipped the “make install” step.

I then created a directory with the binary file and all the other configurations needed:

cd ~/stellaris
mkdir openocd-bin
cp -r ./openocd/tcl/* ./openocd-bin
cp ./openocd/src/openocd ./openocd-bin

Then you’ll need a .cfg file to pass the openOCD, I used the one this guy made, because I’m lazy (haven’t I told you?). So just make a file called LM4F120XL.cfg in the openocd-bin folder and copy the following in it:

# TI Stellaris Launchpad ek-lm4f120xl Evaluation Kits
# NOTE: using the bundled ICDI interface is optional!
# This interface is not ftdi based as previous board were
source [find interface/ti-icdi.cfg]
set CHIPNAME lm4f120h5qr
source [find target/stellaris_icdi.cfg]

Now a quick check, the openocd-bin folder should contain the following files:


Now you’re ready to launch it from here with sudo, connect the board to a USB port and just type in the command line:

sudo ./openocd --file ./LM4F120XL.cfg

Now that you’ve got it running open another terminal to download a template project I made, to run it on the board and debug it! So type:

cd  ~/stellaris
mkdir projects
cd projects
git clone

This will clone the project into the stellaris-launchpad-template-gcc folder. You just need to open up the Makefile with any editor and change this:

# Stellarisware path

With the path to your stellarisware main folder. Then you can just build your project typing:


Then comes the cool part of the process, see if the program it’s running properly, so just connect arm-none-eabi-gdb to open ocd, load the program and see if everything it’s good!

arm-none-eabi-gdb main.axf

This will open up gdb for arm-none-eabi with a target file called main.axf. Next will type to the (gdb) prompt, so let’s do something useful (Again thanks a lot the the stellaristi forum guys for this)!

target extended-remote :3333
monitor reset halt
monitor reset init

Now the target processor it’s halted at the beginning of the startup_handler() code of the LM4F_startup.c file. Supposedly this will work fine doing it’s magic, but check it out, and if you find any strange behavior just tell me opening an issue in the github project page. So let’s go on and just set some breakpoints and display some the variables at each break.

b main.c:51
b Timer1A_ISR
display count

The c command will just continue the execution of the program from the breakpoint. If you need any help just type help in the gdb prompt window.

Everytime you’ll write c to continue executing the program you’ll see that the variable count will be updated, so basically the interrupt routine it’s running and updating the volatile variable. Well, we’re good then!

To exit gdb just enter “q” and confirm with “y”.

To exit from openocd just use “ctrl”+c like every command line program in linux. I’ve noticed that I need to disconnect and riconnect the board sometimes to restart openOCD so if it’s the case, just go for it doing this.

This would hopefully be a starting point for your own projects, just copy this template folder and start doing everything you want! Good hacking!

About these ads

About scompo

Nothing to say...
This entry was posted in Projects, stellaris and tagged , , , , , , , . Bookmark the permalink.

25 Responses to Debugging a program on the stellaris launchpad board

  1. Sam Bristow says:

    Nice little guide here. I think there are a couple of small mistakes in the install step though:
    * WordPress has turned the two dashes before the enable flags into a long dash
    * Small typo in the configure step, missing an ‘i’ in enable-maintainer-mode
    * There shouldn’t be a ./ in front of make

    cd openocd
    ./configure –enable-maintainer-mode –enable-ti-icdi

    • scompo says:

      Thank you! I’ll sure correct the errors!
      Thanks for the catches, btw I didn’t understand why wordpress should change the 2 dashes into a long one in a blockquote -.-

  2. Frankalicious says:

    Really nice.
    Shouldn’t it be

    cp -r ./openocd/tcl/* ./openocd-bin

    instead of

    cp -r * ./openocd/tcl/ ./openocd-bin


  3. Pingback: Revue de presse – 19 Novembre 2012 |

  4. Pingback: How to build OpenOCD with Stellaris Launchpad support

  5. Pingback: Belgaum news | About Belgaum | Belgaum information | Belgaum district | Belgaum city | Belgaum Hotels | Belgaum People | Belgaum tourism | Belgaum entertainment | Belgaum students | Inside facebook | Hack | make use of | technical news | | How to build Op

  6. Pingback: » Nice writeup on debugging with TI’s Stellaris Fuzzy Hypothesis Online

  7. Mike says:

    I like the step by step nature of the guide. But I had some problems. Admittedly I don’t understand every step which is probably where my problems come from.

    I had errors when I did the make command:
    ti_icdi_usb.c:36:31: fatal error: libusb-1.0/libusb.h: No such file or directory
    I tried:
    sudo apt-get install
    to try to appease the error and then another make gave me new errors:

    ./.libs/libopenocd.a(ti_icdi_usb.o): In function `icdi_send_packet’:
    /home/mike/work/stellaris/openocd/src/jtag/drivers/ti_icdi_usb.c:198: undefined reference to `libusb_bulk_transfer’
    /home/mike/work/stellaris/openocd/src/jtag/drivers/ti_icdi_usb.c:206: undefined reference to `libusb_bulk_transfer’
    /home/mike/work/stellaris/openocd/src/jtag/drivers/ti_icdi_usb.c:237: undefined reference to `libusb_bulk_transfer’
    ./.libs/libopenocd.a(ti_icdi_usb.o): In function `icdi_usb_close’:
    /home/mike/work/stellaris/openocd/src/jtag/drivers/ti_icdi_usb.c:644: undefined reference to `libusb_close’
    /home/mike/work/stellaris/openocd/src/jtag/drivers/ti_icdi_usb.c:647: undefined reference to `libusb_exit’
    ./.libs/libopenocd.a(ti_icdi_usb.o): In function `icdi_usb_open’:
    /home/mike/work/stellaris/openocd/src/jtag/drivers/ti_icdi_usb.c:674: undefined reference to `libusb_init’
    /home/mike/work/stellaris/openocd/src/jtag/drivers/ti_icdi_usb.c:679: undefined reference to `libusb_open_device_with_vid_pid’
    /home/mike/work/stellaris/openocd/src/jtag/drivers/ti_icdi_usb.c:685: undefined reference to `libusb_claim_interface’

  8. Mike says:

    Sorry about the last post – it is not useful and can be ignored or removed. I hadn’t installed arm-none-eabi like the directions state.

    New problem – …../stellaris/projects/stellaris-launchpad-template-gcc/main.c has statements:
    #include “inc/hw_ints.h”
    #include “inc/hw_gpio.h”
    #include “inc/hw_memmap.h”
    #include “inc/hw_sysctl.h”
    #include “inc/hw_types.h”
    #include “driverlib/gpio.h”
    #include “driverlib/sysctl.h”
    #include “driverlib/interrupt.h”
    #include “driverlib/timer.h”

    I didn’t have these files. I looked through the instructions and couldn’t find how to get these files. I found them here:
    and maybe here (although for the wrong device perhaps?)

    While in:
    When I try to make

    Making driverlib
    make -C ~/stellaris/driverlib/
    make[1]: Entering directory `/home/mike/stellaris/driverlib’
    make[2]: Entering directory `/home/mike/stellaris/driverlib’
    Makefile.driverlib-cm3:43: ../makedefs: No such file or directory
    make[2]: *** No rule to make target `../makedefs’. Stop.
    make[2]: Leaving directory `/home/mike/stellaris/driverlib’
    make[1]: *** [all] Error 2
    make[1]: Leaving directory `/home/mike/stellaris/driverlib’
    make: *** [main.axf] Error 2

    So it needs othe makefiles? If it’s just me being stupid, feel free to contact me personally and not post this. Thanks!

    • scompo says:

      In the beginning there’s a link to another post describing how to get the stellarisware software. It contains driverlib and the other includes used in the program.

  9. Mike says:

    As a suggestion to improve clarity on this guide, I think it should there be:

    cd ~/stellaris/openocd-bin
    sudo ./openocd –file ./LM4F120XL.cfg

    and at:

    Then you can just build your project typing:
    [cd ~/stellaris/projects/stellaris-launchpad-template-gcc] <-include this

    Is that correct?

  10. shuhrat says:

    Hey, thanks for a good guide
    I did evrth as you wrote but when using gdb it gives this message
    target extended-remote :3333
    Remote debugging using :3333
    Remote ‘g’ packet reply is too long: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    (gdb) monitor reset halt
    “monitor” command not supported by this target.
    (gdb) load
    Am I doing smth wrong???

  11. A note in case anyone else fails at configuring openOCD:
    After cloning the openOCD repository, I had to do `git submodule init` and `git submodule update` in order to get JimTCL source code loaded.

  12. Pingback: Stellaris Launchpad as a JTAG programmer (not yet) « Chris Swan's Weblog

  13. Spencer Oliver says:

    It is probably also worth mentioning that support for the ICDI has been merged into the OpenOCD master branch, so no more patches required.

    Also the git url has changed, due to a project upgrade on sf, use:
    git clone git:// or for those behind firewalls
    git clone

  14. Akhil says:

    When I run your template in debug mode, var_init doesn’t seem to be initialized with it’s expected value. Upon modifying it’s initialization to 0xAA55AA55, I see that pattern when memory browsing in the flash but it doesn’t seem to get loaded properly.

  15. Pingback: Setting up Tiva C Launchpad project template with Sourcery Codebench and Eclipse - Do It Easy With ScienceProg

  16. Stella says:

    I’m sure you don’t know how good this blog is.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s