The Bus Pirate

September 17, 2016

I bought one of these (version 3.6) from Seeed Studio some time ago, figuring that it would be useful someday and that I would be glad to have it on hand.

I am beginning to work with a "STM32F103C8T6 ARM STM32 Minimum System Development Board" and one approach to using the SWD port is to use a bus pirate, so away I go.

I will note right up front that after all of what follows, I abandoned this approach, purchased some inexpensive ST-Link V2 devices, and have found that they work perfectly, are easy to use, and cheap, so there is no point in all this.

My unit has an FTDI FT232RL usb to serial chip and a PIC24FJ64GA. The only other large chip is an HC4066 (this is a "quad bilateral switch" and is used as a level shifter and buffer for 4 signals: cs, clock, mosi, miso).

The PIC is a 16 bit processsor with 64K of flash and 8K of ram. It has a 16 channel 10 bit ADC, sampling up to 500K/s. The processor can run at 8 Mhz and perhaps as fast as 32 Mhz.

There are 4 status LED: Power, USB, Mode, and Vreg.

The outside world connector has 10 pins:

Gnd
+5
Vpu
Clk
CS
3v3
ADC
Aux
Mosi
Miso
There is also a row on 5 pins (unpopulated) at the bottom of the board labelled ICSP. This is for reprogramming the PIC and they say you should never need to use it.
MLCR*
+3v3
Gnd
Pgd
Pgc

Fire it up!

Plugged into my linux system, the FTDI chip gets detected without any special effort and gets set up as /dev/ttyUSB1. Using picocom at 115200 baud, it gives me a prompt "HiZ>". Typing "?" gives a help screen. Doing a reset gives:
Bus Pirate v3b
Firmware v5.10 (r559)  Bootloader v4.4
DEVID:0x0447 REVID:0x3046 (24FJ64GA002 B8)
http://dangerousprototypes.com

Upgrade it

The 5.10 firmware in my unit will not support OpenOCD, which is the first thing I am hoping it will do. So, I need to upgrade the firmware. The current stable firmware is 6.1, which does support JTAG via OpenOCD. The point out that it will be slow and that only binary JTAG (not JTAG serial mode) is supported. I downloaded BusPirate.package.v6.1.zip, unzipped it, and went into directory "BPv3-firmware".

Amazingly, there is alternate firware to turn the Bus Pirate into a "STK500 v2 clone", which is something you may have heard of if you have fooled around with AVR controllers. Amazing, good to know about, but not the droids we are looking for at this point.

To do the firmware upgrade, you need to get the Pirate running its boot loader (the easiest way seems to be typing "$" to the pirate prompt). Then you pick your hex file and run the "pirate-loader" program. The supply compiled executables (including one for linux) as well as source code in case you need to recompile the loader. They think of everything.

./pirate-loader_lnx --dev=/dev/ttyUSB1 --hex=BPv3-frimware-v6.1.hex
Note the misspelling of "frimware", that is really the name of the file ....

So, I get brave and do it. First I run picocom to type the "$" and get the boot loader going (I have to answer a "are you sure" question). Then I exit picocom and type the command above. There is lots of reassuring chatter about pages being erased and written, then it tells me that the installation was successful. I disconnect/reconnect the USB cable, and fire up picocom and it tells me:

Bus Pirate v3.5
Firmware v6.1 r1676  Bootloader v4.4
DEVID:0x0447 REVID:0x3046 (24FJ64GA002 B8)
This seems to have worked!

Power Supplies

The Pirate has 3 voltage regulators. One supplies power (presumably 3.3 volts) for the onboard circuits. The other two supply power to the off board connector (3.3 and 5 volts) and can be switched on and off under software control (use the w/W command when not in HiZ mode). They both get turned on together, and when they are on, the "Vreg" LED comes on.

The Cable

The sad story here is that there are different cable variants, and you need to be really careful to know what your cable is doing. My cable came from Seeed studio (and I ordered it with the Pirate). Apparently Sparkfun did everything in reverse, but then later changed back (or something like that). These notes are for my cable.

The colors refer to the wire in the cable, ignore the color of the probe/clip. Also note that the colors (as in all ribbon cables) follow the resistor color code.

  1. Brown - Ground
  2. Red - 3.3 volts
  3. Orange - 5.0 volts
  4. Yellow - ADC
  5. Green - Vpu
  6. Blue - Aux
  7. Purple - Clk
  8. Grey - Mosi
  9. White - CS
  10. Black - Miso

SWD port on my STM32F103 board

The following post discusses using the Bus Pirate in lieu of ST-LINK along with OpenOCD (and a pending patch) to talk to the SWD port. Sounds like just what I am looking for (and/or buy a cheap clone ST-Link). The SWD port is sort of a poor man's JTAG.

The SWD port is a 4 pin header with:

Gnd
Dclk
Dio
3.3

Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org