# Build your own with a Pico 2

Build a bench link from a Raspberry Pi Pico 2 on a breadboard, wire it to a Dabao and load the firmware.

This page is for people who want to build their own bench link instead of using the [board](/wiki/hardware).

## What you get

A Raspberry Pi Pico 2 next to the Dabao bridges its console UART to the host and drives its `RUN`, `PC13` (PROG) and `ON` pins. The same [`benchlink` command](/wiki/commands) drives it.

## Parts

- A Raspberry Pi Pico 2 or Pico 2 W, with headers.
- Four 1 kΩ resistors, two 10 kΩ, one 100 kΩ.
- One small logic-level N-channel MOSFET (a BSS138 or similar).
- A breadboard, seven jumper wires, and a second USB cable for the Pico.

## Wiring

| Pico | Through | Dabao |
|---|---|---|
| GP4 (pin 6), UART1 TX | 1 kΩ | `PB13`, pin 16 (console RX) |
| GP5 (pin 7), UART1 RX | 1 kΩ | `PB14`, pin 15 (console TX) |
| GP6 (pin 9) | 1 kΩ | `RUN`, pin 30 |
| GP7 (pin 10) | 1 kΩ | `PC13`, pin 1 |
| GP8 (pin 11) | to the MOSFET's gate; 100 kΩ from the gate to GND | the MOSFET's drain to `ON`, pin 37; its source to GND |
| GP26 (pin 31), ADC0 | the middle of two 10 kΩ in series from `3V3`, pin 36, to GND | |
| GND (pin 8) | | GND, pin 13 |

```
Pico 2                                              Dabao
GP4  UART1 TX ──── 1 kΩ ─────────────────────────── PB13  (16)  console RX
GP5  UART1 RX ──── 1 kΩ ─────────────────────────── PB14  (15)  console TX
GP6  ───────────── 1 kΩ ─────────────────────────── RUN   (30)  reset
GP7  ───────────── 1 kΩ ─────────────────────────── PC13  (1)   PROG
GP8  ──┬────────── gate ┐
       └─ 100 kΩ ─ GND  N-MOSFET  drain ─────────── ON    (37)  regulators
                   GND ─ source
GP26 ADC0 ────────────┬── 10 kΩ ─────────────────── 3V3   (36)
                      └── 10 kΩ ── GND
GND ─────────────────────────────────────────────── GND   (13)
```

