From e3cf86ad907338cc3afbeac6da4b8d7958267358 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Tue, 24 Nov 2026 14:48:48 -0600 Subject: [PATCH 1/6] embeddedci: sync features table revision 18 (bus_masters_image) Co-Authored-By: Claude Opus 5.5 --- .../src/embeddedci/benchpod/feature_map.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/embeddedci/src/embeddedci/benchpod/feature_map.json b/packages/embeddedci/src/embeddedci/benchpod/feature_map.json index 242ab2c..c833cfc 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": 17, + "revision": 18, "api": 2, "min_client_api": 2, - "table_sha256": "5aaea199ff12e34b1c1958a91d549b6c9a63828a15286b5a00dcb463d1f3f46e", + "table_sha256": "d091e10e802d2e64bc3183257e23bd5995c13e01d7742268264c4dd22224f413", "floor": "3.9.2", "docs_base": "https://github.com/embeddedci-com/benchpod-firmware/blob/main/docs/", "facts": { @@ -857,6 +857,13 @@ "firmware": "4.0.4", "board": "any", "docs": "API.md#prog_flash--flash-a-chip-over-its-programming-pins" + }, + "bus_masters_image": { + "rev": 18, + "firmware": "next", + "gateware": 65, + "board": "any", + "docs": "API.md#fpga_image--switch-the-running-gateware-image" } } } From 40dad35f60fc4ca64a003dd5f5737bd013bfe074 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Tue, 24 Nov 2026 14:57:26 -0600 Subject: [PATCH 2/6] embeddedci: switch the emulation image (gateware v65) before the bus masters has_bus_masters() and _ensure_bus_masters(): SWD/JTAG flash, SPI, I2C, expansion and capture_la(send) switch to the loop image when no sensor runs, raise BP0059 when one does. Co-Authored-By: Claude Opus 5.5 --- .../src/embeddedci/benchpod/client.py | 60 ++++++++++++++ packages/embeddedci/tests/api_surface.json | 1 + .../embeddedci/tests/test_image_switching.py | 80 +++++++++++++++++++ packages/embeddedci/tests/test_jtag.py | 2 +- 4 files changed, 142 insertions(+), 1 deletion(-) diff --git a/packages/embeddedci/src/embeddedci/benchpod/client.py b/packages/embeddedci/src/embeddedci/benchpod/client.py index 6d60e27..76f6e96 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/client.py +++ b/packages/embeddedci/src/embeddedci/benchpod/client.py @@ -188,6 +188,12 @@ FpgaImage.EMULATION: "sensors_digital"} _IMAGE_FEATURE = {FpgaImage.LOOP: 0x01, FpgaImage.DEEP_REPLAY: 0x02, FpgaImage.EMULATION: 0x04} +#: The first gateware whose emulation image has no bus masters (SWD, JTAG, SPI master, I2C +#: master), and the FPGA_FEATURES bit that says an image has them (loop and deep do, emulation +#: does not). Older gateware has them in every image. +BUS_MASTERS_SPLIT_GATEWARE = 65 +_FEATURE_BUS_MASTERS = 0x20 + #: Pre-trigger samples a capture with a ``send`` keeps, so the decoder sees the first START (an #: edge trigger fires on that START itself; without them the first message is lost). _SEND_PRE_SAMPLES = 64 @@ -1986,6 +1992,7 @@ def flash( 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) + self._ensure_bus_masters("JTAG" if pins["port"] == "jtag" else "SWD") art: Optional[Dict[str, Any]] = None tmpdir = "" @@ -3212,6 +3219,7 @@ def _start_spi(self, sck: int, mosi: int, miso: int, cs: int, *, hz: int, mode: int) -> _spi.SpiSession: """``spi_start`` on four resolved channels (open_spi, and an expander's own session).""" self._require_capability("spi_master", "the SPI master") + self._ensure_bus_masters("the SPI master") req = {"cmd": "spi_start", "sck": sck, "mosi": mosi, "miso": miso, "cs": cs, "clock_hz": int(hz), "mode": int(mode)} stage = getattr(self._transport, "stage_psram", None) @@ -3257,6 +3265,7 @@ def _start_i2c(self, sda: int, scl: int, *, hz: int, pullups: str) -> _i2c_maste if isinstance(hz, bool) or not _i2c_master.HZ_MIN <= int(hz) <= _i2c_master.HZ_MAX: raise ValueError(f"hz must be {_i2c_master.HZ_MIN}..{_i2c_master.HZ_MAX}, got {hz!r}") self._require_gateware(BUS_MASTER_GATEWARE, "the I2C master") + self._ensure_bus_masters("the I2C master") req = {"cmd": "i2c_start", "sda": sda, "scl": scl, "clock_hz": int(hz), "pullups": pullups} if req["sda"] == req["scl"]: raise ValueError("sda and scl must be different LA pins") @@ -3508,6 +3517,9 @@ def _send_request(self, send: Any) -> Dict[str, Any]: raise ValueError(f"send must be an I2CSend, SpiSend or GpioSend, got {send!r}") req = send.to_request() self._require_gateware(BUS_MASTER_GATEWARE, "send and capture") + if not isinstance(send, _i2c_master.GpioSend): + self._ensure_bus_masters("the I2C master" if isinstance(send, _i2c_master.I2CSend) + else "the SPI master") return req def capture_correlated(self, *, adc_samples: int = 4096, @@ -3885,6 +3897,53 @@ def _ensure_image(self, image: FpgaImage, *, needed_for: str, self._wait_for_server_caps(flag) return info + # -- bus masters (not in the emulation image from gateware v65) ------------ + + def has_bus_masters(self) -> Optional[bool]: + """Whether the running gateware image has the bus masters (SWD, JTAG, the SPI master and + the I2C master): always on gateware before v65; from v65 on the loop and deep-replay + images have them and the emulation image does not. ``None`` when the pod does not say.""" + caps = self.capabilities + if 0 < caps.gateware < BUS_MASTERS_SPLIT_GATEWARE: + return True + if caps.gateware >= BUS_MASTERS_SPLIT_GATEWARE and caps.fpga_image in ("loop", "deep"): + return True + running = self._running_image() + if running is None or running.version <= 0: + return None + if running.version < BUS_MASTERS_SPLIT_GATEWARE: + return True + return bool(running.features & _FEATURE_BUS_MASTERS) + + def _ensure_bus_masters(self, feature: str) -> Optional[FpgaImageInfo]: + """Before ``feature`` (``"SWD"``, ``"JTAG"``, ``"the SPI master"``, ``"the I2C master"``) + runs: make sure the running gateware image has the bus masters. + + Nothing to do on gateware before v65 or on the loop and deep-replay images. On the + emulation image of gateware v65+ with digital sensors running, raises the + ``BP0059`` :class:`~embeddedci.benchpod.errors.UnsupportedFeatureError` (stop the sensors + first, or do this before starting them); with none running, switches the pod to the loop + image (~3 s, logged) and returns that switch's :class:`FpgaImageInfo`. + """ + if self.has_bus_masters() is not False: + return None + digital = self.sensors.running_digital() + if digital: + from .errors import firmware_error + + exc = firmware_error("", cmd=feature, code="BP0059", + values={"feature": feature, "image": "loop"}) + exc.args = (f"{exc}; the emulated sensors running now are {', '.join(digital)} " + f"(or do this before starting them)",) + raise exc + info = self._ensure_image(FpgaImage.LOOP, needed_for=feature, switch=True) + if info is None: # a single-image pod: nothing to switch to + return None + if not info.features & _FEATURE_BUS_MASTERS and info.version >= BUS_MASTERS_SPLIT_GATEWARE: + raise BenchPodError(f"switched the FPGA to the loop image for {feature}, but the image " + f"that booted has no bus masters (features=0x{info.features:02x})") + return info + def _running_image(self) -> Optional[FpgaImageInfo]: """The image the iCE40 runs (``{"cmd":"fpga_image"}``), None when the pod does not say.""" try: @@ -4684,6 +4743,7 @@ def expansion( f"{info.name} addresses with addr=[...] instead") n_chips = 1 addrs = self._expansion_addrs(info, addr if addr is not None else block.get("addr")) + self._ensure_bus_masters("the I2C master" if info.bus == "i2c" else "the SPI master") self._detach_expansion() new = _expansion.Expansion(self, info, addrs=addrs, count=n_chips, la=la_map, hz=hz_i, pullups=pull, names={}) diff --git a/packages/embeddedci/tests/api_surface.json b/packages/embeddedci/tests/api_surface.json index a0d838e..bf6573e 100644 --- a/packages/embeddedci/tests/api_surface.json +++ b/packages/embeddedci/tests/api_surface.json @@ -137,6 +137,7 @@ "get_la_voltage": "(self) -> 'LaVoltage'", "gpio": "(self, la: 'Union[Pin, int, str]', mode: 'GpioMode' = 'output', *, level: 'Optional[int]' = None) -> 'GpioPin'", "gpio_pins": "(self, las: 'Sequence[Union[Pin, int, str]]', mode: 'GpioMode' = 'output', *, level: 'Optional[int]' = None) -> 'List[GpioPin]'", + "has_bus_masters": "(self) -> 'Optional[bool]'", "la_dir": "(self, la: 'Union[Pin, int, str, Sequence[Union[Pin, int, str]], None]' = None, dir: 'Optional[str]' = None) -> 'List[LaPinState]'", "la_pins": "(self, la: 'Union[Pin, int, str, Sequence[Union[Pin, int, str]], None]' = None) -> 'List[LaPinState]'", "la_step": "(self, la: 'Union[Pin, int]', *, steps: 'int', delay: 'float', dir_la: 'Optional[Union[Pin, int]]' = None, direction: 'int' = 0) -> 'Dict[str, Any]'", diff --git a/packages/embeddedci/tests/test_image_switching.py b/packages/embeddedci/tests/test_image_switching.py index c8d596a..2dfb56b 100644 --- a/packages/embeddedci/tests/test_image_switching.py +++ b/packages/embeddedci/tests/test_image_switching.py @@ -335,3 +335,83 @@ def test_esp_flash_on_the_deep_replay_image_does_not_switch(tmp_path, monkeypatc pod = EspImagePod(1) assert _flash_esp(pod, tmp_path).ok assert not any(c["cmd"] == "fpga_image" and "image" in c for c in pod.commands) + + +# -- bus masters (gateware v65: not in the emulation image) -------------------------------- + +class SplitPod(ImagePod): + """An ImagePod whose gateware is ``gateware``; from v65 only loop (0x29) and deep (0x2a) + have the bus masters (feature bit 0x20), emulation (0x04) does not.""" + + def __init__(self, image: int, gateware: int) -> None: + super().__init__(image=image) + self.gateware = gateware + + def status(self) -> Dict[str, Any]: + return dict(super().status(), gateware=self.gateware) + + def command(self, req: dict) -> Any: + if req["cmd"] == "fpga_image": + out = super().command(req) + if isinstance(out, dict): + loops = {0: 0x29, 1: 0x2A, 2: 0x04} + out = dict(out, version=self.gateware, + features=loops[self.image] if self.gateware >= 65 else 1 << self.image) + return out + if req["cmd"] == "spi_start": + self.commands.append(req) + return {"active": True} + return super().command(req) + + +def test_has_bus_masters_by_gateware_and_image(): + assert _bp(SplitPod(2, 64)).has_bus_masters() is True + assert _bp(SplitPod(2, 65)).has_bus_masters() is False + assert _bp(SplitPod(0, 65)).has_bus_masters() is True + assert _bp(SplitPod(1, 65)).has_bus_masters() is True + + +def test_bus_master_use_on_the_emulation_image_with_sensors_running_is_refused(): + from embeddedci.benchpod.errors import UnsupportedFeatureError + + pod = SplitPod(2, 65) + pod.sensors = [{"instance": "env", "kind": "i2c", "running": True}] + with pytest.raises(UnsupportedFeatureError, match=r"the SPI master.*env") as info: + _bp(pod)._ensure_bus_masters("the SPI master") + assert info.value.code == "BP0059" and info.value.feature == "the SPI master" + assert "bp.sensors.stop()" in str(info.value) + assert {"cmd": "fpga_image", "image": 0} not in pod.commands + + +def test_bus_master_use_on_the_emulation_image_without_sensors_switches_to_loop_once(caplog): + pod = SplitPod(2, 65) + bp = _bp(pod) + with caplog.at_level(logging.WARNING, logger="embeddedci.benchpod"): + info = bp._ensure_bus_masters("SWD") + assert info is not None and info.image == FpgaImage.LOOP + assert bp._ensure_bus_masters("SWD") is None + assert pod.commands.count({"cmd": "fpga_image", "image": 0}) == 1 + assert "switching the FPGA to the LOOP gateware image" in caplog.text + + +def test_bus_master_use_on_the_loop_or_deep_image_does_nothing(): + for image in (0, 1): + pod = SplitPod(image, 65) + assert _bp(pod)._ensure_bus_masters("SWD") is None + assert not [c for c in pod.commands if "image" in c] + + +def test_bus_master_use_on_gateware_64_emulation_does_nothing(): + pod = SplitPod(2, 64) + pod.sensors = [{"instance": "env", "kind": "i2c", "running": True}] + assert _bp(pod)._ensure_bus_masters("SWD") is None + assert not [c for c in pod.commands if "image" in c] + + +def test_open_spi_switches_the_emulation_image_before_spi_start(): + pod = SplitPod(2, 65) + bp = _bp(pod) + bp.open_spi(sck=1, mosi=2, miso=3, cs=4) + cmds = pod.cmds() + assert cmds.index("fpga_image") < cmds.index("spi_start") + assert {"cmd": "fpga_image", "image": 0} in pod.commands diff --git a/packages/embeddedci/tests/test_jtag.py b/packages/embeddedci/tests/test_jtag.py index be5ba57..7fd1f17 100644 --- a/packages/embeddedci/tests/test_jtag.py +++ b/packages/embeddedci/tests/test_jtag.py @@ -185,7 +185,7 @@ def make(self, wiring: Dict[str, Any], jtag: bool = True) -> BenchPod: 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")) + types.SimpleNamespace(firmware_version="3.10.0", gateware=64)) return bp def flash(self, bp: BenchPod, **kw: Any) -> str: From 16160980d7f21ca98d1e1f0467ecd03009dc1eda Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Tue, 24 Nov 2026 14:57:26 -0600 Subject: [PATCH 3/6] embeddedci: benchpod_capability spi_master/i2c_master leave the emulation image Co-Authored-By: Claude Opus 5.5 --- .../src/embeddedci/benchpod/pytest_plugin.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/embeddedci/src/embeddedci/benchpod/pytest_plugin.py b/packages/embeddedci/src/embeddedci/benchpod/pytest_plugin.py index f635132..2e6d6fb 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/pytest_plugin.py +++ b/packages/embeddedci/src/embeddedci/benchpod/pytest_plugin.py @@ -243,7 +243,9 @@ def pytest_configure(config: "pytest.Config") -> None: "markers", "benchpod_capability(name): skip the test unless the connected device advertises the " "given capability (e.g. 'scope', 'analyzer', 'dac_replay'); 'dac_control_loop' and " - "'dac_deep_replay' switch the gateware image when the pod carries both; 'analog' skips " + "'dac_deep_replay' switch the gateware image when the pod carries both; 'spi_master' and " + "'i2c_master' switch from the emulation image to the loop image (gateware v65+: " + "it has no bus masters) and skip while emulated sensors run; 'analog' skips " "on the digital-only board (firmware that does not say counts as analog).", ) @@ -251,6 +253,10 @@ def pytest_configure(config: "pytest.Config") -> None: #: Capabilities that come with one gateware image, and that image. _IMAGE_CAPABILITIES = {"dac_control_loop": "LOOP", "dac_deep_replay": "DEEP_REPLAY"} +#: Capabilities that need the bus masters, which the emulation image lacks from gateware v65, and +#: the name the SDK gives the feature in its refusal. +_BUS_MASTER_CAPABILITIES = {"spi_master": "the SPI master", "i2c_master": "the I2C master"} + @pytest.fixture(autouse=True) def _benchpod_capability_gate(request: "pytest.FixtureRequest") -> None: @@ -261,6 +267,8 @@ def _benchpod_capability_gate(request: "pytest.FixtureRequest") -> None: ``benchpod`` device and skips on any capability it lacks — except an image-bound one (``dac_control_loop`` / ``dac_deep_replay``) on a pod that carries both gateware images, which is switched to the right image instead, as the SDK does for ``control_loop`` / ``replay``. + ``spi_master`` and ``i2c_master`` switch the emulation image (gateware v65+, no bus + masters) to the loop image, and skip when emulated sensors run. ``analog`` follows :attr:`BenchPod.can_analog`: only the digital-only board skips it. """ if request.node.get_closest_marker("hardware") and not _resolve_connection(request.config): @@ -279,6 +287,14 @@ def _benchpod_capability_gate(request: "pytest.FixtureRequest") -> None: pytest.skip("digital-only board: no analog front end (DAC, ADC, 4-20 mA)") continue if getattr(caps, name, False): + feature = _BUS_MASTER_CAPABILITIES.get(name) + if feature is not None: + from .errors import UnsupportedFeatureError + + try: + pod._ensure_bus_masters(feature) + except UnsupportedFeatureError as exc: + pytest.skip(f"{exc}") continue image = _IMAGE_CAPABILITIES.get(name) if image is not None and (caps.dac_control_loop or caps.dac_deep_replay From 0af098f495bd83d4b60433ee85e2bf7e9d137d82 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Tue, 24 Nov 2026 14:57:26 -0600 Subject: [PATCH 4/6] embeddedci e2e: SPI tier stops sensors and selects the loop image first Co-Authored-By: Claude Opus 5.5 --- packages/embeddedci/tests/e2e/test_e2e_spi.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/embeddedci/tests/e2e/test_e2e_spi.py b/packages/embeddedci/tests/e2e/test_e2e_spi.py index 0b35b32..fbbc781 100644 --- a/packages/embeddedci/tests/e2e/test_e2e_spi.py +++ b/packages/embeddedci/tests/e2e/test_e2e_spi.py @@ -18,7 +18,7 @@ import pytest -from embeddedci.benchpod import FirmwareError, PinConflictError +from embeddedci.benchpod import FirmwareError, FpgaImage, PinConflictError pytestmark = pytest.mark.hardware @@ -31,6 +31,12 @@ def spi_pins(pod, bench): pytest.skip("set BENCHPOD_E2E_SPI=sck,mosi,miso,cs to run the SPI flash tier") if not pod.capabilities.spi_master: pytest.skip("the pod has no SPI master (gateware v45+, capability spi_master)") + # The sensor tests before this module leave the emulation image loaded, which has no SPI + # master from gateware v65: stop the sensors and go back to the loop image. + if pod.has_bus_masters() is False: + if pod.supports("sensors"): + pod.sensors.stop() + pod.fpga_image(FpgaImage.LOOP) sck, mosi, miso, cs = bench.spi return dict(sck=sck, mosi=mosi, miso=miso, cs=cs) From 50824948b9b9927e491000dde0513af476f86fc3 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Tue, 24 Nov 2026 14:57:27 -0600 Subject: [PATCH 5/6] embeddedci-mcp: say the emulation image has no bus masters (gateware v65) Co-Authored-By: Claude Opus 5.5 --- .../src/embeddedci_mcp/guide.py | 2 +- .../src/embeddedci_mcp/server.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/embeddedci-mcp/src/embeddedci_mcp/guide.py b/packages/embeddedci-mcp/src/embeddedci_mcp/guide.py index 9348770..5252bc3 100644 --- a/packages/embeddedci-mcp/src/embeddedci_mcp/guide.py +++ b/packages/embeddedci-mcp/src/embeddedci_mcp/guide.py @@ -31,7 +31,7 @@ - Analog: dac_output (DC), generate (sine/square/sawtooth) and replay drive the DAC and route its path; adc_read gives one calibrated value, capture_adc a waveform summary; dac_stop ends any DAC output. - 4-20 mA input: adc_read(source='current_in') reads terminal J8 and returns current in amps (0.004 to 0.020 for a live loop) next to the voltage across the sense resistor (249 ohm; from analog module v3r5 100 ohm behind a 30 mA limiter, read in the low range by default, so a reading stuck near 28.5 to 31.5 mA is the limiter). calibration shows whether the pod has calibrated its ADC offset there. If not, analog readings can be off by up to about 50 mV: ask the user to disconnect J8, then calibrate (once per pod, stored on the pod; it corrects every ADC source). - 4-20 mA output: current_out(current) holds a loop current on terminal J9, in amps (0.012 is 12 mA), and returns the current actually held and the range. It needs an external floating loop supply on J9 and cannot go below about 4 mA or above about 20 mA. It shares the DAC with the voltage outputs and switches them off; dac_stop does not return the loop to 4 mA, current_out(0.004) does. The loop must float: nothing in it may touch pod ground, also not through a target that shares a ground with the pod (SWD, UART). Ask the user how J9 is wired first, and never suggest wiring J9 straight into J8. generate and replay take dac_path='current_out' to play a waveform as a current (levels in amps); capture_adc(source='current_in') summarises the loop current in amps. -- Gateware images: the FPGA runs either the 'loop' image (control_loop) or the 'deep_replay' image (replays longer than 2048 samples). control_loop and replay switch automatically (~3 s; switched_image in the result says so). A switch resets the FPGA and stops any DAC output, UART session or sensor emulation, so start those after it. fpga_image switches explicitly. I2C/SPI/UART sensors run on a third, emulation image that sensor_start loads by itself (control_loop and deep replays are unavailable while it runs). +- Gateware images: the FPGA runs either the 'loop' image (control_loop) or the 'deep_replay' image (replays longer than 2048 samples). control_loop and replay switch automatically (~3 s; switched_image in the result says so). A switch resets the FPGA and stops any DAC output, UART session or sensor emulation, so start those after it. fpga_image switches explicitly. I2C/SPI/UART sensors run on a third, emulation image that sensor_start loads by itself (control_loop and deep replays are unavailable while it runs). From gateware v65 the emulation image has no SWD, JTAG, SPI master or I2C master: flash first, then start the sensors. While sensors run, flash (SWD/JTAG), spi_*, i2c_*, expansion and capture_la with send i2c/spi refuse with BP0059 (sensor_stop first); with no sensors running the pod switches to the loop image by itself (~3 s). - Logic: capture_la, then decode_la (i2c/uart/spi/usb/modbus/can/pwm/onewire/smbus/pmbus; usb full speed needs a 48 MS/s capture) re-decodes that capture without re-capturing, and la_timing measures edge times, pulse widths, frequency and the delay between two channels (e.g. trigger pin to result pin). - Triggers: capture_adc, capture_la and capture_correlated take trigger_la (+ trigger_edge rising/falling/high/low, trigger_timeout seconds) to start on an event rather than immediately, so t = 0 is that edge. Without the trigger firing the tool fails with "TriggerTimeout: ...". - Power profiles: measure_power(duration) reports the DUT's average/minimum/peak current, voltage, energy and charge over a window, with an optional trace (points). To profile across other tool calls, bracket them with power_profile_start and power_profile_stop. diff --git a/packages/embeddedci-mcp/src/embeddedci_mcp/server.py b/packages/embeddedci-mcp/src/embeddedci_mcp/server.py index 5b48e96..7adb3af 100644 --- a/packages/embeddedci-mcp/src/embeddedci_mcp/server.py +++ b/packages/embeddedci-mcp/src/embeddedci_mcp/server.py @@ -909,6 +909,8 @@ async def spi_flash_info( present=false means the ID read all 00 or all FF: nothing is answering (wiring, power, or /WP and /HOLD not tied high). The pins are released again afterwards. + + Gateware v65+: the emulation image (loaded by sensor_start) has no SPI master. With no I2C/SPI/UART sensor running the pod switches to the loop image by itself (~3 s); with sensors running this refuses (BP0059): sensor_stop first, or do it before sensor_start. """ def op() -> m.SpiFlashInfoResult: pod = SESSION.require() @@ -941,6 +943,8 @@ async def spi_flash_program( 25-series parts, first 16 MB. Throughput is roughly 30 KB/s over the LAN (erase is extra) and slower over the cloud. Fails with the pod's message when nothing answers, the part is write-protected, or a chunk does not verify. + + Gateware v65+: the emulation image (loaded by sensor_start) has no SPI master. With no I2C/SPI/UART sensor running the pod switches to the loop image by itself (~3 s); with sensors running this refuses (BP0059): sensor_stop first, or do it before sensor_start. """ def op() -> m.SpiFlashProgramResult: pod = SESSION.require() @@ -996,6 +1000,8 @@ async def spi_transfer( """One full-duplex SPI transaction (CS asserted for all of tx) with any SPI device on the SPI pins. Returns what came back on MISO. The SPI master is armed for the call and released after it. + + Gateware v65+: the emulation image (loaded by sensor_start) has no SPI master. With no I2C/SPI/UART sensor running the pod switches to the loop image by itself (~3 s); with sensors running this refuses (BP0059): sensor_stop first, or do it before sensor_start. """ data = bytes.fromhex(tx_hex.replace(" ", "")) if not data or len(data) > 4096: @@ -1025,6 +1031,8 @@ async def i2c_open( Then i2c_transfer, i2c_scan, or capture_la with send. SWD, SPI and I2C exclude each other. "i2c busy" means another connection (the desktop app, the web app, a script) holds the pod's I2C master: close it there. + + Gateware v65+: the emulation image (loaded by sensor_start) has no I2C master. With no I2C/SPI/UART sensor running the pod switches to the loop image by itself (~3 s); with sensors running this refuses (BP0059): sensor_stop first, or do it before sensor_start. """ def op() -> m.I2cSessionResult: pod = SESSION.require() @@ -1174,6 +1182,12 @@ async def flash( SWD pins passed mean SWD, else the profile's debug_port (swd or jtag) decides. JTAG needs the pod's `jtag` feature (newer firmware): without it the call fails before anything is armed. + Gateware v65+: SWD and JTAG are not in the emulation image (loaded by sensor_start). Flash + first, then start the sensors (one image switch). With no I2C/SPI/UART sensor running the pod + switches to the loop image by itself (~3 s); with sensors running the flash refuses (BP0059): + sensor_stop first. Flashing over UART or USB, or with the pod's own programming pins, switches + images on its own as before. + 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 an uploaded build on a cloud connection, which embeddedci.com flashes itself. The SWD pins, the @@ -2379,6 +2393,8 @@ async def expansion( EXT pins are not FPGA-timed: gpio_pulse, la_step, capture triggers and la_dir refuse them. The expander's bus closes on its own before flash, i2c_open and SPI tools; i2c_open on the same two pins shares the bus with it. + + Gateware v65+: the emulation image (loaded by sensor_start) has no I2C or SPI master (the expander runs on it). With no I2C/SPI/UART sensor running the pod switches to the loop image by itself (~3 s); with sensors running this refuses (BP0059): sensor_stop first, or do it before sensor_start. """ def op() -> m.ExpansionResult: pod = SESSION.require() @@ -2643,6 +2659,10 @@ async def capture_la( sample_rate_hz goes up to 12 MS/s, or 48 MS/s on gateware v50+ (48, 24 or 16 MS/s); above 12 MS/s a signal changing over ~6 million times per second for long stops early (truncated); retry at 12 MS/s. + + send i2c or spi needs the pod's bus master, which the emulation image (gateware v65+) lacks: + with no I2C/SPI/UART sensor running the pod switches to the loop image by itself (~3 s); with + sensors running it refuses (BP0059): sensor_stop first, or capture before sensor_start. """ def op() -> m.LaCaptureResult: pod = SESSION.require() @@ -3316,6 +3336,10 @@ async def fpga_image( the emulation image once no I2C/SPI/UART sensor runs). The pod never switches back by itself, and refuses to leave the emulation image while I2C/SPI/UART sensors run (sensor_stop first). The switch resets the FPGA (any DAC output or UART session stops). + + Gateware v65+: SWD, JTAG, the SPI master and the I2C master are not in the emulation image. + flash, spi_*, i2c_*, expansion and capture_la with send i2c/spi switch from it to the loop image + by themselves when no sensor runs, and refuse (BP0059) while sensors run. """ img = {"loop": FpgaImage.LOOP, "deep_replay": FpgaImage.DEEP_REPLAY, "emulation": FpgaImage.EMULATION}[image] From c7a9abfb471d27b0973481bbd6413570bb42928a Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Tue, 24 Nov 2026 14:57:27 -0600 Subject: [PATCH 6/6] docs: emulation image has no bus masters from gateware v65 Co-Authored-By: Claude Opus 5.5 --- packages/embeddedci-mcp/CHANGELOG.md | 6 ++++ packages/embeddedci-mcp/README.md | 5 +++- packages/embeddedci/CHANGELOG.md | 11 +++++++ packages/embeddedci/README.md | 44 ++++++++++++++++++++++++---- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/packages/embeddedci-mcp/CHANGELOG.md b/packages/embeddedci-mcp/CHANGELOG.md index d5a3317..9c909b8 100644 --- a/packages/embeddedci-mcp/CHANGELOG.md +++ b/packages/embeddedci-mcp/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog — `embeddedci-mcp` +## Unreleased + +- Tool descriptions and the server guide say that from gateware v65 the emulation image has no SWD, + JTAG, SPI master or I2C master: `flash`, `spi_*`, `i2c_*`, `expansion` and `capture_la` with `send` + switch to the loop image themselves when no sensor runs, and refuse (`BP0059`) while sensors run. + ## 4.0.4 For BenchPod firmware 4.0.4 (the `prog_flash` feature); needs the matching embeddedci (the tool says so on an older SDK). diff --git a/packages/embeddedci-mcp/README.md b/packages/embeddedci-mcp/README.md index 5cad792..754077b 100644 --- a/packages/embeddedci-mcp/README.md +++ b/packages/embeddedci-mcp/README.md @@ -368,7 +368,7 @@ version the SDK pins (0.1.0, bundled) unless `BENCHPOD_SENSOR_LIBRARY`, the CLI' | `control_loop` | Run a tabulated transfer function in the FPGA (for example a solar panel I-V curve). | `curve`, `voc_code`, `sharpness=4`, `points=256`, `k=8192`, `vmin=0`, `vmax=65535`, `tick_div=64`, `source`, `input_code=0`, `step=0`, `input_map`, `switch_image=true` | | `loop_input` | Re-target the running loop's input without re-arming. | `input_code`, `source`, `step` | | `loop_probe` | The running loop's live operating point. | none | -| `fpga_image` | Switch the FPGA to the `loop`, `deep_replay` or `emulation` gateware image (~2-3 s); refused while I2C, SPI or UART sensors run on the emulation image. | **`image`** | +| `fpga_image` | Switch the FPGA to the `loop`, `deep_replay` or `emulation` gateware image (~2-3 s); refused while I2C, SPI or UART sensors run on the emulation image. From gateware v65 the emulation image has no SWD, JTAG, SPI master or I2C master: `flash` (SWD/JTAG), `spi_*`, `i2c_*`, `expansion` and `capture_la` with `send` i2c/spi switch to the loop image themselves when no sensor runs, and refuse (`BP0059`) while sensors run (`sensor_stop` first, or flash before `sensor_start`). | **`image`** | ### CAN @@ -533,6 +533,9 @@ capture tools' summaries, `la_timing` and `decode_la` instead. `fpga_image` switches explicitly. I2C, SPI and UART sensors run on a third, emulation image that `sensor_start` loads by itself; the pod never switches back, so `control_loop` and the deep replays switch back once no such sensor runs (and name `sensor_stop` while one does). + From gateware v65 that emulation image has no SWD, JTAG, SPI master or I2C master: flash first, then + start the sensors. With sensors running those tools refuse with `BP0059`; with none running the pod + switches to the loop image by itself. - **Non-blocking.** Tools run on worker threads under one device lock: a 5-minute flash doesn't freeze the server, sends progress notifications, and concurrent calls can't interleave commands. - **Annotations.** Read-only tools (`status`, `power_status`, `adc_read`, …) are marked so clients diff --git a/packages/embeddedci/CHANGELOG.md b/packages/embeddedci/CHANGELOG.md index 8acc816..ada4ecf 100644 --- a/packages/embeddedci/CHANGELOG.md +++ b/packages/embeddedci/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog — `embeddedci` +## Unreleased + +For gateware v65 (features table revision 18): the emulation image has no SWD, JTAG, SPI master or I2C master. + +- `bp.has_bus_masters()` says whether the running image has them. +- `flash()` over SWD or JTAG, `open_spi()`, `spi_flash()`, `open_i2c()`, `expansion()` and + `capture_la(send=I2CSend/SpiSend)` switch the pod from the emulation image to the loop image (logged, + about 3 s) when no I2C, SPI or UART sensor runs, and raise `UnsupportedFeatureError` (`BP0059`) while + one does: stop the sensors first, or flash before starting them. +- The `benchpod_capability("spi_master")` and `("i2c_master")` markers do the same switch. + ## 4.0.4 For BenchPod firmware 4.0.4 (features table revision 17). diff --git a/packages/embeddedci/README.md b/packages/embeddedci/README.md index 053e7b7..a3f4f3c 100644 --- a/packages/embeddedci/README.md +++ b/packages/embeddedci/README.md @@ -652,6 +652,8 @@ nothing changes. `dac_deep_replay`, `dac_control_loop`, `dac_loop_sources`, `dac_cotrig`, …). For the image-bound `dac_control_loop` and `dac_deep_replay` it switches the pod's gateware image instead of skipping, when the pod carries both images (see [Gateware images](#gateware-images)). + `spi_master` and `i2c_master` leave the emulation image (gateware v65+, no bus masters) for the + loop image, and skip while emulated sensors run. `benchpod_capability("analog")` skips only on the digital-only board (no DAC, ADC or 4-20 mA); firmware that does not announce the flag ran on analog boards only and counts as analog, like `BenchPod.can_analog`. @@ -983,6 +985,12 @@ bp.flash( ) ``` +SWD and JTAG flashing need the pod's bus masters, which the emulation image lacks from gateware v65 +(see [Gateware images](#gateware-images)): flash first, then start the sensors. With sensors +already running, `flash()` raises `UnsupportedFeatureError` (`BP0059`: stop them with +`bp.sensors.stop()` first); with none running the SDK switches the pod to the loop image itself +(~3 s). + By default a failed flash raises `FlashError` (or `TargetUnreachableError` when nothing answers on SWD) carrying OpenOCD's output. Pass `check=False` to get the `FlashResult` and assert yourself: @@ -1285,7 +1293,10 @@ bp.usb_hid_capture(False) # stop and free the ring Pods with gateware v45+ (`bp.capabilities.spi_master`) run an SPI master on any four LA pins, up to 6 MHz, modes 0 and 3. Gateware v55+ also runs modes 1 and 2 (`open_spi(mode=1)`); on older -gateware they raise `UnsupportedFeatureError` before anything is sent. Wire a 25-series SPI NOR flash (W25Q, MX25, GD25, ...) with its SCK, DI, +gateware they raise `UnsupportedFeatureError` before anything is sent. From gateware v65 the +emulation image has no SPI master: with emulated sensors running `open_spi()` and `spi_flash()` +raise `UnsupportedFeatureError` (`BP0059`; stop the sensors first), with none running the SDK +switches the pod to the loop image itself. Wire a 25-series SPI NOR flash (W25Q, MX25, GD25, ...) with its SCK, DI, DO and CS on LA channels (power it at the LA voltage, tie /WP and /HOLD high) and program it: ```python @@ -1322,6 +1333,10 @@ the bus. The pins are open drain, so the bus needs pull-ups: the pod's own on LA on first; they pull to the LA voltage, at 1.8 V on firmware newer than 3.10.12), or the board's with `pullups="external"`. +From gateware v65 the emulation image has no I2C master: with emulated sensors running `open_i2c()` +raises `UnsupportedFeatureError` (`BP0059`; stop the sensors first), with none running the SDK +switches the pod to the loop image itself. + ```python from embeddedci.benchpod import I2CNackError @@ -1730,7 +1745,10 @@ on the first EXT access and keeps it open; it closes it on its own before `flash `spi_flash()`, `open_i2c()`, `open_spi()` and `close()`, and opens it again when an EXT pin is next used. An `open_i2c()` session on the same two pins is used as it is, so the DUT and the expander share one bus; on other pins, or while an `open_spi()` session is open, EXT calls raise -`ExpansionError` naming the session to close. +`ExpansionError` naming the session to close. The expander runs on that engine, so from gateware v65 +it needs the loop or deep-replay image: `expansion()` and EXT access raise +`UnsupportedFeatureError` (`BP0059`) while emulated sensors run, and switch the pod to the loop +image when none do. `EXPANSION_CHIPS` lists every chip the SDK drives as `ExpansionChip` entries (`name`, `bus`, `pins` per chip, `la_pins` it uses, `addrs`, `voltages`, `directions`, `max_hz`, `since`, @@ -2309,7 +2327,9 @@ holds the samples up to that point and `truncated` says why (`"busy"` or `"memor `capture_la(..., send=...)` (gateware v55+) runs one transaction right after the capture arms, in the same command, so a trigger on the bus line catches it. It works over the cloud too, which runs one command at a time. Trigger on the line the transaction starts with: SDA falling (I2C START), CS -falling (SPI), or the GPIO pin's edge. +falling (SPI), or the GPIO pin's edge. `send` with an I2C or SPI transaction needs the bus master +the emulation image lacks from gateware v65: it raises `UnsupportedFeatureError` (`BP0059`) while +emulated sensors run and switches to the loop image when none do. ```python from embeddedci.benchpod import GpioSend, I2CSend, SpiSend, Trigger @@ -2455,6 +2475,18 @@ flag, `sensors_digital` set; `fpga_image` says which runs) they switch back when sensor runs and raise naming `bp.sensors.stop()` otherwise: the pod never switches back by itself. A pod that reports neither flag nor `sensors_digital` has a single image and is never switched. +**Bus masters.** From gateware v65 the emulation image has no SWD, JTAG, SPI master or I2C master +(they are in the loop and deep-replay images; before v65 every image has them). +`bp.has_bus_masters()` says whether the running image does (`None` when the pod does not say). +`flash()` over SWD or JTAG, `open_spi()`, `spi_flash()`, `open_i2c()`, `expansion()` and +`capture_la(send=I2CSend/SpiSend)` check it first: + +* On the emulation image with no I2C, SPI or UART sensor running, the SDK switches the pod to the + loop image (logged, ~3 s) and goes on. The pod's firmware does the same. +* With such a sensor running, they raise `UnsupportedFeatureError` (`BP0059`, `feature` names what + was asked for): `bp.sensors.stop()` first, or do the flash and the bus work before + `bp.sensors.start()`. Flashing first costs one image switch (the sensor start loads emulation). + What a switch does: * It reprograms the FPGA from the pod's config flash and cold-boots it, which takes **~2-3 s**. @@ -2469,7 +2501,9 @@ What a switch does: * The selection is written to the config flash, so the pod normally stays on that image after a power cycle. * In pytest, `@pytest.mark.benchpod_capability("dac_control_loop")` (or `"dac_deep_replay"`) - switches the image for the test instead of skipping it. + switches the image for the test instead of skipping it. `"spi_master"` and `"i2c_master"` switch + from the emulation image to the loop image (gateware v65+) and skip the test while emulated + sensors run. ## In-fabric DAC control loop @@ -2863,7 +2897,7 @@ lease_wait=600.0, lease_ttl=120, wiring=None, lease_purpose=None)`. A context ma | Area | Methods and properties | |---|---| -| Connection and device | `ping()`, `status()`, `diag()` (heap, per-task stacks, network-stack and console counters: the `diag` command), `mac_addresses(status=None)` (the Ethernet and Wi-Fi MACs, see [MAC addresses](#mac-addresses-managed-networks)), `capabilities`, `refresh_capabilities()` (drop the cached capabilities and read them again), `close()`, `leased` (true while this client holds a lease, see [Device leases](#device-leases)), `local_lease()` (the pod's own lease: `LocalLease`), `wiring`, `save_wiring(wiring=None, name=None)` (store a wiring profile on the pod; firmware before 3.10.8: on embeddedci.com), `signal(name)`, `fpga_image(image)`, `usb_cc()`, `usb_network(on=None)` (the USB network setting; `False` turns the adapter off over the USB link), `lan_tls()`, `set_lan_tls_https_only(on)`, `regenerate_lan_tls()`, `set_lan_tls_cert(cert_pem, key_pem)` (the LAN API over TLS, see [TLS on the LAN](#tls-on-the-lan)) | +| Connection and device | `ping()`, `status()`, `diag()` (heap, per-task stacks, network-stack and console counters: the `diag` command), `mac_addresses(status=None)` (the Ethernet and Wi-Fi MACs, see [MAC addresses](#mac-addresses-managed-networks)), `capabilities`, `refresh_capabilities()` (drop the cached capabilities and read them again), `close()`, `leased` (true while this client holds a lease, see [Device leases](#device-leases)), `local_lease()` (the pod's own lease: `LocalLease`), `wiring`, `save_wiring(wiring=None, name=None)` (store a wiring profile on the pod; firmware before 3.10.8: on embeddedci.com), `signal(name)`, `fpga_image(image)`, `has_bus_masters()` (the running gateware image has SWD, JTAG, the SPI and I2C masters: gateware before v65, or the loop and deep-replay images), `usb_cc()`, `usb_network(on=None)` (the USB network setting; `False` turns the adapter off over the USB link), `lan_tls()`, `set_lan_tls_https_only(on)`, `regenerate_lan_tls()`, `set_lan_tls_cert(cert_pem, key_pem)` (the LAN API over TLS, see [TLS on the LAN](#tls-on-the-lan)) | | LA voltage | `set_la_voltage(volts)`, `get_la_voltage()` | | Power and reset | `power_on(efuse=None, *, delay=None)`, `power_off(efuse=None, *, delay=None)`, `target_power(efuse=None, *, on, delay=None)`, `target_status()`, `power_status()`, `measure_power(duration, *, efuse=None, rate_hz=500.0, keep_samples=0)`, `power_profile(*, efuse=None, rate_hz=500.0, keep_samples=4096, max_duration=60.0)`, `reset_target(*, pulse=0.1)`, `set_reset(asserted)`, `reset_state()` | | USB host and flashing | `usb_host(enable=True, *, port=None, timeout_s=60)`, `usb_host_status()`, `usb_wait_device(vid=None, pid=None, timeout=10)`, `usb_flash(file, *, address=None, name=None, leave=True, mode=None, port=None, timeout=None, device_timeout=10, progress=None, verify=False)`, `usb_flash_status()`, `usb_flash_abort()`, `usb_check(test, *, count=None, off_ms=None, timeout_ms=None, duration_ms=None, settle_ms=None, port=None, device_timeout=10, timeout=None, progress=None)`, `usb_check_status()`, `usb_check_abort()`, `usb_hid_interfaces()`, `usb_hid_capture(enable=True)`, `usb_hid_read(count=1, timeout=2.0, instance=None)` (see [USB host mode and USB flashing](#usb-host-mode-and-usb-flashing)) |