At the time of writing this tutorial, there is not official support in OpenOCD for the ICDI protocol used in the Stellaris LaunchPad integrated debugger. But don't worry, Spencer Oliver has patched it to add support. When this patch is pushed into the main OpenOCD branch, it will not be necessary to follow this tutorial. Just install it using the repository of your distro, and it's done. But now we will have to do it the long way:
- Download the sources
cd ~/src/stellaris git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
- Install the required dependencies
sudo apt-get install libtool libusb-dev
- Apply Spencer Oliver patches:
cd openocd git pull http://openocd.zylin.com/openocd refs/changes/22/922/14
- And build it:
./bootstrap ./configure --enable-maintainer-mode --enable-ti-icdi make
- To install it I have also followed scompo's suggestion about not executing make install but copying the required files manually:
cd ~/src/stellaris mkdir openocd-bin cp -r openocd/tcl/* openocd-bin cp openocd/src/openocd openocd-bingdb is already built. We built it in the previous chapter, when we built the toolchain. So we can start using it, but before, we must build something to debug.
Avoiding Stellarisware obscure licensesAs I wrote in previous chapter, there's no problem with StellarisWare library license, but the examples that come bundled with it use a more obscure license terms, including the startup code, the linker scripts and the makefiles. So to avoid problems with this license, you should not use these files. Again, scompo comes to rescue us. He wrote a template project, including a makefile, startup code and a linker script you can use in your own projects. You just have to preserve the header in the files (with the copyright notice) and everything should be fine. Let's build this template project:
- Download the project
cd ~/src/stellaris git clone https://github.com/scompo/stellaris-launchpad-template-gcc.git cd stellaris-launchpad-template-gcc
- Edit the makefile to set the path to the StellarisWare library. Change this line:
- And build:
At last, it's time to start debugging!
Using the debugger
First of all, you have to create a config file for openocd. Rickta59, a Stellarisiti forum user, wrote one working perfect. Then you'll only have to start both openocd and gdb.
- Download the config file:
cd ~/src/stellaris/openocd-bin wget http://pastebin.com/download.php?i=qXxeYsVx -O LM4F120XL.cfg
- With the Stellaris LaunchPad debug port connected to the PC, and the power select switch in the "debug" position, run openocd. Before starting it, make sure you created the udev rule for the Stellaris LaunchPad as written in the previous chapter, to avoid having to run openocd with root privileges:
./openocd --file LM4F120XL.cfg
- openocd should be running without problems. If it fails, try running it as superuser (with the sudo prefix). If it works with sudo, maybe you have not properly created the udev rule! If it's working, now you'll only have to start gdb. Open another terminal and type:
cd ~/src/stellaris/stellaris-launchpad-template-gcc arm-none-eabi-gdb main.axf
- gdb should have started, and you should be greeted by the (gdb) prompt. At this prompt you should start writing some commands. The first one will connect gdb to openocd, and the following ones will load the program and initialize the debug process:
target extended-remote :3333 monitor reset halt load monitor reset init
- You can enable some breakpoints and watch the contents of the count variable. Then continue execution with the 'c' command:
b main.c:51 b Timer1A_ISR display count c
- The execution will hit a breakpoint, and the line at which the code is stopped will be printed, along with the value of the count variable. You can type 'c' command several times to continue execution and watch the contents of the count variable each time the program stops at a breakpoint. When you finish debugging, you can exit gdb with the 'q' command. To exit openocd, just switch to it and hit [CTRL] + C.
And that's all. Now you can build and debug anything you want for your StellarisLaunchpad using GNU/Linux. What did you say? You don't like command-line debugging? Me neither! So stay tuned, because in the next chapter, you'll learn how to set-up an Eclipse project, using its full code building and debugging capabilities!
Happy hacking and stay tuned!
You followed the steps without changing a single thing, and got to step 4 of the "Using the debugger" sub-chapter. But then something went wrong and when trying to connect to openocd with the target command, you received this cryptic error message:
Remote 'g' packet reply is too long: 000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000010000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000
It looks like there's a known bug in openocd causing this issue with some versions of gdb. Until this bug gets fixed, you can workaround it:
- Download this target description file to the directory where the project you want to debug is (in this case, to ~/src/stellaris/stellaris-launchpad-template-gcc).
cd ~/src/stellaris/stellaris-launchpad-template-gcc wget http://pastebin.com/download.php?i=0Lu3Bu0R -O target.xml
- Start gdb as usual, but before issuing any other command, write this one at the gdb prompt:
set tdesc filename target.xml
- Continue writing commands as usual, hopefully the error should be gone, and everything should work perfect now!