Flyswatter2 Pandaboard Windows How To

This guide will walk you through connecting the Flyswatter2 and the TI Pandaboard to your Windows PC, and installing and running OpenOCD. This guide was tested with Windows XP and Windows 7. Instructions are identical on 32-bit and 64-bit versions of Windows unless otherwise noted.

 

Connecting the Flyswatter2 and the Pandaboard

To hook up the Flyswatter2 and the Pandaboard, you will need:

  • 20-pin ARM to 14-pin TI JTAG Adapter Board
  • 14-pin JTAG Ribbon Cable
  • RS-232 Serial Cable with one male, one female head
  • USB Male A/Male B Cable
  • 5V1A Power Cable

Set the EMU pins on the JTAG Adapter Board.

Ti adapter.png

The EMU0 and EMU1 pins should be set to 1. Set both jumpers to the position closest to the 14-pin interface, as in the picture.

 

Connect the JTAG Adapter Board to the Flyswatter2.

Fs2 ti adapter.png

Connect the 20-pin end of the adapter board to the Flyswatter2’s JTAG interface.

 

Connect the 14-pin Ribbon Cable to the JTAG Adapter Board.

Fs2 ti jtag.png

Your cable most likely has a notch on the head to force it into the correct position. If it doesn’t, align Pin 1 on the ribbon cable with the side of the board opposite the EMU pins. (In the picture, Pin 1 is marked by the red stripe on the cable.)

 

Connect the Other End of the Ribbon Cable to the Pandaboard.

Fs2 panda jtag.png

Be sure to align the ribbon cable correctly. Pin 1 on the Pandaboard is the pin closest to the center of the board.

 

Plug in the Serial Cable.

Fs2 panda bothcables.png

Connect the Flyswatter2 and the Pandaboard with the RS-232 serial cable.

 

Connect the USB cable to the Flyswatter2.

Fs2 panda usb.png

Find the USB cable that comes with the Flyswatter2. Connect the B end (the square end, not the flat end) to the Flyswatter.

 

Connect the Power Cable to the Pandaboard.

Fs2 panda power.png

The Pandaboard’s power adapter is next to the USB and ethernet ports.

 

Plug the Power Adapter into a Wall Outlet.

The green power LED on the Pandaboard should come on and remain on.

Plug the USB Cable into your PC.

The green power LED on the Flyswatter2 should come on and remain on.
 

Installing OpenOCD

OpenOCD (Open On-Chip Debugger) is open-source software that interfaces with the Flyswatter2. OpenOCD provides debugging and in-system programming for embedded target devices. You will need to compile OpenOCD from source, and patch the source with one of the OpenOCD Patches for Flyswatter 3 support.

Whichever guide you use, be sure to install the patch! All four guides include instructions on downloading and installing the patch.

Windows 7

Use Windows 7 guides if compiling for Windows Vista.

Compiling OpenOCD Win7

Compiling OpenOCD Win7 D2XX

 

Windows XP

Compiling OpenOCD WinXP

Compiling OpenOCD WinXP D2XX
The first set of instructions uses libFTDI, an open-source driver library for FTDI devices. The second set uses FTD2XX, a closed-source driver library from Future Technology Devices International.

 

Running OpenOCD

Now you are ready to run OpenOCD. Open a command line window; if you’re not sure how to do this, see Running OpenOCD on Windows. Navigate to the folder containing openocd.exe (the openocd-bin folder you created in the compile guide) and type:

cd C:\openocd-bin
openocd -f interface/flyswatter2.cfg -f board/ti_pandaboard.cfg

When you start OpenOCD you should see something like this:

Panda ocdstartup win.png

Telnet Connection

You cannot enter commands directly to OpenOCD. Open a new command window and type:

telnet localhost 4444

You will should see this prompt:

Telnet win.png

You can give commands to OpenOCD through this prompt. If you don’t see the prompt on Windows 7, you may need to enable the Telnet client. See Configuring Windows 7 for OpenOCD.

 

Common OpenOCD Commands

To see a full list of OpenOCD commands, enter help in the telnet window.

reset

Resets the Pandaboard. The output of the Reset command should look like this:

Panda reset win.png

halt

Sends a halt request to the Pandaboard. If the Pandaboard halts, you will see text output in the telnet window. (If the Pandaboard is already halted, you will see no output.)

Panda halt win.png

halt [timeout]

You can also use halt followed by a time in milliseconds. OpenOCD waits for the target to halt the specified amount of time, then gives up if the target has not halted. You can use this to avoid OpenOCD hanging because the Pandaboard fails to halt. For example, to send a halt command with a timeout of one second, type:

halt 1000

resume

Enter resume to end a halt. You will not see any text output in the telnet window.

reg

Displays a numbered list of all of the Pandaboard’s registers.

Panda reg win.png

reg [entry]

