Back to resources
Chip programming
Firmware
HIL

Flashing the STM32F446RE over JTAG with a BenchPod

How a BenchPod flashes an STM32F446RE (NUCLEO-F446RE) over JTAG instead of SWD: the TAP state machine, IDCODEs and the two-TAP scan chain, the wiring, measured flash times and what JTAG is good for.

Edward Viaene · November 24, 2026 · 10 min read

The STM32F446RE is a Cortex-M4 microcontroller with 512 KB of flash. On the NUCLEO-F446RE board it is normally flashed over SWD, two wires, and every Arm debug tool prefers that. The chip also has a full JTAG port on the same pins (plus two more), and that is the interesting part: JTAG is the older, wider standard, shared with FPGAs, CPLDs, RISC-V chips and long scan chains of several devices.

A BenchPod speaks both. Its debug probe is a CMSIS-DAP probe with an SWD side and a JTAG side, so the same pod that flashes a Cortex-M over SWD can flash it over JTAG, read its scan chain and play back SVF files. This article is part of a series, one per chip and method we have run on real hardware: the overview of how the BenchPod flashes microcontrollers lists them all. It covers how JTAG works, how the pod runs it, how to wire a NUCLEO-F446RE, what we measured and when JTAG is worth choosing over SWD.

JTAG in one paragraph

JTAG (IEEE 1149.1) is a four-wire synchronous serial bus that was designed for boundary-scan testing of boards, and was later reused for debugging and programming. The pod drives all four wires, and one optional fifth:

SignalDirection (seen from the chip)Role
TCKinTest clock. Everything moves on its edges
TMSinTest mode select. One bit per TCK picks the next state of the TAP controller
TDIinTest data in: bits shifted into the chain
TDOoutTest data out: bits shifted out of the chain
nTRSTinOptional TAP reset (PB4 on the F446). The pod drives it and releases it high

The chip's reset line is separate; the pod keeps it on its own reset pin, the same as for SWD.

The TAP state machine

Every JTAG device contains a TAP (test access port) controller: a 16-state machine whose only input is TMS, sampled on each rising TCK edge. There is no address and no command byte on the wire. You steer the machine with TMS and, in the two shifting states, move data in and out on TDI and TDO.

The 16 states of the TAP controller, with the data-register column and the instruction-register column and the TMS value on each arrow
The 16 states of the TAP controller, with the data-register column and the instruction-register column and the TMS value on each arrow

Two things are worth remembering:

  • Five TMS = 1 in a row reach Test-Logic-Reset from any state. That is how a host gets a known starting point without knowing where the chain was left, and why nTRST is optional.
  • A scan is a walk through one column. From Run-Test/Idle, TMS = 1, 0, 0 reaches Shift-DR (the data column), and 1, 1, 0, 0 reaches Shift-IR (the instruction column). In Shift, each TCK moves one bit in on TDI and one out on TDO. TMS = 1 on the last bit leaves Shift; Exit1, then Update, applies what was shifted, and TMS = 0 returns to Run-Test/Idle.

IR scans, DR scans and the IDCODE

Each TAP has an instruction register (IR) and several data registers (DR). The instruction register selects which data register sits between TDI and TDO. A typical access is two scans: an IR scan that selects the register, then a DR scan that reads or writes it.

InstructionWhat the DR scan does
IDCODEReads the device's 32-bit identification code. After Test-Logic-Reset, most TAPs select it by default
BYPASSA single-bit register: the TAP passes bits through, so other devices in a chain can be skipped
DPACC, APACC (Arm JTAG-DP)A 35-bit scan that reads or writes one debug-port or access-port register
Boundary scan instructionsCapture and drive the chip's pins

The IDCODE has the same layout in every chip: bit 0 is always 1, bits 11:1 are the JEDEC manufacturer code, bits 27:12 are the part number and bits 31:28 are the version. Reading it is the JTAG equivalent of a wiring check: if the right code comes back, TCK, TMS, TDI and TDO all work.

The F446's scan chain: two TAPs

