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://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:

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

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
#
# http://www.ti.com/tool/ek-lm4f120xl
#
#
# 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:

bitsbytes.tcl
board
chip
cpld
cpu
interface
LM4F120XL.cfg
memory.tcl
mem_helper.tcl
mmr_helpers.tcl
openocd
target
test

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 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
STELLARISWARE_PATH=~/stellaris/stellaris/

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

make

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
load
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
c

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!

A lot of stuff learned!

I’ve been playing around a lot with the Stellaris Launchpad board, looking around the stuff I never noticed that the besides the fact of being licensed with a BSD style license, the Stellarisware SW provided by Texas Instruments has a closed license for the various examples.

The basic files needed to create a program for the board, and basically for all the ARM processors are the following with binutils and gcc:

  • The program you want contained in a .c file.
  • A linker script due to the fact you don’t have an operating system running.
  • A startup code file that zeroes the .bss segment variables, copies the .data segment to ram and setups the NVIC vector table.
  • A Makefile to build everything easily.

The program and the Makefile can be done with not much worries, but the linker script and the startup code are quite difficult, at least for me, to understand and set up properly.

So I ended up building from scratch the whole files needed and licensed them with a BSD license (Basically, do what you want with them, just give me credit I’m happy if someone find them useful, you can contribute, but don’t blame me if it doesn’t work lol)

You can find them in this Github repository

Continue reading “A lot of stuff learned!”

Stellaris Launchpad

So, I got my 2 stellaris launchpad boards from TI.

Launchpad
Stellaris Launchpad

Each board has 2 Stellaris LM4F120H5QR ARM Cortex-M4 MCUs. The nice thing it’s I’ve had them for less than 5$ with free shipment.

I’ve followed the getting started tutorial on a windows machine, as they suggested, using their Code Composer Studio 5, which is free for the launchpad board, with now limitation on code size or time.
I’ve noticed that the examples can be built with a GNU cross-toolchain for arm-none-eabi, like the codesourcery lite if you don’t want to build your own (Yeah, I’m lazy).
I just used my ubuntu pc to test that out, and it was kinda easy to build some sample!

First thing to do it’s downloading the toolchain from here, you’ll need to register on their site. The installation it’s pretty straightforward, just follow the instructions on the site, with the shell change and the adding of the bin directory to the path.

You can verify to have a working toolchain with this test:

arm-none-eabi-g++ –version

Next you need to download the StellarisWare software from here you’ll need to register in here too but also getting an approval.

After downloading the StellarisWare you should create a folder on your home directory:

cd
mkdir stellaris
cd stellaris

Then you just need to run unzip to extract inside your folder the content of the auto-extracting archive you downloaded.

unzip ../downloads/SW-EK-LM4F120XL-9453.exe

Then you’ll just have everything ready to work with that. Get inside a directory and just use make to build the project. The cross compiling and all the variables configurations are in the makedefs file in the stellarisware folder!

The only missing part until now it’s how you load to the compiled bin file into the microcontroller. On windows it can be achieved with the LMLoader program. In linux there’s no way at the moment usually with the ICDI controller on board, the only way it’s using a JTAG adapter connected on the breakout JTAG connector.

The nice thing it’s that there’s also a d DFU Bootloader on the chip, maybe with some work I could get it working and uhm that would be useful somehow.