Run reg with a register number to display the contents of a register, in hexadecimal. The register number corresponds to the output of the reg command with no arguments, above. You must run the halt command before reading registers.

Panda reg0 win.png

If you run reg while the Pandaboard is not halted, you will still see the value stored in the register. However, registers change contents very quickly while the device is running; by the time you see the value, the value actually in the register may be different. If you try to run reg while the device is not halted, you will see this:

Panda reg0 nothalted win.png

 

reg [entry] [value]

Sets the value of a register. The register number corresponds to the output of the reg command with no arguments, above. Make sure the Pandaboard is halted (with the halt command) before you change the value of a register!

You can enter registry values in either decimal, by typing a number by itself, or in hexadecimal, by prefacing the value with 0x.

Panda regset win.png

 

GDB Debugger

GDB, the GNU Project Debugger is a debugging tool provided with the GNU Compiler Collection (GCC). GDB allows you to stop and start a running program, examine its functioning, and make changes. To install and use GDB with OpenOCD, follow the instructions on the Windows GDB Debugger page below.

Windows GDB Debugger

The GDB debugger page will walk you through installing GDB for use with OpenOCD, and loading and testing a simple program.

Flyswatter2 RouterStationPro Windows How To

This guide will walk you through connecting the Flyswatter2 and the Ubiquiti RouterStation Pro to your Windows PC, and installing and running OpenOCD. This guide was tested with Windows XP and Windows 7. Instructions are identical on 32-bit and 64-bit versions of Windows unless otherwise noted.

 

Connecting the Flyswatter2 and the RouterStation Pro

To hook up the Flyswatter2 and the RouterStation Pro, you will need:

  • Flyswatter2
    • 20-pin ARM to 14-pin MIPS JTAG Adapter Board
    • USB Male A/Male B Cable
    • 14-pin JTAG Ribbon Cable
  • RouterStationPro
    • RS-232 Serial Cable with two female connectors
    • CAT6 Cable
    • Power Over Ethernet Injector (with power cable)

The items listed under RouterStationPro are included with the MIPS Linux Starter Kit.

Connect the MIPS JTAG Adapter Board to the Flyswatter2.

Fs2 mips adapter.png

The 14-pin end of the adapter board should face up toward the top of the board, as in the picture.

 

Connect the 14-pin ribbon cable to the Adapter Board.

Fs2 mips jtag.png

The ribbon cable should have a notch on the connector to force it into the correct position. If it doesn’t, make sure to align Pin 1 as shown in the image to the left. (Pin 1 is on the side of the cable with the red stripe.)

 

Connect the Other End of the Ribbon Cable to the RouterStation Pro.

Fs2 rspro jtag.png

Again, be sure to align the red stripe with Pin 1, as shown in the picture. Pin 1 is toward the outer edge of the board. It is also marked on the bottom of the RouterStation Pro.

 

Connect the RS-232 Serial Cable.

Fs2 rspro bothcables.png

Connect the cable as shown in the picture.

 

Connect the USB Cable to the Flyswatter2.

Fs2 rspro usb.png

Connect the Male B adapter to the Flyswatter 3. (The Male B end is the squarish end, not the flat end.)

 

Connect the CAT6 Cable to the Power Over Ethernet Injector.

Poe cat6.png

Leave the boards alone for now. Find the Power Over Ethernet Injector in the MIPS Linux Starter Kit, and connect the CAT6 cable. The PoE injector has two ethernet ports, but only one supplies power. Be sure to use the correct one. The correct ethernet port is labeled.

 

Connect the Power Adapter to the Power Over Ethernet Injector.

Poe power.png

Connect the power cable to the other side of the PoE injector.

 

Connect the Other End of the CAT6 Cable to the RouterStation Pro.

Rspro poe.png

Connect the CAT6 cable to the RouterStation Pro’s Power Over Ethernet port. Warning: The RouterStation Pro has three ethernet ports in addition to the PoE port. Connecting the PoE injector to one of the regular ethernet ports may damage the board. The PoE port is the closest to the center of the board, to the right of the three ethernet ports as shown in the picture. It is labeled POE on the board.

 

Plug the Power Adapter into a Wall Outlet.

The green LEDs on the RouterStation Pro should briefly flash, and the leftmost LED should remain on.

Plug the USB Cable into your PC.

The green power LED on the Flyswatter2 should come on and remain on.
 

Installing OpenOCD

OpenOCD (Open On-Chip Debugger) is open-source software that interfaces with the Flyswatter2. OpenOCD provides debugging and in-system programming for embedded target devices. You will need to compile OpenOCD from source, and patch the source with one of the OpenOCD Patches for Flyswatter 3 support.

Whichever guide you use, be sure to install the patch! All four guides include instructions on downloading and installing the patch.

Windows 7

Use Windows 7 guides if compiling for Windows Vista.

Compiling OpenOCD Win7

Compiling OpenOCD Win7 D2XX

 

