mc683xx-bdm

USB background debug mode (BDM) pod for Motorola/Freescale CPU32 (683xx) parts, primarily the MC68331. Raspberry Pi Pico (RP2040) or Pico 2 (RP2350) + PIO for the serial link, 5 V level shifting, Rust firmware (Embassy) and host.

Goals:

Non-goals (for now): other BDM families (ColdFire, HCS08), real-time trace.

License: the hardware design is CERN-OHL-S-2.0 (hardware/LICENSE); firmware and documentation are GPL-3.0-only (LICENSE).


Target connector

10-pin, 2×5, 0.1” (standard CPU32 BDM):

Pin Signal Pin Signal
1 DS 2 BERR
3 GND 4 BKPT/DSCLK
5 GND 6 FREEZE
7 RESET 8 IFETCH/DSI
9 VDD 10 IPIPE/DSO

Hardware

Function Part Notes
MCU Pico (RP2040) or Pico 2 (RP2350), soldered flat by its castellated edge USB to host; same footprint and pinout; JLCPCB places a Pico (SC0915, C9900019762); a Pico 2 is fitted by hand
3.3 V → 5 V outputs 74AHCT1G125 ×2 (U1 BKPT/DSCLK, U2 DSI), VCC = target VDD 220 Ω series (R1, R2): about 20 mA if DSI and IFETCH overlap (MC68331UM Table A-1: 25 mA per pin), or into an unpowered 74AHCT1G125’s output clamp if the cable’s signals meet before its VDD (SCLS378P 5.1: ±20 mA); each its own OE
74AHCT1G125 input pull-downs 100 kΩ to GND on GP9 and GP3 (R15, R16) The inputs must not float (SCLS378P 5.3, note 1); the Pico’s own pull-downs need it powered
U1 OE pull-up, BKPT/DSCLK 1 kΩ to target VDD (R4), pulled low by Q3 (BSS138BK, gate on GP10, 100 kΩ gate pull-down) The OE edge within the 74AHCT1G125’s 20 ns/V (SCLS378P 5.3): about 8 ns/V into its 10 pF (5.5) and Q3’s 7 pF; 5 mA from VDD while Q3 is on. Output tristated while the pod is unpowered or booting, and between requests unless BKPT is held low (Firmware). Q3 keeps the target’s 5 V off every Pico pin: a GPIO on this pull-up would see 5 V, over the RP2040’s and RP2350’s 3.63 V limit unpowered (RP2040 datasheet 5.5.2.1, RP2350 14.9.1)
DSI enable gate 74AHCT1G00 (U3), VCC = target VDD Drives U2’s OE: NAND(FREEZE, DSI_EN), so DSI is driven only while FREEZE is high and the Pico enables it
DSI_EN pull-down 100 kΩ to GND DSI off while the pod is unpowered or booting
5 V → 3.3 V inputs 74LVC1G17 ×5, Schmitt trigger, VCC = 3.3 V: U4 RESET, U5 IPIPE/DSO, U6 FREEZE, U7 DS, U8 BERR One SOT-23-5 per input, each placed at its J1 pin. RESET and BERR are open drain on the target and rise as its pull-ups let them; a Schmitt input sets no transition-rate limit. 5.5 V inputs at any VCC and Ioff (SCES351Y 5.3, 5.5). IPIPE is pin 10 outside BDM, so U5 reads both. 4.6 ns max A to Y at 3.3 V (SCES351Y 5.6)
74LVC1G17 input pull-downs 100 kΩ to GND, header side (R10-R13, R17) Inputs low with the cable unplugged even at the 74LVC1G17’s worst-case 5 µA input leakage (SCES351Y 5.5); 50 µA load at 5 V
RESET drive BSS138BK (Nexperia, LCSC C282529), open-drain Target also drives RESET; sense separately. RDS(on) at most 6.5 Ω at VGS = 2.5 V, VGSth at most 1.6 V (BSS138BK datasheet, Table 7): specified below the Pico’s 3.3 V gate drive
BERR drive BSS138BK, open-drain Abort hung bus cycles
FET gate pull-downs 100 kΩ to GND RESET and BERR not asserted while the pod is unpowered or booting
VDD sense 100 kΩ / 100 kΩ divider → ADC0, 100 nF to GND 2.75 V at 5.5 V; high value to limit current into an unpowered RP2040; the capacitor holds GP26 while the ADC samples from the divider’s 50 kΩ. Halt and reset refuse below 4.5 V
BDM header 2x5 0.1” shrouded, keyed A reversed cable cannot put VDD on BERR
SWD connector, J2 JST SH 3-pin horizontal, SM03B-SRSS-TB (LCSC C160403) From the Pico’s debug pads: 1 SWCLK, 2 GND, 3 SWDIO, Raspberry Pi’s debug connector order (RP-003139-SP); the Debug Probe’s JST-SH cable plugs in. The RP2040’s internal pull-ups, no external ones
Decoupling 100 nF X7R at each IC No bulk capacitor on target VDD, so plugging in does not load the target’s supply
BKPT pull-up 10 kΩ to target VDD Target runs normally with pod unpowered

