From acd5a69b2be7834ba4e10814147731bef8142353 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Mon, 23 Nov 2026 13:57:11 -0600 Subject: [PATCH 1/5] Wiring: jtag_tck, jtag_tms, jtag_tdi, jtag_tdo, jtag_trst; sync feature table rev 16 Co-Authored-By: Claude Sonnet 5.5 --- .../src/embeddedci/benchpod/feature_map.json | 11 ++++++-- .../src/embeddedci/benchpod/header.py | 6 ++-- .../src/embeddedci/benchpod/wiring.py | 28 +++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/packages/embeddedci/src/embeddedci/benchpod/feature_map.json b/packages/embeddedci/src/embeddedci/benchpod/feature_map.json index ded5629..521a1a1 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/feature_map.json +++ b/packages/embeddedci/src/embeddedci/benchpod/feature_map.json @@ -1,10 +1,10 @@ { "_generated": "GENERATED by tools/gen_features.py from features/features.toml. DO NOT EDIT: edit the table.", "schema": 1, - "revision": 15, + "revision": 16, "api": 2, "min_client_api": 2, - "table_sha256": "87a752cbc4be042b063c8e23015697c6c7d1ff4451a8c186449e232e0ef9036d", + "table_sha256": "62774655c1b30b01bed9e205d16ea5688cc6bdd0d87987657897a896e624e873", "floor": "3.9.2", "docs_base": "https://github.com/embeddedci-com/benchpod-firmware/blob/main/docs/", "facts": { @@ -839,6 +839,13 @@ "firmware": "4.0.3", "board": "any", "docs": "API.md#usb_flash--flash-a-board-over-usb" + }, + "jtag": { + "rev": 16, + "firmware": "next", + "gateware": 61, + "board": "any", + "docs": "dap-over-tunnel.md#jtag" } } } diff --git a/packages/embeddedci/src/embeddedci/benchpod/header.py b/packages/embeddedci/src/embeddedci/benchpod/header.py index 24843eb..86c0215 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/header.py +++ b/packages/embeddedci/src/embeddedci/benchpod/header.py @@ -34,12 +34,14 @@ _ROLE_LABELS = { "uart_rx": "UART RX", "uart_tx": "UART TX", "i2c_sda": "I2C SDA", "i2c_scl": "I2C SCL", "swd_swclk": "SWCLK", "swd_swdio": "SWDIO", "spi_sclk": "SPI SCLK", "spi_mosi": "SPI MOSI", - "spi_miso": "SPI MISO", "spi_cs": "SPI CS", + "spi_miso": "SPI MISO", "spi_cs": "SPI CS", "jtag_tck": "TCK", "jtag_tms": "TMS", + "jtag_tdi": "TDI", "jtag_tdo": "TDO", "jtag_trst": "TRST", } _ROLE_CONNECT = { "uart_rx": "board TX", "uart_tx": "board RX", "i2c_sda": "SDA", "i2c_scl": "SCL", "swd_swclk": "SWCLK", "swd_swdio": "SWDIO", "spi_sclk": "SCLK", "spi_mosi": "MOSI (board SDI)", - "spi_miso": "MISO (board SDO)", "spi_cs": "CS", + "spi_miso": "MISO (board SDO)", "spi_cs": "CS", "jtag_tck": "TCK", "jtag_tms": "TMS", + "jtag_tdi": "TDI", "jtag_tdo": "TDO", "jtag_trst": "TRST (nTRST)", } _SIGNAL_USE = {"input": "the pod reads it", "output": "the pod drives it", "open_drain": "open drain", "bidir": "open drain"} diff --git a/packages/embeddedci/src/embeddedci/benchpod/wiring.py b/packages/embeddedci/src/embeddedci/benchpod/wiring.py index 3240c7e..3a2399a 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/wiring.py +++ b/packages/embeddedci/src/embeddedci/benchpod/wiring.py @@ -42,7 +42,13 @@ #: Profile keys that name the LA channel of a DUT signal role. ROLE_KEYS: Tuple[str, ...] = ("uart_rx", "uart_tx", "i2c_sda", "i2c_scl", "swd_swclk", "swd_swdio", + "jtag_tck", "jtag_tms", "jtag_tdi", "jtag_tdo", "jtag_trst", "spi_sclk", "spi_mosi", "spi_miso", "spi_cs") +#: Role pairs that may share one LA channel: on an ARM part the JTAG TCK and TMS pins are the SWCLK +#: and SWDIO pins, so the probe wires them once. +JTAG_SHARED_ROLES: Tuple[Tuple[str, str], ...] = (("swd_swclk", "jtag_tck"), ("swd_swdio", "jtag_tms")) +#: The four pins JTAG needs (``jtag_trst`` is optional). +JTAG_REQUIRED_ROLES: Tuple[str, ...] = ("jtag_tck", "jtag_tms", "jtag_tdi", "jtag_tdo") #: Valid :attr:`Signal.direction` values. SIGNAL_DIRECTIONS: Tuple[str, ...] = ("input", "output", "open_drain", "bidir") #: Valid :attr:`Wiring.dut_dirs` values: which way the DUT's signal goes. @@ -52,6 +58,9 @@ ROLE_DUT_DIRS: Mapping[str, str] = { "uart_rx": "dut_output", "uart_tx": "dut_input", "i2c_sda": "bidir", "i2c_scl": "bidir", "swd_swclk": "dut_input", "swd_swdio": "bidir", + # TMS is "bidir" because on an ARM part it is the SWDIO pin (see JTAG_SHARED_ROLES) + "jtag_tck": "dut_input", "jtag_tms": "bidir", "jtag_tdi": "dut_input", "jtag_tdo": "dut_output", + "jtag_trst": "dut_input", "spi_sclk": "dut_input", "spi_mosi": "dut_input", "spi_miso": "dut_output", "spi_cs": "dut_input", } #: The default DUT direction of a signal from its :attr:`Signal.direction` (seen from the pod): a @@ -137,6 +146,13 @@ class Wiring: swd_swdio: Optional[int] = None swd_nreset: bool = False swd_target: str = "" + #: JTAG (firmware feature ``jtag``): the four LA channels and the optional nTRST. ``jtag_tck`` may + #: share a channel with ``swd_swclk`` and ``jtag_tms`` with ``swd_swdio``. + jtag_tck: Optional[int] = None + jtag_tms: Optional[int] = None + jtag_tdi: Optional[int] = None + jtag_tdo: Optional[int] = None + jtag_trst: Optional[int] = None spi_sclk: Optional[int] = None spi_mosi: Optional[int] = None spi_miso: Optional[int] = None @@ -487,15 +503,17 @@ def _errors(self) -> List[str]: errs.append(f"dut_dirs.{k}: {k!r} is not a wiring role or a signal name") elif d not in DUT_DIRS: errs.append(f"dut_dirs.{k} must be one of {', '.join(DUT_DIRS)}, got {d!r}") - users: Dict[int, str] = {} + users: Dict[int, List[str]] = {} for name, la in self.assignments(): if not 1 <= la <= 14: continue - if la in users: - errs.append(f"LA{la} is used by both {users[la]} and {name} (move one to a free channel, " + others = users.setdefault(la, []) + clash = [o for o in others + if (o, name) not in JTAG_SHARED_ROLES and (name, o) not in JTAG_SHARED_ROLES] + if clash: + errs.append(f"LA{la} is used by both {clash[0]} and {name} (move one to a free channel, " "or set a role that isn't wired to None)") - else: - users[la] = name + others.append(name) return errs From b7cc2cf8a8435cfd639a70a55d25ae0fe0f86151 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Mon, 23 Nov 2026 13:57:11 -0600 Subject: [PATCH 2/5] dap_start takes the JTAG pins and port Co-Authored-By: Claude Sonnet 5.5 --- .../src/embeddedci/benchpod/transport/base.py | 12 ++++++-- .../embeddedci/benchpod/transport/serial.py | 7 +++-- .../src/embeddedci/benchpod/transport/tcp.py | 29 +++++++++++++++++-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/packages/embeddedci/src/embeddedci/benchpod/transport/base.py b/packages/embeddedci/src/embeddedci/benchpod/transport/base.py index 741e482..461f419 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/transport/base.py +++ b/packages/embeddedci/src/embeddedci/benchpod/transport/base.py @@ -69,8 +69,11 @@ def target_power(self, efuse: int, on: bool, delay_ms: int = 0) -> None: connection can move on to e.g. UART capture meanwhile. """ - def dap_start(self, swclk: int, swdio: int, packet_size: Optional[int] = None, - packet_count: Optional[int] = None, wait_ms: Optional[int] = None) -> RawLink: + def dap_start(self, swclk: Optional[int] = None, swdio: Optional[int] = None, + packet_size: Optional[int] = None, packet_count: Optional[int] = None, + wait_ms: Optional[int] = None, *, tck: Optional[int] = None, + tms: Optional[int] = None, tdi: Optional[int] = None, tdo: Optional[int] = None, + trst: Optional[int] = None, port: Optional[str] = None) -> RawLink: """Arm the SWD engine and return a raw link carrying length-framed CMSIS-DAP packets — the batched flash path that OpenOCD's cmsis-dap TCP backend drives (see :mod:`embeddedci.benchpod.flash`). This is the only @@ -82,6 +85,11 @@ def dap_start(self, swclk: int, swdio: int, packet_size: Optional[int] = None, wait (up to that long) for the target to answer SWD before it acks, for a target whose rail was just switched on. + JTAG (firmware feature ``jtag``): ``tck``, ``tms``, ``tdi`` and ``tdo`` (and optionally + ``trst``) are LA channels; pass them with or instead of ``swclk``/``swdio`` (give at least + one complete set). ``port="jtag"`` arms JTAG first when both sets are given (the default is + SWD); it only matters then. + Target reset is not a parameter: since pod rev3 the pod drives NRST from its own pin (DUT header J1 pin 22) whenever CMSIS-DAP asks, so there is no LA channel to hand over.""" diff --git a/packages/embeddedci/src/embeddedci/benchpod/transport/serial.py b/packages/embeddedci/src/embeddedci/benchpod/transport/serial.py index 7bbad85..28358d6 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/transport/serial.py +++ b/packages/embeddedci/src/embeddedci/benchpod/transport/serial.py @@ -480,8 +480,11 @@ def _needs_network(self, what: str) -> TransportError: def target_power(self, efuse: int, on: bool, delay_ms: int = 0) -> None: raise self._needs_network("target power") - def dap_start(self, swclk: int, swdio: int, packet_size: Optional[int] = None, - packet_count: Optional[int] = None, wait_ms: Optional[int] = None) -> RawLink: + def dap_start(self, swclk: Optional[int] = None, swdio: Optional[int] = None, + packet_size: Optional[int] = None, packet_count: Optional[int] = None, + wait_ms: Optional[int] = None, *, tck: Optional[int] = None, + tms: Optional[int] = None, tdi: Optional[int] = None, tdo: Optional[int] = None, + trst: Optional[int] = None, port: Optional[str] = None) -> RawLink: raise self._needs_network("SWD (flashing)") def uart_proxy_start(self, rx: Optional[int], tx: Optional[int], baud: int, parity: str = "none", diff --git a/packages/embeddedci/src/embeddedci/benchpod/transport/tcp.py b/packages/embeddedci/src/embeddedci/benchpod/transport/tcp.py index 5802f49..2c37208 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/transport/tcp.py +++ b/packages/embeddedci/src/embeddedci/benchpod/transport/tcp.py @@ -531,9 +531,32 @@ def _raw_handshake(self, req: dict, cmd: str, kind: str) -> RawLink: raise return _SocketRawLink(sock) - def dap_start(self, swclk: int, swdio: int, packet_size: Optional[int] = None, - packet_count: Optional[int] = None, wait_ms: Optional[int] = None) -> RawLink: - req: dict = {"cmd": "dap_start", "swclk": swclk, "swdio": swdio} + def dap_start(self, swclk: Optional[int] = None, swdio: Optional[int] = None, + packet_size: Optional[int] = None, packet_count: Optional[int] = None, + wait_ms: Optional[int] = None, *, tck: Optional[int] = None, + tms: Optional[int] = None, tdi: Optional[int] = None, tdo: Optional[int] = None, + trst: Optional[int] = None, port: Optional[str] = None) -> RawLink: + req: dict = {"cmd": "dap_start"} + if swclk is not None or swdio is not None: + if swclk is None or swdio is None: + raise ValueError("dap_start needs both swclk and swdio, or neither") + req["swclk"] = swclk + req["swdio"] = swdio + jtag = {"tck": tck, "tms": tms, "tdi": tdi, "tdo": tdo} + if any(v is not None for v in jtag.values()) or trst is not None: + missing = [k for k, v in jtag.items() if v is None] + if missing: + raise ValueError("dap_start JTAG needs tck, tms, tdi and tdo: missing " + ", ".join(missing)) + req.update(jtag) + if trst is not None: + req["trst"] = trst + if "swclk" not in req and "tck" not in req: + raise ValueError("dap_start needs swclk/swdio or tck/tms/tdi/tdo") + if port is not None: + if port not in ("swd", "jtag"): + raise ValueError(f"dap_start port must be 'swd' or 'jtag', not {port!r}") + if "swclk" in req and "tck" in req: + req["port"] = port if packet_size: req["packet_size"] = packet_size if packet_count: From 035a3eae90296b8b8fef4b67fcdf9cf664cffc32 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Mon, 23 Nov 2026 13:57:11 -0600 Subject: [PATCH 3/5] flash(): pick SWD or JTAG automatically, JTAG-only targets, OpenOCD transport select jtag; tests, docs Co-Authored-By: Claude Sonnet 5.5 --- packages/embeddedci/CHANGELOG.md | 17 + packages/embeddedci/README.md | 15 +- .../src/embeddedci/benchpod/client.py | 99 +++++- .../src/embeddedci/benchpod/flash.py | 63 +++- packages/embeddedci/tests/api_surface.json | 7 +- packages/embeddedci/tests/test_jtag.py | 308 ++++++++++++++++++ 6 files changed, 488 insertions(+), 21 deletions(-) create mode 100644 packages/embeddedci/tests/test_jtag.py diff --git a/packages/embeddedci/CHANGELOG.md b/packages/embeddedci/CHANGELOG.md index 408a34b..eb7d7fe 100644 --- a/packages/embeddedci/CHANGELOG.md +++ b/packages/embeddedci/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog — `embeddedci` +## 4.0.4 + +For BenchPod firmware with the `jtag` feature (features table revision 16, gateware v61 or later). +SWD flashing is unchanged. + +- **JTAG flashing.** The wiring profile takes `jtag_tck`, `jtag_tms`, `jtag_tdi`, `jtag_tdo` and an + optional `jtag_trst` (LA channels 1-14). `jtag_tck` may share a channel with `swd_swclk` and + `jtag_tms` with `swd_swdio`; every other overlap is an error. `bp.flash()` takes `tck`, `tms`, + `tdi`, `tdo` and `trst` like `swclk` and `swdio` (omitted ones come from the profile). +- **No transport option: the SDK picks SWD or JTAG.** JTAG when all four JTAG pins are known and + either no SWD pins are, or the target is JTAG only (`esp32`, `esp32s2`, `gd32vf103`, `fe310`, + `k210`, names starting with `riscv`); otherwise SWD. A pod without the `jtag` feature raises + `UnsupportedFeatureError` before anything is armed. +- `Transport.dap_start()` takes `tck`, `tms`, `tdi`, `tdo`, `trst` and `port`; `swclk` and `swdio` + are optional when the JTAG pins are given. +- The bundled feature table is revision 16. + ## 4.0.3 For BenchPod firmware 4.0.3 (features `usb_host_mode`, `usb_flash`, `uart_usb`, `usb_check`, `usb_hid`, diff --git a/packages/embeddedci/README.md b/packages/embeddedci/README.md index 791f9c6..6b1d8ff 100644 --- a/packages/embeddedci/README.md +++ b/packages/embeddedci/README.md @@ -798,6 +798,7 @@ print(wiring.describe()) # a pin table: bias resistor and | `uart_parity`, `uart_stop_bits` | `"none"`, `1` | The UART frame after the 8 data bits (`"even"`, `"odd"`; 2 stop bits). `open_uart`, `capture_uart` and `power_cycle_and_capture` use it when `parity` / `stop_bits` are omitted; anything but 8N1 needs firmware 3.10.8+ | | `i2c_sda`, `i2c_scl`, `i2c_addr` | not wired, not wired, not set | the I2C bus (emulated sensors default to it; put I2C on LA1-LA6, which have pull-ups) | | `swd_swclk`, `swd_swdio`, `swd_nreset`, `swd_target` | not wired, not wired, `False`, `""` (auto-detect) | flashing | +| `jtag_tck`, `jtag_tms`, `jtag_tdi`, `jtag_tdo`, `jtag_trst` | not wired | JTAG flashing (firmware feature `jtag`); `jtag_trst` is optional. `jtag_tck` may share a channel with `swd_swclk` and `jtag_tms` with `swd_swdio` (the same pins on an ARM part); every other overlap is an error | | `spi_sclk`, `spi_mosi`, `spi_miso`, `spi_cs` | not wired | decoder channels | | `signals` | `[]` | named signals: `Signal(name, la, direction="input"/"output"/"open_drain"/"bidir", active_low=False, description="")` | | `dut_dirs` | `{}` | the DUT direction of a role or signal where its default is wrong: `{"uart_rx": "bidir", "READY": "dut_input"}` (role key or signal name to `dut_input`, `dut_output` or `bidir`); see [pin directions](#gpio-on-the-la-pins) | @@ -990,6 +991,16 @@ result = bp.flash(file="build/app.bin", load_address="0x08000000", assert result.ok, result.stderr # also: returncode, stdout, target_unreachable, stalled, artifact ``` +* **SWD or JTAG is chosen for you** (there is no transport option). `tck`, `tms`, `tdi`, `tdo` and + `trst` are the JTAG pins; omitted ones come from the profile's `jtag_*` fields. The flash uses + JTAG when all four JTAG pins are known and either no SWD pins are, or the target is JTAG only: + `esp32`, `esp32s2`, `gd32vf103`, `fe310`, `k210` and any name starting with `riscv` (the OpenOCD + config's file name, so `target/esp32.cfg` counts). Otherwise it uses SWD. With both wired, an ARM + target keeps SWD (faster). JTAG needs the pod's `jtag` feature (firmware with features table + revision 16, gateware v61 or later, not the emulation FPGA image) and raises + `UnsupportedFeatureError` before anything is armed without it. A bare `"esp32"` target (no + `target/` path) still flashes over the chip's UART bootloader. An uploaded build flashed by + embeddedci.com cannot use JTAG yet: pass `server_side=False`. * `nreset` is a flag, not a pin. With it, `connect_under_reset` defaults to `True`; without it, connect-under-reset is forced off (the pod cannot hold a reset it isn't wired to). * `verify=True` and `reset=True` map to OpenOCD's `program … verify reset`. `verify=False` is @@ -1550,8 +1561,8 @@ The connection never fails over it. The pod forgets the directions on a reboot; sends them again. Every wired role and signal has a direction. The defaults: `uart_rx` and `spi_miso` are DUT -outputs (the DUT drives them); `uart_tx`, `spi_sclk`, `spi_mosi`, `spi_cs` and `swd_swclk` DUT -inputs; the I2C pins and `swd_swdio` `bidir`; a signal with direction `input` (the pod watches it) +outputs (the DUT drives them); `uart_tx`, `spi_sclk`, `spi_mosi`, `spi_cs`, `swd_swclk`, `jtag_tck`, `jtag_tdi` and `jtag_trst` DUT +inputs; `jtag_tdo` a DUT output; the I2C pins, `swd_swdio` and `jtag_tms` `bidir`; a signal with direction `input` (the pod watches it) is a DUT output, `output` a DUT input, `open_drain` and `bidir` are `bidir`. So a pin's direction follows from what it is used for: set a signal's `direction` to change it. `wiring.dut_dir(name)` is one role's or signal's direction, `wiring.pin_dut_dirs()` the per-channel map. Profiles from older diff --git a/packages/embeddedci/src/embeddedci/benchpod/client.py b/packages/embeddedci/src/embeddedci/benchpod/client.py index 82c289d..1313434 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/client.py +++ b/packages/embeddedci/src/embeddedci/benchpod/client.py @@ -1843,6 +1843,11 @@ def flash( *, swclk: Union[Pin, int, str, None] = None, swdio: Union[Pin, int, str, None] = None, + tck: Union[Pin, int, str, None] = None, + tms: Union[Pin, int, str, None] = None, + tdi: Union[Pin, int, str, None] = None, + tdo: Union[Pin, int, str, None] = None, + trst: Union[Pin, int, str, None] = None, nreset: Optional[bool] = None, target: str = "", file: str = "", @@ -1867,9 +1872,15 @@ def flash( tx: Union[Pin, int, str, None] = None, boot: Union[Pin, int, str, None] = None, ) -> FlashResult: - """Flash an SWD target through the pod's CMSIS-DAP probe and report the result. - - ``swclk``/``swdio`` are LA pins (``benchpod.PIN1``..``PIN14`` or 1-14). ``nreset`` is a + """Flash a target over SWD or JTAG through the pod's CMSIS-DAP probe and report the result. + + ``swclk``/``swdio`` are LA pins (``benchpod.PIN1``..``PIN14`` or 1-14). ``tck``, ``tms``, + ``tdi``, ``tdo`` and ``trst`` are the JTAG pins (``trst`` is optional). The port is chosen + for you: JTAG when the pins for it are known (given, else the wiring profile's ``jtag_*``) + and either no SWD pins are or the target is JTAG only (:data:`~embeddedci.benchpod.flash. + JTAG_ONLY_TARGETS`: ``esp32``, ``esp32s2``, the RISC-V names); otherwise SWD. JTAG needs + the ``jtag`` firmware feature (:class:`UnsupportedFeatureError` before anything is armed). + ``nreset`` is a flag, not a pin: pass ``True`` when the target's reset line is wired to the pod's reset pin (DUT header J1 pin 22). ``target`` is an OpenOCD target config (``target/stm32f4x.cfg``) and ``file`` the image. ``target_power`` of @@ -1918,14 +1929,11 @@ def flash( raise FlashError(f"flash ({target or self.wiring.swd_target}): {result.stderr}") return result - swclk_i = self._wired(swclk, "swd_swclk") - swdio_i = self._wired(swdio, "swd_swdio") - if swclk_i == swdio_i: - raise ValueError("swclk and swdio must be different LA pins") if nreset is None: nreset = self.wiring.swd_nreset target = target or self.wiring.swd_target power = coerce_efuse(target_power) if target_power is not None else None + pins = self._flash_pins(swclk, swdio, tck, tms, tdi, tdo, trst, target) art: Optional[Dict[str, Any]] = None tmpdir = "" @@ -1936,8 +1944,11 @@ def flash( target = str((art.get("wiring_defaults") or {}).get("target") or "") use_server = bool(self._device_name) if server_side is None else server_side if use_server: + if pins["port"] == "jtag": + raise ValueError("embeddedci.com cannot flash over JTAG yet: pass server_side=False " + "to download the build and flash it with the local OpenOCD") result = self._flash_build_on_server( - api, art, swclk=swclk_i, swdio=swdio_i, nreset=bool(nreset), target=target, + api, art, swclk=pins["swclk"], swdio=pins["swdio"], nreset=bool(nreset), target=target, load_address=load_address, power=power, verify=verify, reset=reset, connect_under_reset=connect_under_reset, openocd_bin=openocd_bin, extra_configs=extra_configs, extra_args=extra_args, timeout=timeout) @@ -1955,7 +1966,7 @@ def flash( try: result = self._flash_local( - swclk=swclk_i, swdio=swdio_i, nreset=bool(nreset), target=target, file=file, + pins=pins, nreset=bool(nreset), target=target, file=file, load_address=load_address, power=power, verify=verify, reset=reset, connect_under_reset=connect_under_reset, clear_reset_events=clear_reset_events, openocd_bin=openocd_bin, extra_configs=extra_configs, extra_args=extra_args, @@ -2049,7 +2060,71 @@ def by_signal(names: Sequence[str]) -> Optional[int]: return FlashResult(ok=r.ok, returncode=0 if r.ok else 1, stdout="\n".join(lines), stderr=r.error) - def _flash_local(self, *, swclk: int, swdio: int, nreset: bool, target: str, file: str, + def _flash_pins(self, swclk: Any, swdio: Any, tck: Any, tms: Any, tdi: Any, tdo: Any, + trst: Any, target: str) -> Dict[str, Any]: + """The pins and port of a flash: ``swclk``, ``swdio``, ``tck``, ``tms``, ``tdi``, ``tdo``, + ``trst`` (None: not used) and ``port`` (``"swd"``/``"jtag"``, :func:`flash.select_port`). + A pin the caller passes beats the wiring profile's.""" + def optional(given: Sequence[Any], keys: Sequence[str]) -> List[Optional[int]]: + """The pins in ``given`` (else the profile's ``keys``); all None when none is set.""" + if all(g is None for g in given) and all(getattr(self.wiring, k) is None for k in keys): + return [None] * len(keys) + return [self._wired(g, k) for g, k in zip(given, keys)] + + swd_keys = ("swd_swclk", "swd_swdio") + jtag_keys = ("jtag_tck", "jtag_tms", "jtag_tdi", "jtag_tdo") + jtag_given = (tck, tms, tdi, tdo) + jtag_set = [g is not None or getattr(self.wiring, k) is not None + for g, k in zip(jtag_given, jtag_keys)] + if any(jtag_set) and not all(jtag_set): + missing = ", ".join(k for k, ok in zip(jtag_keys, jtag_set) if not ok) + raise ValueError(f"JTAG needs all of tck, tms, tdi and tdo: {missing} is not set (pass it or " + "set it in the wiring profile)") + swd = optional((swclk, swdio), swd_keys) + jtag = optional(jtag_given, jtag_keys) + have_swd, have_jtag = swd[0] is not None, jtag[0] is not None + if not have_swd and not have_jtag: + # name the pin like the SWD-only flash always did + self._wired(swclk, "swd_swclk") + port = _flash.select_port(swd=have_swd, jtag=have_jtag, target=target) + out: Dict[str, Any] = {"swclk": swd[0], "swdio": swd[1], "tck": None, "tms": None, + "tdi": None, "tdo": None, "trst": None, "port": port} + if have_swd and swd[0] == swd[1]: + raise ValueError("swclk and swdio must be different LA pins") + if port == "jtag": + out.update(zip(("tck", "tms", "tdi", "tdo"), jtag)) + out["trst"] = (self._resolve_la(trst, "jtag_trst")[0] if trst is not None + else self.wiring.jtag_trst) + names = {"tck": "tck", "tms": "tms", "tdi": "tdi", "tdo": "tdo", "trst": "trst"} + used: Dict[int, str] = {} + for name in names: + la = out[name] + if la is None: + continue + other = used.get(la) + # an ARM part's SWCLK/SWDIO are its TCK/TMS: the probe wires them once + if other is not None: + raise ValueError(f"{other} and {name} must be different LA pins") + used[la] = name + for swd_name, jtag_name in (("swclk", "tck"), ("swdio", "tms")): + la = out[swd_name] + if la is not None and la in used and used[la] != jtag_name: + raise ValueError(f"{swd_name} and {used[la]} must be different LA pins " + f"({swd_name} may only share a pin with {jtag_name})") + self._require_jtag() + return out + + def _require_jtag(self) -> None: + """Refuse ahead, in words, when the pod has no JTAG (firmware feature ``jtag``).""" + if self.supports("jtag"): + return + fw = self.capabilities.firmware_version or "unknown" + raise UnsupportedFeatureError( + f"JTAG needs newer pod firmware with the 'jtag' feature (and gateware v61+; not the " + f"emulation FPGA image); this pod runs firmware {fw}: update the pod", + feature="jtag", firmware_version=self.capabilities.firmware_version) + + def _flash_local(self, *, pins: Dict[str, Any], nreset: bool, target: str, file: str, load_address: str, power: Optional[Efuse], verify: bool, reset: bool, connect_under_reset: Optional[bool], clear_reset_events: bool, openocd_bin: Optional[str], extra_configs: Sequence[str], @@ -2057,7 +2132,9 @@ def _flash_local(self, *, swclk: int, swdio: int, nreset: bool, target: str, fil with _classified_errors(): return _flash.flash( self._transport, - swclk=swclk, swdio=swdio, nreset=nreset, + swclk=pins["swclk"], swdio=pins["swdio"], tck=pins["tck"], tms=pins["tms"], + tdi=pins["tdi"], tdo=pins["tdo"], trst=pins["trst"], port=pins["port"], + nreset=nreset, target=target, file=file, load_address=load_address, target_power=power, verify=verify, reset=reset, connect_under_reset=connect_under_reset, diff --git a/packages/embeddedci/src/embeddedci/benchpod/flash.py b/packages/embeddedci/src/embeddedci/benchpod/flash.py index 63e67ba..812b1de 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/flash.py +++ b/packages/embeddedci/src/embeddedci/benchpod/flash.py @@ -35,7 +35,9 @@ TARGET_ANSWER_WAIT_MS = 5000 # OpenOCD stderr substrings that mean the probe worked but no target answered. -_SWD_CONNECT_MARKERS = (b"cannot read IDR", b"Error connecting DP") +_SWD_CONNECT_MARKERS = (b"cannot read IDR", b"Error connecting DP", + # JTAG: an empty or floating chain + b"scan chain interrogation failed") # --- CMSIS-DAP-over-TCP framing (must match the firmware's PROTO_DAP frame and # OpenOCD's cmsis_dap_tcp backend; mirrors the Go CLI's internal/openocd/dap.go). @@ -168,11 +170,43 @@ def build_openocd_args( return args +#: OpenOCD targets whose debug port is JTAG only (no SWD): the flash path picks JTAG for them +#: whenever the wiring has JTAG pins. One place; a name is the target config's file name without +#: ``target/`` and ``.cfg`` (``target/esp32.cfg`` -> ``esp32``). Any name starting with +#: :data:`JTAG_ONLY_PREFIXES` counts too. +JTAG_ONLY_TARGETS = frozenset({"esp32", "esp32s2", "gd32vf103", "fe310", "k210"}) +JTAG_ONLY_PREFIXES = ("riscv",) + + +def target_is_jtag_only(target: str) -> bool: + """Whether the OpenOCD ``target`` config (``target/esp32.cfg``, ``esp32s2``) has JTAG only.""" + name = str(target).strip().replace("\\", "/").rsplit("/", 1)[-1].lower() + if name.endswith(".cfg"): + name = name[:-4] + return name in JTAG_ONLY_TARGETS or name.startswith(JTAG_ONLY_PREFIXES) + + +def select_port(*, swd: bool, jtag: bool, target: str = "") -> str: + """``"jtag"`` or ``"swd"`` for a flash. JTAG when all four JTAG pins are available (``jtag``) + and either no SWD pins are (``swd`` False) or the target is JTAG only; otherwise SWD. With + neither, raises :class:`ValueError`.""" + if not swd and not jtag: + raise ValueError("flash needs SWD pins (swclk, swdio) or JTAG pins (tck, tms, tdi, tdo): " + "pass them or set them in the wiring profile") + return "jtag" if jtag and (not swd or target_is_jtag_only(target)) else "swd" + + def flash( transport: Transport, *, - swclk: int, - swdio: int, + swclk: Optional[int] = None, + swdio: Optional[int] = None, + tck: Optional[int] = None, + tms: Optional[int] = None, + tdi: Optional[int] = None, + tdo: Optional[int] = None, + trst: Optional[int] = None, + port: str = "swd", nreset: bool = False, target: str = "", file: str = "", @@ -190,7 +224,10 @@ def flash( ) -> FlashResult: """Arm the CMSIS-DAP probe and run OpenOCD. Returns a :class:`FlashResult`. - ``swclk``/``swdio`` are LA channels 1-14 (already coerced by the caller). + ``swclk``/``swdio`` are LA channels 1-14 (already coerced by the caller). ``port="jtag"`` + arms the probe with ``tck``/``tms``/``tdi``/``tdo`` (and ``trst``) and has OpenOCD use JTAG + (``transport select jtag``); the SWD pins may be given too. The caller chooses the port + (:func:`select_port`). ``target_power`` of 1/2 enables that eFuse first; ``None`` leaves power untouched. @@ -210,6 +247,12 @@ def flash( """ if file and not target: raise ValueError("file= requires target=") + if port not in ("swd", "jtag"): + raise ValueError(f"port must be 'swd' or 'jtag', not {port!r}") + if port == "jtag" and None in (tck, tms, tdi, tdo): + raise ValueError("JTAG needs tck, tms, tdi and tdo") + if port == "swd" and (swclk is None or swdio is None): + raise ValueError("SWD needs swclk and swdio") nreset = bool(nreset) if connect_under_reset is None: connect_under_reset = nreset @@ -237,13 +280,18 @@ def flash( attempts = max(1, connect_attempts) result: Optional[FlashResult] = None for attempt in range(attempts): + pins: dict = {} + if port == "jtag": + pins = {"tck": tck, "tms": tms, "tdi": tdi, "tdo": tdo, "port": "jtag"} + if trst is not None: + pins["trst"] = trst pod_link = transport.dap_start( - swclk, swdio, packet_size=_DAP_MAX_PACKET, packet_count=_DAP_PACKET_COUNT, + swclk, swdio, packet_size=_DAP_MAX_PACKET, packet_count=_DAP_PACKET_COUNT, **pins, # Every attempt, not just the first: a retry after a target that answered too early # (a NUCLEO's ST-LINK still holding it) must wait for it to settle as well. wait_ms=TARGET_ANSWER_WAIT_MS if target_power is not None else None) try: - result = _run_bridge(bin_path, args, pod_link, timeout=timeout) + result = _run_bridge(bin_path, args, pod_link, timeout=timeout, transport=port) finally: pod_link.close() # Retry the transient, transport-level failures (no target on the wire, @@ -288,6 +336,7 @@ def _run_bridge( *, timeout: float, stall_timeout: float = 60.0, + transport: str = "swd", ) -> FlashResult: """Stand up a loopback listener, run OpenOCD's cmsis-dap TCP backend against it, and translate the per-packet framing both ways until OpenOCD exits.""" @@ -306,7 +355,7 @@ def _run_bridge( "-c", "cmsis-dap backend tcp", "-c", "cmsis-dap tcp host 127.0.0.1", "-c", f"cmsis-dap tcp port {port}", - "-c", "transport select swd", + "-c", f"transport select {transport}", *args, ] diff --git a/packages/embeddedci/tests/api_surface.json b/packages/embeddedci/tests/api_surface.json index 4ad70f2..01d8e85 100644 --- a/packages/embeddedci/tests/api_surface.json +++ b/packages/embeddedci/tests/api_surface.json @@ -131,7 +131,7 @@ "enable_pullup": "(self, *las: 'Union[Pin, int]') -> 'None'", "enabled_pulls": "(self) -> 'List[int]'", "expansion": "(self, chip: 'Optional[str]' = '', *, addr: 'Union[int, Sequence[int], None]' = None, sda: 'Union[Pin, int, str, None]' = None, scl: 'Union[Pin, int, str, None]' = None, spi: 'Union[Sequence[Union[Pin, int, str]], Mapping[str, Union[Pin, int, str]], None]' = None, load: 'Union[Pin, int, str, None]' = None, count: 'Optional[int]' = None, hz: 'Optional[int]' = None, pullups: 'Optional[str]' = None, names: 'Union[Mapping[Any, str], Sequence[Optional[str]], None]' = None) -> \"'_expansion.ExpansionStatus'\"", - "flash": "(self, *, swclk: 'Union[Pin, int, str, None]' = None, swdio: 'Union[Pin, int, str, None]' = None, nreset: 'Optional[bool]' = None, target: 'str' = '', file: 'str' = '', load_address: 'str' = '', target_power: 'Optional[Union[Efuse, int]]' = None, verify: 'bool' = True, reset: 'bool' = True, connect_under_reset: 'Optional[bool]' = None, clear_reset_events: 'bool' = True, openocd_bin: 'Optional[str]' = None, extra_configs: 'Sequence[str]' = (), extra_args: 'Sequence[str]' = (), timeout: 'float' = 300.0, connect_attempts: 'int' = 5, check: 'bool' = True, build: 'str' = '', repo: 'str' = '', ref: 'str' = '', artifact: 'str' = '', server_side: 'Optional[bool]' = None, rx: 'Union[Pin, int, str, None]' = None, tx: 'Union[Pin, int, str, None]' = None, boot: 'Union[Pin, int, str, None]' = None) -> 'FlashResult'", + "flash": "(self, *, swclk: 'Union[Pin, int, str, None]' = None, swdio: 'Union[Pin, int, str, None]' = None, tck: 'Union[Pin, int, str, None]' = None, tms: 'Union[Pin, int, str, None]' = None, tdi: 'Union[Pin, int, str, None]' = None, tdo: 'Union[Pin, int, str, None]' = None, trst: 'Union[Pin, int, str, None]' = None, nreset: 'Optional[bool]' = None, target: 'str' = '', file: 'str' = '', load_address: 'str' = '', target_power: 'Optional[Union[Efuse, int]]' = None, verify: 'bool' = True, reset: 'bool' = True, connect_under_reset: 'Optional[bool]' = None, clear_reset_events: 'bool' = True, openocd_bin: 'Optional[str]' = None, extra_configs: 'Sequence[str]' = (), extra_args: 'Sequence[str]' = (), timeout: 'float' = 300.0, connect_attempts: 'int' = 5, check: 'bool' = True, build: 'str' = '', repo: 'str' = '', ref: 'str' = '', artifact: 'str' = '', server_side: 'Optional[bool]' = None, rx: 'Union[Pin, int, str, None]' = None, tx: 'Union[Pin, int, str, None]' = None, boot: 'Union[Pin, int, str, None]' = None) -> 'FlashResult'", "fpga_image": "(self, image: 'Union[FpgaImage, int]') -> 'FpgaImageInfo'", "generate": "(self, waveform: 'Waveshape' = 'sine', *, freq_hz: 'float', amplitude: 'float', offset: 'Optional[float]' = None, dac_path: 'Optional[DacPath]' = None, duration: 'Optional[float]' = None, sample_rate_hz: 'Optional[float]' = None, on_capture: 'bool' = False, route: 'bool' = True) -> 'DacHandle'", "get_la_voltage": "(self) -> 'LaVoltage'", @@ -1545,6 +1545,11 @@ "swd_swdio", "swd_nreset", "swd_target", + "jtag_tck", + "jtag_tms", + "jtag_tdi", + "jtag_tdo", + "jtag_trst", "spi_sclk", "spi_mosi", "spi_miso", diff --git a/packages/embeddedci/tests/test_jtag.py b/packages/embeddedci/tests/test_jtag.py new file mode 100644 index 0000000..243c697 --- /dev/null +++ b/packages/embeddedci/tests/test_jtag.py @@ -0,0 +1,308 @@ +"""JTAG on the pod's CMSIS-DAP probe: the wiring fields, the dap_start JSON, the automatic +SWD/JTAG choice of flash(), and the OpenOCD arguments. No hardware.""" + +from __future__ import annotations + +import json +import types +from typing import Any, Dict, List + +import pytest + +from embeddedci.benchpod import BenchPod, flash as flashmod +from embeddedci.benchpod.errors import UnsupportedFeatureError +from embeddedci.benchpod.header import connections +from embeddedci.benchpod.transport.tcp import TcpTransport +from embeddedci.benchpod.wiring import Wiring + +from test_flash_bridge import FakePodLink +from test_tcp_transport import FakePod + + +# -- wiring fields ------------------------------------------------------------- + +JTAG = {"jtag_tck": 3, "jtag_tms": 4, "jtag_tdi": 5, "jtag_tdo": 6} + + +def test_jtag_fields_default_to_not_wired_and_round_trip(): + assert Wiring().jtag_tck is None and Wiring().jtag_trst is None + w = Wiring(la_mv=3300, **JTAG, jtag_trst=7) + d = w.to_dict() + assert (d["jtag_tck"], d["jtag_tms"], d["jtag_tdi"], d["jtag_tdo"], d["jtag_trst"]) == (3, 4, 5, 6, 7) + assert Wiring.from_dict(d) == w + assert Wiring.from_dict({"version": 2, "jtag_tck": 3}).jtag_tck == 3 + + +@pytest.mark.parametrize("key", ["jtag_tck", "jtag_tms", "jtag_tdi", "jtag_tdo", "jtag_trst"]) +@pytest.mark.parametrize("bad", [0, 15, "3", 3.5, True]) +def test_jtag_fields_must_be_la_channels(key, bad): + with pytest.raises(ValueError, match=f"{key} must be an LA channel 1..14"): + Wiring(**{key: bad}) + + +def test_jtag_pins_must_be_distinct(): + with pytest.raises(ValueError, match="LA3 is used by both jtag_tck and jtag_tdi"): + Wiring(jtag_tck=3, jtag_tdi=3) + with pytest.raises(ValueError, match="LA7 is used by both jtag_tdo and jtag_trst"): + Wiring(jtag_tdo=7, jtag_trst=7) + with pytest.raises(ValueError, match="LA3 is used by both uart_rx and jtag_tck"): + Wiring(uart_rx=3, jtag_tck=3) + + +def test_tck_may_share_swclk_and_tms_may_share_swdio_only(): + w = Wiring(swd_swclk=11, swd_swdio=12, jtag_tck=11, jtag_tms=12, jtag_tdi=5, jtag_tdo=6) + assert w.pins()[11] in ("swd_swclk", "jtag_tck") + with pytest.raises(ValueError, match="LA11 is used by both swd_swclk and jtag_tms"): + Wiring(swd_swclk=11, jtag_tms=11) + with pytest.raises(ValueError, match="LA12 is used by both swd_swdio and jtag_tck"): + Wiring(swd_swdio=12, jtag_tck=12) + with pytest.raises(ValueError, match="LA11 is used by both swd_swclk and jtag_tdi"): + Wiring(swd_swclk=11, jtag_tdi=11) + + +def test_jtag_roles_have_dut_directions_and_header_labels(): + w = Wiring(swd_swclk=11, swd_swdio=12, jtag_tck=11, jtag_tms=12, jtag_tdi=5, jtag_tdo=6) + assert w.dut_dir("jtag_tdo") == "dut_output" and w.dut_dir("jtag_tdi") == "dut_input" + assert w.pin_dut_dirs()[12] == "bidir" # shared with SWDIO + used = {c["name"]: c["used_for"] for c in connections(w)} + assert used["LA11"] == "SWCLK / TCK" and used["LA5"] == "TDI" and used["LA6"] == "TDO" + + +# -- dap_start JSON ---------------------------------------------------------------- + +def _dap_request(**kw: Any) -> Dict[str, Any]: + seen: List[bytes] = [] + + def handler(conn, line): + seen.append(line) + conn.sendall(b'{"status":"ok"}\n') + + pod = FakePod(handler) + try: + link = TcpTransport(pod.addr, timeout=2).dap_start(**kw) + link.close() + finally: + pod.close() + req = json.loads(seen[0]) + req.pop("client", None) + req.pop("client_api", None) + return req + + +def test_dap_start_swd_json_is_unchanged(): + assert _dap_request(swclk=11, swdio=12, packet_size=1, wait_ms=5) == { + "cmd": "dap_start", "swclk": 11, "swdio": 12, "packet_size": 1, "wait_ms": 5} + + +def test_dap_start_jtag_only_json(): + req = _dap_request(tck=3, tms=4, tdi=5, tdo=6, trst=7, packet_count=4) + assert req == {"cmd": "dap_start", "tck": 3, "tms": 4, "tdi": 5, "tdo": 6, "trst": 7, + "packet_count": 4} + + +def test_dap_start_both_sets_carry_the_port(): + req = _dap_request(swclk=11, swdio=12, tck=11, tms=12, tdi=5, tdo=6, port="jtag") + assert req["swclk"] == 11 and req["tck"] == 11 and req["port"] == "jtag" + # the port only matters when both are given + assert "port" not in _dap_request(tck=3, tms=4, tdi=5, tdo=6, port="jtag") + + +@pytest.mark.parametrize("kw, msg", [ + ({}, "needs swclk/swdio or tck"), + ({"swclk": 1}, "both swclk and swdio"), + ({"tck": 1, "tms": 2, "tdi": 3}, "missing tdo"), + ({"swclk": 1, "swdio": 2, "port": "x"}, "port must be"), +]) +def test_dap_start_refuses_incomplete_pins(kw, msg): + t = TcpTransport("127.0.0.1:9", timeout=1) + with pytest.raises(ValueError, match=msg): + t.dap_start(**kw) + + +# -- the automatic choice ---------------------------------------------------------- + +@pytest.mark.parametrize("target", ["esp32", "esp32s2", "target/esp32.cfg", "target/esp32s2.cfg", + "gd32vf103", "fe310", "k210", "target/riscv.cfg", "riscv", + "target/riscv-gd32.cfg", "TARGET/ESP32.CFG"]) +def test_jtag_only_targets(target): + assert flashmod.target_is_jtag_only(target) + + +@pytest.mark.parametrize("target", ["", "target/stm32f4x.cfg", "target/esp32c3.cfg", "esp32c3", + "target/esp32s3.cfg", "target/nrf52.cfg", "target/rp2040.cfg"]) +def test_swd_capable_targets(target): + assert not flashmod.target_is_jtag_only(target) + + +@pytest.mark.parametrize("swd, jtag, target, want", [ + (True, False, "target/stm32f4x.cfg", "swd"), + (True, False, "target/esp32.cfg", "swd"), # no JTAG pins: SWD + (False, True, "target/stm32f4x.cfg", "jtag"), # no SWD pins: JTAG + (True, True, "target/stm32f4x.cfg", "swd"), # both wired, ARM: SWD + (True, True, "target/esp32.cfg", "jtag"), # both wired, JTAG-only target + (True, True, "target/riscv.cfg", "jtag"), +]) +def test_select_port(swd, jtag, target, want): + assert flashmod.select_port(swd=swd, jtag=jtag, target=target) == want + + +def test_select_port_needs_some_pins(): + with pytest.raises(ValueError, match="SWD pins .* or JTAG pins"): + flashmod.select_port(swd=False, jtag=False) + + +class _Transport: + """Records dap_start calls; its link is quiet.""" + + def __init__(self) -> None: + self.calls: List[Dict[str, Any]] = [] + + def dap_start(self, *a: Any, **kw: Any) -> FakePodLink: + self.calls.append({"args": a, **kw}) + return FakePodLink() + + def target_power(self, *a: Any) -> None: + pass + + +@pytest.fixture +def fake_pod(monkeypatch): + """A BenchPod on a recording transport; the OpenOCD bridge is replaced by a recorder.""" + ports: List[str] = [] + + def bridge(openocd_bin, args, pod_link, *, timeout, transport="swd", **kw): + ports.append(transport) + return flashmod.FlashResult(ok=True, returncode=0, stdout="", stderr="") + + monkeypatch.setattr(flashmod, "_run_bridge", bridge) + monkeypatch.setattr(flashmod, "find_openocd", lambda b: "openocd") + monkeypatch.setattr(flashmod, "supports_cmsis_dap_tcp", lambda b: True) + monkeypatch.setattr(flashmod.time, "sleep", lambda s: None) + + class Pod: + def make(self, wiring: Dict[str, Any], jtag: bool = True) -> BenchPod: + self.t = _Transport() + bp = BenchPod(transport=self.t, lease=False, wiring=Wiring(la_mv=3300, **wiring)) + monkeypatch.setattr(BenchPod, "supports", lambda s, f: jtag if f == "jtag" else False) + monkeypatch.setattr(BenchPod, "capabilities", + types.SimpleNamespace(firmware_version="3.10.0")) + return bp + + def flash(self, bp: BenchPod, **kw: Any) -> str: + kw.setdefault("file", "fw.elf") + assert bp.flash(**kw).ok + return ports[-1] + + return Pod() + + +def test_swd_only_wiring_flashes_over_swd_as_before(fake_pod): + bp = fake_pod.make({"swd_swclk": 11, "swd_swdio": 12}) + assert fake_pod.flash(bp, target="target/stm32f4x.cfg") == "swd" + call = fake_pod.t.calls[0] + assert (call["args"][:2]) == (11, 12) and "tck" not in call and "port" not in call + + +def test_jtag_only_wiring_flashes_over_jtag(fake_pod): + bp = fake_pod.make(JTAG) + assert fake_pod.flash(bp, target="target/stm32f4x.cfg") == "jtag" + call = fake_pod.t.calls[0] + assert call["args"][:2] == (None, None) + assert {k: call[k] for k in ("tck", "tms", "tdi", "tdo", "port")} == { + "tck": 3, "tms": 4, "tdi": 5, "tdo": 6, "port": "jtag"} and "trst" not in call + + +def test_both_wired_uses_swd_for_arm_and_jtag_for_jtag_only_targets(fake_pod): + both = {"swd_swclk": 11, "swd_swdio": 12, "jtag_tck": 11, "jtag_tms": 12, "jtag_tdi": 5, + "jtag_tdo": 6, "jtag_trst": 7} + bp = fake_pod.make(both) + assert fake_pod.flash(bp, target="target/stm32f4x.cfg") == "swd" + assert "tck" not in fake_pod.t.calls[0] + assert fake_pod.flash(bp, target="target/esp32.cfg") == "jtag" + call = fake_pod.t.calls[1] + assert call["args"][:2] == (11, 12) + assert (call["tck"], call["tms"], call["tdi"], call["tdo"], call["trst"], call["port"]) == ( + 11, 12, 5, 6, 7, "jtag") + + +def test_explicit_pins_override_the_wiring(fake_pod): + bp = fake_pod.make({"swd_swclk": 11, "swd_swdio": 12}) + # JTAG pins passed, SWD wired, ARM target: SWD still wins by the rule + fake_pod.flash(bp, target="target/stm32f4x.cfg", tck=1, tms=2, tdi=3, tdo=4) + assert "tck" not in fake_pod.t.calls[0] + # ... but a JTAG-only target picks JTAG with the passed pins + fake_pod.flash(bp, target="target/riscv.cfg", tck=1, tms=2, tdi=3, tdo=4, trst=9) + call = fake_pod.t.calls[1] + assert (call["tck"], call["tms"], call["tdi"], call["tdo"], call["trst"]) == (1, 2, 3, 4, 9) + assert call["args"][:2] == (11, 12) + # swclk/swdio passed explicitly beat the wiring too + fake_pod.flash(bp, target="target/stm32f4x.cfg", swclk=8, swdio=9) + assert fake_pod.t.calls[2]["args"][:2] == (8, 9) + + +def test_jtag_without_the_feature_is_refused_before_arming(fake_pod): + bp = fake_pod.make(JTAG, jtag=False) + with pytest.raises(UnsupportedFeatureError) as e: + bp.flash(target="target/stm32f4x.cfg", file="fw.elf") + assert e.value.feature == "jtag" + assert fake_pod.t.calls == [] + + +def test_swd_flash_does_not_need_the_jtag_feature(fake_pod): + bp = fake_pod.make({"swd_swclk": 11, "swd_swdio": 12}, jtag=False) + fake_pod.flash(bp, target="target/stm32f4x.cfg") + assert len(fake_pod.t.calls) == 1 + + +def test_jtag_pin_problems(fake_pod): + with pytest.raises(ValueError, match="all of tck, tms, tdi and tdo: jtag_tdo"): + fake_pod.make({"jtag_tck": 3, "jtag_tms": 4, "jtag_tdi": 5}).flash(target="x.cfg", file="f") + with pytest.raises(ValueError, match="tck and tdi must be different"): + fake_pod.make(JTAG).flash(target="x.cfg", file="f", tdi=3) + with pytest.raises(ValueError, match="swclk may only share a pin with tck"): + fake_pod.make({"swd_swclk": 11, "swd_swdio": 12, **JTAG}).flash( + target="target/riscv.cfg", file="f", tms=11) + with pytest.raises(ValueError, match="swclk was not given"): + fake_pod.make({}).flash(target="x.cfg", file="f") + + +@pytest.mark.parametrize("port", ["swd", "jtag"]) +def test_openocd_gets_the_transport_for_the_port(monkeypatch, port): + seen: List[List[str]] = [] + + class Boom(Exception): + pass + + def popen(args, **kw): + seen.append(list(args)) + raise Boom + + monkeypatch.setattr(flashmod.subprocess, "Popen", popen) + with pytest.raises(Boom): + flashmod._run_bridge("openocd", ["-f", "target/stm32f4x.cfg"], FakePodLink(), timeout=1, + transport=port) + argv = seen[0] + assert f"transport select {port}" in argv + assert f"transport select {'jtag' if port == 'swd' else 'swd'}" not in argv + assert argv.index(f"transport select {port}") < argv.index("-f") + assert "adapter driver cmsis-dap" in argv and "cmsis-dap backend tcp" in argv + + +def test_flash_passes_the_port_to_the_bridge_default_swd(monkeypatch): + seen: Dict[str, Any] = {} + + def bridge(openocd_bin, args, pod_link, **kw): + seen.update(kw) + return flashmod.FlashResult(ok=True, returncode=0, stdout="", stderr="") + + monkeypatch.setattr(flashmod, "_run_bridge", bridge) + monkeypatch.setattr(flashmod, "find_openocd", lambda b: "openocd") + monkeypatch.setattr(flashmod, "supports_cmsis_dap_tcp", lambda b: True) + flashmod.flash(_Transport(), swclk=1, swdio=2, target="t.cfg", file="f") + assert seen["transport"] == "swd" + flashmod.flash(_Transport(), tck=1, tms=2, tdi=3, tdo=4, port="jtag", target="t.cfg", file="f") + assert seen["transport"] == "jtag" + with pytest.raises(ValueError, match="JTAG needs"): + flashmod.flash(_Transport(), swclk=1, swdio=2, port="jtag", target="t.cfg", file="f") + with pytest.raises(ValueError, match="SWD needs"): + flashmod.flash(_Transport(), tck=1, tms=2, tdi=3, tdo=4, target="t.cfg", file="f") From e104251cad1a7f1d94bb672822297a948a60a4e6 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Mon, 23 Nov 2026 13:57:11 -0600 Subject: [PATCH 4/5] MCP: jtag wiring fields and JTAG pins on the flash tool; tests, docs Co-Authored-By: Claude Sonnet 5.5 --- packages/embeddedci-mcp/CHANGELOG.md | 10 ++ packages/embeddedci-mcp/README.md | 2 +- .../src/embeddedci_mcp/server.py | 40 +++++- .../embeddedci-mcp/tests/test_wiring_tools.py | 52 ++++++++ .../embeddedci-mcp/tests/tools_surface.json | 119 +++++++++++++++++- 5 files changed, 215 insertions(+), 8 deletions(-) diff --git a/packages/embeddedci-mcp/CHANGELOG.md b/packages/embeddedci-mcp/CHANGELOG.md index 303ce29..22bfbf5 100644 --- a/packages/embeddedci-mcp/CHANGELOG.md +++ b/packages/embeddedci-mcp/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog — `embeddedci-mcp` +## 4.0.4 + +For BenchPod firmware with the `jtag` feature; JTAG flashing needs embeddedci 4.0.4 (the tool says so on an older SDK). + +- **JTAG flashing.** `flash` takes `tck`, `tms`, `tdi`, `tdo` and `trst` (LA channels or wiring names; + omitted ones come from the profile's `jtag_tck`, `jtag_tms`, `jtag_tdi`, `jtag_tdo`, `jtag_trst`). + There is no transport argument: JTAG is used when the four JTAG pins are known and either no SWD + pins are, or the target is JTAG only (`esp32`, `esp32s2`, `gd32vf103`, `fe310`, `k210`, names + starting with `riscv`); otherwise SWD. `set_wiring` and `wiring` carry the new `jtag_*` fields. + ## 4.0.3 For BenchPod firmware 4.0.3; needs embeddedci 4.0.3. diff --git a/packages/embeddedci-mcp/README.md b/packages/embeddedci-mcp/README.md index 0d620cb..c13c77f 100644 --- a/packages/embeddedci-mcp/README.md +++ b/packages/embeddedci-mcp/README.md @@ -233,7 +233,7 @@ description, ranges and enums, so an agent sees more than this table. | Tool | Purpose | Parameters | | --- | --- | --- | -| `flash` | Program the DUT over SWD through the pod's CMSIS-DAP probe: a local `file` (OpenOCD runs next to the server), or a build uploaded to embeddedci.com (`build` id or `latest`, `repo`, `ref`; embeddedci.com runs OpenOCD on a cloud connection, LAN/USB downloads it). With `target` `esp32` (or `esp32s3`, `esp32c3`, ...) the pod flashes an ESP32-family target over its UART ROM bootloader instead: `file` is a `.bin` or an ESP-IDF `flasher_args.json`, TXD0/RXD0 on `rx`/`tx` (default: the profile's `uart_rx`/`uart_tx`), IO0 on `boot`, EN on the pod's reset pin (`nreset`), a `.bin` at `load_address`. | `swclk`, `swdio`, `target`, `file`, `nreset`, `load_address`, `target_power`, `verify=true`, `reset=true`, `connect_under_reset`, `extra_configs`, `extra_args`, `timeout_s=300`, `connect_attempts=5`, `build`, `repo`, `ref`, `artifact`, `server_side`, `rx`, `tx`, `boot` | +| `flash` | Program the DUT over SWD or JTAG through the pod's CMSIS-DAP probe (JTAG is picked when the wiring has `jtag_tck`, `jtag_tms`, `jtag_tdi` and `jtag_tdo` and there are no SWD pins, or the target is JTAG only: `esp32`, `esp32s2`, `gd32vf103`, `fe310`, `k210`, `riscv*`; needs the pod's `jtag` feature): a local `file` (OpenOCD runs next to the server), or a build uploaded to embeddedci.com (`build` id or `latest`, `repo`, `ref`; embeddedci.com runs OpenOCD on a cloud connection, LAN/USB downloads it). With `target` `esp32` (or `esp32s3`, `esp32c3`, ...) the pod flashes an ESP32-family target over its UART ROM bootloader instead: `file` is a `.bin` or an ESP-IDF `flasher_args.json`, TXD0/RXD0 on `rx`/`tx` (default: the profile's `uart_rx`/`uart_tx`), IO0 on `boot`, EN on the pod's reset pin (`nreset`), a `.bin` at `load_address`. | `swclk`, `swdio`, `tck`, `tms`, `tdi`, `tdo`, `trst`, `target`, `file`, `nreset`, `load_address`, `target_power`, `verify=true`, `reset=true`, `connect_under_reset`, `extra_configs`, `extra_args`, `timeout_s=300`, `connect_attempts=5`, `build`, `repo`, `ref`, `artifact`, `server_side`, `rx`, `tx`, `boot` | | `usb_flash` | Flash the board on the pod's USB host port, the way a computer would (pod firmware 4.0.3+, LAN or cloud). The loader comes from the file and the board that mounted: a UF2 or drag-and-drop drive (Pico, Adafruit, DAPLink), DFU or the STM32 ROM loader, Teensy, Arduino AVR and SAMD, ESP32; `reason` in the result says why. `.hex` and `.dfu` files are converted to a binary with their address. A Pico (RP2040, RP2350) in BOOTSEL gets a `.bin` or `.hex` through PICOBOOT (every page read back); `verify` reads a drive back (`FAIL.TXT`, `CURRENT.UF2`) and the result's `note` says what it found. A drive flash sets the file's date from this computer's clock. Starts host mode when it is off. | **`file`**, `address`, `name`, `leave=true`, `mode`, `port`, `timeout_s`, `verify=false` | | `usb_check` | Check the board's own USB firmware on the pod's host port (pod firmware 4.0.3+, LAN or cloud): `enumerate` (power-on to pull-up, descriptor and mounted over `count` power cycles), `power` (current against `bMaxPower`), `suspend` (suspended current against 2.5 mA, resume, still answers), `reset` (port resets and the time to enumerate again), `replug` (VBUS dropouts of `off_ms`). The board's VBUS must come from the internal 5 V (efuse 1) rail, switched on (`power_on`). Returns when the check ends: `passed` is the verdict, `result` the numbers (uA, ms); a failing board is a normal result. Starts host mode when it is off. | **`test`**, `count`, `off_ms`, `timeout_ms`, `duration_ms`, `settle_ms`, `port`, `timeout_s` | | `usb_hid` | The HID interfaces of the board on the pod's host port and its input reports (keyboard keys, mouse, gamepad; pod firmware 4.0.3+, `usb_host` first): `list` the interfaces with their report descriptors, `start` a capture into a ring of 64 on the pod, `read` reports from it, `stop` it. The capture ends when the board detaches or host mode ends. | `action=list`, `count=1`, `timeout_s=2`, `instance` | diff --git a/packages/embeddedci-mcp/src/embeddedci_mcp/server.py b/packages/embeddedci-mcp/src/embeddedci_mcp/server.py index 390e487..efde94f 100644 --- a/packages/embeddedci-mcp/src/embeddedci_mcp/server.py +++ b/packages/embeddedci-mcp/src/embeddedci_mcp/server.py @@ -581,7 +581,9 @@ def _pod_wiring_state(pod: Any, result: m.WiringResult) -> m.WiringResult: "Once the user confirms this wiring is right on the board, ask whether to save it: " "save_wiring() for this profile, save_wiring(name=...) for another board.") roles = [k for k in result.unsaved_changes if k in ("uart_rx", "uart_tx", "i2c_sda", "i2c_scl", - "swd_swclk", "swd_swdio", "spi_sclk", "spi_mosi", + "swd_swclk", "swd_swdio", "jtag_tck", "jtag_tms", + "jtag_tdi", "jtag_tdo", "jtag_trst", + "spi_sclk", "spi_mosi", "spi_miso", "spi_cs", "signals")] if any(k in _NEVER_AUTOSAVE for k in result.unsaved_changes) or len(roles) >= 4: result.hint += (" This looks like a different board (I/O voltage, power rail, SWD target or " @@ -621,7 +623,7 @@ def op() -> m.WiringResult: async def set_wiring( profile: Annotated[Dict[str, Any], Field(description=( "The profile as a JSON object (schema version 2): la_mv, efuse, uart_rx/uart_tx/uart_baud, " - "i2c_sda/i2c_scl/i2c_addr, swd_swclk/swd_swdio/swd_nreset/swd_target, spi_*, and signals " + "i2c_sda/i2c_scl/i2c_addr, swd_swclk/swd_swdio/swd_nreset/swd_target, jtag_tck/jtag_tms/jtag_tdi/jtag_tdo/jtag_trst, spi_*, and signals " "[{name, la, direction, active_low, description}], pulls (the pull resistors power_on switches " "on, the others off: {\"1\": \"up\", \"2\": \"up\", \"8\": \"down\"}, or a list of channels " "that pull their own way, e.g. [1, 2]; today LA1-LA6 pull up, LA7/LA8 down; left out: " @@ -1066,12 +1068,23 @@ async def i2c_close() -> m.I2cSessionResult: # -- flash ------------------------------------------------------------------------------ -@mcp.tool(annotations=_ann("Flash firmware over SWD", destructive=True)) +@mcp.tool(annotations=_ann("Flash firmware over SWD or JTAG", destructive=True)) async def flash( swclk: Annotated[Optional[LaRef], Field(description=( "LA channel (or wiring name) wired to the DUT's SWCLK; omit for the profile's swd_swclk."))] = None, swdio: Annotated[Optional[LaRef], Field(description=( "LA channel (or wiring name) wired to the DUT's SWDIO; omit for the profile's swd_swdio."))] = None, + tck: Annotated[Optional[LaRef], Field(description=( + "JTAG: LA channel (or wiring name) wired to the DUT's TCK; omit for the profile's jtag_tck."))] = None, + tms: Annotated[Optional[LaRef], Field(description=( + "JTAG: LA channel (or wiring name) wired to the DUT's TMS; omit for the profile's jtag_tms."))] = None, + tdi: Annotated[Optional[LaRef], Field(description=( + "JTAG: LA channel (or wiring name) wired to the DUT's TDI; omit for the profile's jtag_tdi."))] = None, + tdo: Annotated[Optional[LaRef], Field(description=( + "JTAG: LA channel (or wiring name) wired to the DUT's TDO; omit for the profile's jtag_tdo."))] = None, + trst: Annotated[Optional[LaRef], Field(description=( + "JTAG: LA channel (or wiring name) wired to the DUT's nTRST (optional); omit for the " + "profile's jtag_trst."))] = None, target: Annotated[str, Field(description=( "OpenOCD target config, e.g. target/stm32f4x.cfg; omit for the profile's swd_target. " "'esp32' (or esp32s3, esp32c3, ...) flashes an ESP32-family target over its UART ROM " @@ -1117,7 +1130,13 @@ async def flash( "omit for a profile signal named BOOT, IO0 or IO9."))] = None, ctx: Context = None, # type: ignore[assignment] ) -> m.FlashResult: - """Program the DUT over SWD through the pod's CMSIS-DAP probe. + """Program the DUT over SWD or JTAG through the pod's CMSIS-DAP probe. + + SWD or JTAG is chosen for you, there is no transport argument: JTAG when the four JTAG pins + (`tck`, `tms`, `tdi`, `tdo`, from the arguments or the profile's jtag_*) are known and either + no SWD pins are, or the target is JTAG only (esp32, esp32s2, gd32vf103, fe310, k210 and riscv* + OpenOCD configs, e.g. target/esp32.cfg); otherwise SWD. JTAG needs the pod's `jtag` feature + (newer firmware): without it the call fails before anything is armed. Give either `file` (a path on this server's host) or an uploaded build (`build`, or `repo`/`ref` for the newest build of a branch). OpenOCD runs on this server's host, except for @@ -1156,8 +1175,19 @@ def op() -> m.FlashResult: if from_build and "build" not in inspect.signature(pod.flash).parameters: raise ValueError("flashing an uploaded build (build/repo/ref/artifact) needs a newer " "embeddedci SDK; upgrade embeddedci, or pass file= with a local image") + jtag_args = {k: _la(pod, v) for k, v in (("tck", tck), ("tms", tms), ("tdi", tdi), + ("tdo", tdo), ("trst", trst)) if v is not None} + if jtag_args and "tck" not in inspect.signature(pod.flash).parameters: + raise ValueError("flashing over JTAG needs a newer embeddedci SDK; upgrade embeddedci") + if "tck" in inspect.signature(pod.flash).parameters: + # the SDK picks SWD or JTAG from the pins and the target + pins: Dict[str, Any] = {"swclk": None if swclk is None else _la(pod, swclk), + "swdio": None if swdio is None else _la(pod, swdio), **jtag_args} + else: + pins = {"swclk": _channel(pod, swclk, "swd_swclk"), + "swdio": _channel(pod, swdio, "swd_swdio")} result = pod.flash( - swclk=_channel(pod, swclk, "swd_swclk"), swdio=_channel(pod, swdio, "swd_swdio"), + **pins, nreset=pod.wiring.swd_nreset if nreset is None else nreset, target=target or pod.wiring.swd_target, file=file, load_address=load_address, target_power=target_power, verify=verify, reset=reset, diff --git a/packages/embeddedci-mcp/tests/test_wiring_tools.py b/packages/embeddedci-mcp/tests/test_wiring_tools.py index 574f2a5..62b0122 100644 --- a/packages/embeddedci-mcp/tests/test_wiring_tools.py +++ b/packages/embeddedci-mcp/tests/test_wiring_tools.py @@ -193,3 +193,55 @@ def test_wiring_draws_the_profile_on_the_pods_header(connected, monkeypatch): monkeypatch.setattr(type(pod), "board_header", lambda self: None) result = call("wiring") assert result["board_header"] is None and "both are shown" in result["header_map"] + + +JTAG_PROFILE = {"jtag_tck": 3, "jtag_tms": 4, "jtag_tdi": 5, "jtag_tdo": 6, "jtag_trst": 7} + + +def test_set_wiring_takes_and_returns_the_jtag_fields(connected): + result = call("set_wiring", profile={"version": 2, "la_mv": 3300, **JTAG_PROFILE}) + for key, la in JTAG_PROFILE.items(): + assert result["profile"][key] == la + assert {p["la"]: p["wired_to"] for p in result["pins"]}[5] == "jtag_tdi" + assert SESSION.require().wiring.jtag_tdo == 6 + + +def test_set_wiring_validates_the_jtag_fields(connected): + with pytest.raises(ToolError, match="jtag_tck must be an LA channel 1..14"): + call("set_wiring", profile={"version": 2, "jtag_tck": 15}) + with pytest.raises(ToolError, match="LA3 is used by both jtag_tck and jtag_tdi"): + call("set_wiring", profile={"version": 2, "jtag_tck": 3, "jtag_tdi": 3}) + # TCK/TMS may share the SWD pins + call("set_wiring", profile={"version": 2, "swd_swclk": 11, "swd_swdio": 12, "jtag_tck": 11, + "jtag_tms": 12, "jtag_tdi": 5, "jtag_tdo": 6}) + + +def test_flash_passes_jtag_pins_and_leaves_the_choice_to_the_sdk(connected, monkeypatch): + from embeddedci.benchpod.flash import FlashResult + + seen = {} + + def fake_flash(*, swclk=None, swdio=None, tck=None, tms=None, tdi=None, tdo=None, trst=None, + **kwargs): + seen.update(swclk=swclk, swdio=swdio, tck=tck, tms=tms, tdi=tdi, tdo=tdo, trst=trst, **kwargs) + return FlashResult(ok=True, returncode=0, stdout="", stderr="") + + _set() + monkeypatch.setattr(SESSION.require(), "flash", fake_flash) + assert call("flash", file="a.elf", target="target/riscv.cfg", tck=3, tms=4, tdi=5, tdo=6, + trst=7)["ok"] is True + assert (seen["tck"], seen["tms"], seen["tdi"], seen["tdo"], seen["trst"]) == (3, 4, 5, 6, 7) + # nothing passed: the SDK reads the profile (the tool does not pick a port) + seen.clear() + call("flash", file="a.elf") + assert seen["swclk"] is None and seen["tck"] is None and "transport" not in seen + + +def test_flash_jtag_pins_need_a_new_sdk(connected, monkeypatch): + def old_flash(**kwargs): + raise AssertionError("not reached") + + _set() + monkeypatch.setattr(SESSION.require(), "flash", old_flash) + with pytest.raises(ToolError, match="JTAG needs a newer embeddedci SDK"): + call("flash", file="a.elf", tck=3, tms=4, tdi=5, tdo=6) diff --git a/packages/embeddedci-mcp/tests/tools_surface.json b/packages/embeddedci-mcp/tests/tools_surface.json index ea1583a..b38602c 100644 --- a/packages/embeddedci-mcp/tests/tools_surface.json +++ b/packages/embeddedci-mcp/tests/tools_surface.json @@ -2514,7 +2514,7 @@ "idempotentHint": false, "openWorldHint": false, "readOnlyHint": false, - "title": "Flash firmware over SWD" + "title": "Flash firmware over SWD or JTAG" }, "input": { "properties": { @@ -2749,6 +2749,75 @@ "description": "Power this rail on before flashing: internal 5 V (efuse 1) or external (efuse 2).", "title": "Target Power" }, + "tck": { + "anyOf": [ + { + "anyOf": [ + { + "maximum": 14, + "minimum": 1, + "type": "integer" + }, + { + "type": "string" + } + ], + "description": "LA channel 1-14, or a name from the wiring profile \u2014 a signal ('READY') or a role ('uart_rx', 'i2c_sda', 'swd_swclk'). Call `wiring` to see the names. The gpio_* tools also take expander pins ('EXT1') once one is attached (expansion)." + }, + { + "type": "null" + } + ], + "default": null, + "description": "JTAG: LA channel (or wiring name) wired to the DUT's TCK; omit for the profile's jtag_tck.", + "title": "Tck" + }, + "tdi": { + "anyOf": [ + { + "anyOf": [ + { + "maximum": 14, + "minimum": 1, + "type": "integer" + }, + { + "type": "string" + } + ], + "description": "LA channel 1-14, or a name from the wiring profile \u2014 a signal ('READY') or a role ('uart_rx', 'i2c_sda', 'swd_swclk'). Call `wiring` to see the names. The gpio_* tools also take expander pins ('EXT1') once one is attached (expansion)." + }, + { + "type": "null" + } + ], + "default": null, + "description": "JTAG: LA channel (or wiring name) wired to the DUT's TDI; omit for the profile's jtag_tdi.", + "title": "Tdi" + }, + "tdo": { + "anyOf": [ + { + "anyOf": [ + { + "maximum": 14, + "minimum": 1, + "type": "integer" + }, + { + "type": "string" + } + ], + "description": "LA channel 1-14, or a name from the wiring profile \u2014 a signal ('READY') or a role ('uart_rx', 'i2c_sda', 'swd_swclk'). Call `wiring` to see the names. The gpio_* tools also take expander pins ('EXT1') once one is attached (expansion)." + }, + { + "type": "null" + } + ], + "default": null, + "description": "JTAG: LA channel (or wiring name) wired to the DUT's TDO; omit for the profile's jtag_tdo.", + "title": "Tdo" + }, "timeout_s": { "default": 300.0, "exclusiveMinimum": 0, @@ -2756,6 +2825,52 @@ "title": "Timeout S", "type": "number" }, + "tms": { + "anyOf": [ + { + "anyOf": [ + { + "maximum": 14, + "minimum": 1, + "type": "integer" + }, + { + "type": "string" + } + ], + "description": "LA channel 1-14, or a name from the wiring profile \u2014 a signal ('READY') or a role ('uart_rx', 'i2c_sda', 'swd_swclk'). Call `wiring` to see the names. The gpio_* tools also take expander pins ('EXT1') once one is attached (expansion)." + }, + { + "type": "null" + } + ], + "default": null, + "description": "JTAG: LA channel (or wiring name) wired to the DUT's TMS; omit for the profile's jtag_tms.", + "title": "Tms" + }, + "trst": { + "anyOf": [ + { + "anyOf": [ + { + "maximum": 14, + "minimum": 1, + "type": "integer" + }, + { + "type": "string" + } + ], + "description": "LA channel 1-14, or a name from the wiring profile \u2014 a signal ('READY') or a role ('uart_rx', 'i2c_sda', 'swd_swclk'). Call `wiring` to see the names. The gpio_* tools also take expander pins ('EXT1') once one is attached (expansion)." + }, + { + "type": "null" + } + ], + "default": null, + "description": "JTAG: LA channel (or wiring name) wired to the DUT's nTRST (optional); omit for the profile's jtag_trst.", + "title": "Trst" + }, "tx": { "anyOf": [ { @@ -5274,7 +5389,7 @@ "properties": { "profile": { "additionalProperties": true, - "description": "The profile as a JSON object (schema version 2): la_mv, efuse, uart_rx/uart_tx/uart_baud, i2c_sda/i2c_scl/i2c_addr, swd_swclk/swd_swdio/swd_nreset/swd_target, spi_*, and signals [{name, la, direction, active_low, description}], pulls (the pull resistors power_on switches on, the others off: {\"1\": \"up\", \"2\": \"up\", \"8\": \"down\"}, or a list of channels that pull their own way, e.g. [1, 2]; today LA1-LA6 pull up, LA7/LA8 down; left out: power_on leaves the pulls as they are). What it leaves out is undefined (not wired); a pin set to null is not wired. {\"version\": 1} objects fill in the old default pins.", + "description": "The profile as a JSON object (schema version 2): la_mv, efuse, uart_rx/uart_tx/uart_baud, i2c_sda/i2c_scl/i2c_addr, swd_swclk/swd_swdio/swd_nreset/swd_target, jtag_tck/jtag_tms/jtag_tdi/jtag_tdo/jtag_trst, spi_*, and signals [{name, la, direction, active_low, description}], pulls (the pull resistors power_on switches on, the others off: {\"1\": \"up\", \"2\": \"up\", \"8\": \"down\"}, or a list of channels that pull their own way, e.g. [1, 2]; today LA1-LA6 pull up, LA7/LA8 down; left out: power_on leaves the pulls as they are). What it leaves out is undefined (not wired); a pin set to null is not wired. {\"version\": 1} objects fill in the old default pins.", "title": "Profile", "type": "object" }, From 9978e74ed70d3a73b2286058b666562709f74b3e Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Mon, 23 Nov 2026 14:36:25 -0600 Subject: [PATCH 5/5] MCP tests: the jtag wiring tests skip on an SDK without the jtag_* fields (mcp-min-sdk) Co-Authored-By: Claude Opus 5.5 --- packages/embeddedci-mcp/tests/test_wiring_tools.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/embeddedci-mcp/tests/test_wiring_tools.py b/packages/embeddedci-mcp/tests/test_wiring_tools.py index 62b0122..14184f9 100644 --- a/packages/embeddedci-mcp/tests/test_wiring_tools.py +++ b/packages/embeddedci-mcp/tests/test_wiring_tools.py @@ -196,8 +196,13 @@ def test_wiring_draws_the_profile_on_the_pods_header(connected, monkeypatch): JTAG_PROFILE = {"jtag_tck": 3, "jtag_tms": 4, "jtag_tdi": 5, "jtag_tdo": 6, "jtag_trst": 7} +# The wiring fields are validated by the SDK: the mcp-min-sdk job runs these against the oldest +# SDK the MCP supports, which may predate them. +needs_jtag_sdk = pytest.mark.skipif(not hasattr(Wiring, "jtag_tck"), + reason="the installed embeddedci SDK has no jtag_* wiring fields") +@needs_jtag_sdk def test_set_wiring_takes_and_returns_the_jtag_fields(connected): result = call("set_wiring", profile={"version": 2, "la_mv": 3300, **JTAG_PROFILE}) for key, la in JTAG_PROFILE.items(): @@ -206,6 +211,7 @@ def test_set_wiring_takes_and_returns_the_jtag_fields(connected): assert SESSION.require().wiring.jtag_tdo == 6 +@needs_jtag_sdk def test_set_wiring_validates_the_jtag_fields(connected): with pytest.raises(ToolError, match="jtag_tck must be an LA channel 1..14"): call("set_wiring", profile={"version": 2, "jtag_tck": 15})