Windows XP

Compiling OpenOCD WinXP

Compiling OpenOCD WinXP D2XX
The first set of instructions uses libFTDI, an open-source driver library for FTDI devices. The second set uses FTD2XX, a closed-source driver library from Future Technology Devices International.

 

Running OpenOCD

Now you are ready to run OpenOCD. Open a command line window; if you’re not sure how to do this, see Running OpenOCD on Windows. Navigate to the folder containing openocd.exe (the openocd-bin folder you created in the compile guide) and type:

cd C:\openocd-bin
openocd -f interface/flyswatter2.cfg -c "jtag_khz 15000" -f target/ar71xx.cfg

When you start OpenOCD you should see something like this:

rspro ocdstartup win.png

Telnet Connection

You cannot enter commands directly to OpenOCD. Open a new command window and type:

telnet localhost 4444

You will should see this prompt:

Telnet win.png

You can give commands to OpenOCD through this prompt. If you don’t see the prompt on Windows 7, you may need to enable the Telnet client. See Configuring Windows 7 for OpenOCD.

 

Common OpenOCD Commands

To see a full list of OpenOCD commands, enter help in the telnet window.

reset

Resets the RouterStation Pro. The output of the Reset command should look like this:

Rspro reset win.png

halt

Sends a halt request to the RouterStation Pro. If the RouterStation Pro halts, you will see text output in the telnet window. (If the RouterStation Pro is already halted, you will see no output.)

Rspro halt win.png

halt [timeout]

You can also use halt followed by a time in milliseconds. OpenOCD waits for the target to halt the specified amount of time, then gives up if the target has not halted. You can use this to avoid OpenOCD hanging because the RouterStation Pro fails to halt. For example, to send a halt command with a timeout of one second, type:

halt 1000

resume

Enter resume to end a halt. You will not see any text output in the telnet window.

reg

Displays a numbered list of all of the RouterStation Pro’s registers.

Rspro reg win.png

If the board is not halted, the board registers will be displayed but not their values.

reg [entry]

Run reg with a register number to display the contents of a register, in hexadecimal. The register number corresponds to the output of the reg command with no arguments, above. You must run the halt command before reading registers.

Rspro reg0 win.png

If you run reg while the RouterStation Pro is not halted, you will still see the value stored in the register. However, registers change contents very quickly while the device is running; by the time you see the value, the value actually in the register may be different. If you try to run reg while the device is not halted, you will see this:

Rspro reg0nothalted win.png

Note that the RouterStation Pro does not show any warning if you run the reg command while the board is running.

 

reg [entry] [value]

Sets the value of a register. The register number corresponds to the output of the reg command with no arguments, above. Make sure the RouterStation Pro is halted (with the halt command) before you change the value of a register!

You can enter registry values in either decimal, by typing a number by itself, or in hexadecimal, by prefacing the value with 0x.

Rspro regset win.png

 

GDB Debugger

GDB, the GNU Project Debugger is a debugging tool provided with the GNU Compiler Collection (GCC). GDB allows you to stop and start a running program, examine its functioning, and make changes. To install and use GDB with OpenOCD, follow the instructions on the Windows GDB Debugger page below.

Windows GDB Debugger

The GDB debugger page will walk you through installing GDB for use with OpenOCD, and loading and testing a simple program.

Flyswatter2 LPC2214 How To

This guide will walk you through connecting the Flyswatter2 and the mikroElektronika mikroBoard for ARM 144-pin to your Linux PC, and installing and running OpenOCD. The mikroBoard used in this guide is mounted on the MikroElektronika UNI-DS6 development system.

This guide was written for Ubuntu 12.04 LTS.

 

Connecting the Flyswatter2 and the LPC2214 mikroBoard

To hook up the Flyswatter2 and the LPC2214 mikroBoard, you will need:

  • Flyswatter2
    • USB Male A/Male B Cable
    • 20-pin JTAG Ribbon Cable
  • MikroElektronika mikroBoard for ARM 144-Pin (LPC2214)
  • MikroElektronika UNI-DS6 development system
    • 9V DC Power Cable

 

Mount the mikroBoard LPC2214 on the UNI-DS6 motherboard

uni-ds6 top.jpg

Look for the silkscreen “mikroBoard Socket” on your UNI-DS6. Carefully align the pins on the bottom of the mikroBoard with the socket, and press firmly on all four corners to secure the connection. Make sure the 20-pin JTAG and mini-USB connectors are oriented to the top of the board.

Your UNI-DS6 and mikroBoard may have shipped with the mikroBoard already mounted, as shown in the picture to the left. If so, skip this step.

Check the Jumper Settings on the UNI-DS6 motherboard.

unids6 power jumper.png

The LPC2214 mikroBoard has 3.3V I/O so you must set the UNI-DS6 motherboard to 3.3V I/O as well. Set the J16 jumper to 3.3V as shown in the picture. This is located in the upper left corner of the motherboard in the POWER SUPPLY section.

 

