picobridge

USB-to-Ethernet bridge firmware for a Pico 2 with a WIZnet W6300. On the Mac the board shows up as a USB network adapter (CDC-NCM). Every frame the Mac sends goes out the W6300 unchanged, and every frame the W6300 receives (MACRAW, unfiltered) comes back up to the Mac. That lets Ethernet-only boards such as picomap be reached from a machine that only has the Pico on USB.

It uses limen (submodule at firmware/limen), but only limen's w6300 driver. limen's dispatch loop disables interrupts around its poll, which TinyUSB can't tolerate, so picobridge runs its own polled loop: tud_task(), NCM ↔ W6300 forwarding, and a status console.

USB interfaces

Interface What it's for
CDC-NCM "picobridge Ethernet" The bridged link. macOS names it picobridge in Network settings and self-assigns a 169.254 address, which is the same link-local range picomap uses.
CDC-ACM "picobridge console" Send anything to get one line of counters back. It has no commands.
RP2 reset interface Lets picotool's -f reach a running bridge, so a board can be reflashed without pressing BOOTSEL (picotool load ... -f). picotool reboot -f --ser <serial> restarts it. (picotool reboot -u -f --ser <serial> does reach BOOTSEL, but picotool 2.3.1 then hangs; kill it, then run picotool reboot --ser <serial> with the same serial to resume.)

The NCM link always reports "connected" to the host. picobridge doesn't track the W6300's Ethernet carrier, so an unplugged cable shows up as lost traffic, not as a link-down interface. The bridge is meant for a fixed cable to its partner board.

The NCM host MAC is 02:62: followed by the last 4 bytes of the board's USB serial. For example, board 2557F63FD79AD6F6 is 02:62:d7:9a:d6:f6.

Brick safety

  • The watchdog (2 s) resets a hung loop. A reboot caused by the watchdog, or any hard fault, goes into BOOTSEL instead of rerunning the image, so a hang can't turn into a boot loop that picotool can't reach.
  • Try a new build from RAM first. A no_flash image leaves flash alone, and a normal reset brings back whatever is in flash. A watchdog reset during a RAM trial also boots flash, but if flash holds picobridge, its guard sees the watchdog marker and goes straight to BOOTSEL. Run picotool reboot --ser <serial> to get back to the flashed bridge.
  • A USB-requested BOOTSEL reboot always keeps PICOBOOT enabled. Hosts can only turn off the mass-storage drive.

Build

git submodule update --init
export PICO_SDK_PATH=~/opt/pico-sdk PATH=~/opt/arm-gnu-toolchain-15.3.rel2-darwin-arm64-arm-none-eabi/bin:$PATH
cmake -S firmware -B firmware/build -G Ninja && ninja -C firmware/build                               # flash image
cmake -S firmware -B firmware/build-ram -G Ninja -DPICOBRIDGE_NO_FLASH=ON && ninja -C firmware/build-ram  # RAM-only

picobridge builds with Pico SDK 2.3.1, and configure fails on any other release. A build directory keeps the SDK path it was configured with, so after changing SDKs, delete it and configure again.

Load

picotool load -x firmware/build-ram/picobridge.uf2 --ser <serial> -f      # run from RAM
picotool load -v -x firmware/build/picobridge.uf2 --ser <serial> -f       # write to flash

Test

bridgetest needs no root. It sends IPv6 link-local multicast UDP out one picobridge interface with multicast loopback off, so a datagram can only reach another interface by crossing the Ethernet cable.

go run ./cmd/bridgetest pairs                     # which bridges share a wire
go run ./cmd/bridgetest run -a en12 -b en13       # 1000 full-size datagrams each way

Using it with picomap

picomap's client pins its socket to the -iface interface (Darwin IP_BOUND_IF), so traffic crosses the named bridge's cable even with several bridges up. From picomap's root, with flags before the target name:

go run ./cmd/picomap info -iface en12
go run ./cmd/picomap load -iface en12 picomap

A picomap board has no USB stack. limen sends it to BOOTSEL when its watchdog fires, and picomap reboot -bootsel -iface enN does the same on request. From BOOTSEL, reload it with picotool load --ignore-partitions -v -x <uf2> --ser <serial>. limen's AGENTS.md has the full recovery table.

S
Description
No description provided
Readme
56 KiB
0 Stars 1 Watchers 0 Forks
Languages
Go 35.4%
C 27.9%
CMake 22.7%
C++ 14%