Electronics, DIY, programming and more…
Programming Bus Pirate v4 without ChipKit
After some hours of unsuccessful attempts I arrived to the conclusion that the firmware of my Bus Pirate has some bug on JTAG/SWD function. I downloaded newer firmware from https://github.com/BusPirate/Bus_Pirate/releases/tag/v7.0 and tried to burn it using pirate-loader but I was unable to communicate with the device even shorting PGC-PGD, tried lots of things until I remembered last time I programmed Bus Pirate was with my own compiled firmware and PICKit instead of using BP own bootloader, so probably I deleted accidentally the bootloader.
My only option was to program the Bus Pirate using directly the ICSP port, but my PICKit is at my home far away.
Analyzing what I have around most feasible option was FT232RL serial port adapter or an Arduino Nano, I started searching if there are any program for those devices capable of programming the PIC24FJ256GB106 on Bus Pirate v4.
|Pickle Microchip PIC ICSP||Pickle is an PICMicro in-circuit serial programmer for Linux, Windows and MACOS/X, supports PIC micros from the PIC10 to the PIC32 and can use different devices for programming like FT232RL or Raspberry Pi GPIO. |
|pictools||A PIC programmer based on an Arduino Due. Only the PIC32MM0256GPM064 family is supported.|
|Arduino as PIC18F programmer||Arduino as programmer for some PIC18F devices|
Most feasible option seems Pickle as other tools doesn’t support PIC24F devices, but I was first unsuccessful using it and I tried to adapt https://github.com/maximevince/arduino-as-pic18f-programmer code for supporting PIC24F.
I was half way on the process of deciphering DS39907A – PIC24FJXXXGA1/GB1 Families Flash Programming Specification when I decided to use GDB to debug Pickle to better understand the flow, then I noticed the command line I was using is not issuing the commands to the PIC24FJ256GB106 on the way it should be, I corrected the command line and voila the PIC responded identifying itself correctly.
One of my intentions of writing this post was to leave this information here in case somebody else gets to the same situation as Pickle documentation is not very clear about how to use it.
Using FT232RL with Pickle
First we have to create a configuration file defining we want to use FTDI device and the pin assignments, the file should be called .pickle and can be placed on the home or in the same directory where the application is launched, in my case ~/pickle-ftdi/src/.pickle, the documentation includes configurations for other devices, I have edited the recommended settings to use the pins TX/RX/DTR on the header of my FT232RL device.
# DB0 TXD => VPP (MCLR) # DB1 RXD => PGC # DB2 RTS# # DB3 CTS# # DB4 DTR# => PGD # DB5 DSR# # DB6 DCD# # DB7 RI# DEVICE=FTDI IFACE=0 BITRULES=0x1000 SLEEP=100 VPP=0 PGC=1 PGD=4 PGM=-1 # DISABLED DEBUG=0
Pickle includes a test program quite useful to verify the connections are ok, I connected the FT232RL to some leds and checked that PGC/PGD/MCLR are on the pins I defined.
#> sudo ./ptest 2 2 TEST MODE 2 [ICSP] VPP LOW (0V) (ICSP 1) [2 seconds] PGD IN: 0 VPP HIGH (12V) (ICSP 1) [2 seconds] PGD IN: 0 PGD LOW (0V) (ICSP 4) [2 seconds] PGD IN: 0 PGD HIGH (5V) (ICSP 4) [2 seconds] PGD IN: 0 PGC LOW (0V) (ICSP 5) [2 seconds] PGD IN: 0 PGC HIGH (5V) (ICSP 5) [2 seconds] PGD IN: 0 TEST DONE #> sudo ./ptest PGC 3 TEST MODE VPP|PGD|PGC|PGM PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds] PGC HIGH (ICSP 5) (D-SUB-9 RTS 7) [3 seconds] PGC LOW (ICSP 5) (D-SUB-9 RTS 7) [3 seconds] TEST DONE
Connecting FT232RL to the ICSP port
After ensuring the correct pins are used we can attach FTDI to the ICSP header on the Bus Pirate and check we can get deviceid and other information with Pickle.
#> sudo ./p24 select PIC24FJ256GB106 LVP id  [PROGRAM] 15600 WORDS [02ABFA] [CONFIG3] FFFF [02ABFC] [CONFIG2] 239E [02ABFE] [CONFIG1] 3E7F [8007F0] [APPID] FF [8007F0] [CALIB1] FFFFFF [8007F2] [CALIB2] FFFFFF [8007F4] [CALIB3] 2ED573 [8007F6] [CALIB4] 0D0071 [8007F8] [CALIB5] FF008A [8007FA] [CALIB6] FFFFFF [8007FC] [CALIB7] FFFF1B [8007FE] [CALIB8] 00F800 [FF0000] [DEVID] 1019 FAM:40 DEV:19 PIC24FJ256GB106 [FF0002] [DEVREV] 0004 MAJOR:0 DOT:4
Programming Bus Pirate bootloader
Programming with this setup very slow, so we will just program the bootloader and then program the new firmware using Bus Pirate own USB.
#> sudo ./p24 select PIC24FJ256GB106 LVP program ~/personal/BusPirate/fw/bpv4_boot4.10_opt1_18092016.hex noblank Total: 7768 3:36.42 time elapsed
Is important to verify that it was programmed correctly, the first time I programmed BusPirate did’t even was recognized as USB device, verification identified that 1600 of the 7768 words were incorrect, programming again fixed the problem.
#> sudo time ./p24 select PIC24FJ256GB106 LVP verify ~/personal/BusPirate/fw/bpv4_boot4.10_opt1_18092016.hex Total: 7768 Fail: 0 6:08.59 elapsed
Hello Bus Pirate bootloader
Now that the bootlader was programmed, we can connect Bus Pirate via USB and check if it responds, I had to connect PGC to PGD on ICSP header to be able to enter the bootloader, also point out that I have to reconnect the device to USB after hello command or it wouldn’t respond to next commands.
#> ./pirate-loader --dev=/dev/ttyACM0 --hello +++++++++++++++++++++++++++++++++++++++++++ Pirate-Loader for BP with Bootloader v4+ Loader version: 1.0.3 OS: UNKNOWN +++++++++++++++++++++++++++++++++++++++++++ Opening serial device /dev/ttyACM0...OK Configuring serial port settings...OK Sending Hello to the Bootloader...OK Bootloader version: 4,10 Device ID [f1]:PIC24FJ256GB106
Programming Bus Pirate firmware
#> ./pirate-loader --dev=/dev/ttyACM0 --hex=busPirate.X.production.hex +++++++++++++++++++++++++++++++++++++++++++ Pirate-Loader for BP with Bootloader v4+ Loader version: 1.0.3 OS: UNKNOWN +++++++++++++++++++++++++++++++++++++++++++ Parsing HEX file [busPirate.X.production.hex] Found 22576 words (67728 bytes) Opening serial device /dev/ttyACM0...OK Configuring serial port settings...OK Sending Hello to the Bootloader...OK Bootloader version: 4,10 Device ID [f1]:PIC24FJ256GB106 Erasing page 0, 0000...OK Writing page 0 row 0, 0000...OK Writing page 0 row 1, 0080...OK Writing page 0 row 2, 0100...OK Writing page 0 row 3, 0180...OK Writing page 0 row 4, 0200...OK Writing page 0 row 5, 0280...OK Writing page 0 row 6, 0300...OK Writing page 0 row 7, 0380...OK Erasing page 8, 2000...OK ..... Firmware updated successfully :)!
Now is time to program the firmware, I compiled the latest version of https://github.com/BusPirate/Bus_Pirate and sent it to the Bus Pirate, it was quite fast compared to FT232RL.
I removed the connection between PGC/PGD and reconnected the Bus Pirate to the USB, entered on the serial console and that’s it, it has the new version.
#> picocom /dev/ttyACM0 --b 115200 HiZ>i Bus Pirate v4 Community Firmware v7.1 - goo.gl/gCzQnW [HiZ 1-WIRE UART I2C SPI 2WIRE 3WIRE KEYB PIC DIO] DEVID:0x1019 REVID:0x0004 (24FJ256GB106 UNK) http://dangerousprototypes.com
Next is to check if OpenOCD is now able to use Bus Pirate, but lets leave this for other post.