Check the Jumper Settings on the mikroBoard.

mikroboard jumpers .png

The J1 “ENABLE” jumper should be connected (shorted) and the J2 “STANDALONE” jumper should be left open, as shown in the image to the left.

Note: You can leave the J2 jumper installed at a 90 degree angle so you will not loose the yellow jumper.

Connect the JTAG cable to the Flyswatter2.

fs2 jtag20.png

Plug the 20-pin ribbon cable into the Flyswatter2’s JTAG interface. Note the position of PIN 1, indicated by the red stripe on the cable in the image.

 

Connect the Flyswatter2’s 20-pin JTAG cable to the mikroBoard.

fs2 ribbon jtag.jpg

Connect the Flyswatter2’s 20-pin JTAG ribbon cable to the mikroBoard’s JTAG interface. The mikroBoard’s JTAG interface does not have a shrouded header to prevent connecting the cable “backwards”, so take careful note of the position of the pins. Pin #1 on the mikroBoard is on the inner left, marked on the board with a small white triangle. Make sure it aligns with Pin #1 on the ribbon cable. In the picture to the left, Pin #1 is marked with a red stripe on the cable.

 

 

unids6 fs2a.jpg

Notice the “loop” in the JTAG ribbon cable. This “loop” helps align Pin #1 on the JTAG ribbon cable connector to Pin #1 on the mikroBoard’s JTAG connector.

 

Connect the USB Cable to the Flyswatter2.

unids6 fs2 usb.png

Find the USB cable that comes with the Flyswatter2. Connect the B end (the square end, not the flat end) to the Flyswatter2.

 

Connect the Other End of the USB Cable to your PC.

Plug the USB cable into your PC, connecting it to the Flyswatter 2. You should see the green “Power” LED light up on the Flyswatter2.

Connect the Power Cable to the UNI-DS6.

unids6 fs2 power.jpg

Connect the 9V-DC power cable to the Uni-DS6’s power jack (connector). The power jack is at the UNI-DS6’s upper left corner.

 

Plug the Power Cable into a Wall Outlet.

The UNI-DS6 has a power switch, so if the power is OFF you won’t see anything happen.

Set the UNI-DS6’s Power Switch to ON.

unids6 power labeled.jpg

The power switch is just below the power adapter. Slide the switch to the right to turn power ON. The power LED should illuminate.

 

 

Installing OpenOCD

OpenOCD (Open On-Chip Debugger) is open-source software that interfaces with the Flyswatter2. OpenOCD provides debugging and in-system programming for embedded target devices. You will need to compile OpenOCD from source. For instructions, see the guide below:

Compiling OpenOCD v07 Linux

 

The LPC2214 Config File

OpenOCD uses specific configuration files for different devices. The config file for the Flyswatter2 is included with OpenOCD, but you will need to download or create a config file for the mikroBoard LPC2214. You can download the file here:

Download lpc2214.cfg (Right Click and “Save As”)

 

Or you can create the file yourself. Open a text editor and create a new file called lpc2214.cfg. Select the following text and copy it all into the file:

jtag_rclk 500
source [find target/lpc2xxx.cfg]
reset_config trst_and_srst srst_pulls_trst

proc init_targets {} {
	echo "Warning - assuming default core clock 14MHz! Flashing may fail if actual core clock is different."
	setup_lpc2xxx lpc2214 0x4f1f0f0f 0x40000 lpc2000_v1 0x4000 14000 1666
}

Save the file into OpenOCD’s /target/ directory. If you followed the compile guides above, you can find the /target/ directory
at
~/openocd-bin/target.

 

Running OpenOCD

Now you are ready to run OpenOCD. If you installed the OpenOCD Ubuntu package, open a terminal window and type the following from any directory:

openocd -f interface/flyswatter2.cfg -f target/lpc2214.cfg -c init -c "reset init"

If you compiled OpenOCD yourself, navigate to the openocd-bin directory you created in the compile guide and type:

cd ~/openocd-bin
sudo ./openocd -f interface/flyswatter2.cfg -f target/lpc2214.cfg -c init -c "reset init"

Your terminal window should now look something like this:

ocdstartup lpc2214.png

Pay careful attention to this line:

Info : JTAG tap: lpc2214.cpu tap/device found: 0x4f1f0f0f (mfg: 0x787, part: 0xf1f0, ver: 0x4)

If you don’t see that, you’ve got an error of some kind. Check the connections on the JTAG ribbon cable or refer to OpenOCD Troubleshooting, and try again.

Telnet Connection

You cannot enter commands directly into OpenOCD. Open a new terminal window and start a telnet session by typing:

telnet localhost 4444

You will should see this prompt:

Telnet.png

You can give commands to OpenOCD through this prompt.

Common OpenOCD Commands

To see a full list of OpenOCD commands, enter help in the telnet window.

