Skip to content

About

Stimulates the interfaces of a device under test; usable by AI agents over MCP

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

fixtureaction

Stimulates the interfaces of a device under test (DUT): digital and analog inputs, relays, frequencies, encoders, thermocouples. Measures how it reacts: voltages, edges, latency. An STM32G0B1 does both and serves JSON-RPC 2.0 over USB serial. An MCP server gives them to AI agents as tools.

AI agent ──MCP──► fixtureaction-mcp ─┐
scripts  ──────► FixtureClient ──────┼─JSON-RPC / USB CDC──► STM32G0B1 ──► DUT
shell    ──────► fixtureaction ──────┘

Status

Runs on a NUCLEO-G0B1RE over its ST-LINK port. Tested there by reading pins and registers back: GPIO, pulses, frequencies, quadrature order, DAC voltages with its own ADC, edge capture, latency, storage, lease, watchdog. Not tested yet: the native USB port, I2C and SPI with real devices, and anything that needs an oscilloscope or a meter. See docs/bring-up.md before connecting a DUT.

Channels

Set by a configuration, through the API or at build time:

Type What
digital low, high or high-Z; ms pulses; pin readback
relay active high or low; interlocks
analog on-chip DAC (waveforms 0.1 Hz–5 kHz) or PWM, MCP4725 (I2C), MCP4822/4922 (SPI)
thermocouple types B E J K N R S T in °C, with cold junction; ramps
freq 0.1 Hz–1 MHz, duty, exact pulse counts, sweeps, quadrature
adc voltage: mean, extremes, RMS, recordings; 1 kHz
input level, edge counts, frequency, duty, pulse widths, up to 20 kHz

The built-in configuration of the Nucleo:

Channels Pins
DOUT1–DOUT8 PC0–PC7
RLY1–RLY8 PB0 PB1 PB2 PB10–PB14
AOUT1, AOUT2 PA4, PA5 (DAC; PA5 also drives LED LD4)
AOUT3, AOUT4 PA8, PA9 (15.6 kHz PWM, needs an RC filter)
FREQ1, FREQ3, FREQ4 PA0, PB8, PB9
FREQ2 PA6, quadrature B on PA7
AIN1 PA1
IN1–IN4 PC8–PC11 (pull-down)

All pins are bare 3.3 V logic. Protection, relay drivers (with pull-downs) and scaling for other voltages belong on a front end. Frequencies and times are as accurate as the internal oscillator, about 1 %.

There are two ports, with the same protocol:

  • ST-LINK: the connector of the Nucleo, 230400 baud. Name it with --port. The fixture cannot see an unplugged cable here: use a lease.
  • Native USB: PA12 (D+), PA11 (D−), GND; wire a connector. Found automatically.

Build

cd firmware
cmake --workflow --preset host      # simulator and unit tests
cmake --workflow --preset target    # build-target/target/fixtureaction.{elf,bin,hex}

The target build looks for an arm-none-eabi-gcc that runs, in the STM32Cube bundles and in PATH. ARM_GCC_DIR overrides it. Needs GCC ≥ 13.

Flash with the ST-LINK, for example:

STM32_Programmer_CLI -c port=SWD -w build-target/target/fixtureaction.hex -rst

Host tools and their tests (they run against the simulator):

uv sync
uv run pytest
FIXTUREACTION_HW_PORT=/dev/cu.usbmodem1303 uv run pytest tests/test_hardware.py  # on a board

For AI agents

claude mcp add fixtureaction -- uv --directory /path/to/fixtureaction \
  run fixtureaction-mcp --port /dev/cu.usbmodem1303 --profile examples/fan-controller.json

The profile says what is wired where, and what the agent may do. Without one, the only limits are those of the hardware. To try it without a board, run firmware/build-host/fixtureaction-sim and pass the path it prints as --port.

Tools: list_channels, get_state, all_safe, set_digital, pulse_digital, read_digital, set_relay, set_analog, start_waveform, start_frequency, sweep_frequency, start_quadrature, stop_frequency, set_thermocouple, ramp_thermocouple, read_adc, record_adc, fetch_adc, start_edges, stop_edges, read_edges, measure_latency, run_sequence, get_sequence_status, abort_sequence, wait_for_events. With --allow-config also get_configuration, scan_bus and configure.

Measuring

f.call("adc.read", channel="AIN1")  # volts, min_v, max_v, rms_v, ac_rms_v
f.capture_adc("AIN1", count=500, every_ms=2)  # one second
f.call("edge.start", channel="IN1", duration_ms=1000)
f.call("edge.read", channel="IN1")  # rising, falling, hz, duty, widths

# How long after the relay opens does the DUT's output fall?
f.measure_latency(
    {"method": "relay.set", "params": {"channel": "RLY1", "closed": False}},
    {"channel": "IN1", "edge": "falling"},
    timeout_ms=2000,
)  # {"status": "done", "latency_us": ..., "resolution_us": 1}

A response can also be a voltage threshold, or a signal that stops toggling. See docs/protocol.md. A worked example, the first DUT: docs/safekiln.md.

Profiles

See examples/fan-controller.json.

  • channels.<id>: alias, description, enabled, min/max (V, Hz or °C), and safe (digital: low, high or z).
  • interlocks: groups of relays of which at most one may be closed. The next one can close 20 ms after the previous one opened.
  • lock: refuses any other profile or configuration until the board is reset.

The limits are enforced by the firmware. They guard against an agent's mistakes: an agent that can also open the serial port or run a debugger can get around the MCP server, though not around a locked profile without resetting the board.

What makes the fixture safe

Safe means relays open, analog 0 V (even if the profile's min is higher), frequencies off and low, digital outputs at their safe level, thermocouples at safe_c. It happens

  • at boot, on system.safe and when a profile or configuration is loaded,
  • when the native USB is suspended or unplugged,
  • when the lease expires. The MCP server takes a 5 s lease, so the fixture goes safe if the server dies. The CLI takes none: outputs hold between commands,
  • when a sequence, or a ramp, fails while running.

A watchdog resets the board if the firmware hangs. After a reset all pins are high impedance until the firmware starts.

This is not a safety function. Anything that can hurt people or burn needs a hardware emergency stop.

Shell and Python

uv run fixtureaction methods
uv run fixtureaction call freq.start channel=FREQ1 hz=1000 duty=0.25
uv run fixtureaction call relay.set channel=RLY1 closed=true
uv run fixtureaction state
uv run fixtureaction safe
from fixtureaction import FixtureClient

with FixtureClient() as f:
    f.hold_lease()
    f.call("analog.set", channel="AOUT1", volts=1.2)

Protocol

See docs/protocol.md.

Layout

firmware/core/     engine (limits, interlocks, timing, safe state) and JSON-RPC; no hardware
firmware/config/   built-in configuration
firmware/target/   STM32G0B1: CMSIS registers, TinyUSB
firmware/sim/      the core on a pseudo terminal
firmware/test/     unit tests of the core
src/fixtureaction/ client, CLI, MCP server

Another board or chip needs the pin tables of firmware/core/config.cc and an implementation of firmware/core/hal.h.

About

Stimulates the interfaces of a device under test; usable by AI agents over MCP

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages