Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/embeddedci-mcp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/embeddedci-mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
40 changes: 35 additions & 5 deletions packages/embeddedci-mcp/src/embeddedci_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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: "
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
58 changes: 58 additions & 0 deletions packages/embeddedci-mcp/tests/test_wiring_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,61 @@ 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}
# 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():
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


@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})
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)
Loading