reset

Resets the mikroBoard. The output of the Reset command should look like this:

lpc2214 ocdreset.png

Notice the two warnings about slow performance. If you want to speed up the board, you can enable fast memory access and DCC downloads by entering:

> arm7_9 fast_memory_access enable
> arm7_9 dcc_downloads enable

LPC2214 fastenable.png

With fast memory access and DCC downloads enabled, you should be able to reset the board with no warnings:

LPC2214 reset.png

halt

Sends a halt request to the mikroBoard. If the mikroBoard halts, you will see text output in the telnet window. (If the mikroBoard is already halted, you will see no output.)

lpc2214 ocdhalt.png

halt [timeout]

You can also use halt followed by a time in milliseconds. OpenOCD waits for the target to halt the specified amount of time, then gives up if the target has not halted. You can use this to avoid OpenOCD hanging because the mikroBoard fails to halt. For example, to send a halt command with a timeout of one second, type:

halt 1000

resume

Enter resume to end a halt. You will not see any text output in the telnet window.

reg

Displays a numbered list of all of the mikroBoard’s registers.

lpc2214 ocdreg.png

reg [entry]

Run reg with a register number to display the contents of a register, in hexadecimal. The register number corresponds to the output of the reg command with no arguments, above. You must run the halt command before reading registers.

lpc2214 reg0.png

If you run reg while the mikroBoard is not halted, you will still see the value stored in the register. However, registers change contents very quickly while the device is running; by the time you see the value, the value actually in the register may be different. If you try to run reg while the device is not halted, you will see this:

lpc2214 reg0 nothalted.png

 

reg [entry] [value]

Sets the value of a register. The register number corresponds to the output of the reg command with no arguments, above. Make sure the mikroBoard is halted (with the halt command) before you change the value of a register!

You can enter registry values in either decimal, by typing a number by itself, or in hexadecimal, by prefacing the value with 0x.

lpc2214 ocdregset.png

 

Setting up Eclipse for ARM Cross-Development and Debugging

For information on setting up cross-development toolchain, Eclipse, and GDB Debugger for use with the UNI-DS6 and mikroBoard, see the following guide:

LPC2214 Eclipse and GDB

OpenOCD

OpenOCD (Open On-Chip Debugger) is open-source software that interfaces with the Flyswatter’s JTAG port. OpenOCD provides debugging and in-system programming for embedded target devices. OpenOCD provides the ability to flash NAND and NOR FLASH memory devices that are attached to the processor on the target system. Flash programming is supported for external CFI compatible flashes (Intel and AMD/Spansion command set) and several internal flashes (LPC2000, AT91SAM7, STR7x, STR9x, LM3 and STM32x).

OpenOCD supports the following cores:

CORE TYPE EXAMPLE PROCESSORS
ARM7TDMI LPC2148, AT91SAM7
ARM720T LH79520, EP7312
ARM9TDMI
ARM920T S3C2410, S3C2440
ARM922T
ARM926EJS S3C2412, STN8811, STN8815
ARM966E STR91XF
ARM11 S3C6400, OMAP2420, MSM7200
ARM1136
ARM1156
ARM1176
CORTEX-M3 LM3S series, STM32 series
CORTEX-A8 OMAP3530 BeagleBoard
CORTEX-A8 DM3730 BeagleBoard-xM
CORTEX-A9 OMAP4430 PandaBoard
XSCALE PXA255, PXA270, IXP42X
MARVEL FEROCEON CPU CORE
MIPS M4K

OpenOCD was originally developed by Dominic Rath at the University of Applied Sciences Augsburg. The OpenOCD source code is now available through the GNU General Public License (GPL).

Installing OpenOCD

Compiling OpenOCD

OpenOCD Ubuntu Package

OpenOCD Patches

OpenOCD Config Files

 

Running OpenOCD

Running OpenOCD on Linux

Running OpenOCD on Windows

OpenOCD Troubleshooting

 

External Links

OpenOCD website: http://openocd.sourceforge.net/

OpenOCD source: http://sourceforge.net/projects/openocd/files/openocd/0.7.0/openocd-0.7.0.tar.gz/download

GNU GPL (OpenOCD license): http://www.gnu.org/licenses/gpl.html

GDB Debugger

This guide was written for Ubuntu 10.04. For the windows page, see Windows GDB Debugger.

GDB, the GNU Project Debugger is a debugging tool provided with the GNU Compiler Collection (GCC). GDB allows you to stop and start a running program, examine its functioning, and make changes.

 

GDB Support in OpenOCD

The configure script provided with OpenOCD 0.5.0 already compiles OpenOCD to support the GDB debugger. The OpenOCD Ubuntu Package also includes GDB Support. If you have installed OpenOCD according to the guides on the Compiling OpenOCD page, your version of OpenOCD already supports GDB.