The STM32F446RE puts two TAPs on the one set of JTAG pins: the Arm Cortex-M4 JTAG debug port and an ST boundary scan TAP. A host that resets the chain and shifts out the IDCODEs sees both:

TAPIDCODEManufacturer (bits 11:1)Used for
Cortex-M4 JTAG-DP0x4BA004770x23B, ArmMemory access, flash programming, debug
Boundary scan0x064210410x020, STBoundary scan, SVF playback

The boundary scan TAP reads `0x06421041`: the STM32F446's own code, with its device ID 0x421 in the part number field. The F405/F407 report 0x06413041, so a chain configuration written for one chip expects a different value on another.

To talk to one TAP, the host has to put the other in BYPASS: it shifts the target instruction into the right TAP and all 1s into the others, so the instruction register of the whole chain is the concatenation of every TAP's IR. The pod's CMSIS-DAP side handles that from the chain description the host sends (the length of each IR, the order of the devices), and the Cortex-M4's debug port uses the 4-bit instructions ABORT, DPACC, APACC and IDCODE.

Why you would choose JTAG

On an Arm chip that has SWD, SWD is the better way to flash it, and the pod's docs say so. JTAG earns its place elsewhere:

  • Chips with no SWD. RISC-V parts, the classic ESP32, and older Arm chips with only a JTAG port. The same pod and OpenOCD's configs should work for them; the F446 is the chip we have run over JTAG.
  • Boundary scan. The boundary scan TAP can read and drive every pin of the chip through the scan chain, without any firmware running on it. That finds shorts and open solder joints, and it does not need the chip to boot.
  • SVF playback. An SVF file is a recorded sequence of IR and DR scans with expected TDO values. It is how FPGA and CPLD vendors ship programming and test vectors. OpenOCD plays it with its svf command, and the pod runs those scans like any others.
  • Chains with several devices. Several chips on one TDI to TDO loop need only four pins at the pod.

How the pod runs it

The host runs OpenOCD, the pod's MCU speaks CMSIS-DAP and the FPGA's JTAG sequencer drives TCK, TMS, TDI and TDO to the two TAPs on the STM32F446RE
The host runs OpenOCD, the pod's MCU speaks CMSIS-DAP and the FPGA's JTAG sequencer drives TCK, TMS, TDI and TDO to the two TAPs on the STM32F446RE

The work is split three ways:

  • The host runs OpenOCD with the chip's config, such as target/stm32f4x.cfg. It reads the firmware image, talks CMSIS-DAP to the pod over the LAN, USB or the cloud, and decides what to write where. The Python SDK, the CLI and the MCP server all start it for you.
  • The pod's MCU is the CMSIS-DAP processor. It runs DAP_JTAG_Sequence exactly as the host sends it, and implements the JTAG debug port transfers (DPACC and APACC scans, with the ACK check and retries on WAIT) for tools that use them.
  • The FPGA has a JTAG sequencer, added in gateware v61. It takes sequences of TCK cycles with the TMS level and the TDI bits, changes TDI and TMS while TCK is low, samples TDO at the end of the TCK-high half, and leaves TCK low between sequences. The four signals can go on any of the 14 LA pins, at the target's I/O voltage (1.8 or 3.3 V).

JTAG needs firmware 4.0.4 or later (gateware v61 or later). The sequencer lives in the loop and deep-replay FPGA images; the image used for sensor emulation has no room for it, so stop emulated sensors before a JTAG flash.

Wiring a NUCLEO-F446RE

The NUCLEO-F446RE's ST-LINK is not used here. On the bench the board's own JTAG pins are wired to the pod, and the board is powered from the pod, as in the process-node example (examples/process-node-stm32).

Pod LA pinNUCLEO-F446RE pinJTAG signal
LA9PA15TDI
LA10PB3TDO
LA11PA14 (SWCLK)TCK
LA12PA13 (SWDIO)TMS
pin 22, resetNRSTchip reset (not part of JTAG)
GNDGNDground
Five wires from the pod's J1 header to the NUCLEO-F446RE: LA9 to PA15, LA10 to PB3, LA11 to PA14, LA12 to PA13 and ground (the reset wire, pin 22 to NRST, is in the table above)
Five wires from the pod's J1 header to the NUCLEO-F446RE: LA9 to PA15, LA10 to PB3, LA11 to PA14, LA12 to PA13 and ground (the reset wire, pin 22 to NRST, is in the table above)