The Dabao's pins are numbered 1 to 16 and 25 to 40, as on a Pico with the lower eight positions missing. Check the wiring against the Dabao's silkscreen and its [pin table](https://github.com/baochip/dabao/blob/main/docs/pinout/pins.csv) before powering anything.

The Dabao keeps its own USB cable for power, the `BAOCHIP` volume in `boot1` and the application's USB link. Once that cable carries data, `boot1` moves its console to the Dabao's own USB serial port. With the cable in a charger, which carries no data, `boot1` keeps its console on the UART, and images go through it with `benchlink flash --uart`.

## Why each part is there

**The link never drives a Dabao that has no power.** A pin driven high into an unpowered chip feeds it through the pad. GP6 and GP7 only pull low or float. GP4 floats while the Dabao's 3.3 V rail, read on GP26, is below 2,500 mV. Without the divider on GP26 the console is read-only.

**The 1 kΩ resistors limit current** if the firmware is wrong, if the Pico holds a line low while `boot1` drives `PC13` high, or if a wire lands one pin off.

**`RUN` and `PC13` are open-drain.** The Dabao pulls `RUN` up with 10 kΩ, so through 1 kΩ the pin goes down to about 0.3 V. Released, both lines float. The Dabao's own buttons keep working.

**`ON` goes through a MOSFET** because the Dabao pulls that pin up to `VSYS`, which is above 3.3 V. GP8 high turns the MOSFET on and the regulators off. The 100 kΩ keeps the MOSFET off while the Pico is unpowered or starting, so the Dabao runs normally then.

**The divider on GP26** halves the Dabao's 3.3 V rail for the ADC. `benchlink status` reports it as `target`. The Dabao counts as powered from 2,500 mV up.

**Nothing else shares `PB13` and `PB14`.** `boot1`'s console takes commands on `PB13` with no authentication, destructive ones included.

## Optional: one cable

One more wire, from the Pico's `VSYS` (pin 39) to the Dabao's `VSYS` (pin 39), powers the Dabao from the Pico's USB cable. That cable is then the only one. The Dabao's USB carries nothing, so `boot1`'s console stays on the UART and images go through it with `benchlink flash --uart`.

Cautions:

- **`VSYS` to `VSYS`, not `VBUS`.** Each board has a Schottky diode from its `VBUS` to its `VSYS`. If the Dabao's own cable is plugged in as well, neither USB port can feed the other.
- **Not the `3V3` pin.** `VSYS` is close to 5 V. On the Dabao's `3V3`, three pins away, it lands on the chip's supply rail. Place the wire with both boards unplugged and read the silkscreen at both ends.
- **The ground wire now carries the Dabao's supply current.** A ground wire with poor contact can stop the Dabao from starting and make `benchlink status` show an unsteady rail above 3.3 V. Seat both ends. If `status` does not show a steady 3.3 V a moment after plugging in, unplug. A second ground wire between the two boards' pins 38, next to the power wire, does no harm.
- **No current limit.** The wire connects the Pico's `VSYS` straight to the Dabao. Nothing limits or measures the current.

The two boards start together. The Pico's firmware is up a moment after the Dabao's `boot0`, so the first lines of that first boot are not captured. `benchlink reset` gives a whole log.

## Building and loading the firmware

The build needs Rust with the `riscv32imac-unknown-none-elf` target, and Raspberry Pi's [`picotool`](https://github.com/raspberrypi/picotool) for the UF2 file. Get them in one of two ways:

- With [Nix](https://nixos.org/) and [direnv](https://direnv.net/), run `direnv allow` once in the repository. The dev shell from `flake.nix` has Rust with the RISC-V target, `just` and `picotool`. Without direnv, `nix develop` opens the same shell.
- Without Nix, install Rust from [rustup](https://rustup.rs/). The repository's `rust-toolchain.toml` asks it for the toolchain and the target. Install `picotool` yourself. `just` is optional.

```sh
just fw
```

This builds `target/riscv32imac-unknown-none-elf/release/benchlink-fw` and writes `target/benchlink-fw.uf2`. Without `just`, run the two commands behind it:

```sh
cargo build -p benchlink-fw --target riscv32imac-unknown-none-elf --release
picotool uf2 convert -t elf target/riscv32imac-unknown-none-elf/release/benchlink-fw -t uf2 target/benchlink-fw.uf2
```

To load it:

1. Use a Pico 2 whose flash holds no partition table: a new one, or one erased with `picotool erase`.
2. Hold BOOTSEL while plugging the Pico in. It shows up as a volume named `RP2350`.
3. Copy `target/benchlink-fw.uf2` onto that volume. The Pico restarts into the firmware by itself.

To load a newer build, do the same again. The firmware has no command that returns to BOOTSEL.

The firmware starts with the three lines released. A Pico that is unplugged or in BOOTSEL leaves them released, so a bench link that is not running does not disturb the Dabao.

Install the host tool and check the link:

```sh
just install        # without just: cargo install --path apps/benchlink
benchlink status
```

More in [/wiki/firmware](/wiki/firmware) and [/wiki/getting-started](/wiki/getting-started).

## Differences from the board

| | Pico 2 build | Board |
|---|---|---|
| Cables | two, or one with the `VSYS` wire | one |
| Power to the Dabao | optional wire, no limit, no switch | current-limited feed, switched by the firmware |
| Current and voltage monitor | none | INA228 on the feed |
| Voltage readings | the Dabao's 3.3 V rail | the Dabao's 3.3 V rail, its pin 40, the board's `VBUS` |
| Fault indication | none | `FLT` LED and a fault line |
| Status LEDs | the Pico's own | `PWR`, `ACT`, `D3V3`, `FLT`, `USR` |
| Marker inputs | none | `M1`, `M2` |
| Dabao mount | jumper wires | solderless site: spring probes or sockets |
| Breakouts | none | every Dabao pin on two rows |
| I2C connector | none | JST SH with switchable pull-ups |
| Console line into the Dabao | driven directly through 1 kΩ | through an inverter powered from the Dabao |
| `RUN` and `PC13` | pulled low by the Pico pin | pulled low by a MOSFET |
| Board revision pins | read 111 | read 011 |

The board drives GP4, GP6 and GP7 with the opposite polarity to the Pico 2 build. Its revision pins (GP11, GP15, GP24) tell the two apart.