The -g flag tells the gcc compiler to build with GDB support. OpenOCD’s configure script already includes the -g flag.

GDB Debugger is provided by default on Ubuntu 10.04. However, this version of GDB is only built to debug programs running on a Linux PC. You will need to download or compile a version of GDB that supports embedded devices. One such GDB build is provided with the CodeSourcery ARM toolchain.

 

Installing the CodeSourcery ARM Toolchain

CodeSourcery provides development tools for use with embedded devices, including a GCC cross-compiler and a GDB build for ARM targets. Download the latest version of the .bin installer from http://www.codesourcery.com/sgpp/lite/arm/portal/release1592. Direct link is here. Save this file anywhere on your computer, then navigate to it in a terminal window.

Run the installer like this:

sh arm-2010.09-51-arm-none-eabi.bin

You should see a loading bar followed by an installer GUI. However, you may see an error stating that the installer doesn’t support the DASH shell.

Arm-none-eabi dash err.png

If you see this error, disable DASH by typing

sudo dpkg-reconfigure -plow dash

This will give you the option to enable DASH by choosing <YES> or disable it by choosing <NO>. Choose no and run the installer again.

 sh arm-2010.09-51-arm-none-eabi.bin

You should see the installer GUI now. The installer is fairly straightforward. This guide will assume that you choose the default option on each page.

Sourcery-install.png

The installer installs the CodeSourcery toolchain to your home directory. Add it to your PATH by editing your environment variables:

sudo cp /etc/environment /etc/backup_environment
sudo gedit /etc/environment

This backs up your environment file and then opens it a text editor. (The backup is just in case something goes wrong; unless you make a mistake, you can delete backup_environment later.) Find the line “Path=…” (probably the only line). Add the following to the end of that line, inside the quotes:

:~/CodeSourcery/Sourcery_G++_Lite/bin

That line should now read something like this:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:~/CodeSourcery/Sourcery_G++_Lite/bin"

Restart your computer.

Make sure everything installed correctly by running arm-none-eabi-gcc from anyhere, with no arguments. If everything installed correctly, you will see:

arm-none-eabi-gcc: no input files

 

Starting GDB

In the terminal window, run arm-none-eabi-gdb from any directory.

arm-none-eabi-gdb

Your terminal window should look like the image below, with a prompt reading (gdb) in place of the normal > command prompt.

Eabi-gdb startup.png

 

Connecting to OpenOCD

Run OpenOCD as normal, as described in Running OpenOCD on Linux. To connect to OpenOCD, start GDB as above:

arm-none-eabi-gdb

OpenOCD listens for GDB connections on port 3333. In GDB, connect to OpenOCD by typing target remote localhost:3333. (In this guide if you see (gdb) at the beginning of a command, that means enter that line into the GDB command prompt. Don’t actually type the characters (gdb).)

(gdb) target remote localhost:3333

Before doing anything else, run reset init on the target. Use the monitor command to tell GDB to send the command to OpenOCD, like this:

(gdb) monitor reset init

Monitor reset init.png

This is important. You need to do this while GDB is connected to the OpenOCD, or you won’t be able to halt or reset the target. If you don’t run monitor reset init, you will encounter errors like this:

Gdb packet err.png

 

Sending Commands to OpenOCD

You can send commands to OpenOCD through GDB just like you can through a telnet connection. Type monitor, then the command, then enter. You can see a list of common OpenOCD commands here.

Gdb openocd commands.png

You can use the Linux command cd to change the current working directory in GDB. This changes the current directory only for GDB, not for Linux; when you exit GDB, you will be back in the directory where you started.

To quit GDB, type quit.

 

.gdbinit

Instead of typing commands yourself every time you start GDB, you can create a script to always start GDB with the same series of commands. This script file is named .gdbinit. GDB looks for it in the current working directory.

You can use the script below to have GDB automatically connect to OpenOCD and run reset init on the target. Create a new folder in your home directory called GDB_OpenOCD_init, and a new text file in that folder. Copy the code below into the file:

echo Executing GDB with .gdbinit to connect to OpenOCD.\n
echo .gdbinit is a hidden file. Press Ctrl-H in the current working directory to see it.\n
# Connect to OpenOCD
target remote localhost:3333
# Reset the target and call its init script
monitor reset init
# Halt the target. The init script should halt the target, but just in case
monitor halt

Save the file as .gdbinit and close it. Like any file whose name begins with a period, .gdbinit is a hidden file. To see it, open the folder and press CTRL-H.

To test the init script, start OpenOCD as normal. Then navigate to GDB_OpenOCD_init/ and run CodeSourcery GDB.

cd ~/GDB_OpenOCD_init
arm-none-eabi-gdb

You should see something like the image below. (In this image the target device is the Beagleboard. With different hardware the output of reset init will be different.)

Gdbinit.png

 

Debugging a Program on the Beagleboard