On the STM32 the JTAG and SWD ports share two pins: TMS is SWDIO (PA13) and TCK is SWCLK (PA14). Only TDI (PA15) and TDO (PB3) are extra. A board wired for both ports therefore needs just two more wires than one wired for SWD, and the pod claims each shared pin once.

In the pod's wiring profile the same wiring looks like this:

{
  "swd_swclk": 11, "swd_swdio": 12,
  "jtag_tck": 11, "jtag_tms": 12, "jtag_tdi": 9, "jtag_tdo": 10,
  "debug_port": "jtag"
}

How the tools choose JTAG

There is no "use JTAG" flag in the CLI, SDK or MCP server. All of them pick the port from the pins they know, in this order:

  1. Pins in the call win. A call that carries the four JTAG pins and no SWD pins uses JTAG; SWD pins and no JTAG pins use SWD. A call with both sets or neither goes on to step 2.
  2. The profile's `debug_port`. "swd" or "jtag". If that port's pins are not all set, the tool stops and names the missing profile fields.
  3. Automatic. JTAG when all four of TCK, TMS, TDI and TDO are known and either no SWD pins are, or the chip only has JTAG (the OpenOCD targets esp32, esp32s2, gd32vf103, fe310, k210 and names starting with riscv). Otherwise SWD.

An Arm chip wired for both ports therefore flashes over SWD unless debug_port says "jtag" or the call passes only JTAG pins. That is why the wiring profile above sets debug_port.

Bench results

We ran a NUCLEO-F446RE with the wiring above and OpenOCD's CMSIS-DAP driver over the pod's USB network adapter, on 2026-11-23:

  • The scan chain read `0x4BA00477` (Cortex-M4 JTAG-DP) and `0x06421041` (boundary scan).
  • A 52 KB image was programmed and verified in 8.2 s over JTAG, against 3.4 s over SWD on the same board.
  • An SVF file played back correctly through OpenOCD's svf command, TDO comparisons included.

Things to know

JTAG is slower than SWD for Arm chips, and TCK does not change that. The JTAG flash time stayed the same when TCK went from 1 to 6 MHz. OpenOCD's JTAG path is bound by packet round trips between OpenOCD and the pod, not by the wire, while SWD transfers queue in the pod's FPGA and go out together. A faster JTAG clock would therefore not shorten an Arm flash. The value of JTAG is boundary scan, SVF and chips that have no SWD.

Read the IDCODEs first. A chain that reports 0x4BA00477 and 0x06421041 confirms all four wires and the I/O voltage. All 1s or all 0s means TDO is not connected or the chip is not powered. A code you did not expect means the chain differs from what the config assumes.

Using it

From Python, with the pytest package, on a pod whose wiring profile has the JTAG pins and debug_port:

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", nreset=True)
    assert r.ok, r.stderr

To pass the pins in the call instead, give all four and no SWD pins:

r = bp.flash(target="target/stm32f4x.cfg", file="app.elf", tck=11, tms=12, tdi=9, tdo=10)

From the command line:

benchpod flash --target target/stm32f4x.cfg --file app.elf --tck 11 --tms 12 --tdi 9 --tdo 10

--trst is optional. From an AI agent, the MCP server's flash tool takes the same arguments. Underneath, the pod's CMSIS-DAP side is started with dap_start and the LA channels of tck, tms, tdi, tdo and optionally trst; the API docs describe the command.

Chips over JTAG need firmware 4.0.4 or later and gateware v61 or later; on older pods the tools stop before anything is armed and say to update with benchpod flash-self; with the sensor emulation image loaded the pod refuses with BP0058 or BP0059, listed in the error codes. The wiring fields, the choice rules and the list of chips are on the chips over JTAG page; the SWD side is on Arm chips over SWD. Every chip and method we have verified on real hardware is in How the BenchPod flashes microcontrollers.