Two output enables: BKPT must be driven to request a halt while DSI stays tristated, because pin 8 is IFETCH, a CPU output, whenever FREEZE is negated (gotcha below). DSI’s is gated in hardware by FREEZE itself, so DSI goes off whatever ends background mode: GO, CALL, a reset from the target’s side, a watchdog, a raw Transfer. From FREEZE falling to DSI off is at most 20 ns: 10 ns through the 74AHCT1G00 and 10 ns for the 74AHCT1G125 to disable, both at 50 pF over temperature (SCLS316P 5.6, SCLS378P 5.6). The manuals give no bound on how soon IFETCH is driven after FREEZE negates (MC68331UM Table A-7, Figure A-14); the series resistor limits any overlap’s current.

The Pico’s DSI_EN is a PIO pin as well: the program drops it 8 PIO cycles, the whole high phase, after the last rising edge of GO’s opcode or CALL’s last word, 500 ns at 1 MHz DSCLK and 125 ns at 4 MHz (PIO program), which may beat FREEZE negating. The firmware raises it once FREEZE asserts, or once a CALL has left FREEZE high (Firmware).

Pico pins (GPn):

GP Signal Direction
2 IPIPE/DSO PIO in
3 DSI PIO out
4 DSI_EN, to the 74AHCT1G00 PIO set, high enables
5 FREEZE in, pull-down
6 DS in
7 BERR drive (Q2 gate) out, high asserts BERR
8 BERR sense in
9 BKPT/DSCLK PIO side-set and set
10 BKPT/DSCLK driver enable (Q3 gate) out, high enables
11 RESET drive (Q1 gate) out, high asserts RESET
12 RESET sense in
25 LED (on the Pico and Pico 2; the Pico W’s is on its wireless chip, unsupported) out, lit while U1 drives BKPT: don’t unplug
26 VDD sense (ADC0) analog

Board: a 4-layer carrier (JLCPCB JLC04161H-7628 stackup, ENIG) with the translators and the BDM header; the Pico is soldered on flat, placed by JLCPCB. A custom RP2040 PCB only if the carrier proves too bulky. 68 x 59 mm. In1 is solid GND; In2 is VDD left of x = 74 mm and +3V3 right of it; GND is poured on F.Cu and B.Cu too, stitched along the edge, on a 5 mm grid (stitch --grid 5 --near 2.5) and by hand. Every signal runs on F.Cu over In1; the Fast net class’s nets have no vias (hardware/fastcheck.py reports the plane under each segment). VDD reaches the sense divider (R8) on the +3V3 side in short runs on B.Cu.

Translators stay on either Pico: the RP2350’s GPIOs are “5 V-tolerant (powered) and 3.3 V-failsafe (unpowered)” (RP2350 datasheet, chapter 1 features), and the pod must sit harmlessly on a running target while unpowered.

Unpowered sides (TI datasheets in third_party/ti/):

Gotcha: pin 8 is IFETCH (an output) when the CPU is not in BDM. Keep the DSI driver tristated until FREEZE is asserted.


Protocol summary

Response bit 16 (MC68331UM Table 5-6):

Bit 16 Data Meaning
0 xxxx Valid data
0 FFFF Command complete; status OK
1 0000 Not ready; clock NOP and retry
1 0001 BERR-terminated bus cycle
1 FFFF Illegal command

Opcodes (b/w/l), CPU32RM 7.2.8.4–7.2.8.15. RSREG’s figure there (7.2.8.6) prints 0x2480, the same as WSREG’s: a misprint. 0x2580 is from Pisa’s driver documentation (References), confirmed on silicon (Bring-up checklist: RSREG ATEMP after a reset entry).

