Please note that User Registration has been temporarily disabled due to a recent increase in automated registrations. If anyone needs an account, please request one here: RequestAccount. Thanks for your patience!--Wmat (talk)
Please email User:Wmat if you experience any issues with the Request Account form.

Flyswatter2 PIC32MX How To

From eLinux.org
Revision as of 02:34, 18 April 2012 by Wmat (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This guide will walk you through connecting the Flyswatter2 and the Olimex PIC-P32MX board to your Linux PC, and installing and running OpenOCD. This guide was written with Ubuntu 10.04.


Connecting the Flyswatter2 and the Olimex Development Board

To hook up the Flyswatter2 and the PIC-P32MX board, you will need:


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 JTAG cable to the PIC-P32MX.

Fs2 pic32mx jtagcable.png
The PIC-32MX has a 10-pin and a 14-pin port. Connect the ribbon cable to the 14-pin port, the one closest to the printed word "Olimex." If your cable doesn't have a notch to force it into the correct position, be sure to align Pin 1 as shown in the picture.


Connect the RS232 Serial Cable.

Fs2 pic32mx connected.png
Plug the serial cable into the Flyswatter2 and the Olimex board's RS232 ports. Tighten the screws on either side of the cable heads to hold the connections in place.


Connect the USB cable to the Flyswatter2.

Fs2 pic32mx usb.png
Connect the Male B head of the USB cable to the Flyswatter2. The Male B head is the squarish head, not the flat one.


Plug the 9V power adapter into a wall outlet.

9vdc.png 9vdc walloutlet.png

Plug the power adapter into the PIC-P32MX.

Fs2 pic32mx 9vpowered.png
There are two LEDs next to the board's power adapter. You should see the red one light up.


Connect the USB cable to your PC.

You should see a green LED light up on the Flyswatter2.


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 2 support.

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


Compiling OpenOCD Linux - This set of instructions uses libFTDI, an open-source driver library for FTDI devices.

Compiling OpenOCD Linux D2XX - This set of instructions uses FTDXX, a closed-source driver library from Future Technology Devices International.


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 board/olimex_pic32mx.cfg

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 board/olimex_pic32mx.cfg

For general information on running OpenOCD, see Running OpenOCD on Linux. When you start OpenOCD, you should see this: Openocd fs3 pic32mx.png

Telnet Connection

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

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 PIC-P32MX. The output of the Reset command should look like this:

Pic32mx reset.png

halt

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

Pic32mx halt.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 PIC-P32MX 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 PIC-P32MX's registers.

Pic32mx reg.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.

Pic32mx reg0.png

If you run reg while the PIC-P32MX 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:

Pic32mx reg0 nothalted.png

Note that unlike with some other boards, OpenOCD provides no warning that the device is not halted. Be careful.


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 PIC-P32MX 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.

Pic32mx regset.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. GDB is installed on Ubuntu 10.04 by default, but you will need a different version of GDB build for embedded targets. Follow the instructions on the GDB Debugger page below.

GDB Debugger

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