An SWD multiplexer lets one J-Link reach several target boards without moving a cable: put one 74HC4051 analog mux on each SWD signal (VTref, SWDIO, SWCLK, nReset) and drive their shared select pins from an FT232H. On my bench this switches between boards in about 1 second from a Linux shell, and SWD stays reliable up to 3.5 MHz through the mux, so I run it at 2 MHz.
This guide covers the wiring and truth table, a small Python control script built on pyftdi, the FT232H gotcha that breaks one-shot scripts, stable device names with udev, and the switch times and SWD speed limits I measured on October 23, 2026. Written October 24, 2026; commands were checked against the official SEGGER, pyftdi, NXP, SparkFun, FTDI and systemd documentation on that date.
Why build an SWD multiplexer for one J-Link?
My bench has one SEGGER J-Link Ultra and several Arm Cortex-M target boards. The design scales to eight boards: each 74HC4051 has eight channels (Y0–Y7), and the three select lines already encode eight values. For now I wired only four channels as a temporary build, and this initial bring-up covers two of them, so every measurement in this post comes from those two boards. Each board also has its own CAN adapter and UART adapter. Everything is controlled from a Linux PC over SSH, and sometimes from a Claude Code session I drive from my phone (the headless setup is similar to running Claude Code with n8n).
Re-plugging the 10-pin SWD cable by hand does not work when nobody is at the bench. Buying four probes costs more and still leaves you picking the right probe for each board. A mux in front of a single probe keeps one tool, one license, one serial number in your scripts, and makes "which board am I talking to?" a software command.
| Option | Cost | Remote switching | Catch |
|---|---|---|---|
| Re-plug the cable | none | no | needs a person |
| One probe per board | 4 probes | yes | select each probe by serial |
| One probe + SWD mux | 4 × 74HC4051 + FT232H | yes | lower SWD ceiling, switch delay |
Parts list for the SWD mux
- 1 × SEGGER J-Link (mine is a J-Link Ultra; it is a USB device only, with no tty)
- 4 × SparkFun 74HC4051 8-channel multiplexer breakout boards (BOB-13906), one per signal, powered from 5 V
- 1 × Adafruit FT232H breakout (product 2264) to drive the select lines from USB
- Per target board: a CANable 2.0 (slcan firmware, CAN at 250 kbit/s) and a CP2102 USB-UART (230400 baud)
- A powered USB hub for the adapters
- Common ground between the J-Link, the FT232H, the muxes and every board
Only two boards are installed right now. Channels 3 and 4 are wired and waiting.
74HC4051 wiring and truth table
Each 74HC4051 has one common pin (Z), eight channel pins (Y0–Y7), three address pins (S0–S2) and an active-low enable (E). I use one mux per signal:
- J-Link pin → mux common pin Z
- Mux Y0, Y1, Y2, Y3 → target boards 1 to 4 (Y4–Y7 reserved for boards 5 to 8)
- FT232H ADBUS D4 → S0, D5 → S1, D6 → S2, D7 → E
Only Y0–Y3 are wired today; Y4–Y7 are free for boards 5 to 8 later, with no change to the select logic. The same S0/S1/S2/E bus goes to all four muxes, so VTref, SWDIO, SWCLK and nReset always move to the same board together. Driving E high turns every channel off, which gives a clean "nothing connected" state.
Eight is not a hard limit either. Combining more demux banks should take it further: build a second bank of four 74HC4051s (one per signal), tie its Z pins to the same J-Link lines in parallel with the first bank, share S0–S2, and give each bank its own enable line from a spare FT232H GPIO pin (D0–D3 on the same ADBUS port are still free in my build). Keeping exactly one bank's E low gives 8 boards per bank, so two banks reach 16. A two-level tree, where a first mux picks the bank and a second picks the board, is another option. I have not built either yet. Each extra switch in the path adds capacitance and on-resistance, so expect the SWD ceiling to drop and measure it again before choosing a speed.
| Command | E (D7) | S2 S1 S0 | Connected |
|---|---|---|---|
| off | 1 | x x x | nothing |
| 1 | 0 | 0 0 0 | Y0 → board 1 |
| 2 | 0 | 0 0 1 | Y1 → board 2 |
| 3 | 0 | 0 1 0 | Y2 → board 3 |
| 4 | 0 | 0 1 1 | Y3 → board 4 |
| — | 0 | 1 0 0 | Y4 → reserved (board 5) |
| — | 0 | 1 0 1 | Y5 → reserved (board 6) |
| — | 0 | 1 1 0 | Y6 → reserved (board 7) |
| — | 0 | 1 1 1 | Y7 → reserved (board 8) |
The 74HC4051 is an analog switch, so it passes the bidirectional SWDIO line without any direction control. I still disable the mux before changing the address, so a target never sees a half-switched bus (more on that below).
Control the SWD multiplexer with FT232H and pyftdi
pyftdi's GpioAsyncController drives the FT232H pins as plain GPIO. The pin math is short:
import time
S0, S1, S2, E = 1 << 4, 1 << 5, 1 << 6, 1 << 7
MASK = S0 | S1 | S2 | E # ADBUS D4..D7 are outputs
def select_bits(mcu):
ch = mcu - 1
return (S0 if ch & 1 else 0) | (S1 if ch & 2 else 0) | (S2 if ch & 4 else 0)
def switch(gpio, arg):
pins = gpio.read() & MASK
gpio.write(pins | E) # always disable first
time.sleep(1.0) # let the bus settle
sel = select_bits(int(arg))
gpio.write(sel | E)
gpio.write(sel) # enable
assert gpio.read() & MASK == selThe controller is opened once with D4–D7 as outputs:
from pyftdi.gpio import GpioAsyncController
gpio = GpioAsyncController()
gpio.configure('ftdi://ftdi:232h/1', direction=MASK)
gpio.write(E) # start disconnectedThe FT232H gotcha: one-shot scripts drop the pins
My first version was a one-shot script: open the FT232H, set the pins, exit. It did not hold. On my bench, opening the FT232H resets its bit mode, so the select lines dropped as soon as the next process opened the device. The pyftdi GPIO docs do not promise that pin state survives an open or close, so do not rely on it.
The fix is a long-lived server that owns the FT232H and keeps the pins driven:
mux.py serveruns in a tmux session, opens the FT232H once, and starts with E high (no target connected).mux.py 1,2,3,4,offandstatusare thin clients. They talk to the server over a Unix socket in$XDG_RUNTIME_DIR.- Every switch runs the same sequence, reads the pins back, and prints either
MCU1 (Y0) -> MCU2 (Y1)or an ERROR. - On shutdown, the server drives E high before it closes the device.
View PlantUML source
@startuml
skinparam shadowing false
participant "mux.py 2" as C
participant "mux.py serve" as S
participant "FT232H" as F
C -> S : switch to 2 (Unix socket)
S -> F : E = 1 (all off)
S -> S : wait 1 s
S -> F : set S0..S2
S -> F : E = 0 (enable)
S -> F : read pins back
S --> C : MCU1 (Y0) -> MCU2 (Y1)
@endumlStable USB device names with udev
With one FT232H, one J-Link and eight serial adapters, /dev/ttyUSB* and /dev/ttyACM* numbers change with plug order. Matching by serial number did not work on my bench: every CP2102 reported the same factory serial, 0001, and the FT232H had no serial at all.
So the udev rules match the USB port path with KERNELS instead. The udev man page defines KERNELS as a match that searches the device path upwards, which is exactly the hub-and-port chain:
SUBSYSTEM=="tty", KERNELS=="1-3.4.2", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="mcu1-uart"The full rule set gives fixed names: /dev/mcu1-can … /dev/mcu4-can, /dev/mcu1-uart … /dev/mcu4-uart, and /dev/mux-ftdi. Another rule sets the USB device nodes to MODE="0664", GROUP="dialout" so usbreset and pyftdi work without root.
Install and reload:
sudo cp 99-bench.rules /etc/udev/rules.d/
sudo udevadm control --reload
sudo udevadm triggerThe current udevadm man page documents --reload; older guides, and my own notes, use --reload-rules. --reload only affects new events, which is why trigger follows it.
To find each port path, I plugged the channels in one at a time and wrote down the result in a port map. Keep that map: moving an adapter to another hub port, or the hub to another PC port, changes the path and silently breaks the name. One UART adapter refused to enumerate on three different ports; it was a bad unit, not a rule problem, and a replacement fixed it.
View PlantUML source
@startuml
skinparam shadowing false
left to right direction
node "Linux PC" as PC
node "FT232H\n/dev/mux-ftdi" as FT
node "4-port hub\n(2 sub-hubs)" as HUB
node "J-Link\n(-USB <SN>)" as JL
node "CANable x4\n/dev/mcuN-can" as CAN
node "CP2102 x4\n/dev/mcuN-uart" as UART
PC --> FT
PC --> HUB
HUB --> JL
HUB --> CAN
HUB --> UART
@endumlUse J-Link Commander through the mux
Because the J-Link has no tty, select it by serial number. SEGGER documents -USB <SerialNo> for J-Link Commander (V7.92d and later), and SelectEmuBySN <SN> as the first line of a command file. A switch-and-read call looks like this:
python3 mux.py 2
JLinkExe -USB <SN> -device <YOUR_DEVICE> -if SWD -speed 2000 -autoconnect 1 -CommandFile read.jlinksavebin dump.bin <FLASH_BASE> 0x40000
g
exitconnect leaves the CPU halted, so end the command file with g (or r then g) to let the firmware run again. After an r + g, check that the target is actually running: on one of my boards, halting and resuming a running target could end in a fault, so I halt once and confirm state afterwards.
74HC4051 datasheet timing
Before reading my numbers, here is what the chip itself promises. My muxes are SparkFun's 8-channel 74HC4051 breakout (BOB-13906), and SparkFun links the NXP 74HC4051/74HCT4051 product data sheet (Rev. 8, 5 February 2016) for it, so the figures below come from that document. The four muxes run from VCC = 5 V on a single supply, and the targets use 3.3 V I/O, which the switch can pass as long as the signals stay between VEE and VCC.
| Parameter (74HC4051, 25 °C, CL = 50 pF) | VCC = 2 V | VCC = 4.5 V | VCC = 6 V |
|---|---|---|---|
| Propagation delay Vis → Vos (tpd), typ / max | 14 / 60 ns | 5 / 12 ns | 4 / 10 ns |
| Turn-on time from E (ton), typ / max | 72 / 345 ns | 29 / 69 ns | 21 / 59 ns |
| Turn-off time from E (toff), typ / max | 58 / 290 ns | 31 / 58 ns | 17 / 49 ns |
| ON resistance RON(peak), typ / max | — | 100 / 180 Ω | 90 / 160 Ω |
At exactly 5 V the data sheet lists typical values with CL = 15 pF: 22 ns turn-on and 18 ns turn-off from E, and 20 ns / 19 ns from the select inputs. Capacitance: 3.5 pF on each control input, 5 pF on each Yn pin and 25 pF on the common Z pin. The −3 dB bandwidth is about 180 MHz (±4.5 V supply).
What this means for the bench:
- The 1-second settle wait is very conservative. Even at 2 V the chip needs at most 345 ns to turn a channel on and 290 ns to turn it off. The 1 s wait is a deliberate safety margin I chose, not something the mux needs; a few milliseconds would satisfy the data sheet many times over. I have kept it for now because switching is rare and the time is not a bottleneck.
- Disabling E first is worth it. The NXP data sheet does not promise break-before-make between channels, and my four chips switch from a shared bus anyway. E high gives every signal a defined "off" state while S0–S2 change.
- Propagation delay hits SWDIO twice. SWCLK goes through one mux to the target, and the target's SWDIO answer comes back through another. At 5 V that is roughly 2 × 5 ns typical and under 2 × 12 ns worst case at 25 °C, plus wiring. A low supply would cost much more (up to 2 × 60 ns at 2 V), which is one reason I power the muxes from 5 V.
- Neither the mux delay nor its RC explains the ceiling on its own. At 5 V the round trip through two mux paths is well under 25 ns, and 180 Ω × (25 pF + 5 pF) is about 5 ns, both small next to the 125 ns half-period at 4 MHz. That points to the jumper wiring and the probe's sampling margin as the more likely cause of the 3.5–4 MHz ceiling I measured, but I have not proved it with a scope.
Control logic levels: 3.3 V FT232H into a 5 V mux
The select and enable pins are driven by an Adafruit FT232H breakout (product 2264). The FT232H I/O cells are 3.3 V CMOS outputs; FTDI's DS_FT232H data sheet (v1.81) gives VOH of at least 2.4 V at 2 mA, and with the mux's tiny input current the pins sit close to 3.3 V. The question is whether the 74HC4051 reads that as HIGH when it runs from 5 V.
| 74HC4051 VIH (HIGH-level input, 25 °C) | Guaranteed min | Typical |
|---|---|---|
| VCC = 4.5 V | 3.15 V | 2.4 V |
| VCC = 5 V (interpolated, not in the data sheet) | ≈ 3.5 V | ≈ 2.7 V |
| VCC = 6 V | 4.2 V | 3.2 V |
3.3 V is above the typical threshold, which is why the bench switches reliably, but below the guaranteed minimum, so it is not covered by the data sheet across parts and temperature. This matters most on E: if a HIGH were misread, a channel you think is off could stay connected. Three ways to put it back in spec:
- 74HCT4051 instead of the HC part: same pinout, TTL-level inputs (VIH 2 V min), VCC 4.5–5.5 V. The SparkFun board ships with the HC part, so this means another board or through-hole chips.
- A 3.3 V → 5 V level shifter on S0–S2 and E only. The SWD signals do not need it.
- Run the muxes from 3.3 V. The HC threshold then drops to about 2.3 V, but RON and delays grow, so re-measure the SWD ceiling, and every switched signal must stay at or below 3.3 V.
On a single supply, also keep VEE tied to GND. On the SparkFun board that is jumper JP1, closed by default; SparkFun's hookup guide says to open it only for a bipolar supply. With JP1 closed, VEE is already tied to GND on the board, so the VEE header pin can stay unconnected; that is how my four boards are set up. The data sheet limits Yn and Z to the range between VEE and VCC, so a floating VEE leaves that range undefined.
Measured switch time and SWD speed through the mux
All numbers below are from my bench on October 23, 2026, on the two channels brought up so far.
| Action | Time |
|---|---|
mux.py <ch> switch | 1.04 s average (1.03–1.05 s, n=6) |
mux.py status | 0.03 s |
| Switch + JLinkExe connect + read one word | 1.14–1.18 s |
The switch time is almost all the deliberate 1-second settle wait. The J-Link part of the third row is 0.10–0.14 s.
For SWD speed, I read 256 KB of flash with savebin and compared the md5 against a reference, three runs per speed. Times are the total JLinkExe run, connect included.
| SWD speed | Board 1 | Board 2 |
|---|---|---|
| 1000 kHz | 3/3 OK, 3.19 s | 3/3 OK, 3.20 s |
| 2000 kHz | 3/3 OK, 1.63 s | 3/3 OK, 1.64 s |
| 3000 kHz | 3/3 OK, 1.14 s | 3/3 OK, 1.13 s |
| 3500 kHz | 3/3 OK, 0.98 s | 3/3 OK, 0.99 s |
| 4000 kHz | 0/3 | 0/3 |
| 5000 kHz | 0/3 | 0/3 |
Earlier runs on board 1 put the ceiling somewhere between 3 and 4 MHz: one run passed at 3.5 MHz, another failed there. Nothing above 4 MHz ever passed. VTref read 3.10–3.13 V through the mux in every run, so the reference voltage reaches the probe fine.
I have not measured the exact cause of the ceiling. Based on the datasheet timing above, the mux itself (at 5 V) accounts for only a small part of the budget, so the jumper wiring is the most likely limit. If you need more speed, shorten and twist the SWD wiring with ground, keep the mux at 5 V, and re-measure. I chose 2000 kHz as the default because it leaves margin below that roughly 3.5 MHz edge.
SWD mux gotchas and checklist
- Connect under reset changes the target. On my bench, when a connect failed, J-Link's connect-under-reset pulled nReset and reset the board. Failing high-speed tests therefore change target state, so do not run them on a target whose state matters.
- The CPU stays halted after connect. Finish with
g(orr+g) and confirm the target is running. - Disable before you switch. E high, wait, set S0–S2, E low, read back. Never change the address with E low.
- Keep the server running. Put
mux.py servein tmux or a systemd user service; one-shot GPIO scripts lose the pins. - Keep the port map. udev names depend on physical ports; document them.
- Share ground. J-Link, FT232H, muxes and boards all need a common GND.
- Tie VEE to GND on a single supply. On the SparkFun board keep JP1 closed; the VEE header pin can then stay unconnected.
- Mind the control levels. A 3.3 V controller into a 5 V 74HC4051 is below the guaranteed VIH; use 74HCT4051, a level shifter, or a 3.3 V mux supply.
I manage the bench over SSH; if you are on a recent OpenSSH, my OpenSSH 10.6 upgrade checklist covers config changes worth checking first.
FAQ
Can a 74HC4051 pass SWD signals? Yes. It is an analog switch, so the bidirectional SWDIO line passes without direction control. On my bench, SWD worked reliably at 3.5 MHz and failed at 4 MHz and above, so expect a lower ceiling than a direct cable.
Why use four muxes instead of one? Each 74HC4051 switches one signal. VTref, SWDIO, SWCLK and nReset each need their own mux, and all four share the select and enable lines so they switch together.
Why does my FT232H GPIO script lose its pin state? On my bench, opening the FT232H reset its bit mode, so a script that sets pins and exits does not hold them. Keep one process that owns the device and send it commands over a socket.
How do I pick a J-Link when several are connected? Use JLinkExe -USB <SN> (J-Link Commander V7.92d and later) or put SelectEmuBySN <SN> as the first line of a command file.
Can this go beyond eight boards? In principle, yes, by combining demux banks: one bank of four 74HC4051s per eight boards, each bank enabled by its own GPIO line, or a two-level mux tree. I have not tested it; every added switch loads the lines, so re-measure the SWD ceiling.
What SWD speed should I use through a mux? Measure your own ceiling with a read-and-compare test, then run well below it. Mine passed at 3.5 MHz and failed at 4 MHz, so I use 2000 kHz.
Summary
Four 74HC4051 muxes, one per SWD signal, plus an FT232H on the shared select bus turn one J-Link into a multi-board debugger: four channels wired today, two brought up, and room for eight. Run the FT232H from a long-lived server, always disable the mux before switching, name your adapters by USB port path with udev, and measure the SWD ceiling before picking a default speed. On my bench that means about 1 second per switch and SWD at 2 MHz.
Written on October 24, 2026. Measurements are from my own bench on October 23, 2026, with two target boards installed; your ceiling will depend on your wiring and boards.
References
- SEGGER Knowledge Base: J-Link Commander (command-line options,
connect,savebin,r,g,speed) — kb.segger.com (checked Oct 24, 2026) - NXP 74HC4051; 74HCT4051 product data sheet, Rev. 8, 5 February 2016 (static characteristics: VIH, RON; dynamic characteristics: tpd, ton, toff; capacitance), as linked by SparkFun for BOB-13906 — sparkfun.com (checked Oct 24, 2026)
- SparkFun Multiplexer Breakout Hookup Guide (VEE and jumper JP1) — learn.sparkfun.com (checked Oct 24, 2026)
- Adafruit FT232H Breakout, product 2264 — adafruit.com (checked Oct 24, 2026)
- FTDI FT232H data sheet DS_FT232H v1.81 (I/O characteristics, VOH) — ftdichip.com (checked Oct 24, 2026)
- pyftdi GPIO API (
GpioAsyncController,read,write, direction) — eblot.github.io/pyftdi (checked Oct 24, 2026) - pyftdi URL scheme (
ftdi://ftdi:232h/1) — eblot.github.io/pyftdi (checked Oct 24, 2026) - udev(7) man page (
KERNELS,ATTRS,SYMLINK,MODE,GROUP, rules directories) — freedesktop.org (checked Oct 24, 2026) - udevadm(8) man page (
control --reload,trigger) — freedesktop.org (checked Oct 24, 2026)