Command Opcode
RDREG/RAREG (D0–D7 = 0–7, A0–A7 = 8–F) 0x2180 \| r
WDREG/WAREG 0x2080 \| r
RSREG 0x2580 \| s
WSREG 0x2480 \| s
READ 0x1900 / 0x1940 / 0x1980
WRITE 0x1800 / 0x1840 / 0x1880
DUMP 0x1D00 / 0x1D40 / 0x1D80
FILL 0x1C00 / 0x1C40 / 0x1C80
GO 0x0C00
CALL 0x0800
RST 0x0400
NOP 0x0000

System register select codes s (CPU32RM 7.2.8.6): RPC 0, PCC 1, ATEMP 8, FAR 9, VBR A, SR B, USP C, SSP D, SFC E, DFC F.

DUMP and FILL are valid only after a READ/DUMP or WRITE/FILL; NOP pads between them without losing the address (CPU32RM 7.2.8.10, 7.2.8.11).


PIO program

.program cpu32_bdm
.side_set 1 opt              ; side-set pin = BKPT/DSCLK, idle high
.wrap_target
    pull block               ; word << 15 (left-justified)
    set x, 16
bit:
    out pins, 1     side 0 [6]   ; DSCLK low: drive DSI
    in  pins, 1                  ; sample DSO at the end of the low phase
    jmp !x last     side 1       ; DSCLK rises: target takes DSI, then shifts DSO
    jmp x-- bit            [6]   ; rest of the high phase, if a bit follows
last:
    out y, 1                 ; release flag: the OSR bit after the word
    jmp !y keep
    nop             [4]      ; DSI held to the high phase's end
    set pins, 0              ; DSI_EN low: DSI off
keep:
    push block               ; 17 bits, right-justified
.wrap

Config: out and in shift left, no autopull/autopush. out base = DSI, in base = DSO, side-set base = DSCLK, set base = DSI_EN (GP4, count 1).


Repo layout

The host Rust workspace is the repository’s root (Cargo.toml, Cargo.lock): the host crates and the shared mc683xx-bdm-proto, all in crates/, so cargo, cargo-deb and maturin all run at the root. Each crate’s directory is its short name (crates/proto is mc683xx-bdm-proto), as in mc683xx. firmware/pod-fw builds only for the Pico targets, so it is its own workspace with its own Cargo.lock, and takes mc683xx-bdm-proto by path. One pinned toolchain (rust-toolchain.toml) and one clippy.toml and rustfmt.toml, at the root, which cargo, clippy and rustfmt find from either workspace by searching upward.

mc683xx-bdm/
├── hardware/
│   ├── mc683xx-pod/      # KiCad schematic + board
│   ├── production/       # each release as ordered
│   └── ee_tooling/      # shared KiCad tooling and house style (submodule, release/0.2)
├── crates/
│   ├── proto/           # mc683xx-bdm-proto: BDM words and command sequences; USB commands; no_std
│   ├── host/            # mc683xx-bdm: Rust library + `bdm` CLI (nusb); git-version.rs, the git commit in its and pod-fw's versions
│   ├── py/              # mc683xx-bdm-py: Python bindings, `mc683xx_bdm` (PyO3, maturin, uv)
│   ├── model/           # mc683xx-bdm-model: a CPU32 in background mode at the serial word, and a board around it; no_std; test target
│   └── stand-in/        # mc683xx-bdm-stand-in: `bdm-stand-in`, a pod on a socket over the model; test aid
├── firmware/
│   └── pod-fw/          # Pico / Pico 2 firmware, embassy-rp, PIO; its own workspace
├── packaging/           # Debian changelog, udev rule
├── scripts/             # published-crates.sh (release workflow), actionlint.sh (make lint)
├── third_party/         # vendor manuals + NOTICE
├── Cargo.toml           # the host workspace
├── rust-toolchain.toml  # the toolchain, for both workspaces
├── README.md
├── PLAN.md
└── TODO.md

Firmware (Pico / Pico 2)

Embassy (embassy-rp, embassy-usb, PIO through embassy_rp::pio). A Cargo feature picks the chip: rp2040 (thumbv6m-none-eabi, the default) or rp235xa (thumbv8m.main-none-eabihf). Reasons: async USB and PIO FIFO waits without a hand-written state machine; embassy-usb vendor class; matches the async rules in AGENTS.md.