This part of the guide will demonstrate how to run and debug a simple program on the Beagleboard. The program will only work on the Beagleboard, but the commands are the same on other target devices.

 

Installing Packages

For this section you will need the Ubuntu packages git and make. Install the following packages by opening a new terminal window and typing:

sudo apt-get install git make

You may see a message stating that these pachages are already installed. That’s fine.

 

Compiling LEDblink

Navigate to your home directory and use git to clone into https://github.com/mlu/cortal_dendrites.git.

cd ~
git clone https://github.com/mlu/cortal_dendrites.git

You should now have a folder in your home directory called cortal_dendrites/. Navigate to /home/USERNAME/cortal_dendrites/cortex_a8/standalone/LEDblink. This directory contains the source for LEDblink. Run make to compile it.

cd ~/cortal_dendrites/cortex_a8/standalone/LEDblink
make

The folder should now contain a binary file called LEDblink. It also contains a hidden file called .gdbinit. This script should start GDB and load LEDblink, but the file is outdated and no longer works. Delete it so that you can’t accidentally run it later.

rm .gdbinit

 

Loading LEDblink

Start OpenOCD as normal, then open a new terminal window. Run GDB, connect it to OpenOCD, and reset the Beagleboard. You can do this manually:

arm-none-eabi-gdb
(gdb) target remote localhost:3333
(gdb) monitor reset init

…or using the .gdbinit script you created above:

cd ~/GDB_OpenOCD_init
arm-none-eabi-gdb

Beagle usrleds.png

The USR0 and USR1 LEDs on the Beagleboard should now be off. The Beagleboard has just been reset and is halted. Tell the Beagleboard to resume to let it boot. You should see USR0 and USR1 come on.

(gdb) monitor resume

Wait for the lights to come on, and then halt the Beagleboard again.

(gdb) monitor halt

Navigate to the directory containing LEDblink and load it:

(gdb) cd ~/cortal_dendrites/cortex_a8/standalone/LEDblink
(gdb) load LEDblink
(gdb) symbol-file LEDblink

Ledblink load.png

Now run the program by typing:

(gdb) cont

You should see the USR0 and USR1 LEDs pulse on and off in sequence. LEDblink will run forever if you let it. When you’re ready to stop it, press CTRL-C in the GDB terminal. To start it again, type cont again.

 

Breakpoints

When debugging a program it’s often useful to stop it in the middle to see what it’s doing. You can do that with GDB using breakpoints. When you ran the command symbol-file LEDblink above, you loaded a file that allows GDB to map lines and functions in the source code to instructions in the executable. You can now instruct GDB to stop the program when it reaches a particular line or function.

Add a breakpoint associated with line 22 of LEDblink.c, then let LEDblink continue, like this:

(gdb) break 22
(gdb) cont

GDB will run until it hits line 22, then return you to the command prompt. Line 22 is inside a loop that never terminates, so GDB will hit this breakpoint over and over. Each time GDB hits the breakpoint, you can tell it to proceed by typing cont again.

You can have multiple breakpoints at a time. Type:

(gdb) break 30

…to create a second breakpoint at line 30. You can get a list of all breakpoints by typing:

(gdb) info breakpoints

info breakpoints lists your breakpoints by number. You can delete a breakpoint by entering delete followed by a number.

(gdb) delete 1

…deletes Breakpoint 1.

Ledblink breakpoints.png

 

Reading Memory

You can use GDB to read the value stored in a memory address with the x command. Type x followed by a memory address to output the value at that address. GDB assumes that the address is in decimal format unless you preface it with 0x to indicate hexadecimal. Memory addresses are usually expressed in hexadecimal, so remember to type 0x.

(gdb) x 0x49056090

Gdb x.png

The values at 0x49056090 and 0x49056094 control the USR0 and USR1 LEDs. The 22nd bit of each (0x00400000, in hex) controls USR0, and the 21st bit (0x00200000) controls USR1. Writing to 0x49056090 turns a light off, and writing to 0x49056094 turns a light on.
address 0x49056090 = 0x00400000: turn USR0 off

address 0x49056090 = 0x00200000: turn USR1 off

address 0x49056090 = 0x00600000: turn both LEDs off
address 0x49056094 = 0x00400000: turn USR0 on

address 0x49056094 = 0x00200000: turn USR1 on

address 0x49056094 = 0x00600000: turn both LEDs on
You can type x 0x49056090 and x 0x49056094 when LEDblink reaches a breakpoint to see what the program is doing.

 

External Links

GDB man page

Flyswatter 2

The Flyswatter2 is an high performance USB to JTAG in-circuit debugger and programmer designed for use with ARM and MIPS target devices. It uses the open source OpenOCD (Open On-Chip Debugger) software to provide debugging and in-system programming of embedded target devices.

