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
14 changes: 14 additions & 0 deletions packages/embeddedci-mcp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog — `embeddedci-mcp`

## Unreleased

For BenchPod firmware with the `prog_flash` feature; needs the matching embeddedci (the tool says so on an older SDK).

- **`flash` takes the pin-programmer targets** `avr-updi`, `pic`, `efm8`, `attiny-tpi` and `xmega`
(`updi`, `c2`, `tpi` and `pdi` work too): the pod flashes AVR tinyAVR/megaAVR/DA/DB/DD, PIC16F1xxx,
PIC16F18xxx and PIC18F Q-series, Silicon Labs EFM8 and C8051F, ATtiny4/5/9/10/20/40/102/104 and
XMEGA chips over their own programming pins from a `.hex`, `.elf` or `.bin`. New arguments: `device`
(name the chip; omitted, its ID decides), `clk`, `data` and `reset_pin` (LA pins or wiring names; default
a profile signal named for the protocol, else `swd_swclk` / `swd_swdio`), `erase` (`chip`, `page`,
`none`) and `dry_run` (only read the chip's ID: a wiring test). A failure is `ok=false` with
what to check in `stderr_tail`. The server instructions describe the flow. The ATtiny4/5/9/10/20/40
need 5 V, which the pod cannot give.

## 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).
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 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*`; the wiring profile's `debug_port` (`swd` or `jtag`) picks for a board wired for both, and JTAG or SWD pins passed in the call beat it; 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` |
| `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*`; the wiring profile's `debug_port` (`swd` or `jtag`) picks for a board wired for both, and JTAG or SWD pins passed in the call beat it; 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`. With `target` `avr-updi` (tinyAVR 0/1/2, megaAVR 0, AVR DA/DB/DD), `pic` (PIC16F1xxx, PIC16F18xxx, PIC18F Q), `efm8` (Silicon Labs EFM8, C8051F), `attiny-tpi` (ATtiny4/5/9/10/20/40/102/104) or `xmega` (also `updi`, `c2`, `tpi`, `pdi`) the pod flashes a chip over its own programming pins (pod firmware with `prog_flash`, the `xip_prog` blob installed): `file` is a `.hex`, `.elf` or `.bin`, the chip is identified by its ID and the image cut into its memories (flash, EEPROM, fuses, user row), `device` names the chip to check, pins come from `clk`, `data`, `reset_pin` or wiring signals named for the protocol (else `swd_swclk`/`swd_swdio`; the reset of `pic` and `attiny-tpi` is the pod's reset pin), `erase` is `chip` (default), `page` or `none`, `dry_run` only reads the chip's ID. The ATtiny4/5/9/10/20/40 need 5 V, which the pod cannot give. | `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`, `device`, `clk`, `data`, `reset_pin`, `erase=chip`, `dry_run=false` |
| `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
1 change: 1 addition & 0 deletions packages/embeddedci-mcp/src/embeddedci_mcp/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

Typical flows:
- Flash and boot: flash(file) then power_cycle_and_capture(until_regex) — with a wiring profile that is all; otherwise pass swclk, swdio, target, nreset and rx, tx.
- Flash a chip over its own programming pins (firmware with `prog_flash`, no SWD or bootloader needed): flash(target='avr-updi' | 'pic' | 'efm8' | 'attiny-tpi' | 'xmega', file=.hex/.elf/.bin). The pod runs UPDI (tinyAVR 0/1/2, megaAVR 0, AVR DA/DB/DD), PIC ICSP (PIC16F1xxx, PIC16F18xxx, PIC18F Q), C2 (Silicon Labs EFM8, C8051F), TPI (ATtiny4/5/9/10/20/40/102/104) or PDI (XMEGA) itself and the SDK splits the image into the chip's memories (flash, EEPROM, fuses, user row). Pins: a wiring-profile signal named for the protocol (UPDI, ICSPCLK/ICSPDAT, C2CK/C2D, TPICLK/TPIDATA, PDI_CLK/PDI_DATA, MCLR) or swd_swclk/swd_swdio, or pass clk, data, reset_pin; pic and attiny-tpi use the pod's reset pin (nreset). Run flash(..., dry_run=true) first: it only reads the chip's ID. erase is 'chip' by default (unlocks a locked chip, erases it); device names the chip when you want the check. ATtiny4/5/9/10/20/40 need 5 V, which the pod cannot give. A failure says what to check; the xip_prog blob (`benchpod install-blobs`) must be installed.
- SPI flash (a 25-series chip on four LA pins, wiring spi_sclk/spi_mosi/spi_miso/spi_cs): spi_flash_info to see it answers, then spi_flash_program(file, addr); hold_reset=true keeps the DUT off the bus. spi_transfer talks to any other SPI device.
- Flash over USB (firmware 4.0.3+, LAN or cloud, not connection 'usb'): the pod hosts the board's USB port (digital v3r4: its USB-A port; older pods: USB-C through a breakout). usb_host reads or starts host mode and reports the device that enumerated; usb_flash(file) starts host mode itself and picks the loader from the file and the board: UF2 or drag-and-drop drive (Pico, Adafruit, DAPLink), DFU and the STM32 ROM loader, Teensy, Arduino AVR and SAMD, ESP32 (`reason` says why; .hex and .dfu files are converted). There is no mode to choose; the board must already be in its bootloader where it needs a button (Pico BOOTSEL, STM32 BOOT0, Teensy). connected=false in usb_host means no D+/D- link; line_speed 'low' means D+/D- are swapped. A Pico in BOOTSEL gets a .bin or .hex through PICOBOOT (every page read back); verify=true reads a drive back (FAIL.TXT, CURRENT.UF2). The board's serial port is a UART like any other: uart_open(port='usb') or capture_uart(port='usb') (baud, dtr, rts; no pins) reads its boot log over the cable it was flashed through. usb_check(test) measures the board's own USB firmware with its VBUS on the internal 5 V (efuse 1) rail (power_on first): enumerate, power, suspend, reset, replug; passed false is a result. usb_hid(action) lists the board's HID interfaces and catches its input reports: list, start, read, stop.
- I2C master (gateware v55+): set_pull(la=[sda, scl], pull="up"), i2c_open, then i2c_transfer(addr, write_hex, read) or i2c_scan; i2c_close. capture_la(send={...}) runs one I2C, SPI or gpio transaction right after the capture arms and triggers on it. la_dir marks DUT outputs so the pod never drives against them; connect and set_wiring send the wiring profile's directions, so this is on by default.
Expand Down
70 changes: 68 additions & 2 deletions packages/embeddedci-mcp/src/embeddedci_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ def _is_esp_target(target: str) -> bool:
return bool(re.fullmatch(r"esp32(-?(s2|s3|c2|c3|c5|c6|h2|p4))?", str(target).strip().lower()))


#: ``flash(target=...)`` names for chips with their own programming pins (the SDK's prog.TARGETS).
_PROG_TARGETS = frozenset({"avr-updi", "updi", "pic", "efm8", "c2", "attiny-tpi", "tpi", "xmega", "pdi"})


def _is_prog_target(target: str) -> bool:
return str(target).strip().lower() in _PROG_TARGETS


def _channel(pod: Any, value: Any, key: str) -> int:
"""Like :func:`_la`, but an omitted channel comes from the profile's ``key`` role."""
if value is not None:
Expand Down Expand Up @@ -1089,11 +1097,16 @@ async def flash(
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 "
"bootloader instead of SWD."))] = "",
"bootloader instead of SWD. 'avr-updi' (tinyAVR 0/1/2, megaAVR 0, AVR DA/DB/DD), 'pic' "
"(PIC16F1xxx, PIC16F18xxx, PIC18F Q), 'efm8' (Silicon Labs EFM8, C8051F), 'attiny-tpi' "
"(ATtiny4/5/9/10/20/40/102/104) and 'xmega' flash a chip over its own programming pins "
"instead (updi, pic, c2, tpi and pdi work too)."))] = "",
file: Annotated[str, Field(description=(
"Firmware image path on the machine running this server. Leave empty to flash an uploaded "
"build instead (build/repo/ref/artifact). For an ESP32: a .bin written at 0 (esptool "
"merge_bin) or an ESP-IDF build/flasher_args.json."))] = "",
"merge_bin) or an ESP-IDF build/flasher_args.json. For avr-updi, pic, efm8, attiny-tpi and "
"xmega: a .hex, .elf or .bin (a .bin goes at load_address into the flash). Empty is fine "
"with dry_run."))] = "",
nreset: Annotated[Optional[bool], Field(description=(
"The target's reset line is wired to the pod's reset pin: enables connect-under-reset. "
"Omit for the profile's swd_nreset."))] = None,
Expand Down Expand Up @@ -1129,6 +1142,27 @@ async def flash(
boot: Annotated[Optional[LaRef], Field(description=(
"ESP32 only: LA channel (or wiring name) wired to the target's IO0 (IO9 on the C3/C6); "
"omit for a profile signal named BOOT, IO0 or IO9."))] = None,
device: Annotated[str, Field(description=(
"avr-updi, pic, efm8, attiny-tpi, xmega: the chip, e.g. 'ATtiny1616' or 'PIC16F18446'. "
"Omit: the chip's ID identifies it. Given, the ID must match."))] = "",
clk: Annotated[Optional[LaRef], Field(description=(
"pic, efm8, attiny-tpi, xmega: LA channel (or wiring name) wired to the chip's clock "
"(ICSPCLK, C2CK, TPICLK, PDI_CLK); omit for a profile signal of that name, else swd_swclk."))] = None,
data: Annotated[Optional[LaRef], Field(description=(
"avr-updi, pic, efm8, attiny-tpi, xmega: LA channel (or wiring name) wired to the chip's "
"data pin (UPDI, ICSPDAT, C2D, TPIDATA, PDI_DATA); omit for a profile signal of that name, "
"else swd_swdio."))] = None,
reset_pin: Annotated[Optional[LaRef], Field(description=(
"pic and attiny-tpi: LA channel (or wiring name) wired to the chip's reset (MCLR, RESET), "
"driven open drain; omit for the pod's reset pin (nreset) or a profile signal named MCLR "
"or RESET."))] = None,
erase: Annotated[Literal["chip", "page", "none"], Field(description=(
"avr-updi, pic, efm8, attiny-tpi, xmega: 'chip' (default, before the first write when the "
"image has flash; also unlocks a locked chip), 'page' (only the pages written; TPI chips "
"erase their whole code section) or 'none'."))] = "chip",
dry_run: Annotated[bool, Field(description=(
"avr-updi, pic, efm8, attiny-tpi, xmega: only enter programming mode and read the chip's "
"ID (a wiring test): stdout_tail names the chip, nothing is written."))] = False,
ctx: Context = None, # type: ignore[assignment]
) -> m.FlashResult:
"""Program the DUT over SWD or JTAG through the pod's CMSIS-DAP probe.
Expand All @@ -1152,6 +1186,21 @@ async def flash(
(`nreset`); `file` is a .bin written at `load_address` (default 0) or an ESP-IDF
flasher_args.json. No OpenOCD or esptool needed; works over the cloud too. stdout_tail names
the chip and each region written; `reset` false leaves the target in its loader.

A chip with its own programming pins and no SWD, JTAG or bootloader is flashed by the pod:
target 'avr-updi' (AVR tinyAVR 0/1/2, megaAVR 0, AVR DA/DB/DD, one pin), 'pic' (PIC16F1xxx,
PIC16F18xxx, PIC18F Q-series, low-voltage entry), 'efm8' (Silicon Labs EFM8 and C8051F, C2),
'attiny-tpi' (ATtiny4/5/9/10/20/40/102/104) or 'xmega' (XMEGA, PDI). `file` is a .hex, .elf or
.bin; the tool reads the chip's ID, finds it in its device table, cuts the image into the
chip's memories (flash, EEPROM, fuses or configuration words, user row or user ID) at their
usual hex addresses and writes and reads back each page. Pins come from `clk`, `data` and
`reset_pin`, else from wiring-profile signals named for the protocol (ICSPCLK, C2CK, UPDI, ...),
else the profile's swd_swclk and swd_swdio; pic and attiny-tpi also use the pod's reset pin
(`nreset`, the default) for MCLR or RESET. `erase` is 'chip' by default; `dry_run` only reads
the chip's ID (check the wiring first). ATtiny4/5/9/10/20/40 need 5 V, which the pod's 1.8 and
3.3 V I/O cannot give: the call fails before anything is written. A failure is ok=false with
stderr_tail saying what to check (wiring, power, locked chip: erase 'chip' unlocks it). Needs
firmware with the `prog_flash` feature and the xip_prog blob (`benchpod install-blobs`).
"""
from_build = {k: v for k, v in (("build", build), ("repo", repo), ("ref", ref),
("artifact", artifact)) if v}
Expand All @@ -1160,6 +1209,23 @@ async def flash(

def op() -> m.FlashResult:
pod = SESSION.require()
if _is_prog_target(target):
if from_build:
raise ValueError(f"{target} is flashed from a file (a .hex, .elf or .bin), not an "
"uploaded build")
if "dry_run" not in inspect.signature(type(pod).flash).parameters:
raise ValueError(f"flashing with target {target} needs a newer embeddedci SDK; "
"upgrade embeddedci")
r = pod.flash(target=target, file=file, load_address=load_address, nreset=nreset,
reset=reset, check=False, target_power=target_power, device=device,
clk=None if clk is None else _la(pod, clk),
data=None if data is None else _la(pod, data),
reset_pin=None if reset_pin is None else _la(pod, reset_pin),
erase=erase, dry_run=dry_run)
return m.FlashResult(ok=r.ok, returncode=r.returncode,
target_unreachable=r.target_unreachable, stalled=False,
stdout_tail=clip(r.stdout, 4000)[-4000:],
stderr_tail=clip(r.stderr, 4000)[-4000:])
if _is_esp_target(target or pod.wiring.swd_target):
if from_build:
raise ValueError("an ESP32 target is flashed from a file (a .bin or "
Expand Down
Loading