USB: vendor class, one bulk OUT and one bulk IN endpoint, 64-byte packets, one request per packet and one reply per request (mc683xx-bdm-proto’s usb). Each request but Hello carries a tag byte the reply echoes, so a host that gave up on a reply (a timeout, Ctrl-C) discards it when it comes later instead of taking it for the next request’s; Hello is untagged and fixed across versions, so a version mismatch is still reported as one. The tags also let the host keep several requests outstanding: a block read keeps up to 4 sent ahead (IN_FLIGHT, crates/host/src/pod.rs), so the pod, which reads the next request as soon as it has written a reply, starts it without waiting a USB round trip for the host; the USB transport keeps as many reads waiting, so replies complete back to back. No firmware or protocol change: the pod still answers one request at a time, in order. On a failure the host sends nothing more, and the reads already sent run anyway, their replies discarded later as stale. A block write stays one request at a time: a write sent ahead would change memory past a failed chunk. With a request always waiting and its words spun for, nothing in the serve loop need await, so it yields after each reply: the watchdog’s feeder, FREEZE’s watcher and USB are joined with it in one task, and without the yield the pod reset itself 8 s into a long block read. Each reply also carries FREEZE’s edge count (low 8 bits), so a host sees a leave and re-entry that FREEZE’s level hides. The answer to each request is mc683xx-bdm-proto’s pod, over a Board trait: the firmware’s board (board.rs) is the Pico’s pins, ADC, PIO link and timeouts, so the request rules run in host tests too. VID:PID 1209:0001, pid.codes’ shared test pair: the pod has no PID of its own, and none is applied for. Serial number string: the chip’s unique ID in uppercase hex, 16 characters, read once at boot (serial.rs): the RP2040’s flash unique ID (embassy-rp’s blocking_unique_id), the RP2350’s OTP chip ID; pico-sdk’s pico_unique_board_id convention, so picotool and lsusb -v show the same string. It is what tells two pods apart (bdm --pod usb:SERIAL). Requests:

Watchdog (watchdog.rs, mc683xx-bdm-proto’s watchdog): the chip’s hardware watchdog, 8 s on either chip, the RP2040’s longest (2^24 ticks of 1 us, counted twice: RP2040-E1). A task checks once a second and feeds it while the serve loop waits for a request, however long the host is idle, and while the request it is carrying out makes progress: a word over the link (each PIO word counts) or the request’s end. So the chip resets when the executor stops (a loop without an await, the panic handler’s loop, a hard fault) or a request goes 8 s without a link word.

The firmware’s own sizes, release builds (make size, also in CI’s summary): 32248 bytes of text on the RP2040 and 30520 on the RP2350, 2896 bytes of statics on either.

Handle not-ready retries in firmware; report BERR and illegal-command errors to the host. mc683xx-bdm-proto’s session does both, over a Link trait that the PIO state machine implements. Two sets of host tests run it: scripted word sequences from CPU32RM’s figures (mc683xx-bdm-proto), and mc683xx-bdm-model, a CPU32 in background mode that answers each word as CPU32RM 7.2.8 says, decodes opcodes independently of mc683xx-bdm-proto, and records what a real CPU would not take: clocks while running, words lost while busy, DUMP or FILL without READ or WRITE, GO or CALL without the DSI release, BERR while running. Its board can reset the target in the middle of a command and make CALL’s FREEZE fall late. It is no_std so a second Pico can run it as a stand-in target later.

Each result is collected with NOPs, so a DUMP or FILL block costs about two transfers per access. Sending the next DUMP in place of the NOP would nearly halve that; done if the throughput test asks for it.

Flash and debug: a Raspberry Pi Debug Probe on J2, the carrier’s 3-pin JST-SH SWD connector (SWCLK, GND, SWDIO, from the Pico’s debug pads), with probe-rs (cargo run in firmware/pod-fw), which supports RP2040 and RP235x; without a probe, picotool load -x over BOOTSEL.

Stack peak: cortex-m-rt’s paint-stack fills the stack with 0xCCCCCCCC at reset, and firmware/pod-fw/stack-peak reads it back over SWD (probe-rs) and reports the deepest word changed. No firmware code and no unsafe; no USB request, so the protocol is unchanged.

Host (Rust)


Bring-up checklist

How to run each item and what to expect: docs/bring-up.md.

Open questions

None.

References