Features

  • USB 2.0 Hi-speed device interface (480 Mbits/sec)
  • Can be used to debug and program all ARM and MIPS processors supported by OpenOCD
  • Provides a standard ARM 20-pin JTAG interface connector (Male shrouded header, 2 rows x 10 pins)
  • Adds a virtual RS232 serial port to your computer or laptop with full modem signals: TXD, RXD, RTS, CTS, DTR, DSR, DCD, RI
  • Supports target voltages of: 5.0V, 3.3V, 2.5V, 1.8V, 1.6V (voltage range: 1.6V to 5.0V)
  • No external power supply required – the Flyswatter2 gets its power from the computer’s USB port
  • Uses open source software: OpenOCD – Open On-Chip Debugger debugger software
  • Package Includes: Flyswatter2, USB Cable, 12 inch serial cable, and 8 inch 20-pin JTAG ribbon cable
  • Compact Size: 3.15 inches (width) x 2.7 inches (length) x 0.8 inches (height)

Supported Devices

OpenOCD supports the following ARM cores:

ARM CORE EXAMPLE PROCESSORS
ARM7TDMI LPC2148, AT91SAM7
ARM720T LH79520, EP7312
ARM9TDMI
ARM920T S3C2410, S3C2440
ARM922T
ARM926EJS S3C2412, STN8811, STN8815
ARM966E STR91XF
ARM11 S3C6400, OMAP2420, MSM7200
ARM1136
ARM1156
ARM1176
CORTEX-M3 LM3S series, STM32 series
CORTEX-A8 OMAP3530 BeagleBoard
CORTEX-A8 DM3730 BeagleBoard-xM
CORTEX-A9 OMAP4430 PandaBoard
XSCALE PXA255, PXA270, IXP42X
MARVEL FEROCEON CPU CORE

OpenOCD also supports the following MIPS cores (requires a ARM20MIPS14 MIPS JTAG Adapter):

MIPS CORE EXAMPLE PROCESSORS
MIPS M4K, MIPS32

JTAG Interface

The Flyswatter provides a standard ARM-compatible 20-pin JTAG interface. The JTAG interface connects to the target device with a 20-pin ribbon cable. This connection enables access to the on-chip debug module which is integrated into the ARM CPU. The debug module enables a programmer to debug the software on an embedded target system.

The second purpose of the JTAG interface is to allow the programming of NOR and NAND FLASH memory devices that are connected to or embedded within the target CPU.

JTAG Connector Pinout

Serial Port Interface

The Flyswatter2’s serial port provides you with an independent functional “USB to RS-232” serial device. The serial port is completely independent from OpenOCD on both Linux and Windows. You can use the Flyswatter2’s serial port without having to use OpenOCD or JTAG, or you can use it together with OpenOCD and have both a serial port and JTAG interface operating at the same time for debugging and communicating with your target device.

For Linux, the RS232 driver for the FT2232 is part of the main kernel tree and is provided in most standard Linux distributions. In Windows, you have to load the Windows driver for the FT2232. Once the driver is loaded, Windows will assign a virtual COM port to the Flyswatter2’s serial port. It operates just like a standard COM port. You can use the Flyswatter2’s serial port on laptops or PC’s that do not have a 9-pin legacy serial connector.

Supports all standard baud rates: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200

You can use Minicom to communicate with the Flyswatter2’s serial port on Linux. See the Minicom page for setup instructions.

Flyswatter2 How To Guides

BeagleBone Black – Linux

This guide walk a first time user through connecting the Flyswatter2 to the BeagleBone Black Board, and installing and running OpenOCD and GDB Debugger.

Olimex LPC-P2148 – Linux

Olimex LPC-P2148 – Windows

These guides walk a first time user through connecting the Flyswatter2 to the Olimex LPC-P2148 Prototype Board, and installing and running OpenOCD and GDB Debugger.

Olimex PIC-P32MX – Linux

Olimex PIC-P32MX – Windows

These guides walk a first time user through connecting the Flyswatter2 to the Olimex PIC-P32MX board, and installing and running OpenOCD and GDB Debugger.

Beagleboard – Linux

Beagleboard – Windows

These guides provide a first time user with instructions for the Beagleboard, and installing and running OpenOCD and GDB Debugger.

Beagleboard XM – Linux

Beagleboard XM – Windows

These guides provide a first time user with instructions for the TI Beagleboard XM, and installing and running OpenOCD and GDB Debugger.

Pandaboard – Linux

Pandaboard – Windows

These guides provide a first time user with instructions for the TI Pandaboard, and installing and running OpenOCD and GDB Debugger.

RouterStation Pro – Windows

These guides walk a first time user through connecting the Flyswatter2 to the Ubiquiti RouterStation Pro, and installing and running OpenOCD and GDB Debugger.

Flyswatter2 LPC2214 How To Linux

These guides walk a first time user through connecting the Flyswatter2 to the MikroElektronika LPC2214 mikroBoard, and installing and running OpenOCD, GDB Debugger and Eclipse.