The STM32F446RE is a Cortex-M4 microcontroller with 512 KB of flash. On a NUCLEO-F446RE board it normally gets programmed through the ST-LINK on the board, over SWD (Serial Wire Debug), the two-wire debug interface of Arm Cortex-M chips. In a test rack that is awkward: the debugger is a USB device that has to be plugged into whichever machine runs the tests.
A BenchPod is its own debug probe. It runs the probe protocol itself and drives SWD on two of its logic analyzer pins, so the same pod that powers, resets and observes the board also flashes it. This article is part of a series, one per chip we have run on real hardware: the overview of how the BenchPod flashes microcontrollers lists them all. It covers how SWD works on the wire, how the pod turns it into a probe, how to wire the board, what we measured, and the SWD details that matter in practice.
SWD in one paragraph
SWD uses two signals: SWCLK, a clock the probe always drives, and SWDIO, one bidirectional data line. Behind those pins sits the chip's debug port (DP), which in turn gives access to one or more access ports (APs). On a Cortex-M4 the access port that matters is the AHB-AP: through it the probe reads and writes the chip's whole memory map, which is how flash gets programmed. The probe never talks to flash directly. It reads and writes registers, and the chip's memory bus does the rest.
Every register access is one transfer:
| Phase | Bits | Driven by | Content |
|---|---|---|---|
| Request | 8 | probe | start, APnDP (DP or AP), RnW (read or write), two address bits, parity, stop, park |
| Turnaround | 1 | nobody | SWDIO changes direction |
| ACK | 3 | target | OK, WAIT or FAULT |
| Data | 32 + 1 | target (read) or probe (write) | the value, least significant bit first, then parity |
| Turnaround | 1 | nobody | back to the probe (reads); on writes it comes before the data |
The first thing a probe does is send a line reset (50 or more clocks with SWDIO high) and a fixed 16-bit sequence that switches a JTAG-capable chip over to SWD. It then reads the debug port's DPIDR register. If the chip answers with a valid ID, the link is alive. After that the probe powers up the debug domain, selects the AHB-AP and uses it to read and write memory.
Reading the chip's identity
On the bench NUCLEO-F446RE the first raw reads through the pod gave this:
| Register | Value | Meaning |
|---|---|---|
DPIDR | 0x2BA01477 | an Arm SW-DP |
AHB-AP IDR | 0x24770011 | an AHB-AP, the memory access port |
CPUID (memory read at 0xE000ED00) | 0x410FC241 | Cortex-M4 |
These three reads are also the quickest wiring check there is. DPIDR proves SWCLK and SWDIO are connected, the AHB-AP IDR proves the debug domain powered up, and CPUID proves the access port can read the chip's memory.
How the pod becomes a debug probe
The pod does not bit-bang SWD from the network. It runs a CMSIS-DAP probe, the standard Arm debug probe protocol, in its firmware. The work is split three ways:
- The host runs OpenOCD, with the
target/stm32f4x.cfgconfiguration for the chip family. OpenOCD knows the STM32F4 flash controller, the flash loader and the verify and reset steps. It uses itscmsis-dapbackend over TCP, a backend added to OpenOCD after the 0.12.0 release, so you need a recent build. On a cloud connection the packets go through embeddedci.com to the pod and your local OpenOCD still runs them; for a build uploaded from CI, embeddedci.com can run OpenOCD itself, with nothing to install. - The pod's MCU runs a CMSIS-DAP processor. OpenOCD sends whole DAP packets (batches of register transfers) and the MCU executes them against the wire. On a LAN or USB connection a small bridge on the host frames them for the pod's
dap_startcommand; in the cloud they travel over the pod's existing connection. The CMSIS-DAP over TCP article follows a packet through that path, so it is not repeated here. - The FPGA has an SWD engine that drives the clock and the data line on any two of the 14 logic analyzer pins, at the target's I/O voltage, and samples SWDIO.
The point of that split is round trips. If every clock edge crossed the network, flashing would take minutes. Because the pod executes each DAP transfer next to the pins, the timing of the SWD wire never depends on the network, and the same flash behaves the same over the LAN, USB or the cloud.
The pod holds no flash knowledge. OpenOCD's exit code is the verdict: 0 means the image was programmed and verified.
Connect under reset
Some firmware makes SWD hard to reach. It can re-purpose the SWD pins as ordinary I/O, put the core to sleep or run too tight a loop for the debug port to get a word in. The cure is connect under reset: hold the chip's reset line low, connect the debug port while the application has not started, then halt the core before releasing reset.
The pod has its own reset pin (DUT header J1 pin 22). Wire it to the target's NRST and the pod can hold the board in reset on demand. The tools use it by default when the board is wired for reset: the OpenOCD configuration the pod passes is reset_config srst_only srst_nogate connect_assert_srst, which makes OpenOCD assert reset first and connect afterward.
Why the clock boost is skipped
OpenOCD's STM32F4 configuration has a reset-init event that runs right after a reset: it raises the core clock and the debug adapter speed so flashing is fast. On a probe on a short USB cable that works well. Over a link with more latency per packet, those clock writes can race the core coming out of reset.
So by default the tools clear the reset-start and reset-init events, and flashing runs at the chip's reset clock: a bit slower, reliable every time. The CLI's --keep-reset-init flag keeps the events if you want the boost anyway.
Wiring the NUCLEO-F446RE
| Pod (J1) | NUCLEO-F446RE | Signal |
|---|---|---|
| LA11 | SWCLK | clock, driven by the pod |
| LA12 | SWDIO | bidirectional data |
| pin 22, reset | NRST | reset, for connect under reset |
| GND | GND | common ground |
On our bench this is the board the pod flashes before every run of a long hardware test suite for the process-node example, a small process controller on the same NUCLEO that talks CAN, runs a thermostat loop and raises alarms. Its wiring profile stores the SWD pins and the reset flag, so tools find them without arguments:
{"swd_swclk": 11, "swd_swdio": 12, "swd_nreset": true, "swd_target": "target/stm32f4x.cfg"}The pod's SWD pins are just logic analyzer channels, so any two will do. On a chip with both ports, the same two pins are JTAG's TCK and TMS; JTAG adds TDI and TDO on two more.
Bench results
We measured on a NUCLEO-F446RE:
- A 52 KB image was programmed, verified and the board reset in 3.4 s over SWD.
- A flash of a cold board (just powered on) took 6.1 s with SWCLK at 2 MHz on an earlier firmware.
DPIDR, AHB-APIDRandCPUIDread back as listed above.
Since the pod is the debug probe, the suite begins with a flash: every test run starts from a known image, on the same wires the tests use to observe the board.
Things to know about SWD
"Cannot read IDR" usually means the chip is not listening. Application firmware that turns PA13 and PA14 into GPIOs, or puts the chip into a deep sleep, takes the debug port away before the probe can read DPIDR. The probe is fine. Connect under reset (the reset line on the pod's reset pin) catches the chip before the application runs, which is why it is part of the default wiring.
Access port reads right after a write need idle clocks. The AHB-AP needs a few clocks to finish a write; a read issued right after it answers WAIT. The pod adds at least 8 idle clocks after each transfer, so this never shows up in a flash.
Using it
From Python, with the pytest package:
from embeddedci.benchpod import BenchPod
with BenchPod("192.168.1.50", la_voltage=3.3) as bp:
r = bp.flash(target="target/stm32f4x.cfg", file="app.elf", swclk=11, swdio=12, nreset=True)
assert r.ok, r.stderrWith a wiring profile that names the SWD pins, bp.flash(file="app.elf") is enough. nreset=True says the target's reset line is on the pod's reset pin, and connect under reset follows from it. Pass target_power to power the board first.
From the command line, with the CLI:
benchpod flash --target target/stm32f4x.cfg --file app.elfFrom an AI agent, the MCP server's flash tool takes the same arguments. All three run OpenOCD with the same target configuration; only a build uploaded to embeddedci.com (build= / --build) can be flashed by embeddedci.com itself on a cloud connection.
Underneath, the pod arms its probe with one JSON command, dap_start, and the connection then carries CMSIS-DAP packets; the API docs have the reference. The Arm chips over SWD page covers other families: it is the same path and any chip OpenOCD supports over SWD works with a different target configuration.
Every chip and method we have verified on real hardware is in How the BenchPod flashes microcontrollers.