Dreg
October 28, 2026, 12:38pm
1
I opened a PR that adds a binmode to the Bus Pirate 5/6/7 firmware to unbrick a Bus Pirate v3. It writes the v3’s bootloader v4.5 through its ICSP header:
main ← bp3unbrick-binmode
opened 12:36PM - 28 Oct 26 UTC
A Bus Pirate v3 with a blank or broken flash can't load firmware over USB, and u… ntil now it needed a PICkit to get its bootloader back. This binmode writes the bootloader v4.5 to the PIC24FJ64GA002 of a Bus Pirate v3 through its ICSP header. After that, buzzloader loads the firmware over the v3's own USB port as usual.
## Wiring
| Bus Pirate v3 JP2 | Signal | Bus Pirate 5/6/7 |
|---|---|---|
| 1 | PGC | IO7 |
| 2 | PGD | IO6 |
| 3 | GND | GND |
| 4 | 3V3 | VOUT, or not connected |
| 5 | MCLR | IO5 |
The Bus Pirate v3 runs from its own USB cable.
## What it does
Run `binmode` and pick "Bus Pirate v3 unbrick: bootloader v4.5 (ICSP)". It does the job once and then gives the binary port back to the default binmode.
1. It checks that IO5-IO7 are free and that the v3 pulls MCLR up, then sets VOUT: the power supply at 3.3 V and 50 mA, or the v3's own 3.3 V when pin 4 is wired to VOUT. The three lines must follow, the PIC must echo through VISI and DEVID must be 0x0447.
2. It asks before erasing. It erases user memory only, so the FRC calibration in executive memory is never touched, writes the 6 rows of the bootloader and verifies all 22016 words. A failed attempt is retried at half and a quarter of the PGC speed. After a failure that follows the erase, the v3 stays in reset while you decide whether to try again.
3. It can hold the v3 in its bootloader, with PGC low as the PGC-PGD jumper does, while buzzloader loads the firmware. Any key or the button releases it.
## Code
- `pirate/pic24_icsp.c`: plain ICSP (DS39768) on the bio_* functions: entry, SIX, REGOUT, packed table reads, chip erase of user memory and row writes.
- `binmode/bp3unbrick.c`: the binmode. It uses psucmd_enable, pullups_disable, amux_sweep, the pin labels, the bp_cmd prompts and the terminal progress bar, and runs from the setup message hook, so never at boot.
- `binmode/bp3unbrick_bootloader.h`: the bootloader as data. Its source, ds30 Loader, is GPL and lives in `lib/ds30loader`. It is documented in `docs/licenses.md`, with the license text in `docs/third_party_licenses`.
## Testing
Bus Pirate 6 and Bus Pirate v3.5 (PIC24FJ64GA002 rev B8), with a logic analyzer on the ICSP lines:
- The decoded traffic shows one chip erase of user memory and the 6 row writes, equal to the .hex file and each written once. PGC phases are 590 ns at least, and PGD never changes while PGC is high.
- 25 complete runs, binmode then buzzloader. The v3 answered with its firmware after each one.
- Also checked: cancel, the power supply already at 3.3 V or at 5 V, pull-ups on, an aux pin and a PWM pin on the lines, VOUT wired to the v3, the v3 unplugged (no edge on the lines, and "Try again?" carries on once it is plugged in), the button, and two test builds, one with PGC and PGD swapped and one whose verify always fails.
- bus_pirate5_rev8, bus_pirate5_rev10, bus_pirate5_xl and bus_pirate6 build. I only had a Bus Pirate 6 to try it on.
## Found on the way, not changed here
- `psucmd_enable()` sets `system_config.pin_changed = 0xff`, which drops pending label changes and leaves out IO7.
- `lcd_irq_enable()` adds a repeating timer without cancelling the running one, so `BP_ICM_FORCE_LCD_UPDATE` alone leaks a timer. The binmode sends `BP_ICM_DISABLE_LCD_UPDATES` first, as display/default.c does.
- `psu_measure_vout()` and `psu_measure_vreg()` pass an ADC reading to `hw_adc_to_volts_x2()`, which uses it as an index into `hw_adc_raw[]`.
- `binmode_setup()` leaves `i_override` uninitialized when `psu_en_current` is not 0.
If a v3 lost its bootloader, or you replaced its PIC24FJ64GA002 with a blank one, you used to need a separate programmer like a PICkit to bring it back. Now the Bus Pirate you already have does it, with four wires:
v3 JP2
BP5/6/7
1 PGC
IO7
2 PGD
IO6
3 GND
GND
5 MCLR
IO5
Pin 4 (3V3) can go to VOUT, but it’s optional. Run binmode, pick “Bus Pirate v3 unbrick” and confirm. About 10 seconds later the bootloader is written and the whole flash verified. It can then hold the v3 in bootloader mode, as the PGC-PGD jumper does, so you can load the firmware with pirate-loader right away.
I really like that a modern Bus Pirate can fix an old one. There are still lots of v3s out there, and a lost bootloader or a swapped PIC shouldn’t be the end of them.
I tested it on a Bus Pirate 6 and a v3.5, with a logic analyzer on the lines and 25 full runs. It also builds for the BP5,
3 Likes
ian
October 31, 2026, 8:36am
3
This is killer, however there is GPL code in there and it isn’t compatible with our MIT license codebase.
Is it the ds30 loader code? If there’s a description of the spec then do a clean room rewrite?
1 Like
Dreg
October 31, 2026, 12:17pm
4
Good idea. Almost all the code is from my MIT bp3unbricker project but the ds30 loader is GPL, I’m going to make a compatible MIT loader to see if I can pull it off, I’ll comment updates on this post.
Unbrick a Bus Pirate v3 with a Raspberry Pi Pico or Pico 2: writes bootloader + firmware to its PIC24FJ64GA002 over ICSP, every word verified. No PICkit, no MPLAB. Also programs any .hex from a computer.
1 Like
Dreg
October 31, 2026, 1:20pm
5
I just made short 5 cm Dupont cables for the Saleae. No housing. Heat shrink on every wire.
Setup ready to dev!
2 Likes
Dreg
November 1, 2026, 6:17am
6
The Bus Pirate v3 unbrick binmode is ready to merge.
The GPL code is gone. The binmode now writes bp3mitloader, a new MIT bootloader for the Bus Pirate v3 that shares no code with ds30 Loader:
MIT serial bootloader for the Bus Pirate v3 (PIC24FJ64GA002). Works like bootloader v4.5 with pirate-loader and buzzloader, in the same flash page. Includes buzzloader for Windows, Linux and macOS, and buzzloader.py.
It uses the same protocol as bootloader v4.5 and sits in the same flash page, so nothing changes for users. pirate-loader, buzzloader and the v5.x, v6.x and v7.x firmware work with it as they are, and the firmware shows “Bootloader v4.6”. With no firmware it waits in the bootloader by itself. An upload cut halfway leaves it waiting too, so you don’t need the jumper to try again.
Firmware PR:
main ← bp3unbrick-binmode
opened 12:36PM - 28 Oct 26 UTC
A Bus Pirate v3 with a blank or broken flash can't load firmware over USB. Until… now getting its bootloader back took a PICkit, or a Raspberry Pi Pico with bp3unbricker (https://github.com/therealdreg/bp3unbricker/). This binmode writes a bootloader to the PIC24FJ64GA002 of a Bus Pirate v3 through its ICSP header. Then pirate-loader loads the firmware over the v3's own USB port, as usual.
The bootloader is bp3mitloader v4.6, MIT: https://github.com/therealdreg/bp3mitloader. pirate-loader and buzzloader use it like bootloader v4.5, and it sits in the same flash page, so any firmware that fits with v4.5 fits. It replaces the GPL ds30 bootloader v4.5 that the first version of this PR carried. Its repo also has buzzloader for Windows, Linux and macOS, and buzzloader.py.
The docs are in DangerousPrototypes/BusPirate-docs-hugo#11.
## Wiring
| Bus Pirate v3 JP2 | Signal | Bus Pirate 5/6/7 |
|---|---|---|
| 1 | PGC | IO7 |
| 2 | PGD | IO6 |
| 3 | GND | GND |
| 4 | 3V3 | VOUT, or not connected |
| 5 | MCLR | IO5 |
The Bus Pirate v3 runs from its own USB cable.
## What it does
Run `binmode` and pick "Bus Pirate v3 unbrick: bootloader v4.6 (ICSP)". It does the job once, then gives the binary port back to the default binmode.
1. It checks that IO5-IO7 are free and that the v3 pulls MCLR up. Then it sets VOUT: the power supply at 3.3 V and 50 mA, or the v3's own 3.3 V when pin 4 is wired to VOUT. The three lines must follow, the PIC must echo through VISI, and DEVID must be 0x0447.
2. It asks before erasing. It erases user memory only, so the FRC calibration in executive memory stays. It writes the 8 rows of the bootloader and verifies all 22016 words. A failed attempt is retried at half and a quarter of the PGC speed. After a failure that follows the erase, the v3 stays in reset while you decide whether to try again.
3. With no firmware the v3 waits in its bootloader by itself. The binmode can also hold it there with PGC low, as the PGC-PGD jumper does, while pirate-loader loads the firmware. Any key or the button releases it.
## Code
- `pirate/pic24_icsp.c`: plain ICSP (DS39768) on the bio_* functions: entry, SIX, REGOUT, packed table reads, chip erase of user memory and row writes.
- `binmode/bp3unbrick.c`: the binmode. It uses psucmd_enable, pullups_disable, amux_sweep, the pin labels, the bp_cmd prompts and the terminal progress bar. It runs from the setup message hook, so never at boot.
- `binmode/bp3unbrick_bootloader.h`: the bootloader as data, generated from bp3mitloader.hex, with its copyright and license.
## Testing
Bus Pirate 6 and Bus Pirate v3.5 (PIC24FJ64GA002 rev B8), on Windows 11 and on native Linux (Ubuntu 26.04):
- With a logic analyzer on the ICSP lines, the decoded traffic shows one chip erase of user memory and the 8 row writes, equal to bp3mitloader.hex, each written once. PGC phases are 600 ns at least, and PGD never changes while PGC is high.
- 72 complete runs, 37 on Windows and 35 on Linux: binmode, then pirate-loader or buzzloader, with and without the hold. The v3 answered with its firmware after each one.
- The checks of the first version ran again on this build: cancel, the power supply already at 3.3 V or 5 V, pull-ups on, an aux pin and a PWM pin on the lines, and the write without and with the hold. With no firmware the v3 waits in its bootloader. On Linux the checks by hand too: the v3 unplugged, the button, and VOUT wired to the v3.
- The two fault builds were not run again: only the bootloader data and its texts changed in the binmode.
- bus_pirate5_rev8, bus_pirate5_rev10, bus_pirate5_xl and bus_pirate6 build.
The tests of the bootloader itself are in its README.
## Found on the way, not changed here
- `psucmd_enable()` sets `system_config.pin_changed = 0xff`, which drops pending label changes and leaves out IO7.
- `lcd_irq_enable()` adds a repeating timer without cancelling the running one, so `BP_ICM_FORCE_LCD_UPDATE` alone leaks a timer. The binmode sends `BP_ICM_DISABLE_LCD_UPDATES` first, as display/default.c does.
- `psu_measure_vout()` and `psu_measure_vreg()` pass an ADC reading to `hw_adc_to_volts_x2()`, which uses it as an index into `hw_adc_raw[]`.
- `binmode_setup()` leaves `i_override` uninitialized when `psu_en_current` is not 0.
Docs PR, a new page with asciinema casts:
main ← bp3unbrick-binmode
opened 01:17PM - 28 Oct 26 UTC
Docs for the "Bus Pirate v3 unbrick: bootloader v4.6 (ICSP)" binmode. The code i… s in DangerousPrototypes/BusPirate5-firmware#313. The bootloader is bp3mitloader v4.6, MIT: https://github.com/therealdreg/bp3mitloader
- New page in Software Support, next to AVRDUDE and Flashrom: wiring to the ICSP header JP2, the terminal session, loading the firmware with pirate-loader, and the errors.
- Two asciinema casts, recorded on a Bus Pirate 6 with a Bus Pirate v3: the whole session, with pirate-loader loading the firmware during the hold, and an error. The term blocks come from those casts, and the pirate-loader output from a real run.
- The command reference lists the binmode under Software support and links the page.
- The binmode menu screen in the command reference shows the current list of modes, with this one as 8.
The bp3mitloader repo also has buzzloader for Windows, Linux and macOS, and buzzloader.py, the same loader in Python for any system. Without a Bus Pirate 5/6/7, bp3unbricker does the job with a Raspberry Pi Pico:
Unbrick a Bus Pirate v3 with a Raspberry Pi Pico or Pico 2: writes bootloader + firmware to its PIC24FJ64GA002 over ICSP, every word verified. No PICkit, no MPLAB. Also programs any .hex from a computer.
Tested on a Bus Pirate 6 with a Bus Pirate v3.5, on Windows 11 and on native Ubuntu 26.04:
70 uploads of random data over the whole firmware area, read back word by word: no word different
11000 malformed, cut and random packets: every answer was the expected one
72 full rounds of binmode plus pirate-loader or buzzloader
v5.10, v6.1, v6.2, v6.3 and v7.1.12 loaded with both loaders
uploads stopped halfway, a USB cable pulled during an upload, a real PGC-PGD jumper, replugs
the ICSP traffic decoded with a logic analyzer: one erase and the 8 rows, each written once
all four firmware targets build, and the CI passes
@ian both PRs can be merged when you have time.
3 Likes
ian
November 1, 2026, 8:30am
7
Wow, good feature updates. I like the resilience to being cut half way through.
1 Like