Stellaris Launchpad with OpenOCD and Linux

From Texas Instruments Wiki
Jump to: navigation, search




LaunchPad Resource Portal  LaunchPadRocket.png


This wiki is open and can be edited by all!

More information available @ www.ti.com/launchpad


LaunchPad Banner.jpg

Introduction

In this project we will walk you through the process of building OpenOCD on Linux to work with Launchpad, debugging a project with GDB, and modifying the project behavior. OpenOCD opens up debug level development with GDB and GNU tools, but the current stable version does not have Launchpad support. Using this method of building the stable version with a patch provided by Spencer Oliver, we will be able to run OpenOCD with Launchpad support.

Download and install Software You Will Need

Install git and other dependencies that are required by this tutorial, and by OpenOCD.

$ sudo apt-get install git-core libtool autoconf texinfo libusb-dev libusb-1.0 screen vim

Install the EABI Release of CodeBench Lite,which is a set of tools that allows cross-compiling on a host-computer for a different architecture. In our case we are cross compiling on Linux for an ARM architecture. Addressing any possible confusion, the GNU/Linux Release is intended more for a target that will run a full operating system, such as Linux. The fact that we are using a Linux host does not have an influence on this selection.

CodeSourcery.jpg

Once you have downloaded the .bin file, we need to change permissions on the file to make it executable. From there we can start the installation, which is straight-forward. One option we need to ensure is checked is to modify PATH for the current user.

$ chmod +x arm-*
$ ./arm-*

Download and install StellarisWare, which is listed as SW-EK-LM4F120XL on http://www.ti.com/tool/sw-ek-lm4f120xl. StellarisWare provides an API to simplify development, and it will also provide examples to test with. For the purposes of this tutorial, we will be using the built example files.
StellarisWare.jpg

Create a folder for StellarisWare inside your home folder, and build it.

  
$ mkdir ~/StellarisWare
$ cd ~/StellarisWare
$ unzip ../Downloads/SW-EK-LM4F120XL-9453.exe
$ make

Build OpenOCD

From here we need to fetch the OpenOCD source code. This will create the code/ folder, so for convenience, we will rename it to openocd/.

$ cd
$ git clone http://git.code.sf.net/p/openocd/code openocd

As of version 0.7.0 of OCD (May 2013), support for the TI-ICDI is merged into the main development branch, so all you need is the main OpenOCD release.

Now that we have the stable version's source code, we can proceed to configure, build, and install OpenOCD.

$ ./bootstrap
$ ./configure --enable-maintainer-mode --enable-ti-icdi
$ make
$ sudo make install

Run OpenOCD

Now this build of OpenOCD is installed completely. The main difference between this and installing the stable version with apt-get is that the files will be placed under /usr/local instead of /usr. From here, connect the launchpad and start OpenOCD.

$ sudo openocd --file /usr/local/share/openocd/scripts/board/ek-lm4f120xl.cfg

This should result in an output looking like the following to indicate that OpenOCD has successfully connected:
OpenOCD Output.jpt.jpg

This terminal will need to stay open and we will no longer be entering commands in it. From here, open up two other terminal windows, one for gdb and the other to act as a serial terminal. For this tutorial, we will use the project0 example, which already has a CCS tutorial.

In the terminal window that is being used as a serial terminal, simply type the following command:

$ sudo screen /dev/ttyACM0 115200

In the debugging window, we need to startup gdb with the project0.axf file, connect gdb to the target, and initialize the program to halt in the startup code.

$ arm-none-eabi-gdb ~/StellarisWare/boards/ek-lm4f120xl/project0/gcc/project0.axf
(gdb) target extended-remote :3333
(gdb) monitor reset halt
(gdb) load
(gdb) monitor reset init

At this point we are halted in the startup_gcc code. We can run the program simply by continuing with the following command:

(gdb) continue

Once you see that the blue LED is blinking, you can stop the program with:

(gdb) kill

Modify Project0

Now we will look to modify the code to blink multiple colors. First you need to open up an editor to modify project0.c. For this tutorial, we are using vim. Note that all three LED colors are already defined on lines 36-38 of project0.c

 
 #define RED_LED   GPIO_PIN_1
 #define BLUE_LED  GPIO_PIN_2
 #define GREEN_LED GPIO_PIN_3

Note on line 75 of project0.c that all three LED GPIO pins have been configured for output mode

GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED);

Copy Lines 82 through 90 of project0.c. Note that the 2nd parameter serves as a bit mask for which pins to write.

//
// Turn on the LED
//
GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, RED_LED);

//
// Delay for a bit
//
SysCtlDelay(2000000);

Paste the copied lines below line 100. The 'while(1)' should now look like this:

while(1)
{
    //
    // Turn on the LED
    //
    GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, RED_LED);

    //
    // Delay for a bit
    //
    SysCtlDelay(2000000);

    //
    // Turn on the LED
    //
    GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, BLUE_LED);

    //
    // Delay for a bit
    //
    SysCtlDelay(2000000);
    
    //
    // Turn on the LED
    //
    GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, RED_LED);

    //
    // Delay for a bit
    //
    SysCtlDelay(2000000);
}

Change line 105 from RED_LED to GREEN LED.

GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, GREEN_LED);

In order to save and close project, simply type :wq. From there, we just need to execute another make and re-run gdb.

$ make
$ arm-none-eabi-gdb gcc/project0.axf

Congratulations! You have just imported, modified, downloaded and debugged your first StellarisWare Project.

References/Further Reading