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:
git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
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 http://openocd.zylin.com/openocd 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:
./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:
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 WORKAREASIZE 0x4000
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:
git clone https://github.com/scompo/stellaris-launchpad-template-gcc.git
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!
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.
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!