Kleidos API Search

In development. It changes without notice.

The bench meter firmware — architecture

The design as it stands, at firmware 0.16.6. This page is kept current: a change to the firmware that makes a statement here false corrects it in the same commit. Where the page and the code disagree, the code and the SCPI command set win and the page is the bug; the changelog lists every change on the wire. The design as it was settled before the first image is the first design, frozen on 2026-11-22 as the record of firmware 0.1.0: a comment or a document cites this page's sections, never that one's (tests/firmware/test_no_stale_references.py fails on a citation of the record's sections anywhere but the record and the changelog).

Scope The firmware of the DAQ instrument: an ESP32-S3-N16R8 on a DSX063-1 carrier, reading a TI INA228 on an R100 shunt, with a relay pair that nulls it without hands. What it does at boot, how it samples, what it keeps where, what runs on which core, and what it deliberately does not do.
Depends on The INA228 reference (registers, LSBs, the range arithmetic), the carrier board's guide (GPIOs, the two USB ports, the LED), the wiring guide (the rig as wired, rev D), the SCPI command set (the protocol), the MISRA record (the coding rules and what ESP-IDF allocates), the testing guide (the host tests)
Sources [DS] is TI's INA228 datasheet SLYS021A, through ina228-reference.md; ESP-IDF is the pinned 6.1.1 tree (framework-espidf 4.60101.0); the sources of the 0.1.0 design are listed in firmware-design.md's last section.

1. The design in one page

Question Decision Where
The sensor and its wires TI INA228 at 0x40, SDA GPIO4, SCL GPIO5, ALE GPIO6 by the default pin map, a stored map's otherwise; the address is checked by a scan or pinned by the map, not assumed §2.1, §2.6
Bus speed The map's boot clock, 400 kHz by default, settable from 50 kHz to 1 MHz (SYSTem:COMMunicate:I2C:FREQuency); BURST needs 1 MHz; the clock is a rewrite of the own I2C master's timing registers, nothing allocated §2.1, §2.4
Which core talks to the INA228 Core 1 only, the sampler's, where the bus was opened; the console's transactions are routed there one at a time, and the own I2C master refuses any other core §2.2, §2.4
Bring-up Identity, reset defaults and MEMSTAT verified; a failure is carried and every command that would invent a number is refused §2.3
Range and SHUNT_CAL ADCRANGE = 0 by default, 1 by command; SHUNT_CAL = 0x1000 always; the shunt is corrected in software, per range §3.1
Profiles BURST 100 µs · TRACE 280 µs · STATE 1152 µs · SLEEP 67.52 ms §3.2
Pacing STATE, SLEEP: the ALE pin with a DIAG_ALRT read per edge, probed at every INITiate, the host timer if the probe fails; TRACE, BURST: the host timer §3.3
Primary quantity and arithmetic VSHUNT, integer picovolts and nanoamps; floats never, not even at the print boundary of the report keys §3.5, §3.6
Null and quality A per-range offset null with its die temperature; every report says q=uncal, stale, cal or invalid §3.7
Statistics Computed in the loop from every sample: deviation, batch means, the maximum's place, voltage, power, the CHARGE mean, a threshold §3.8
Sinks TRACE, BURST → a 1,048,576-sample ring in PSRAM; STATE, SLEEP → a live stream; any profile → statistics only §3.9, §4.1
The line UART0 through the CH343P at 6 Mbps; a stream above 80 % of it is refused, never absorbed §4.2
Tasks meter-sample (Core 1, priority 10, over static storage) and the console on ESP-IDF's main task, main (Core 0, raised to priority 5; FW-17: app_main() becomes the console and never returns), both supervised by the firmware's own watchdog on Timer Group 0 (5 s, a system reset) §5.1
The hot path From IRAM: everything a conversion executes on Core 1, ours and ESP-IDF's, held by a gate on the linked image §5.2
The null without hands K1 (HW-316, GPIO7) opens the DUT's lead, K2 (Relay 2 Click, GPIO15) bypasses the shunt, where the pin map puts them; released at boot before anything but the map's read, make-before-break, checked on the shunt, held 120 s at most §6
Self-test and health *TST? reads every part back; SYSTem:HEALth? reads nothing of the device and is safe under a capture §7
The LED Blanked at boot and never lit again §8
Radio None, ever: serial-only, and every unused GPIO parked §9
Memory Nothing allocates or frees from app_main()'s first line, for any command (allocs_since_main=0 frees_since_main=0); every task, queue, semaphore and buffer is static, no allocator is reachable from our code in the image's call graph, and what ESP-IDF allocates before app_main() is registered in misra.md §5.1, §10

2. The sensor, its bus and its bring-up

2.1 Pins, bus and address

Signal GPIO Carrier terminal Source
SDA GPIO4 left rail 4 carrier-board.md §3, first choice
SCL GPIO5 left rail 5 idem
ALE GPIO6 left rail 6 idem
VCC 3.3 V left rail 1 carrier-board.md §3, never 5 V
GND ground left rail 22 idem

These are the default pin map's (pinmap::kDefaultMap in firmware/src/pinmap.h, generated from firmware/board/pins.toml and held by a static_assert there to the rig as wired); from 0.18.0 a stored map may put them, and the relays, elsewhere (§2.6). The default map's relays take GPIO7 and GPIO15 (§6.1); the LED lines are GPIO48 and GPIO38 (§8) and the console is UART0 on GPIO43 and GPIO44 (§4.2), and no map may take one of those four.

Address 0x40, the breakout's A0 and A1 straps both at ground ([DS] Table 7-2). The firmware does not trust the straps: unless the pin map pins an address, when that one alone is probed, the bring-up probes the whole space of 0x40 to 0x4F and refuses (NoDevice, §2.3) when nothing answers, and DIAGnostic:I2C:SCAN? lists every address that acknowledged, so a cold joint shows up as a wandering address instead of a silent instrument.

Bus speed. The pin map's boot clock, 400 kHz by default (PinMap::sclHz), settable at runtime from 50 kHz to 1 MHz with SYSTem:COMMunicate:I2C:FREQuency <hz> and read back by its query; *RST returns it to the map's boot clock. BURST needs 1 MHz (docs/scpi.md). Fast-mode plus is the ceiling: the own I2C master (§2.4) sets any rate of that range by rewriting its timing registers, the range ESP-IDF 6.0.3's driver offered until FW-14 (it had no high-speed-mode master code: i2c_device_config_t carried scl_speed_hz and nothing of the kind). The breakout's three 01C resistors read as 10 kΩ pull-ups, which is not yet confirmed with a meter (README.md, open questions): at a short-wire 50 pF a 10 kΩ pull-up gives a 424 ns rise time (t_r ≈ 0.847 · R_p · C_b) against fast mode's 300 ns (NXP UM10204, TI SLVA695 Table 1), so keep the wires under about 10 cm or fit 4.7 kΩ in parallel; a bad bus is one command away from 100 kHz rather than a reflash. That 424 ns is a bound on an assumed 50 pF, and the rig measures better than it: on its short wiring, SYSTem:COMMunicate:I2C:FREQuency 1000000, two and a half times past fast mode, ran a 20 s BURST capture and a 7.85 MB dump with read_err=0 and no corrupted byte. Keep the calculation as the warning it is for longer wiring, and re-measure after changing the harness: read_err on ABORt is what says the bus stopped carrying it. The default map enables the internal pull-ups on all three lines (i2c_bus::begin(), and Sampler::begin() for ALE), so a missing pull-up does not float a pin; a map may turn each one off.

Two timing facts make the bus deterministic: the INA228 does not clock-stretch and does not support PEC ([DS] Figure 7-8 notes). It does not auto-increment its register pointer either: the pointer is retained ([DS] §7.5.1.1), which is what makes TRACE's read affordable (§3.5).

2.2 One core owns the bus (0.16.4, 0.16.5)

Every transaction the driver makes (a probe, a register transfer, a change of the bus clock) runs on the core that opened the bus: the sampler's, Core 1 (§5.1). Ina228Driver holds the rule by construction. Each transaction entry compares the calling core with the one openBus() ran on; there it makes its call in place, and from the other core it hands that one call to the bus's core through esp_ipc_call_blocking() and waits for it (firmware/src/ina228.h). The scan's sixteen probes went first, in 0.16.4; from 0.16.5 every transaction does. Until FW-14 the bus was ESP-IDF's I2C master, whose interrupt ran on that core; from FW-14 it is the own master (§2.4), which takes no interrupt, clears every status before a transaction ends, and refuses every call from a core other than the one its begin() ran on, so the rule is the bus's own as well as the driver's. Up to 0.16.3 the console probed from Core 0, up to 0.16.4 it read and wrote from there, and ESP-IDF 6.0.3's driver then left the bus in a state its next transaction misread:

  • What ESP-IDF's driver did (until FW-14). A probe of an address that does not answer receives the NACK interrupt, waits for the bus to go idle, masks the interrupt and returns (i2c_master_probe(), ESP-IDF's esp_driver_i2c/i2c_master.c). The STOP it sent after the NACK raises TRANS_COMPLETE as the bus goes idle. When the interrupt runs on the probe's own core it preempts the wait and clears that bit while it is still enabled. When it runs on the other core, the probe has masked it first, and the bit stays latched in the peripheral. The next transaction unmasks it, the interrupt on the far core posts I2C_EVENT_DONE after the transaction has reset its event queue, and the transaction takes it for its own completion: it returns ESP_OK at once with its transfer still on the wire. A probe so answered reports a device that is not there; a register read returns its zeroed buffer, and its own completion stays latched for the next one. A register transfer that meets a NACK (a breakout that stops answering, a loose header wire) takes the same path in the driver (s_i2c_send_commands(), then the interrupt masked in s_i2c_transaction_start()), so from the far core it leaves the same latch.
  • What the bench showed (2026-11-21, a diagnostic image reading I2C0's INT_RAW before and after each probe): from Core 0, every probe of a silent address ended with TRANS_COMPLETE latched (INT_RAW 0x8292 where a probe of 0x40 left 0x8212), the probe after it returned ESP_OK, and the scan listed seven or eight of 0x40…0x4F, a different set each time, at 400, 100 and 50 kHz. Every DIAGnostic:REGister? after it read 0x0000 with no error until a transaction failed, or one ran on Core 1 (*TST?'s probe), and reset the state; the second scan of one session rebooted the chip (reset=panic). Run on Core 1, every probe of a silent address left 0x8212, as the probe of 0x40 does, and six scans at 400 and 50 kHz listed 0x40 alone with the identity reading right after each.
  • What moved to Core 1 in 0.16.5. Every transaction the console made from Core 0: DIAGnostic:REGister? and DIAGnostic:ALERt?; *TST?'s identity, SHUNT_CAL and DIAG_ALRT reads and the writes its pacing probe needs; the null path's V_SHUNT reads around each relay step (ROUTe:NULLpath ON, with its ADC_CONFIG writes); a range change (CONFIG, RSTACC and the two DIAG_ALRT reads around the discarded period, from SENSe:CURRent:RANGe and *RST); SENSe:CHARge? and SENSe:CHARge:RESet; a capture's and a null's setup in beginCapture() (the profile's ADC_CONFIG, DIAG_ALRT and clip limits, the consistency read, the boundary temperature with its triggered conversion, the charge read, the stale-flag clear) and their close in stop() and finishZero(); and a change of the bus speed (SYSTem:COMMunicate:I2C:FREQuency, *RST), the device handle's re-creation until FW-14 and a rewrite of the timing registers since. The capture loop, which takes every sample of a capture and of a null, the pacing probe and the boot's bring-up already ran on Core 1 and make their calls in place, as before.
  • What the host tests hold. Until FW-14 the harness modeled ESP-IDF's driver: its bus remembered the core that created it, a NACKed probe or register transfer from the other core latched a completion the next transaction from that core took, and every call into the I2C master from the other core was counted; before 0.16.5's change 103 of the 208 firmware cases failed on it, among them a register read after a failed one returning 0x0000 as ESP_OK. From FW-14 it models I2C0's registers (§2.4), and every case that boots a Bench fails when they were reached from a core other than the one that clocked them; the driver's own cases ask each transaction from the far core by name and check that it reached the wire. The harness sees only the paths a test runs, so a source gate (tests/firmware/test_i2c_on_bus_core.py, every test run) reads firmware/src and fails on a call into I2C master anywhere but where the routing owns it: begin() in openBus(), the transfers, the probe and the clock change in makeCall(), and the in-place branch of onBusCoreNow() ? in the three IRAM entries; and on any call of ESP-IDF's I2C master, which the image no longer links (scripts/check_drivers_absent.py). A planted call of each kind proves it still sees one.

On the bench (2026-11-21, 0.16.5's clean build, ELF 44038b5fc6701826, the T-Deck asleep behind K1 at about 41 µA): 100 of 100 *TST? answered 0; 20 scans listed 0x40 alone; 200 rounds of DIAGnostic:REGister? 0x3E and 0x3F and DIAGnostic:ALERt? read 0x5449, 0x2281 and memstat=1 every time; a range change to 1 and back, MEASure:CURRent? on both ranges (40.7 to 41.6 µA), STATE and SLEEP statistics captures of 15 s (pace=alert, 8 edges, pace_err_ppm +100 and +103, 0 dropped, 0 stale, 0 read errors) and a null-path cycle all ended with no error, allocs_after_init=0 and the watchdog's stalls=0. The IRAM gate reaches 73 functions, as before, with no failure.

What a routed transaction costs. ESP-IDF's IPC call takes two static semaphores and allocates nothing, and the IPC task polls the own master's transaction to its end on Core 1 (§2.4). It runs at the caller's priority (CONFIG_ESP_IPC_USES_CALLERS_PRIORITY, the default): the console's 5 on Core 1, below the sampler's 10, so a console transaction never preempts the sampler, and one asked while a capture's loop spins waits for the capture to end. That is why every command that makes a transaction is refused while a window runs (the R flag of docs/scpi.md), and why a capture's close makes its reads only once the loop has acknowledged the stop. Each routed call is one transaction (a few hundred microseconds at most, 20 ms on a fault), never a sequence: a wait, such as the triggered temperature's poll or a range change's discarded period, runs in the caller's task between two calls. The sampler pays one comparison of the core number per transaction; the routed path is out of line and in flash, a cold exit of the IRAM gate (§5.2).

Should the IPC call be refused, nothing is made: the scan reports nothing (found=- n=0) and a transaction returns the refusal (ESP_ERR_INVALID_STATE, i2c ESP_ERR_INVALID_STATE on the console), the driver's lastError() with it. When the IPC call was refused at boot, the bus was opened on Core 0 with the console; the console's transactions are then made in place, and the sampler's go to Core 0 one by one, slower and still correct.

2.3 Bring-up and identity

Ina228Driver::bringUp() runs on the bus's core at boot, in the order of ina228-reference.md §8.6, and returns a verdict (BringUpResult, firmware/src/ina228.h):

Step Action Verdict if it fails
1 probe 0x40 to 0x4F, or the one address the pin map pins NoDevice
2 CONFIG ← 0x8000 (RST, self-clearing), then a settle longer than TPOR ([DS] §6.5) BusError
3 MANUFACTURER_ID == 0x5449 and DEVICE_ID >> 4 == 0x228, the low nibble being the silicon revision NotIna228
4 ADC_CONFIG == 0xFB68 and SHUNT_CAL == 0x1000, the documented reset values, which also prove MSB-first framing ([DS] §7.5.1.1) BadResetDefaults
5 DIAG_ALRT bit 0 MEMSTAT == 1: the trim memory's checksum ([DS] Table 7-16) TrimChecksum, a hard stop
6 SHUNT_CAL ← 0x1000 explicitly, as every power-up of the part requires ([DS] §8.2.2.3), then CONFIG for range 0 BusError

The verdict is carried, not thrown away. On anything but Ok the console queues one -241 (Hardware missing) at boot with the reason in its detail (bringUpReason(); a stored bus that could not fall back is one 117 in its place, §2.6), *TST? says so, and every command that would report a number from a part that did not come up is refused by name.

A free consistency check, at every INITiate. CURRENT_LSB is V_LSB / R exactly in both ranges (§3.1), so CURRENT counts track VSHUNT counts one for one up to the device's own rounding; the capture header reports the difference as vs_cur_delta=, and anything beyond ±2 counts says SHUNT_CAL is not what the firmware wrote.


2.4 The own I2C master (FW-13, FW-14)

ESP-IDF's I2C master keeps its bus object, five semaphores, a queue, the port's handle slot and each device's object on the heap, claims its interrupt through the allocator, and changes the bus clock by removing the device's object and allocating it again: 12 allocations at boot (allocs_since_main 35 on FW-12's image, 23 on FW-14's) and two allocations and two frees at every clock change, until FW-14 (docs/misra.md, "How the allocations left"). firmware/src/i2c_bus.cpp does what the instrument asks of the bus with static state and no interrupt, semaphore or queue, on I2C0's registers (ESP-IDF's hal/i2c_ll.h) and the GPIO matrix's (hal/gpio_ll.h). FW-13 wrote it beside the driver; from FW-14 Ina228Driver makes every transaction through it (§2.2), the clock change included, and ESP-IDF's I2C master, its CONFIG_I2C_ISR_IRAM_SAFE and the linker fragment that put its transfer path in IRAM are gone from the image (scripts/check_drivers_absent.py, §5.2).

  • Set-up. i2c_bus::begin() gates I2C0's bus clock on and pulses its reset under ESP-IDF's peripheral clock lock, selects the 40 MHz crystal (I2C_CLK_SRC_DEFAULT), sets master mode with open-drain pads and no arbitration, both FIFOs in FIFO mode and most significant bit first, a glitch filter of 7 cycles and the SCL time-out at 2 ms (2^17 cycles, ESP-IDF's driver's default for a device), enables the four statuses a transaction waits for (the controller's interrupt source is routed to no CPU line, so no interrupt is raised), sets the clock, and gives the two pads to the controller through the GPIO matrix as ESP-IDF's driver does: driven high, open drain, the internal pull-ups on, the output enable the peripheral's, both input signals read back from the pads. It records the core it ran on as the bus's.
  • The clock. Any rate from 50 kHz to 1 MHz, the range of SYSTem:COMMunicate:I2C:FREQuency, is set by rewriting the timing registers with the HAL's own arithmetic (i2c_ll_master_cal_bus_clk()) and latching them (i2c_ll_update()): i2c_bus::setClock() resets nothing and frees and allocates nothing, so the command kept its range through FW-14 and the protocol did not change. Ina228Driver::setBusSpeed() makes it on the bus's core, and *RST makes it only when the clock is not 400 kHz already.
  • A transaction. probe(), write(), read() and writeRead() each write one command list into the controller's eight command registers and its bytes into the 32-byte transmit FIFO: a START, the address byte, the bytes written, a repeated START and the read address for a read, the bytes read with the last one not acknowledged, and a STOP (at most 30 bytes each way). The caller then polls the interrupt status until the STOP's completion, a NACK, the controller's time-out or a lost arbitration, within 20 ms of esp_timer_get_time() (the xfer_timeout_ms Ina228Driver gives ESP-IDF's calls). A NACK ends the transaction once the bus is idle again, after the STOP the controller sends, and every status is cleared before the next one starts: no completion is left latched for a later transaction to take for its own, the fault of ESP-IDF's driver §2.2 records. A NACK answers ESP_ERR_INVALID_RESPONSE (ESP_ERR_NOT_FOUND from a probe), as ESP-IDF's driver does; a command that meets one reports i2c ESP_ERR_INVALID_RESPONSE.
  • Recovery. A time-out, a lost arbitration, a bus still busy after a NACK's budget, and a bus busy before a transaction starts reset the controller and restore its configuration, clock nine SCL pulses so that a device holding SDA low inside a byte finishes it and lets go, wait the pulses out, and reset and configure it again; the second reset also clears the pulse generator's enable, which ESP-IDF's LL says cannot be read back on this chip. The transaction answers ESP_ERR_TIMEOUT, or is not started when the bus stays busy through the pulses. i2c_bus::clearBus() asks for the same recovery. It is out of IRAM, a cold exit of the gate.
  • One core, one at a time. Every call but begin() is refused from the other core with ESP_ERR_INVALID_STATE before it touches a register, and so is one that starts while another runs on the bus's core (a task or an IPC call that preempted it): the preempted transaction completes untouched. The protocol already keeps the console's transactions and a capture apart (the R flag of docs/scpi.md, above); the refusal makes a breach visible as an error instead of two command lists interleaved in the registers.
  • On the bench (FW-14, 2026-11-22, ELF 45c88011a4310051, against FW-12's image b7f6e739ae8cee1f on the same rig an hour before, the T-Deck asleep behind the shunt at about 44 µA): 0.16.5's acceptance (§2.2) repeated, 100 of 100 *TST? 0, 20 scans at each of 400, 100 and 50 kHz with 0x40 alone, 200 rounds of the identity right; 15 s statistics captures with 0 read errors, dropped and stale edges, pace_err_ppm +86 (STATE), +87 (SLEEP), 0 (TRACE) and 0 (BURST at 1 MHz), where FW-12's image read +90, +88, 0 and 0; the null path's STATE floor 18.85 µA, where FW-12's read 18.81 and 18.86. Polling the transaction on Core 1 instead of waiting for ESP-IDF's interrupt moved neither the pacing nor the noise, so the fallback the plan kept (an interrupt on the static route, with a static semaphore) was not needed. allocs_since_main fell from 35 to 23, and three clock changes leave every heap count as it was (tests/bench/test_i2c_bench.py).
  • The host tests. The harness models I2C0's registers (sim::I2c, firmware/test/native/harness/sim.h): the clock and reset, the configuration, the timing staged and latched, both FIFOs, the command registers, the statuses appearing at the bit times the latched clock gives each transaction, and the INA228 model on the far side, whose own faults (a transaction failed by count or by register, a caller stalled) are NACKs and waits on the wire since FW-14, when the fake of ESP-IDF's driver went; and it can arm NACKs on an address or a data byte, a time-out that leaves the state machine stuck until a reset, a NACK whose STOP never comes, a device that holds SDA low until the pulses (or for good), and a controller that never answers. Every Bench and Scope fails a case that reached I2C0 from a core other than the one that clocked it, unclocked, or its clock outside the lock, started a transaction unconfigured, over another or from a command list the hardware would not run as meant, or overran or underran a FIFO. firmware/test/native/test_i2c_bus.cpp holds the set-up and its refusals, the clock across its range, each transaction's list on the wire, NACKs, the time-out, a stuck bus, a silent controller, the recovery and both refusals; i2c_bus.cpp is at 100 % of lines, branches and MC/DC conditions (the branch baseline was 122 after FW-14; it is 0 since FW-29, docs/testing.md). firmware/test/native/test_ina228.cpp holds the driver on it: every transaction from the far core reaches the wire on Core 1, a clock change at every rate of the range rewrites the timing and asks ESP-IDF for nothing, and a pin or clock begin() refuses leaves the bus closed. tests/firmware/test_i2c_on_bus_core.py holds I2C0's registers to i2c_bus.cpp alone.

2.5 The pin map's record (FW-03)

The pin map (firmware/src/pinmap.h: each role's GPIO, the relays' active levels, the pulls, the INA228's address and the boot clock) is kept the way the calibration is (§3.7), as the newest record of an append-only log over two 4 KiB sectors of raw flash, but in a log of its own: Record logs keeps a state, a buffer and an Acceptor for each of its two logs (flash_log::Log::Calibration and Log::Pins, 144 bytes of buffer each), and the pin map's sectors are the pins partition at 0xB000, right after calib, in what 0x9000 to 0xFFFF left unused (firmware/partitions.csv, flash_port.h kPinLogBaseAddress). The two logs share only the port, and the region check (§3.7) admits each log's two sectors and nothing between or across them, so a pin save never writes a sector the calibration log reads, and a calibration restore never rewrites the pins. The other places considered were refused: NVS allocates and is out of the build (§3.7); the calibration blob's spare bytes would make a calibration restore rewrite the pins and a pin change write a calibration record, which the registry holds to its hash; records of two kinds in one log would need a copy-forward of the other kind's newest record whenever a save changes sector, which the log does not have and its power-cut proof does not cover; RTC memory is lost at power-on.

The record (firmware/src/pinmap_store.h) is a 44-byte blob: the magic PINM, the layout's version (1), the board table's digest (pin_table::kPinTableDigest), the five roles' GPIOs, the boot clock, the three pulls, the two active levels and the address, every field explicitly sized and the padding named. The store's Acceptor takes a record only if this image would have written it: its length, magic and version, this table's digest, each pull and level byte 0 or 1, the padding zero, and a map pinmap::validate() takes; a save the Acceptor would refuse is not written. pinmap_store::load() mounts the log as a reboot does and answers Stored with the newest record's map, or the default map with Empty (no record), Unreadable (a read failed) or Refused: a refused record not older than the one taken means the map last applied was written under another table, layout or rule, and the defaults run rather than an older map nobody chose after it. Nothing is allocated and the store keeps no state of its own. An app flash leaves 0xB000 as it was, so on the first image with this table the sectors hold what an older image left there (erased, or NVS pages of an image before FW-16), which the log reads as no record. The host tests cut the power after every byte of every write and erase of a run that moves each log between its sectors three times, and read the other log back, byte for byte and by a mount, after each cut (docs/testing.md). The boot reads the map (§2.6); SYSTem:PINS:APPLy saves it from FW-05.

2.6 The boot from the pin map (FW-04)

app_main() reads the stored map before it drives a pin (pin_boot::load(), the two sectors of §2.5 and nothing else), because the map says where the relays are; it then releases them there (§6.1), parks every pin no role holds (§9), and brings the INA228 up on the map's bus on Core 1 (pin_boot::bringUp()): its pads, its pulls, its clock, and the address it pins or the scan. Sampler::begin() takes ALERT's pin and pull from the same map. With no record, a record this image refuses, or a flash that cannot be read, it is the default map (src=default), and a record of the defaults is the defaults.

What the read adds before the relays are released: 196 µs with an empty log, 537 µs with one record, and 13.0 ms with 135 records in the log, one short of both sectors full, of which each record's header, bytes and CRC-32 cost about 95 µs (esp_timer around pin_boot::load() on the meter, 2026-11-25, five resets each for the empty log and three for the full one, every reading within 1 µs of the others; a build of this package's code with the probe, not committed). Bank::begin() itself takes 0.47 ms, most of it the 18 parked pins after the relays are released, and app_main() starts 1.08 ms after ESP-IDF's timer does. A log the instrument writes holds one record per apply, so a rig reaches the 13 ms only after some 135 of them. Until then the relay pins are the floating inputs reset left, which the HW-316's inputs and the Click's LED both read as released (carrier-board.md §8.1), so nothing is energized in that time. Nothing else may come before the release, and the source gate (tests/firmware/test_meter_relays_fail_safe.py) holds that order and that the read reaches no pin.

The fallback. The bus is the one part of a map a boot can prove, because the INA228 answers on it or it does not. When a stored map's bus gets no answer (NoDevice, or a transaction that fails), the default bus (SDA on GPIO4, SCL on GPIO5, both pulls, the address scanned, 400 kHz) takes its place if the map with that bus is still one pinmap::validate() takes, that is, if no other role of it holds GPIO4 or GPIO5: the stored bus's pads are parked first, so they carry nothing of the new bus, the live map is the stored one with the default bus, SYSTem:PINS? reads src=fallback, one 117 names the bus that did not answer, and the record is left as it was for the person to see. When a role does hold one of those pins there is nothing to fall back to: src=stored, chip=none, one 117 that says so, and the console, on UART0's pins which no map may take, is the way back. ALERT and the relays never fall back by themselves: nothing tells a wrong pin from an absent part (a wrong ALERT pin shows as pace=timer, a wrong relay pin in the null path's check). A part that answers and is not an INA228, or fails its reset defaults or its trim checksum, is not a wrong bus and is reported as it is; and a map whose bus is already the default one has nothing to fall back to. At boot verified reads 1 for the default map's relays, which the rig's records checked, and 0 for any others until a null path passes its check on them (§2.7). No command stores a bus that was not proved (FW-05), so on the rig the fallback needs a wire moved after the apply; the host harness proves every case, its board's wires moved by the tests (sim::RigWires, firmware/test/native/test_pin_boot.cpp), and the meter showed five of them on 2026-11-25 on the same uncommitted build, whose APPLy stored the staged map with no proof: GPIO4 and 5 with 0x40 pinned at 100 kHz (src=stored, *TST? 0), the bus on GPIO18 and 21, the two lines swapped and 0x41 pinned (each src=fallback, one 117, *TST? 0, 400 kHz), and the bus on GPIO18 and 21 with ALERT on GPIO4 (src=stored, chip=none, one 117, the console answering, path=shunt pads=ok); allocs_since_main=0 frees_since_main=0 after the stored and the fallback boots. The records were then erased (0xB000, 8 KiB).

On the bench (FW-04, 2026-11-25, ELF d64cfbef9f136e24, the first image with the pins partition of §2.5 to run on the meter): SYSTem:PINS? read the default map, src=default verified=1 table=0x90072FE9, *TST? 0, kleidos-meter calibration verify applied before and after the bench suite (the partition table's change left the calibration log as it was), and DIAGnostic:HEAP? pre_main_allocs=0 pre_main_frees=0 allocs_since_main=0 frees_since_main=0 after it. The null path's STATE floor read 18.91 µA in the mean of ten 15 s captures (18.69 to 19.17) against 18.90 (18.61 to 19.12) on FW-03's image (aee38d0c1a9ebcd1) minutes later: the map moves no noise. Two of the ten, and three of FW-03's ten, read above the 19.0 µA the bench suite held one capture to: that is the spread of a 13,100-sample estimate (0.6 %), so the suite now allows a capture three standard errors of its own over the same 19.0 µA (tests/bench/test_i2c_bench.py FLOOR_ERRORS).

2.7 A map applied, proved, or put back (FW-05)

SYSTem:PINS:APPLy and SYSTem:PINS:DEFault change the map without a reflash (the SCPI command set, "The pin map"). The console refuses them under a window, with any coil energized and for a map the rules refuse, so a move starts with every relay released and the sampler asleep. pin_apply::moveTo() (firmware/src/pin_apply.h) is one move, whichever way it goes; the console calls it to try a map and, when the proof fails, again with the two maps the other way round:

  1. The relays (relay::Bank::move()), on the console's core: each new pin's latch at its released level before the pad is an output, as at the boot (§6.1). A pin a relay leaves, unless another role takes it, is parked toward the level that released that relay: pull-up for an active-low part, pull-down for an active-high one. A pull-down on an active-low module's input is a path through its input LED, so the pin is parked the other way; the next boot parks it low like any other no role holds, which leaves Relay 1 released on the rig (below, "On the bench").
  2. On the bus's core, through Ina228Driver::runOnBusCore() (esp_ipc_call_blocking(); in place when the bus is the console's core's, §2.2): ALERT moves (Sampler::moveAlert(): the old pin's enable, status and edge type cleared, the new one set as begin() sets it, the CPU line and its handler unchanged); the bus is forgotten (closeBus()); every pin no role holds any longer is parked, which takes the old pads off the controller's outputs so that they carry nothing of the bus that moves; and pin_boot::bringUpOn() opens the bus on its new pads and brings the INA228 up, the boot's own sequence. Two roles may change places: each step configures its own pads whole, and a pad another role of the new map holds is never parked.

The proof is the bring-up (§2.3) and the self-test's parts a map reaches (Console::partsTest(), which *TST? shares, §7). The bring-up resets the INA228, so the range is put back after it and the CHARGE window starts again. A map that passes is saved and read back (§2.5) and only then reported; a save that fails is a failure like any other. The revert is the same move and the same proof, the running bus clock put back, and exactly one 117 whatever was found on either side; a last good map that fails its own proof (the part lost its supply meanwhile) leaves chip=none with the reason a boot would give and the console answering. DEFault is kept whatever its proof finds, because it is the way back when nothing answers. The bus is the only part that can be proved: a relay pad reads back its own level on any pin, so verified falls to 0 with any move of a relay and a null path's check is what raises it. What the DUT's current can say of relays that moved, it says at rest: the shunt is read before the move and again after the proof and the release settle (50 ms), and a share of 2 mA or more that falls to three quarters or less (relay::shareLeftShunt(): a bypass closed, or a lead opened, by an active level that energizes its part when the relay is told it is released) puts the map back as a failed proof does, reason=rest, the two readings in the 117. A move that leaves the share standing, or a DUT under the floor, proves nothing either way (the relay may be on a pin with no wire), and verified stays 0.

The one exception is an IPC call the bus's core refuses, which ESP-IDF does only before its scheduler runs: ALERT and the bus have then not moved, so even DEFault is put back rather than report a map the bus is not on.

firmware/test/native/test_console_pins.cpp holds all of it on the simulated board, whose INA228 and relays sit on wires a test moves: each wrong map reverted with one error and the board pad for pin as it was, a good one surviving a reboot, each refusal, two roles that change places, a power cut at every byte of the save, DEFault with no INA228, no allocation. tests/bench/test_pins_bench.py is the same on the meter. What no test does on hardware is a board rewired to another map, since the rig stays rev D.

On the bench (FW-05, 2026-11-25, ELF 0e07120e923709dd, the T-Deck asleep behind the shunt): SDA on GPIO18, SCL on GPIO18, the pair swapped and the address pinned to 0x41 were each put back with one 117 (reason=no_chip), and ALERT on GPIO18 too (reason=alert, tst=32), in 50 to 60 ms from the order to its answer, with *TST? 0, q=cal, the scan 0x40 alone, the pads right and DIAGnostic:HEAP? at 0 allocations and 0 frees after each. addr=0x40 scl_hz=100000 applied, was src=stored after a reset and ran at 100 kHz, and SYSTem:PINS:DEFault brought 400 kHz and src=default back, over another reset. Relay 1 moved to GPIO16, where nothing is wired, with the HW-316's IN1 still on GPIO7: the DUT's current read 40.9 µA with GPIO7 driven high, 40.9 µA with it parked high after the move and 40.8 µA with it parked low after a reset, so K1 stayed released and the lead closed in all three (the null path, the lead open, read −2.0 µA in the same session). The pull-down, 45 kΩ, does not energize the input; what it sinks through the input's LED was not measured, and the pin a relay leaves is parked toward its released level for the session all the same. The sleeping T-Deck draws too little for the null path's check (check=unverified, 2 mA needed), so verified=1 from check=ok has been seen on the host harness only; a reset on the rig's own relays read verified=1. The rest of the bench suite passed on the same image, the heap sweep with an apply, a revert and DEFault in its pins family, and 0.16.5's I2C acceptance. On 2026-11-26 (ELF f7e84874d9376d08, the integration of 0.18.0) Relay 2 moved to GPIO17 the same way: the DUT's current read 42.5 µA driven, 42.3 µA moved, 41.9 µA after a reset and 42.3 µA back, the Relay 2 Click's K2 released throughout; no null path was asked of it there, because under the check's 2 mA floor ROUTe:NULLpath ON opens K1 whether K2 closed or not (“The pin map” in the SCPI command set), and Relay 1 on GPIO16 took one that formed check=unverified, the rig's K2 closing beside a K1 that never opened. The same day the boot-time fallback was seen on the meter: a record of SDA on GPIO18 written into the pin log with esptool booted src=fallback on the default bus with one 117, the record kept, and SYSTem:PINS:DEFault brought src=default back (“The figures of record: 0.18.0” in the testing guide).

3. What is measured, and how

3.1 Range and calibration

Register Value Why
CONFIG (0x0) 0x0000 on range 0, ADCRANGE set on range 1 TEMPCOMP = 0, CONVDLY = 0
SHUNT_CAL (0x2) 0x1000 = 4096, always Exact in both ranges; also the reset value
SHUNT_TEMPCO (0x3) 0x0000 Left off (§11)

ADCRANGE = 0 is the default and the range a campaign needs. It covers 10 µA to 1.6384 A in one setting, range 1 clips at 409.6 mA, and across [DS] Table 8-2 the noise ratio of range 1 to range 0 has median 1.000: the quantizer is dithered by 16 LSB of noise, so averaging recovers resolution far below the LSB either way (ina228-reference.md §8.2). SENSe:CURRent:RANGe:INDex 1 stays a manual choice for a run guaranteed to stay under 409.6 mA, refused while a window runs, because a switch costs a discarded conversion period, an RSTACC and that range's own null.

What range 1 buys is a smaller margin, and the Kleidos campaign takes it where it is safe. The host's uncertainty model charges the INL as ±2 m% of the range's full scale, 32.8 µA on range 0 and 8.2 µA on range 1, and half a count of quantum, 1.56 against 0.39 µA. So the Kleidos QA harness selects SENSe:CURRent:RANGe:INDex 1 itself for the captures whose stored windows its power store has shown could not hide a conversion past 300 mA (TD-08's floor and TD-16's lsleep and c3 plans), with a null of that range; refuses any capture that reaches 73 % of its range's full scale or clips (the clip detector, §3.5); repeats such a range-1 capture once on range 0, with range 0's null, when the run needs no hands; and puts the instrument back on range 0 when the row ends (the Kleidos firmware repository's qa/qa_lib/power/ranges.py and docs/testing/power-campaign-tdeck.md §1.6).

SHUNT_CAL is never corrected. The ×4 the datasheet asks for ADCRANGE = 1 cancels exactly the 4× smaller CURRENT_LSB of that range, so 4096 is right in both ([DS] §8.1.2 Equations 2–3, worked in ina228-reference.md §8.3).

The measured shunt is applied in software, as shunt_uohm, one value per range (SENSe:CURRent:SHUNt:RANGe<n>, from 0.4.0). A SHUNT_CAL correction would have 1/4096 granularity where shunt_uohm has 1/100000, and it would apply to CURRENT, POWER and CHARGE and not to VSHUNT, the primary path (§3.5), which is a split brain in the one place an instrument must not have one. The factor 100000 / shunt_uohm is applied on the device to every quantity it reports but the raw CHARGE count (§3.6), and the capture header names it.

3.2 The four profiles

The requirements are five orders of magnitude apart in current and in time, and no single AVG setting both resolves 10 µA and shows a BLE peak (ina228-reference.md §8.4), so they are four configurations of one instrument, chosen per run (SENSe:PROFile). Each ADC_CONFIG word is derived from the [DS] §7.6.1.2 field encodings by adcConfigWord() and checked by a static_assert against the value stated here; none is a copied literal (kProfileSpecs, firmware/src/sampler.cpp, which carries each row's reasons):

bits 15-12 MODE | 11-9 VBUSCT | 8-6 VSHCT | 5-3 VTCT | 2-0 AVG
BURST 1010 (Ah) | 000 (50us) | 000 (50us) | 000 | 000 (1) -> 0xA000
TRACE 1010 (Ah) | 000 (50us) | 011 (280) | 000 | 000 (1) -> 0xA0C0
STATE 1111 (Fh) | 000 (50us) | 101 (1052) | 000 (50) | 000 (1) -> 0xF140
SLEEP 1111 (Fh) | 000 (50us) | 111 (4120) | 000 (50) | 010 (16) -> 0xF1C2
BURST TRACE STATE SLEEP
The job Resolve a transient Shape a burst Measure a state Measure deep sleep
MODE Ah shunt only Ah shunt only Fh bus + shunt + temp Fh bus + shunt + temp
Period 100 µs (two conversions) 280 µs 1152 µs 67,520 µs
Sink ring ring stream stream
Pacing timer timer alert pin alert pin
Bus 1 MHz 400 kHz 400 kHz 400 kHz

A conversion lasts ( VBUSCT + VSHCT + VTCT ) × AVG over the inputs the mode enables, because they convert sequentially and averaging repeats the whole sequence ([DS] §7.3.4), and a sample is one conversion on every profile but BURST, which takes every second one: its loop cannot read a 50 µs conversion inside 50 µs, so its period is stated as two (conversionsPerSample), which keeps t0 + index × period honest. The reasons behind the choices, each kept beside its row in kProfileSpecs:

  • AVG = 1 on the ring profiles. Averaging dilutes an event shorter than its window: at AVG = 16 a 1 ms, +100 mA burst shows up once, as +22 mA. At AVG = 1 it spans three to four TRACE samples. Average afterwards, on the host, where the raw samples are still there.
  • Temperature on STATE and SLEEP, for 50 µs a period: the die temperature is what says the null has gone stale (§3.7). TRACE and BURST take it at the boundaries instead, one triggered conversion (MODE = 4h) before the first sample and one after the last, outside the capture, because writing ADC_CONFIG restarts a conversion in progress ([DS] §7.3.4); the header carries die_mc_start= and the close die_mc_end=.
  • BURST buys time resolution and nothing else. The 50 µs conversion is noisier per point, its mean is not a level, and its offset is its own (§3.4): a null taken on another profile does not apply to it. Use BURST to see an event and STATE to put a number on a level.

What each profile is worth. A shorter conversion is noisier per point by roughly the square root of the ratio of the windows, so the mean of a whole second is no better on BURST than on TRACE:

BURST TRACE STATE SLEEP
Sample rate 9,898 Sa/s 3,571 Sa/s 868 Sa/s 14.81 Sa/s
Per-sample noise ≈84 µA rms ≈35 µA rms ≈21 µA rms ≈2.3 µA rms
After 1 s of host averaging ≈0.84 µA rms 0.59 µA rms 0.73 µA rms 0.60 µA rms

BURST needs a 1 MHz bus, and the rule is half the period. One retained read costs about 38 µs at 1 MHz and 95 µs at the 400 kHz default (§3.5). INITiate refuses a ring profile whose read does not come in under half its period (firmware/src/sampler.cpp, retainedReadMicroseconds()), a threshold measured rather than rounded: a 95 µs read, which does fit inside 100 µs, slips BURST to 150 µs, three conversions a sample instead of two, because the loop's own non-bus work is worth tens of microseconds, and half classifies every combination measured on this rig correctly, BURST and TRACE at 400 kHz and at 1 MHz. A slip that gets past it is caught after the fact by pace_err_ppm in FETCh:STATistics?, and by pace_unmet past 3 %.

The averaging override (0.18.0, FW-06). A profile's averaging count and shunt conversion time are its definition, and they can be overridden as a measurement setting, off by default, for a run that wants the INA228 to average (SENSe:AVERage, docs/scpi.md "The averaging override"). The sampler keeps one override per profile (Sampler::averaging_, three static bytes each, set back to the profile's own by begin() and by *RST, stored nowhere); Sampler::conversion() is the profile's row with the override's AVG and VSHCT in it and the word and the period derived again by the functions the table itself is derived with, or the row untouched while it is off. beginCapture() takes that once, uses it for the word, the wait, the pacing probe and the boundary temperature's restore, and latches it in windowSpec_, in internal RAM, which the loop, stop(), the null's end and a later dump read: a setting changed after the window closes re-times nothing. CaptureInfo carries the count, the time, the period and whether the override was on to the header. Off, every byte of a capture is 0.17.0's (the golden transcript's sessions before the override's own are unchanged byte for byte).

What paces a profile says what it can be given, and a setting outside it is refused before it changes anything:

  • BURST has no override. Its 50 µs conversion is its definition, and its loop already takes every second one.
  • The shortest period is over twice the bus time a sample's reads take at the running clock, the margin the ring profiles' rule above measured: 525 µs of reads on STATE and SLEEP at 400 kHz (four registers, §3.5) and 210 µs at 1 MHz, so 1051 and 421 µs; one retained read on TRACE, so 191 µs at 400 kHz. On TRACE it is never under 100 µs, the period BURST's loop keeps (§3.4) and the shortest shown. It is judged when the override is set and again at INITiate, because the bus clock moves at run time. At the fastest clock it keeps a four-channel stream inside its share of the line (a static_assert, as for the profiles' own).
  • The longest period is 200 ms, kCaptureFeedUs: the loop then checks in with the watchdog at least once a sample, a stop is acknowledged inside its 500 ms even on a dead ALERT wire (two periods and 10 ms, §3.3), and INITiate's first conversion and eight probed ones hold the console 1.8 s, under half the watchdog's 5 s. static_asserts hold the three. Averaging longer than that is the host's, which loses nothing by it (§3.8).

*TST?'s probe is STATE's own word whatever the override.

On the bench (FW-06, 2026-11-25, ELF 512499c7a306c77a, the T-Deck asleep behind the shunt, tests/bench/test_averaging_bench.py). STATE streamed 15 s at each count, pace=alert pace_edges=8, dropped=0 read_err=0 stale_edges=0 pace_fallback=0; off again period_us=1152; DIAGnostic:HEAP? 0 allocations and 0 frees since app_main() after each. The null path's standard deviation, on 15 s statistics captures (the first run):

STATE ADC_CONFIG period_us pace_err_ppm streamed Null path sd_na (samples) Against AVG 1 The square root says
off (AVG 1) 0xF140 1,152 (+96 on the null path) 18,850 (13,101) 1 1
AVG 16 0xF142 18,432 +98 4,854 (819) 1 / 3.88 1 / 4
AVG 64 0xF143 73,728 +96 2,378 (204) 1 / 7.93 1 / 8

The periods next to each limit were kept too, 15 s of statistics each with nothing lost: STATE 4 × 50 µs (600 µs) and 1 × 540 µs (640 µs) at 1 MHz at +102 and +100 ppm, STATE 4 × 280 µs (1,520 µs) at 400 kHz at +102, TRACE 4 × 50 µs (200 µs) at 400 kHz and 1 × 150 µs at 1 MHz at 0, SLEEP 512 × 280 µs (194.56 ms) at +103, every ALERT-paced one on ALERT. A second run of the suite an hour later read 18,819, 4,685 and 2,553 nA on the null path and kept every period again. In both runs the STATE 4 × 280 µs capture counted one stale edge, where 25 one-second captures and a 60 s one of the same override counted none: its first sample came 1,619 and 1,616 µs after the start at a 1,520 µs period, so a conversion had ended while the start's own DIAG_ALRT read released the pin, and its edge found no flag. Only that conversion is lost, and the profiles' own periods have the same window.

The conversion time changes the offset. The null path's means above were −3.2, −2.7 and −2.1 µA at AVG 1, 16 and 64, and CHARGE, which sums every conversion whatever the count, read −3.5, −3.1 and −2.4 beside them: a drift along the three captures that the count had no part in. The conversion time is another matter. At AVG 16, the sleeping T-Deck, three interleaved 6 s captures of each time, read 41.6 µA at 2,074 µs, 41.4 at 1,052, 41.3 at 540, 40.8 at 280, 40.5 at 150, 39.2 at 84 and 25.8 at 50 µs: the 50 µs conversion's own offset that BURST shows (§3.4), 15.6 µA below the others, whatever it is averaged by, and 2 µA at 84 µs. So an override of 50 or 84 µs is for seeing an event, not for a level, and a null taken on another time does not apply to it.

3.3 Pacing

Two ways to know a conversion is ready: the ALE pin (DIAG_ALRT CNVR = 1, APOL = 0: active low, open drain), whose falling edge an interrupt on Core 1 turns into a binary semaphore the sampler takes; and the host timer at the profile's nominal period, esp_timer_get_time() with a short spin for the sub-millisecond remainder (a 280 µs cadence is below the FreeRTOS tick, so no blocking primitive can express it).

What the pin does (bench, 2026-11-20, a probe build that counted and timed the edges). CNVRF is set "after all conversions and averaging is completed" and clears on reading DIAG_ALRT or writing ADC_CONFIG ([DS] §7.3.4), and the pin follows CNVRF: it goes low at a conversion's end and stays low until DIAG_ALRT is read, in either ALATCH mode. A reader that reads DIAG_ALRT after each edge sees one edge per conversion:

Profile, ALATCH = 1, one DIAG_ALRT read per edge Edges per second Expected Missed, extra Interval sd CNVRF set at the read
STATE (1,152 µs) 868.0 868.06 0, 0 0.5 µs 100 %
SLEEP (67.52 ms) 14.81 14.81 0, 0 3.5 µs 100 %
TRACE (280 µs) 3,171 3,571 4,000 in 10 s 92 µs —

TRACE cannot be paced so: the edge, the wake and a DIAG_ALRT read take about 145 µs at 400 kHz, the loop misses one conversion in nine, and the read would move the retained VSHUNT pointer the profile's period rests on (§3.5). BURST is shorter still. So the instrument paces by profile and measures the pin at every INITiate (0.9.0):

TRACE, BURST: pace = timer, no probe (pace_edges=0 pace_expect=0)
STATE, SLEEP (in the sampler task on Core 1, where the capture runs, 0.16.2):
1. Write the profile's ADC_CONFIG; arm the falling-edge interrupt on ALE (GPIO6),
then read DIAG_ALRT to clear CNVRF and release the pin (the loop's order).
2. For 8 conversion periods, read DIAG_ALRT after every edge, as the capture will.
3. edges within +/-1 of 8 -> pace = alert (one sample per edge)
otherwise -> pace = timer (the wire is absent, or the pin rings)
4. Report pace= in the header. Every capture says which it used.

On pace = alert the loop takes the semaphore, stamps the sample with the time it woke (the conversion's end, before the reads' bus time), reads DIAG_ALRT first (which releases the pin for the next conversion and ORs the latched clip bits into flags=), then the profile's registers. An edge whose DIAG_ALRT read finds CNVRF clear had no conversion behind it: it takes no sample and is counted as stale_edges= in FETCh:STATistics?. Starting the loop also reads DIAG_ALRT once after enabling the interrupt, because a conversion that ended since the start's last read left the pin low with no edge. A wait that times out (two periods and 10 ms) means the pin stopped: the capture falls back to the timer from there and says pace_fallback=1; a DIAG_ALRT read that fails ends the same way. On the alert path the task blocks and IDLE1 runs; the spin exists only on the timer path (§5.1).

On pace = timer the INA228's oscillator (±0.5 % at 25 °C, ±1 % over temperature, [DS] §6.5 FOSC_TOL; about +90 ppm on this part) and the S3's crystal drift apart, so a long ring occasionally repeats or skips a conversion at a rate bounded by that skew; the drift anchors (§4.1) let the host see the real times. pace_err_ppm in FETCh:STATistics? compares the achieved period, from the first sample to the last over samples - 1 (0.15.0), with the nominal one: on a timer-paced capture it measures whether the loop kept its own deadline, on an alert-paced one the INA228's oscillator. A timer-paced loop that arrives more than a period past its deadline re-bases the deadline to the arrival instead of reading back to back, and counts it in rebased= (0.14.0).

Where and in what order the probe runs (0.16.2, 0.16.3). Up to 0.16.1 the console ran the probe on Core 0 and released the pin before arming the interrupt; a late read there let a conversion end on a pin still low, which makes no edge, and a conversion that ended between the release and the arm left the pin low for the whole window. On the NW-00 spike's image (2026-11-21, 40 probes a state) the console's probe chose timer in 6 of 40 with the station sending 200 kB/s and in 20 of 40 with the SoftAP sending; run in the sampler task and armed first, it chose alert in every probe under either radio, waking 15–17 µs after the edge at the median. Since 0.16.2 the console asks the sampler task for the probe and waits for its answer (8 periods and 500 ms), and an answer that does not come is pace=timer; since 0.16.3 it asks only a task that is waiting for a start, so a stop the loop has not acknowledged (107) makes the probe say timer at once.

*TST? lets a conversion end before its probe (0.16.4). A conversion that ends inside the ADC_CONFIG write pulls ALE low, and the write clears CNVRF behind it ([DS] §7.3.4): the pin stays low, no read releases it, and the probe counts no edge. On the bench 6 of 60 *TST? calls failed so; Sampler::probeAlert() now lets two periods (2.3 ms) pass after its writes, and 150 of 150 passed with 8 edges. INITiate's probe never met it, because beginCapture() lets a period pass after its writes and makes four reads before the probe.

3.4 The sampler task on the bench (0.9.0)

Measured on 2026-11-20 on instrument KM-0000000000, firmware 0.9.0 (image meter, ELF 9f812041835d2a89, a clean build), in the real sampler task (Core 1, priority 10), the DUT a T-Deck behind K1 and also on its USB supply (about 38 µA through the shunt), the bus at 400 kHz except for BURST at 1 MHz. STATE and SLEEP streamed i_ua for 60 s each, three times; the intervals are the stream's own t=; a gap over 1.5 periods counts as missed conversions, one under half a period as an extra.

Capture Header Samples stale_edges Missed, extra Interval mean, sd (min–max) pace_err_ppm
STATE × 3, 60 s pace=alert pace_edges=8 pace_expect=8 52,156 / 52,142 / 52,145 0 0, 0 1,152.11 µs, 2.2 µs (1,018–1,283 µs) +78 / +82 / +74
SLEEP × 3, 60 s pace=alert pace_edges=8 pace_expect=8 889 / 889 / 890 0 0, 0 67,526.2 µs, 3.6–3.8 µs (67,516–67,539 µs) +57 / +55 / +60
TRACE × 3, 10 s pace=timer pace_edges=0 pace_expect=0 35,912 / 35,912 / 35,887 0 — 280.008 µs (dur_us / samples) +28 / +28 / +25
BURST × 3, 10 s, 1 MHz pace=timer pace_edges=0 pace_expect=0 99,202 / 99,162 / 99,171 0 — 101.36 µs +13,590 / +13,600 / +13,600

Every capture closed with dropped=0 read_err=0 pace_fallback=0 flags=0xC003, so the fresh-sample ratio was 1.0 on all six alert-paced captures, and DIAGnostic:HEAP? ended the session at allocs_after_init=0 frees_after_init=0. The alert-paced interval mean sits 50 to 100 ppm above nominal, the INA228's oscillator against the S3's crystal; the sd is the wake latency of the sampler task, and the widest interval pairs with the narrowest next to it (an edge served late, not a conversion lost). The same profiles on the null path (ROUTe:NULLpath ON, 2 × 15 s each) gave the same: 0 missed, 0 extra, 0 stale.

BURST does not keep its period, and that is the loop. A timer-paced pace_err_ppm compares the achieved period with the S3's own clock, so it cannot see the INA228's oscillator: TRACE on the same loop reads +28 ppm. BURST's +13,600 ppm is its loop costing 101.36 µs a sample against a 100 µs deadline. One more esp_timer_get_time() per sample on that path (a candidate build of this change) moved it to +20,500 ppm and 102.05 µs, which is how close to the bone it runs; the 0.8.0 heap-proof session's +14,470 ppm is the same loop. It is inside pace_unmet's 3 % and the drift anchors carry the real times, so a BURST trace is still reconstructed correctly from its anchors, but t0 + index × period drifts 1.4 % and two conversions per sample is three now and then. The optimization level and the loop's own work are WP-15's (the plan's -O2 and timer re-base), with this figure as the before.

-O2 keeps BURST's period (0.14.0). Every image before 0.14.0 was built at IDF's default -Og; the per-sample work 0.10.0 to 0.12.0 added had put BURST's loop at 103.5 µs against its 100 µs deadline (+35,000 ppm). Moving the interrupts to Core 1 gave back 0.4 µs (103.1 µs, +31,000 ppm); CONFIG_COMPILER_OPTIMIZATION_PERF gave back the rest: 100.01 µs a sample, +110 to +120 ppm over two 10 s captures, with 7 re-based deadlines in each (bench, 2026-11-20, the T-Deck asleep behind the shunt). TRACE (+28 to +32 ppm), STATE and SLEEP (the INA228's own +57 to +63 and +3 to +12 ppm) and the boot did not move.

A late timer-paced loop is re-based (0.14.0). Before, the deadline only ever advanced by a period (nextDeadlineUs_ += periodUs), so a loop that came late by more than one, a stalled read or a preemption, read back to back until the deadline caught up, taking the same conversion more than once. waitUntil() now returns the clock as it first read it, at no extra read, and an arrival more than a period past the deadline re-bases the deadline to the arrival and counts it in FETCh:STATistics?'s rebased=. A ring's implicit t0 + index × period is off after a re-base until the next anchor, which the count says.

pace_err_ppm from the first sample, not the start (0.15.0). Up to 0.14.0 the achieved period was dur_us / samples, and dur_us runs from the capture's start: on an alert-paced capture the first edge comes at the part's own phase, anywhere up to a period after the start (65.8 ms of SLEEP's 67.5 ms on this rig, 0.5 ms of STATE's 1.15 ms), so the figure read that phase as an error of up to 1 / samples. That is why SLEEP read 30 to 60 ppm below STATE above, on one oscillator. Measured on 2026-11-21 (T-Deck asleep, 2 × 20 s STATE, 2 × 30 s SLEEP): the streams' own intervals gave +94.3 to +95.9 ppm on both profiles; 0.14.0 reported +61 and +63 (STATE), +35 and +37 (SLEEP); 0.15.0, which takes the span from the first sample to the last over samples - 1, reported +94, +95, +93 and +90, each within 1 ppm of its stream. On a timer-paced capture the first sample's own read latency is all that is left at the span's ends (TRACE: −18 ppm over 5 s, a 95 µs read against 5 s). The pace_err_ppm figures of the tables above are the earlier estimate's.

BURST reads its own offset. The 0.8.0 session's BURST mean of −4.3 µA beside +11 to +13 µA on the other profiles repeated here: under the DUT, BURST read 20.6 to 21.0 µA where TRACE, STATE and SLEEP read 36.8 to 41.5 µA, and on the null path −7.5 µA where the others read −3.4 to −5.3 µA. The hardware CHARGE accumulator says the same with the bus silent: after a capture closes the device keeps converting on its word, so SENSe:CHARge:RESet, 20 s with no I²C traffic and SENSe:CHARge? integrate one conversion time alone. Raw (no null applied), twice each, the 50 µs conversion integrated 32.1 and 32.3 µA where 280 µs and 1,052 µs integrated 58.4 to 60.3 µA under the DUT, and 5.8 and 6.1 µA where they integrated 15.0 to 16.2 µA on the null path (whose check said unverified, the DUT drawing microamps). So the deficit belongs to the 50 µs conversion itself, not to the bus traffic or the loop: its offset differs from the longer conversion times' by about 1 µV on the null path and by 2.7 µV under the DUT (the common-mode and the load differ between the two). A null taken on another profile does not apply to BURST, and its mean is not a level, as its entry in the profile table of sampler.cpp already says ("use it to see an event, not to put a number on a level"); a per-conversion-time null is the registry's question, not this change's.

3.5 What is read per sample

Profile Per sample Bus time At the window's boundaries
BURST VSHUNT only, pointer retained about 38 µs at 1 MHz DIETEMP (triggered), DIAG_ALRT, CHARGE
TRACE VSHUNT only, pointer retained about 95 µs at 400 kHz DIETEMP (triggered), DIAG_ALRT, CHARGE
STATE DIAG_ALRT (it releases the ALE pin, §3.3), VSHUNT, VBUS, DIETEMP about 526 µs CHARGE
SLEEP DIAG_ALRT, VSHUNT, VBUS, DIETEMP about 526 µs CHARGE

VSHUNT, not CURRENT, is the primary. CURRENT_LSB = V_LSB / R exactly in both ranges (§3.1), so CURRENT carries no information VSHUNT does not; VSHUNT is untouched by SHUNT_CAL, so a mis-programmed calibration cannot corrupt the primary number, only be detected (§2.3); and it is the raw quantity the software shunt correction divides and the null subtracts, in the units it was measured in.

POWER is never read. TRACE and BURST do not produce it (MODE = Ah, [DS] §7.3.2), and on the bus profiles it is computed from VBUS and the corrected current (§3.6), which costs no bus time and sidesteps the register whose 24 bits have no reserved nibble ([DS] §7.6.1.9).

DIAG_ALRT is read every sample on SLEEP and on every alert-paced capture, and at every close, to catch MATHOF (bit 9, "current and power data may be invalid", latched until a new conversion or RSTACC, [DS] Table 7-16) and the clip detector's SHNTOL and SHNTUL (below); the close reports flags=0x…, and a window with MATHOF set is q=invalid.

The clip detector. On SLEEP a sample averages 16 conversions, so a sample well under full scale can hide one conversion that clipped. The INA228's shunt comparator sees every raw conversion (SLOWALERT = 0), and the firmware arms it at full scale: SOVL = 7FF8h and SUVL = 8008h, eight limit counts (128 VSHUNT counts, 0.024 %) inside each end on either range, written at every INITiate and CALibration:ZERO, with ALATCH = 1 so that SHNTOL and SHNTUL hold until the next DIAG_ALRT read and reach the close's flags= (firmware/src/ina228_regs.h kShuntOverLimitClip). FETCh:HEADer? carries the setting, diag_cfg=0xC001 alatch=1 sovl=0x7FF8 suvl=0x8008, and a healthy window closes at flags=0xC003 (ALATCH, CNVR, CNVRF and MEMSTAT) with neither 0x0040 (SHNTOL) nor 0x0020 (SHNTUL) set. A capture from an image that armed no detector (0.1.0 as built before 2026-10-31) carries no such keys, and the host then holds every filed window to the bound one hidden conversion of it could have read instead. The limits are the one use of the alert thresholds the instrument keeps (§11).

The boundary CHARGE reads are the capture's own, charge_raw_start in the header and charge_raw_end at the close, against the capture's own charge_us (§3.8). Neither resets the accumulator, so a window the operator opened with SENSe:CHARge:RESet is left alone.

The retained pointer is what makes the ring profiles affordable: "If repeated reads from the same register are desired, it is not necessary to continually send the register pointer bytes" ([DS] §7.5.1.1). The driver writes the pointer once (setPointer()) and then only reads three bytes a sample (readRetained()); the bus profiles change pointers and use a write-read per register. That one write must take: the start's last read leaves the pointer on DIAG_ALRT, so a failed write would make every read return DIAG_ALRT's bytes as shunt counts, with no read failing. Sampler::retainShuntPointer() writes it again after a failure, three times at most, and if none takes the capture ends at once with no sample and read_err=1 (the review of 2026-11-24).

3.6 The conversion arithmetic — integer, exact, no float

The measurement path carries no floating point, and neither does the print boundary: every value on the wire is formatted from integers in the device's own units (firmware/src/scale.h, host-tested; the report keys carry their unit in their name, docs/scpi.md). Units are picovolts and nanoamps, chosen so every datasheet LSB is an exact integer.

Decoding the wide registers ([DS] §7.6.1.5–7.6.1.11): VSHUNT, VBUS and CURRENT carry a 20-bit signed value in bits 23 to 4 with four reserved bits below, POWER uses all 24, and CHARGE is 40 bits signed. decode20() and decode40() sign-extend them.

The LSBs, as exact integers, from [DS] §7.6.1 and §8.1.2 with SHUNT_CAL = 4096:

Quantity ADCRANGE = 0 ADCRANGE = 1 Integer constant
VSHUNT 312.5 nV 78.125 nV 312500 / 78125 pV
VBUS 195.3125 µV same 195312500 pV
DIETEMP 7.8125 m°C same 125/16 m°C
CURRENT 3.125 µA 0.78125 µA 3125000 / 781250 pA
Charge 3.125 µC 0.78125 µC 3125000 / 781250 pC

The conversions, each exact:

shunt_pv = decode20( vshunt_raw ) * shunt_lsb_pv // +/-1.638e11, int64
i_na = ( shunt_pv - offset_pv ) * 1000 / shunt_uohm // pv / uohm is microamps
bus_pv = decode20( vbus_raw ) * bus_lsb_pv // always >= 0
vbus_uv = bus_pv / 1000000 // the SOURCE side
die_mc = dietemp * 125 / 16
v_dut_pv = bus_pv - ( shunt_pv - offset_pv ) // the DUT's side
p = ( v_dut_pv / 1000000 ) * i_na // reduced to uV first
charge_nc = decode40( charge_raw ) * charge_lsb_pc / 1000 // NOMINAL shunt

With the nominal shunt_uohm = 100000, one count of range 0 gives exactly 312500 · 1000 / 100000 = 3125 nA, which is CURRENT_LSB: the arithmetic checks itself. The voltage is reduced to microvolts before the product with the current, which would otherwise reach 3.8e20 at 3.8 V and 100 mA and overflow int64_t.

CHARGE is the one quantity not shunt-corrected on the device. A full-scale count in nanocoulombs is 1.7e15, and × 100000 / shunt_uohm on top of it overflows 64 bits; so SENSe:CHARge? reports the raw count beside a conversion at the nominal 100 mΩ, and the host applies the factor. The capture's own CHARGE mean (§3.8) is a current, small enough to correct on the device, and is.

Two voltages, and the key names which. vbus_uv is what the INA228 measured on the source side of the shunt; the stream's v_mv is v_dut_pv, what the DUT sees, less the burden voltage (13 mV at 130 mA). The burden voltage is free: it is the offset-corrected shunt voltage itself, provided VBUS is wired upstream of the shunt, which it must be anyway, because the pin's 1 MΩ input ([DS] §6.5 ZVBUS) draws 3.8 µA at 3.8 V and would put it through the shunt downstream. The header's vbus_side= says which terminal the owner recorded (CALibration:VBUSside), and rig-wiring.md records the rig's.

3.7 The offset null and the quality token

At 0.100 Ω, 10 µA is 1 µV, exactly the part's maximum offset (Vos ±1 µV, [DS] §6.5). The null is not a refinement; it is the measurement. CALibration:ZERO <seconds> runs the live profile over a window of up to 600 s on a circuit whose shunt carries no DUT current, the source still on IN+ so that the null is taken at the common mode it will be measured at, and stores the mean VSHUNT in picovolts for the live range with the die temperature it was taken at, reporting the sample standard deviation so that a bad null is visible. With the relays, the lead is opened by K1 and the DUT stays fed through K2 (ROUTe:NULLpath ON, §6.1); by hand, the DUT's lead is unmated.

What is kept, and where. One blob, the newest record of the calibration record log (written by CalibrationStore, firmware/src/calibration.h, from FW-16; an NVS blob of the same layout, version 3, before): each range's shunt_uohm, each range's offset and its die temperature, vbus_side, the opaque cal_tag (at most 24 bytes, written by the host and only echoed) and the calibration date (CALibration:DATE, checked to be a calendar date and never compared with anything: there is no wall clock on this instrument). The blob is a working copy: the calibration is the registry in calibration/ (calibration/README.md), which survives a flash erase, and kleidos-meter calibration restore writes it back. A save that fails queues 106 and leaves the value live until reboot. There is no migration from NVS, which would need NVS: the first boot of an image that keeps the log reports q=uncal until the restore.

The record log (FW-15, used from FW-16). Every NVS save allocated, so the blob is kept by firmware/src/flash_log.cpp instead: an append-only log over two 4 KiB sectors of raw flash, nothing allocated. A record is a 16-byte header (the magic KLOG, a sequence one above the highest the sectors hold, the blob's length, and a CRC-32 over those three words and the blob, each word least significant byte first) and the blob, at most 128 bytes, at a 4-byte boundary of its sector. A mount reads both sectors record after record until an erased header, a header or CRC that does not hold (that sector then takes nothing more) or the sector's end, and the record with the highest sequence is the log's. A save appends after the newest record when its sector held nothing invalid, the record fits and its bytes read erased; otherwise, and only then, it erases the other sector and writes the record at its start, so the sector holding the newest record is never erased. Each save reads its record back and compares it byte for byte; each load reads the record again and checks it. A save makes at most two changes (the erase and the write), and a power cut in either leaves the last complete record the newest, which the host tests prove at every write and erase of a run that changes sectors several times (docs/testing.md). What it does not survive is a bit the flash loses inside a record a later one follows in the same sector: the scan stops there, and the registry, not the log, is the calibration.

What the store takes. The mount is given the store's judgment of a record (flash_log::Acceptor): the current layout (its length, magic and version 3) and shunts this firmware could have measured, the common one in 0.05..0.2 Ω and each range's 0 or in it. A record it refuses is passed over as one whose CRC does not hold: the scan of its sector stops there, and the newest record before it is the calibration, else the defaults and q=uncal. It is never clamped into the window, because a clamped shunt would convert every reading with a resistance nobody measured, under q=cal. The next save is numbered above the refused record too, so that it is the newest the sectors hold; a save the store would refuse is not written (106). *TST?'s bit 128 reads the log again and sets for a read that fails or a refused record not older than the one taken.

Where it lives, and how it is written (FW-16). The log's sectors are the calib partition of firmware/partitions.csv, at 0x9000 right after the partition table, a constant of the firmware (flash_port.h kLogBaseAddress), so nothing looks a partition up; the table holds only it, the pin map's pins (from FW-03, §2.5) and the image (no NVS, no PHY data), and tests/firmware/test_partition_table.py holds the CSV to the constants and to both builds' settings. firmware/src/flash_port.cpp reads, writes and erases through esp_flash_read(), esp_flash_write() and esp_flash_erase_region() on the default chip, from the log's static buffer in internal RAM, which needs no bounce buffer. ESP-IDF checks each write and erase of the main flash first, and its check walked the partition table with an iterator it allocated: the image is linked with -Wl,--wrap=esp_partition_is_flash_region_writable (firmware/CMakeLists.txt), so the check is the firmware's, a comparison with the two logs' regions (the calibration's two sectors and, from FW-03, the pin map's two in the pins partition, §2.5; a range that runs from one into the other is refused), and CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED leaves out ESP-IDF's second check, which needed the running partition. The protection is narrower, not wider: every write or erase outside those 16 KiB, the bootloader, the table and the image included, is refused before the flash is touched. A write or an erase stops both cores for its few milliseconds; a save is never made while a capture runs (the calibration commands are refused while a window is open), and the interrupts that stay enabled meanwhile, UART0's and the ALERT pin's, run from IRAM (§4.2, §5.2). An app flash writes the bootloader, the table and the image and leaves 0x9000 as it was, so the working copy survives a firmware update; the first image of FW-16 found an older image's NVS pages there, which the log reads as no record and erases at its first save.

The quality token, q=, carried by SYSTem:STATus?, the capture header, the close, FETCh:STATistics? and every relay reply:

q= Meaning
uncal No null for the live range, or the shunt never measured
stale Nulled, but die_mc has moved more than ±5 °C since the null
cal Nulled for the live range, shunt measured, within ±5 °C
invalid MATHOF was set during the window, or the shunt was off the DUT's current (path=both or path=bypass) at any moment of it (§6.1)

The ±5 °C is the offset drift (dVos/dT ±10 nV/°C max, ±0.1 µA/°C at 0.100 Ω) reaching the ±0.5 µA floor that ina228-reference.md §8.5 sets for the instrument: about ±5 % on a 10 µA reading. Nothing in the range or AVG choice improves that floor; a larger shunt would, at the cost of the burden voltage, and that is a second rig, not a change to this one.

3.8 The capture statistics (0.10.0)

The uncertainty model in the Kleidos QA harness needs more of a window than its mean: the spread of the samples, how many of them are independent, where the peak fell, and how far the battery sagged under it. Every figure here is computed in the sampling loop on Core 1, from every sample the loop took, so a sample the stream dropped is still in them, and the same loop serves a ring, a stream, a null and a statistics-only capture alike.

  • The standard deviation is the sample standard deviation of the current, from the deviations of every sample's raw shunt count from the first: a 20-bit count differs from another by under 2^20, so each square is under 2^40 and the variance too (kMaxVarianceCounts). Their sum is carried in 128 bits (firmware/src/wide.h: two 64-bit words, an addition with a carry per sample), because 2^24 of those squares, 78 minutes of TRACE, fill 64. The variance, ( sum(d^2) - sum(d)^2 / n ) / ( n - 1 ), is formed once when the capture closes, by a shift-and-subtract division; scaled by 10^6 before that division so that it keeps six decimals of a count squared (the null's, which divided first and truncated to whole counts, read 1.2 % low at six counts and nothing below one; the null now shares this computation), and its root is the integer one, in thousandths of a count, and the conversion to picoamps uses the capture's own LSB and shunt.
  • The batch means. 64 slots, each the sum of one batch of samples. A batch starts as one sample; when every slot holds a complete one, the slots are merged pairwise into 32 and the batch doubles. So a closed capture of 32 samples or more reports between 32 and 63 complete batches of equal size, whatever its length, and FETCh:STATistics:BATCh? gives their means; a partial last batch is left out. From their spread a host estimates the effective sample size without the instrument guessing an autocorrelation time.
  • The maximum's place: its sample index and its timestamp (max_n, max_t_us), the first sample to reach the highest current.
  • The DUT's voltage and power: the sums for the means and the extremes, on a profile that converts the bus. FETCh:VOLTage?, :POWer?, :ENERgy? and :TEMPerature? now read these, not the console's sums over the samples that reached it; the energy is the mean power times the capture's own duration (dur_us), where before it was times the samples the console saw, so a dropped sample shortened it ("R1" of the review).
  • The CHARGE mean: the pair of boundary reads divided by the time between those two reads (charge_us), not by dur_us: the pair integrates from before the pacing probe to after the stop, a few milliseconds more than the samples span, which on a one-second capture is a 1 % bias (found by the host tests). Corrected for the measured shunt, in nanoamps, and not for the null: the INA228 integrates its own CURRENT, so the figure carries the sense loop's offset, offset_pv / shunt_uohm above mean_na (on the bench, 2026-11-20, 57.8 µA against a sample mean of 37.3 µA with a stored null of 2.076 µV, 20.7 µA at 0.1 Ω). It is the hardware's independent check of the integral, and the offset is what it checks the null against.
  • A threshold (SENSe:CURRent:THReshold, :HYSTeresis): a two-state counter. It rises when a sample reaches the level and falls when one is below the level less the hysteresis; the capture reports the rises, the samples taken in the high state and that count times the period (above_us). That is a duty cycle and a wake count without a stream.
  • The statistics-only capture (SENSe:CAPTure STATistics): the same loop with nothing queued for the line and nothing written to the ring, on any profile for any duration. TRACE's rate for hours fits neither the 293 s ring nor the line budget; this keeps its statistics.

What a sample costs in the loop: one 64-bit square, two additions with a carry, a comparison for the maximum, one addition to a batch slot, the threshold's comparison when it is set, and on a bus profile the voltage and power of the sample (the console used to compute them per streamed sample). On BURST, whose loop ran past its 100 µs period until the hot path moved to IRAM (§3.4, §5.2), the cost is measured on the bench rather than assumed.

3.9 The triggered ring, marks in order, a capture that ends itself (0.11.0)

  • The ring runs circular under a level trigger. TRIGger:SOURce LEVel starts a ring capture (Sampler::startTriggered()) whose ring wraps from INITiate on: the write position is a head that wraps at the ring's size, and ringAt() unrolls it from the oldest held sample. Every index the instrument reports is the capture's own sample index, never a place in the ring, so t0 + index × period and the drift anchors stay unambiguous across a wrap; the oldest held sample is first = samples - held. The anchors are a circular array too, the last kAnchorSlots of them: every regular anchor a full ring's span holds and up to kMaxForcedAnchors forced ones (0.15.0; before, a forced anchor pushed out the oldest regular one, the t0 anchor of an untriggered ring). The trigger fires on the first sample at or beyond the level after one on its other side (a current already beyond it at INITiate primes nothing), keeps TRIGger:PRETrigger samples from before it and ends the capture after the ring's size less those. The check is one comparison per sample until it fires.
  • Marks travel the stream queue. A streamed sample is counted after it is queued, so when the console records a TRACe:MARK (or a LIVE relay move) at index n, every sample below n is already in the queue; the mark is queued behind them as a record (RecordKind::Mark, its slot) and printed when the console reaches it. A full queue prints it at once: the line is then dropping samples anyway. Threshold crossings (SENSe:CURRent:THReshold:MARK ON) are queued by the sampler right behind the sample they were seen at, at most kMaxThresholdMarks (1,024) a capture, so a level set inside the noise cannot flood the line.
  • A capture that ends itself. SENSe:CAPTure:LIMit ON hands SAMPle:COUNt to the stream or statistics-only capture as its sample limit, the one the null window already had. *OPC is pending while a window that ends by itself runs (Sampler::endsItself()), and the console's loop sets the ESR's bit 0 once the sampler stops; *OPC? and *WAI stay immediate, because a blocking query cannot be interrupted by ABORt on this line.
  • The dump's CRC-32. Console::write() feeds every byte of the block into an IEEE CRC-32 (crc32.h, a compile-time table) while the rows before METER_DUMP_END are written, in the counting pass and in the writing pass alike, and the closing row carries it with the byte count. The bench's 6 Mbps line has no parity; a filed dump can now be held to its bytes (the garbled tokens of queue item 47 are the case it detects).

4. Where samples go

4.1 The ring and the stream

The sink is forced by arithmetic. The line carries 600,000 B/s (§4.2), and a METER t=… ch=i_ua v=… line is bounded at 48 bytes, derived in sampler.h (kStreamLineBytes) from the widest each field can print and held by a static_assert:

Profile Rate One channel costs Sink
BURST 10,000 Sa/s 480 kB/s (80 %) the ring: no headroom for a second channel
TRACE 3,571 Sa/s 171 kB/s (29 %) the ring: it would fit the line, but the ring keeps a burst's shape off the host's scheduler
STATE 868 Sa/s 41.7 kB/s (7 %) the stream: three channels are 21 %
SLEEP 14.81 Sa/s 0.71 kB/s the stream

The ring. A sample is 4 bytes, the sign-extended 20-bit VSHUNT count; the timestamps are implicit, the period being fixed. The ring holds kTraceSamples = 1,048,576 samples (4 MiB, 293 s of TRACE, 105 s of BURST) in PSRAM's .ext_ram.bss, reserved at link time in app_main() (CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY, §10) and handed to the sampler, so no capture allocates; the header's ring= says its size. It was 32,768 samples in internal RAM while PSRAM was off (0.13.0 and earlier): a window that short could not show an autocorrelation time. TRACe:DATA? dumps it (docs/scpi.md, "The ring dump"), with the block's CRC-32 on its closing row (§3.9).

Drift anchors. Every kAnchorEvery = 1024 samples the loop stores { n, t_us }, 1,024 anchors over a full ring, and a forced one at the sample after a failed read, at most kMaxForcedAnchors = 16 a capture, in an array sized for both, so a forced anchor never pushes out a regular one (0.15.0). The host reconstructs the real timestamps by interpolation and sees a stall or the oscillator's skew instead of trusting the nominal period. The dump interleaves them as A n=<idx> t=<us>.

Marks. TRACe:MARK "<label>" stores { n, label[16] }, up to kMaxMarks = 16 a capture, with two more slots for the hold's own marks (§6.3), so a trace aligns to an event on the DUT's own console; LIVE relay moves are marked the same way (§6.1). A ring prints them in the dump as K n=<idx> label=<text>, a stream as mark records in sample order (§3.9).

The stream. The sampler never prints. It hands each finished sample to the console task through a static FreeRTOS queue of kStreamQueueDepth = 256 records, and the console formats and writes them; a slow line can never stall the cadence, it can only raise dropped=.

Back-pressure is refused, never absorbed. No stream may need more than kLineBudgetPercent = 80 % of the line, and that is a fact of the profile table rather than a check at INITiate: sampler.cpp asserts at compile time that every channel at once on each streaming profile fits (167 kB/s on STATE against 480 kB/s), so a profile that broke it would not build (FW-27; the run-time refusal it replaces, -221 stream too fast, could not be reached). At runtime the console counts what uart0::write() could not place (a line that took nothing for 10 ms, §4.2) as dropped=, instead of assuming a write took everything, and sets QUEStionable bit 9 (§7).

4.2 The line is 6 Mbps, and that is measured

The console is UART0 on GPIO43/44 behind the carrier's CH343P bridge, not the S3's native USB (carrier-board.md §7), so the baud rate is a real divider and not a USB formality. It was 921600, then 2 Mbps; a timed TRACe:DATA? showed 2 Mbps delivering 196 kB/s — 98 % of its own ceiling, i.e. saturated, so the line and not the firmware's formatting was what bounded a dump.

The CH343P is rated to 6 Mbps and the S3's fractional divider puts 6 Mbps 0.08 % off exact from the 80 MHz APB, inside any UART's tolerance. Measured on a 7.85 MB dump of 209,936 samples: 582.6 kB/s, 97 % of the line, every one of the 209,936 sample lines parsing in full, zero non-ASCII bytes, and timestamp gaps forming the exact arithmetic progression the declared period predicts. A dump that would have taken 195 s at 921600 takes 13 s.

On its registers, with no driver (FW-12). ESP-IDF's UART driver kept its object, a 1 KiB receive ring buffer, an event queue, its mutexes and its interrupt's records on the heap (docs/misra.md D1). firmware/src/uart0.cpp does what the console needs with nothing allocated. uart0::begin(), from Console::begin() on Core 0 before the console task exists, gates UART0's bus clock on and pulses its reset under ESP-IDF's peripheral clock lock, selects the 80 MHz APB clock and the divider for 6 Mbps (uart_ll_set_baudrate(), the divider ESP-IDF's driver computed from the same clock), sets 8 data bits, no parity, one stop bit, no flow control and the plain UART mode, gives GPIO43 and GPIO44 to the port through the IO MUX as ESP-IDF gives a port its default pins, empties both FIFOs, and routes UART0's interrupt to a free level-1 line of Core 0 through interrupt::routeHere() (§5.1).

  • Receiving. The interrupt is raised when the receive FIFO holds more than 64 bytes (half of it: 107 µs before it overflows at 6 Mbps, where the driver's 120 left 13 µs), when the line has idled for ten frames after a byte (17 µs), and when the FIFO overflows. The handler moves the FIFO into a static ring of 1,024 bytes and gives a static binary semaphore, on which uart0::read() waits for a first byte (Console::receive()); a read returns as soon as anything is there. A full ring leaves the rest in the FIFO and turns the two data interrupts off; the next read moves what the FIFO holds into the room it made and turns them back on once the FIFO is empty. So the ring and the FIFO hold 1,152 bytes the console has not read before anything is lost, as the driver's ring and FIFO did, and only an overflow loses bytes: the handler latches it and empties the FIFO, as the driver did, and Console::noteOverrun() turns the latch into one -363 and discards the message it fell in (docs/scpi.md), as it did the driver's UART_FIFO_OVF event.
  • Transmitting is polled. uart0::write() puts each byte into the 128-byte transmit FIFO as it has room; the console is the only writer, and the driver, given no transmit ring, blocked it the same way. A line that takes nothing for 10 ms (6,000 bytes' time; with no flow control the FIFO empties in 213 µs) ends the write with what it placed, which the console counts as dropped= (§4.1).
  • One core, and IRAM. The ring and its two flags are plain variables of one static object: the handler runs on Core 0, and the console task, pinned there, touches them only with the core's interrupts masked. The handler is in IRAM, and a root of the IRAM gate (§5.2): its line is not the allocator's, and ESP-IDF masks during a flash write only the lines its allocator gave a handler outside IRAM (esp_intr_noniram_disable()), so it runs with the cache off while a calibration is saved. The driver's handler was in flash and its line masked then.

The host harness models UART0's registers (firmware/test/native/harness/sim.h sim::Uart): the clock and reset, the frame, both FIFOs, the threshold as a level and the time-out and the overflow as latches, the bytes a host sends arriving one at a time, and a line that stalls, carries a set number of bytes, or resumes at a set time. Every Bench and Scope fails a case that reached the port from Core 1, reached its clock outside the lock, wrote into a full transmit FIFO, read an empty receive one or left its interrupt pending. scripts/check_drivers_absent.py fails an image that links any member of esp_driver_uart.

On the bench (2026-11-22, FW-12's image, ELF b7f6e739ae8cee1f; tests/bench/test_uart_bench.py and the rest of the bench suite with --bench-long): 1,000 *IDN? answered, each within 1 s; a 60 s STATE stream reached the host whole, every line a record, with dropped=0; 4,097 bytes sent while a TRAC:DATA? SCAL dump held the console overflowed the FIFO and answered one -363, after which the console answered at once; a full TRACE ring of 1,048,576 samples dumped RAW with its CRC-32 correct; the heap sweep, the forced watchdog reset, the 600 s idle and the watchdog's full-ring case all passed; and DIAGnostic:HEAP? read pre_main_allocs=35 allocs_since_main=35 frees_since_main=8, 15 allocations fewer than FW-11's image.


5. Tasks, cores and the hot path

5.1 Tasks, cores and the watchdog

Task Core Priority Job
meter-sample 1 10 Pace, read, decode, append to the ring or hand to the writer
main (the console) 0 5 Read UART0 lines, dispatch, print

The console is the main task (FW-17). ESP-IDF creates main before app_main(), on Core 0 at priority 1 with CONFIG_ESP_MAIN_TASK_STACK_SIZE bytes of stack, and runs app_main() on it. app_main() does the boot and then calls Console::run(), which raises the task to priority 5 and never returns. Until FW-17 app_main() returned once the console had its own static task, meter-console, and ESP-IDF deleted main, the idle task then freeing its stack and control block: two frees after app_main()'s first line, and a second 8 KiB stack the console did not need. The main task's stack is now the console's 8,192 bytes (sdkconfig.defaults; console.cpp fails the build when it differs from kConsoleStackBytes or the task is not pinned to Core 0), allocated by ESP-IDF before app_main() (docs/misra.md D1), and SYSTem:HEALth?'s stack_console reads it. The console's stack also holds the boot's own frames below its loop; the instrument's objects are statics of app_main(), not on it. Should UART0 not come up, app_main() prints its one ROM line and waits for good rather than return.

The split mirrors the fleet's own: the latency-critical loop gets a core to itself, and everything that blocks runs on the other (the Kleidos firmware repository's AGENTS.md §8). The interrupts follow the sampler (0.14.0). ESP-IDF allocates an interrupt on the core that installs it, and app_main() runs on Core 0, so until 0.14.0 the I2C master's ISR and the ALERT pin's GPIO ISR ran beside UART0's at 6 Mbps while the task they wake runs on Core 1: every transfer's completion crossed cores. (From FW-14 the bus takes no interrupt at all: the own master polls each transaction to its end, §2.4.) app_main() now runs the bring-up and Sampler::begin() on Core 1 through esp_ipc_call_blocking() (the IPC task's stack raised to 4 KiB for it), and only the console's UART interrupt stays on Core 0 with the console (routed by the firmware's own UART driver since FW-12, §4.2). Should the IPC call be refused, the same steps run on Core 0 as before. From 0.16.5 every I2C transaction is made on the core the bus was opened on, the console's through the IPC task (§2.2). The sampler never prints; it hands finished samples to the console through a FreeRTOS queue when streaming, so a slow line can never stall the cadence — it can only raise dropped=.

The ALERT pin's interrupt is routed statically (FW-09). ESP-IDF's GPIO ISR service allocated a table of 49 handlers and the interrupt allocator a record for its line and its handler, three allocations at boot (docs/misra.md D1). Sampler::begin() now routes the GPIO's interrupt source (ETS_GPIO_INTR_SOURCE) itself, through firmware/src/interrupt.cpp: interrupt::routeHere() picks the lowest level-1, level-triggered line of the calling core that the CPU's descriptor table neither reserves nor marks special and that has no handler (esp_cpu_intr_get_desc(), esp_cpu_intr_has_handler()), sets alertIsr() on it in the Xtensa port's static handler table (esp_cpu_intr_set_handler()), routes the source to it in the interrupt matrix (esp_rom_route_intr_matrix()) and enables it (esp_cpu_intr_enable()), with the core's interrupts masked between the search and the claim. Nothing is allocated, and the route is never taken down. The pin's own interrupt (its type, its enable and its status) is set through ESP-IDF's hal/gpio_ll.h: gpio_config() leaves it off, begin() sets the falling edge, the loop and the probe set the enable when they listen and clear it when they stop, each after clearing a status bit latched while nothing listened (what gpio_intr_enable() did), and alertIsr() reads the status, clears every bit it read (the line is level-triggered, and a bit left set raises it again as the handler returns) and counts an edge and gives the semaphore only for the ALERT pin's. The pin must be one of GPIO0 to 31, whose status is in that register; begin() refuses another. The line sat beside ESP-IDF's allocator, which the I2C master used until FW-14 (UART0's line is routed the same way since FW-12, on Core 0, §4.2), and still does beside the lines ESP-IDF's own startup takes: the allocator refuses a line whose handler is set (is_vect_desc_usable(), components/esp_hw_support/intr_alloc.c line 330 in ESP-IDF 6.0.3) and sets one on every line it gives out, which the route refuses in turn, so the I2C master's line and the ALERT pin's were two lines of Core 1 until FW-14 (the host tests' boot case showed it on ESP-IDF's ESP32-S3 table, and the bench's alert-paced captures, which need both, ran with no stale edge and no read error on FW-09's image, 2026-11-22). tests/firmware/test_interrupt_routing.py holds the CPU's lines to interrupt.cpp and the GPIO's interrupt registers to sampler.cpp, and no source calls the allocator or ESP-IDF's GPIO interrupt driver; the host harness models both cores' line tables (ESP-IDF's ESP32-S3 table), the matrix, the GPIO's status and enable, a driver's allocation taking a line, and a level line its handler leaves pending, which fails the case (firmware/test/native/harness/sim.h).

Supervision (0.14.0). Both tasks subscribe to the watchdog from their own task (the console from Console::run(), on the main task), and a task that goes 5 s without checking in resets the chip: every relay releases to the measuring circuit and SYSTem:HEALth? names it reset=task_wdt. The console checks in at most every 100 ms from its loop, from every write (a dump or a stream is its longest work, a dump's counting pass included), from the acquisition loop and from a settle, and at each check-in blocks for one tick, so that Core 0's idle task, which the watchdog also waits for, runs under work that never blocks: a full ring's TRACe:DATA? formats every row twice, once to count the block's bytes and once onto the wire, and the counting pass makes no blocking call (0.58 s for 107,336 samples on the meter, so about 5.6 s for a full ring), which reset the instrument on FW-11's first image and would have under the task watchdog since 0.14.0, whose idle check and the console's feed it starved alike; the sampler checks in while it waits for a start (in 1 s slices) and, in a capture, every 200 ms' worth of samples by count, so the loop reads no clock for it. The watchdog sees a task that stops; the console also watches a sampler that runs and takes nothing: a running capture whose count has not moved for 2 s (thirty periods of SLEEP, the slowest), queues 107 once and sets QUEStionable TIME. DIAGnostic:WATChdog:TEST stops the console's check-ins to prove the path on the bench. A watchdog reset under a held null path is the exposure §6.1 describes for any reset ("What the relays cannot do"), bounded by the relays' release times.

The watchdog is the firmware's own (FW-11). Until FW-11 the supervision was ESP-IDF's task watchdog, which kept its subscribers on the heap (its object and Core 0's idle task's entry before app_main(), an entry per task after) and claimed its timer's interrupt through the allocator (docs/misra.md D1). CONFIG_ESP_TASK_WDT_EN is now off, and firmware/src/watchdog.cpp runs the same timer, Timer Group 0's main watchdog timer (the interrupt watchdog keeps Timer Group 1's), through ESP-IDF's hal/mwdt_ll.h, with nothing allocated and no interrupt. app_main() starts it right after the LED's frame (watchdog::begin()): it registers an idle hook on Core 0 (esp_register_freertos_idle_hook_for_cpu(), a static table of eight in ESP-IDF), takes a reference on the group's bus clock under ESP-IDF's peripheral clock lock as the task watchdog did (the first user turns the clock on and pulses the group's reset), and sets one stage, a system reset after 10,000 ticks of 500 µs (the 80 MHz APB divided by 40,000), with the other stages, the interrupt and the flash boot protection off, both reset signals at 3.2 µs, and the registers locked again. The parties are three bits of a static check-in mask: the console, the sampler and Core 0's idle task, whose hook checks it in on every pass of its loop, so a console that spins without blocking starves it and is caught as well. watchdog::checkIn() (in IRAM, the sampler's loop calls it) sets its party's bit, and the check-in that completes the subscribed set clears the mask and feeds the timer, as ESP-IDF's task watchdog fed its own: a party that stops resets the chip between 5 s and 5 s plus the longest interval of the others (the sampler's 1 s idle slice) after its last check-in. Until a task subscribes the round is Core 0's idle task alone, so a boot that hangs on Core 0 also resets. The timer's reset of the digital core is RESET_REASON_CORE_MWDT0, which esp_reset_reason() reads as ESP_RST_TASK_WDT (ESP-IDF's components/esp_system/port/soc/esp32s3/reset_reason.c), so SYSTem:HEALth? still says reset=task_wdt, and RTC memory, with the coils the reset found (§6), survives it. The panic handler and esp_restart() disable the timer themselves, as they did with ESP-IDF's. DIAGnostic:WATChdog? keeps every key: console and sampler are each task's subscription, timeout_s watchdog::kTimeoutSeconds, and panic 1 because a starved party resets the instrument. Should the idle hook not register or the timer not read back enabled, nothing is supervised and both subscriptions read 0. The host harness models the timer's registers, its write key, the group's clock and reset and the idle hook (Core 0's idle task runs once a simulated millisecond unless a test starves it), and fails every case that let the timer run out unless the case provoked it (firmware/test/native/harness/sim.h).

Core 1's idle task is not supervised. A spinning sampler on Core 1 starves IDLE1, so only Core 0's idle task has a check-in bit. The spin only exists on the pace = timer path; on the pace = alert path the task blocks on a semaphore and IDLE1 runs normally. The interrupt watchdog is left alone.

A queue or semaphore that both tasks may reach is created before the consumer task exists, never by a bare if ( handle == nullptr ) create — both cores can pass that check and build it twice into one control block (the Kleidos firmware repository's AGENTS.md §8).

5.2 The hot path in IRAM (0.16.1)

Why. The ESP32-S3 fetches code and constants from flash through one instruction cache and one data cache, both shared by the two cores. Code that runs from flash on Core 1 waits for every line Core 0's work has evicted, and a radio on Core 0 evicts a great deal. The NW-00 radio spike (branch spike/nw00, never merged: Wi-Fi linked into the image, a station sending CSV to a LAN client) measured what that costs an alert-paced capture: STATE statistics-only captures of 15 s read pace_err_ppm +85 with the radio off, +83 with the station idle, +33,740 sending 50 kB/s and +171,658 sending 200 kB/s, with dropped=0, 723 samples a second instead of 868 and the floor's sd up from 19.0 to 25.8 µA. Wi-Fi's and lwIP's buffers in internal RAM instead of PSRAM gave the same or worse, so the data cache was not the cause. The conversions are lost without a count because of how the pin works (§3.3): ALE stays low from a conversion's end until DIAG_ALRT is read, so a loop that comes back to its read more than a period after the edge leaves the pin low through the next conversion, which then makes no edge of its own; the next sample is a period late, and pace_err_ppm is the only figure that sees it.

What moved. Everything a conversion executes on Core 1, found from the relocations of every object the image is linked from rather than guessed (scripts/check_iram_hot_path.py, below), 70 functions in all (73 since 0.16.2, which runs the pacing probe in the loop's task, 72 since FW-09, whose ALERT handler no ISR service calls, 75 since FW-11, whose watchdog check-in and the atomic or it makes, __atomic_fetch_or_4() and the S32C1I routine behind it, are in IRAM, 76 since FW-12, whose UART0 handler on Core 0 is a root of its own for another reason, §4.2, and reaches nothing the others do not but itself, 80 since FW-13, whose own I2C master's three transactions, i2c_bus::write(), read() and writeRead(), were roots until FW-14 gave them the sampler as their caller, §2.4, and 57 since FW-14, whose loop reaches those three and their shared transact() through the driver, the rest of their path inlined, and no longer ESP-IDF's driver's transfer path, its interrupt handler or the FreeRTOS calls only they made):

  • Ours, IRAM_ATTR: Sampler::runCapture() (the loop), waitForConversion(), readSample(), accumulate(), addToBatch(), storeInRing(), queueThresholdMark(), retainShuntPointer(), alertIsr() (the ALERT pin's handler), and waitUntil(), alertPacing(), currentNanoamps() and noteDieMilliCelsius(), which the compiler inlines into them; the driver's readRegister(), read16(), read24(), readDiagAlrt(), readRetained(), setPointer() and note(). The profile table the loop reads every sample, kProfileSpecs, is DRAM_ATTR: it was the one named constant of the hot path in flash.
  • FreeRTOS (CONFIG_FREERTOS_IN_IRAM): ESP-IDF 6 places every FreeRTOS function in flash but those an interrupt calls, and the loop blocks on xQueueSemaphoreTake() for every edge, sends to the stream queue (xQueueGenericSend()), delays (vTaskDelay()), and until FW-14 ESP-IDF's I2C driver took its bus lock, reset and waited on its event queue (xQueueGenericReset(), xQueueReceive()), each with the list and scheduler functions behind them. The option moves all of FreeRTOS, the idle task's included.
  • The I2C master's transactions (FW-14): the own master's i2c_bus::write(), read(), writeRead() and transact() are IRAM_ATTR, and their register access is ESP-IDF's hal/i2c_ll.h's inline functions. Until FW-14 the path was ESP-IDF's driver's: CONFIG_I2C_ISR_IRAM_SAFE moved the command builders the task and the interrupt share and the HAL's i2c_hal_master_trans_start(), and firmware/src/linker.lf the synchronous path the option left in flash (i2c_master_transmit_receive(), i2c_master_receive(), i2c_master_transmit(), i2c_master_multi_buffer_transmit(), s_i2c_synchronous_transaction(), s_i2c_transaction_start(), s_i2c_send_commands(), _i2c_hal_set_bus_timing(), i2c_hal_master_set_scl_timeout_val()); the option and the fragment went with the driver.

Already in IRAM by the pinned ESP-IDF's defaults, and so not set: esp_timer_get_time() and the system timer behind it, the interrupt dispatch, the cross-core yield and the atomics; memcpy(), memset() and the 64-bit divisions are in ROM. The ALERT pin's interrupt was already on Core 1 (§5.1). Left in flash, because no conversion runs them, each named in the gate with its reason: watchdog::subscribe() (once, when the task starts; until FW-11 esp_task_wdt_add(), and esp_task_wdt_reset() every 200 ms of samples, where the own watchdog's checkIn() is now in IRAM), until FW-14 the I2C driver's error recovery s_i2c_hw_fsm_reset() and its asynchronous path, which a bus with no transaction queue never took, from 0.16.5 Ina228Driver::transferOnBusCore(), the out-of-line route a transaction asked from the other core takes to the bus's (§2.2), which the sampler, on the bus's core, never calls, and from FW-13 the own I2C master's recover(), which only a timed-out, faulted or stuck transfer runs (§2.4). The pacing probe of §3.3 ran in the console task, on Core 0, until 0.16.2 moved it into the sampler task; the gate reaches it from the loop since, and measurePace() is in IRAM with the rest. Until FW-09 the ALERT pin's handler ran under ESP-IDF's GPIO ISR service (gpio_intr_service(), in IRAM by default) and the loop turned the pin's interrupt on and off through gpio_intr_enable() and gpio_intr_disable(), two cold exits in flash; since, the port's dispatcher calls alertIsr() straight from its CPU line (§5.1), and the pin's interrupt enable and status are register writes inlined from hal/gpio_ll.h into the loop, the probe and the handler (listen(), stopListening()).

The cost (xtensa-esp32s3-elf-objdump -h of the clean builds of 0.16.0 and 0.16.1): .iram0.text 60,967 → 76,475 bytes (+15,508), .flash.text 163,864 → 148,164 (−15,700); DIAGnostic:HEAP? at the end of the bench sessions below, free_internal 330,543 → 313,695, min_free_internal 294,180 → 277,332, largest_internal 233,460 → 217,076. The steady state still allocates nothing (allocs_after_init=0 frees_after_init=0).

The gate (scripts/check_iram_hot_path.py, CI's firmware job, after the object gate). It reads objdump -t and objdump -r of the firmware's own objects and of every ESP-IDF archive the image links, which name each call and each literal-pool reference exactly (a disassembly of the image loses edges to misdecoded instructions: it missed the driver's s_i2c_send_commands() here), walks the call graph from the loop, the ALERT pin's handler and (FW-12) UART0's handler (until FW-14 also from the I2C master's interrupt, and in FW-13 from the own master's three transactions, which the loop now reaches), and fails on a function it reaches in a .flash section, on a named constant a reached function loads from .flash.rodata, on a missing root and on an exception the walk never meets. It stops at the failure exits (abort, assert, log) and at the cold exits above. On 0.16.0's image it reports 42 failures; on 0.16.1's, none. tests/firmware/test_iram_hot_path_gate.py holds its parsing and its verdicts.

On the bench, radio off (2026-11-21, instrument KM-0000000000, the DUT a T-Deck behind K1 and on its USB supply, about 37 µA through the shunt; clean builds of main, 0.16.0 at e4ade81, ELF 697a09218f7e0dec, and 0.16.1, ELF 14986195a0d8ec35, flashed and measured one after the other). STATE and SLEEP streamed i_ua for 60 s each, three times; missed and extra are counted from the stream's own t= as in §3.4; TRACE and BURST (1 MHz) filled their rings for 10 s, three times:

Capture 0.16.0 0.16.1
STATE × 3, 60 s, pace=alert 0 missed, 0 extra, 0 stale; interval sd 6.4–6.7 µs (980–1,315 µs); pace_err_ppm +97, +94, +99 0 missed, 0 extra, 0 stale; interval sd 0.80–0.82 µs (1,147–1,167 µs); +99, +99, +96
SLEEP × 3, 60 s, pace=alert 0, 0, 0; sd 4.1–4.8 µs (67,517–67,541 µs); +97, +96, +99 0, 0, 0; sd 3.5 µs (67,520–67,539 µs); +95, +94, +96
STATE statistics-only × 2, 30 s 869.30 samples/s; +99, +96 869.17 samples/s; +98, +104
TRACE × 3, 10 s 280.009 µs a sample; −5, −4, −3 ppm; 0 re-based 280.007 µs; 0, 0, 0 ppm; 0 re-based
BURST × 3, 10 s, 1 MHz 100.013–100.014 µs; +105 to +112 ppm; 7 re-based each 100.002 µs; 0, 0, 0 ppm; 0 re-based

Every capture closed with dropped=0 read_err=0 pace_fallback=0. Both sessions ended at allocs_after_init=0, DIAGnostic:WATChdog? console=1 sampler=1 panic=1 stalls=0, SYSTem:HEALth? reset=poweron and no error queued. So the radio-free image was paying for the shared cache too: the console's 6 Mbps stream and command handling on Core 0 run from flash, and the alert-paced interval's spread (the sampler's wake latency, §3.4) fell by a factor of eight. The same change measured earlier the same day against 0.15.0 (d7ab72f, ELF 0abaa2ff63107a52, the same tree with this change built as 0.15.1, ELF 4d466526f311b9cd) gave the same 0.80 µs against 4.6–5.3 µs, and showed how much the flash-resident loop's timing depended on where the linker happened to put things: 0.15.0's BURST ran 100.37 to 100.40 µs a sample with 339 to 368 re-based deadlines in 10 s, where 0.16.0's, the same loop in another layout, ran 100.014 µs with 7; from IRAM both ran 100.002 µs with none.

With the radio (the same day, the spike image de088408924084af, 0.15.0 with Wi-Fi, against the same image with this change applied, ELF 48e8884358274b99; station joined to the lab network, sending the spike's CSV stream to the bench host at the rate shown, measured at the host as 49.4 kB/s and 196 to 199.6 kB/s; STATE statistics-only, 15 s each):

State spike, 2 runs spike + IRAM, 3 runs
Radio off +96, +90 ppm; 870.5 samples/s +94, +93, +89; 870.4
Station idle +94, +92; 870.6 +95, +96, +93; 870.5
Sending 50 kB/s +26,280, +40,610; 848 and 837 samples/s +96, +97, +94; 870.4
Sending 200 kB/s +182,712 (736 samples/s); one run pace=timer +94, +92 (870.1); one run pace=timer

The conversions the radio cost are all back: every alert-paced capture with the station sending reads the INA228's own oscillator, as with the radio off. One capture of each image at 200 kB/s started on the timer instead (pace=timer, pace_err_ppm +7 and 0, still 869.7 and 869.9 samples/s): the pacing probe of §3.3 did not count 7 to 9 edges in its eight periods. The probe ran in the console task on Core 0, beside the Wi-Fi tasks, and 0.16.2 moved it into the sampler task (§3.3); the header names the pace every capture used, so such a capture is never mistaken for an alert-paced one.


6. The relays

6.1 The null without hands

The one step of a campaign that needed hands was the null of §3.7: the DUT lead open, the source still on IN+. A relay pair now does it, and does it without the DUT losing power: K1 opens the lead while a bypass feeds the DUT around the shunt. firmware/src/relay.h holds the whole design as one table and a set of constexpr functions; the console runs it. The rig is hardware/rig.kicad_sch rev D, as wired since 2026-11-20.

The lead, K1, is one SRD-05VDC-SL-C Form C relay (COM / NC / NO, 10 A at 30 VDC) of an HW-316 module, behind a 1 kΩ input resistor, an IN LED, a PC817 opto and an S8050 driver with a 1N4148 flyback diode; VCC on carrier terminal 21 (5V), GND on 22 (G), the JD-VCC jumper fitted. Its input is low-level triggered: driven low, it sinks about 2 mA through the IN LED and the opto LED in series and energizes the coil; driven high at 3.3 V, or left floating, the coil stays off, because those two LEDs need about 3 V between them and 5 − 3.3 V cannot light them. It stays a mechanical relay on purpose: closed at rest, so the DUT stays fed with the meter off, and with no PhotoMOS on-resistance in series with the DUT.

The bypass, k2 on the wire, is one LCA717 PhotoMOS (OptoMOS) of a MikroE Relay 2 Click, its RL2 channel, normally open, between the VIN+ node and K1's NC (the DUT's battery +). Its input is active high: GPIO15 sources current into the LCA717's LED to close it, and an LED with no current is an open bypass, so low at rest and at boot (docs/relay2-click-wiring.md). The Click takes 3.3 V and ground from carrier terminals 1 and 22. Open, the LCA717 leaks 1 µA at most with 30 V across it (IXYS, DS-LCA717-R04, page 2), around the shunt; what that can cost a reading at the branch's real voltage, and why Relay 2 is a solid-state relay at all, is docs/relay2-click-wiring.md, "Which relay to fit as Relay 2", which the panel's Pins view carries as its note.

Channel Part Input GPIO (default map) Left-rail terminal Role Contacts
K1, the map's Relay 1 HW-316 relay K1 IN1, active low 7 7 lead COM on VIN−, the shunt's DUT end; NC to the DUT battery +
K2, the map's Relay 2 Relay 2 Click RL2 its control pin, active high 15 8 bypass the VIN+ node (cell +) and K1's NC (DUT battery +)
K3 none (the HW-316's IN3 is not wired) none spare, unwired
K4 none (the HW-316's IN4 is not wired) none spare, unwired

Until 2026-11-20 (rev C, the meter image until 0.7.0) the bypass was the HW-316's own K2 on IN2, active low; its silver contacts did not close the dry circuit of a few millivolts across the shunt and K1, and the bypass moved to the Click (calibration/records/2026-11-20.md §1), driven by the meter_relay2 image from 0.3.0 to 0.7.0 and by the one image, meter, from 0.8.0 (relay.h kChannels). From 0.18.0 the table holds what each channel is, not where: the GPIO and the level that energizes each relay are the pin map's, and relay::Bank drives and reads back the map begin() was given. Of the HW-316 only GND, IN1 and VCC are wired, so its K2, K3 and K4 never energize. From 0.13.0 the spares k3 and k4 are marked unwired (ChannelSpec::wired), so GPIO16 and GPIO17 are never driven; from 0.16.6 both are parked at boot, inputs with the internal pull-down (§9).

GPIO4/5/6 are the INA228's SDA/SCL/ALE (§2.1), so the relays take the next four terminals of the same rail; all four are free on this board (carrier-board.md §2), and GPIO15/16 are free of their 32 kHz crystal role because the image runs the RTC on its internal RC (CONFIG_RTC_CLK_SRC_INT_RC). The negatives are not switched.

Released is the safe state, and the wiring makes it the measuring one. K1's NC contact is in series with the shunt and the normally open bypass is across it, so every coil off is the DUT on the shunt with the bypass open — the circuit before the module was fitted. That is what a meter reset, a reflash, a meter with no firmware, or a pin the driver failed to configure all leave behind. The two contacts make four circuits, which every relay line names:

path= K1 K2 The DUT is fed The shunt carries
shunt closed open through the shunt everything: the measuring circuit and the boot state
bypass open closed around the shunt nothing of a DUT that is running: the null, and no place for a capture
both closed closed both ways a fraction, so every reading is q=invalid
none open open not at all from the battery nothing, which is what the DUT draws: a capture there is valid

relay::shuntCarriesAll() is that last column made a rule: only shunt and none are readings of the DUT.

The boot order. gRelays.begin( gPins.map ) is the first call of app_main() that reaches a pin, ahead of the LED frame of §8; only the pin map's read comes before it (§2.6). For each relay pin of the map it writes the GPIO output latch to that relay's released level, high for an active-low input such as K1's and low for an active-high one such as the Click's LED, before gpio_config() makes the pad an output: in 4.60003.0, as in 4.60101.0, gpio_set_level() writes the output register whether or not the pad is enabled, and gpio_output_enable() inside gpio_config() only routes the plain GPIO signal to the pad, enables the driver and selects the GPIO function (ESP-IDF's components/esp_driver_gpio/src/gpio.c) — so the pad's first driven level is the released level written beforehand, never the register's reset value. From that line on every pin is push-pull and never floating. Before it the pins are not driven by this image at all; the module reads a floating input as off, and the ESP32-S3 datasheet's Table 2-1 gives none of the four a pull-down at reset. Its Table 2-2 gives all four a 60 µs low-level glitch at power-up: on K1's input, which energizes on low, far shorter than the milliseconds a coil needs to pull in, and on the Click's, a low that leaves the bypass open. The first-power check in rig-wiring.md §8.5 (every IN LED dark, no click, through a reset and a power-up) is what confirms both on the bench. The pads are GPIO_MODE_INPUT_OUTPUT, so ROUTe:STATe? reads each one back against the level it is driven to (pads=). A pin gpio_config() refuses leaves the bank not ready: the boot queues 100 (Relays unavailable), SYSTem:INFormation? says relays=0, and every order is refused rather than reported as done.

Orders are planned before they are driven. Each command becomes a plan of at most two steps, each a coil change and the settle time after it. The plans and the interlocks are constexpr, and the orders this module exists for are static_asserts beside them, so a change that breaks make-before-break fails the meter's own build:

Order From rest (path=shunt) Steps
ROUTe:NULLpath ON → bypass read the shunt; energize K2 (bypass closes), settle, read; energize K1 (lead opens), settle, read — each reading judged below
ROUTe:NULLpath OFF from bypass → shunt release K1 (lead recloses), settle; release K2 (bypass opens), settle
ROUTe:LEAD OPEN\|CLOSE K1 alone
ROUTe:BYPass ON\|OFF K2 alone
ROUTe:RELay3\|RELay4 ON\|OFF a spare alone, refused since 0.13.0 because neither is wired (§6.2); ROUTe:RELay1 and RELay2 are refused by name (-114), so each role has one spelling and one set of interlocks

From any other state ROUTe:NULLpath runs only the steps still missing, in the same order, and no step of either direction ever passes through path=none.

The settle times. There is no contact sense on the module, so every order waits out the relay's own bounds before it answers, and these are bounds, not observations; what the rig measured against them, every move well inside its wait, is docs/relay-timing.md:

Value Source
Operate time 10 ms max Songle SRD sheet; LCSC and JLCPCB listings of part C35449
Release time 10 ms max used Songle's sheet says 5 ms, the LCSC and JLCPCB listings 10 ms; the larger is used
Flyback diode 30 ms allowance on a release The bounds are for a bare coil; a plain diode across the coil gives "the slowest" current decay (TE Connectivity, coil suppression), and no source gives the figure for this part. Three times the release bound. Measured on 2026-11-21: the release, diode and all, took 11.20 ms (docs/relay-timing.md)
Bounce 10 ms margin No source states one; the margin equals the operate bound. The record of 2026-11-21 shows the operate's step at 1.96 to 2.52 ms and the release's at 11.20 ms, bounce included (docs/relay-timing.md)
Settle after energizing 20 ms kOperateSettleMs
Settle after releasing 50 ms kReleaseSettleMs
Relay 2 Click bypass (the one image from 0.8.0; meter_relay2 before) 10 ms each way kSsrOperateSettleMs, kSsrReleaseSettleMs: IXYS's 3 ms LCA717 bound at 5 mA, doubled for the Click's unstated LED current, plus 4 ms; the TRACE run of docs/relay2-click-wiring.md step 7 measured 0.56 to 1.12 ms on and 0.56 to 0.84 ms off on 2026-11-21 (docs/relay-timing.md)

The release wait is the one make-before-break rests on when it opens the bypass: ROUTe:NULLpath OFF must not open K2 before K1's NC contact has reclosed. ROUTe:NULLpath is therefore about 100 ms each way, ON's checks included. Every reply's settle_us is the time the order actually took, on esp_timer. Two bench runs check the bounds: a TRACE across LIVE, FORCe orders, which shows each contact's real time against its mark (run on 2026-11-21 and filed in docs/relay-timing.md), and a relay null against a hand-removed-lead null, which should agree within 0.1 µV (rig-wiring.md §8.6).

The checks: what ROUTe:NULLpath ON sees. A commanded state is not evidence: a module with no 5 V (carrier-board.md §6 makes that the likely first-power case), a loose IN wire or a coil below its 3.75 V pull-in leaves every relay where it was while the console reports the order done — and a null taken through such a "null path" measures the DUT's own current through the shunt and would be stored as the offset. So ROUTe:NULLpath ON, when no capture is open and the INA228 is up, reads the shunt before the first step and after each one. Each reading is a 16.8 ms average (continuous shunt-only, 1052 µs × 16, read 20 ms after ADC_CONFIG is written, the profile's word written back afterwards: continuous rather than triggered, so the accumulators stay valid), and its share is the reading less the stored null for the live range. The verdicts are constexpr in relay.h, with static_asserts on the T-Deck's own numbers:

Step Passes when Why that bound
K2 closes the share falls to ≤ ¾ of the share before, and to no less than 1/16 of it (0.18.0) K2's branch is a contact and two short wires, the shunt's 0.100 Ω plus a contact and one wire; with every contact at its 100 mΩ maximum against the other at nothing, a closed K2 leaves the shunt 55 % at worst. The lower bound tells a bypass that closed from a lead that opened, which leaves the shunt nothing but its offset: the bypass branch measured about 34 mΩ (2026-11-20), so a closed K2 leaves the shunt 25 % with K1's contact and wire at nothing and 13 % with them at 120 mΩ, twice a sixteenth; a share that falls under it is refused as the shunt lost all of the dut's current (Relay 2 driving Relay 1's part, as relays swapped onto each other's wires with matching levels do)
K1 opens (or any step that lands on path=bypass) the reading is ≤ 50 µV and, when the first share was judged, the share is ≤ ½ of the one before; a first share judged with K1 already open fails it (0.18.0) 50 µV is seven times the largest null this rig has measured (−6.85 µV, 2026-10-27) and 500 µA through the shunt. The half test catches a K1 that never moved but whose leftover share happens to sit under the limit. With K1 open before the order only K2 moves, and no step shows K1 leave the shunt dead: the DUT's current in the first reading is what says it is stuck closed
Judged at all the first share is ≥ 200 µV (2 mA) below it neither move stands clear of the offset and of the DUT's own variation between readings

A failed step releases the path again, make-before-break, and refuses with every reading it rests on (103, bypass check failed; 104, lead check failed). A passed order carries its verdict in the relay tokens as check=: ok (both moves seen), unverified (under 2 mA: only the 50 µV limit applied), skipped (ROUTe:NULLpath ON,LIVE under a capture, which reads nothing), or - (any other order, or boot). ROUTe:NULLpath OFF is not checked: both of its steps are spring releases, which need no coil supply to happen.

The last line of defense is in CALibration:ZERO: a window opened with K1 commanded open (path=bypass or path=none) whose offset comes out beyond 50 µV reports its numbers and queues 102 (Null not stored), and neither RAM nor the flash takes it. The hand null (path=shunt) is not bounded: the relays cannot see that lead.

The hold. A release nobody commanded — a meter reset, a panic, a brown-out, the meter's USB lost, a port opened with RTS and DTR in the wrong order — drops both coils at once, and with the null path held K2's NO can open before K1's NC recloses. So the null path is held at most kNullPathHoldS = 120 s: armed by any order that ends on path=bypass, re-armed whenever a window closes. When it expires the console loop runs ROUTe:NULLpath OFF itself and prints nothing; every relay reply says hold_s=, and ROUTe:STATe? counts the releases in hold_released=. From 0.13.0 an open lead is held too, and from 0.16.0 a bypass across a closed lead, and no capture suspends the hold any longer, only a null window that samples (§6.3).

The interlocks.

  1. No order disconnects a powered DUT unless it says FORCe. A step that takes the circuit into path=none from a powered one — ROUTe:LEAD OPEN with the bypass open, ROUTe:BYPass OFF with the lead open — is refused with 109 (Order disconnects the DUT) unless it says FORCe. The test is a transition into none, so a spare switched while a cold power cycle has the DUT disconnected is not refused again. ROUTe:LEAD OPEN,FORCe with the DUT's USB port cut at the hub is the hands-free cold power cycle.
  2. No contact moves under a running capture unless the order says LIVE, and none moves under a running CALibration:ZERO even then, because a null assumes one circuit for its whole window. A LIVE move records a mark per coil at the sample index it was driven at, and writes it as TRACe:MARK's are written, a mark record (METER_MARK mark=k1:open n=… t=… in TEXT, docs/scpi.md "Stream records") before the relay reply: a streamed capture has no TRACe:DATA? to replay a K line from, and the marks share TRACe:MARK's table of kMaxMarks. The reply says live=1 and how many marks it stored. An order that changes nothing is answered with the state whatever is running.
  3. A shunt off the DUT's current is never measured silently. INITiate is refused on path=both and on path=bypass (101) unless it says FORCe, naming the order that gives the shunt the whole current back (ROUTe:BYPass OFF, ROUTe:NULLpath OFF). CALibration:ZERO is refused on path=both with no override, because nothing makes that a null. A LIVE move that would take a running capture's shunt off the DUT's current (relay::bypassesShunt(): every ROUTe:NULLpath order, ROUTe:BYPass ON) needs FORCe too (110), because the header has already gone out with its q=. A capture that was off the DUT's current at any moment then says q=invalid on its ABORt, in SYSTem:STATus? and in every relay reply — and in its header too when it was so at INITiate. SYSTem:STATus? and SYSTem:INFormation? say q=invalid for as long as the shunt is off the DUT's current.
  4. Every record says which circuit it was taken in. Each capture header carries relays=1 k1=… k2=… k3=… k4=… path=… (FETCh:HEADer?, docs/scpi.md "The capture header"), and both CALibration:ZERO lines carry the same tokens as the window's start found them — the result line too, so an order between the window's last sample and ABORt cannot rewrite the circuit the null was taken in. path=bypass there is a null taken with the lead opened by K1, path=shunt one that rests on a lead opened by hand, which the relays cannot see, and check= what ROUTe:NULLpath ON saw of the path.

Nothing waits on a relay but the console. Orders run on the console task (Core 0). A settle wait drains the stream queue every millisecond instead of sleeping through it, so a LIVE order never holds back a capture's samples, and the sampler task on Core 1 never sees a relay at all. The checks read the device only with no capture open, so they never move the register pointer out from under a TRACE. The console is the bank's only user after boot, so no order can interleave with another.

The RTC slow clock stays on the internal RC. GPIO15 and GPIO16 are the 32 kHz crystal pins; sdkconfig.defaults states CONFIG_RTC_CLK_SRC_INT_RC=y (and test_meter_sdkconfig_reaches_the_build checks it arrives), and relay.cpp refuses to compile with an external crystal or oscillator selected, which would put a clock on the bypass relay's input.

What the relays cannot do. They cannot see whether the DUT is also fed by USB. They cannot order a release they did not command: while the null path is held, a meter reset releases both coils at once, K2's NO contact can open before K1's NC recloses, and the DUT can lose its battery for a few milliseconds; a slow fall of the 5 V can even release K2 first and leave path=none with the firmware still reporting bypass. The hold bounds the exposure, and a host should still close the path in a finally. They cannot see below 2 mA (the checks above). And each energized coil draws about 71 mA from the carrier's 5 V terminal (Songle's coil chart: 70 Ω, 71.4 mA), so holding the null path costs about 145 mA there — which assumes the terminal carries 5 V with only the USB cable attached, measured loaded as carrier-board.md §10 check 6 asks. The module's 5 V must also never outlive the meter's 3.3 V: an unpowered ESP32-S3 clamps every IN toward ground through its protection diodes (carrier-board.md §6).

6.2 The lead cycle, the open lead's hold, the unwired spares (0.13.0)

  • ROUTe:LEAD:CYCLe opens K1 with ROUTe:LEAD OPEN's interlocks and arms a deadline; the console's loop recloses it when the deadline passes, waiting for input no longer than the time left, so the reclose is late by the loop's own work only. The deadline runs from the opening's drive. A capture started meanwhile does not hold the battery back: the reclose is marked as a LIVE move.
  • The hold covers an open lead. updateHold() arms the 120 s hold on path=bypass and, from 0.13.0, on path=none; when it fires on an open lead it recloses K1 alone and queues 114. Every order and every release calls updateHold(), so an armed hold always stands on a path off the shunt (from 0.16.0 path=both as well, §6.3).
  • K3 and K4 are not wired (ChannelSpec::wired): their pins are never driven, their pads not read, their tokens unwired, and their orders refused. Until 0.16.5 GPIO16 and GPIO17 were left as reset made them; from 0.16.6 they are parked, inputs with the internal pull-down (§9), so that neither floats. The temporary load NW-00 wired to GPIO16 (the Relay 2 Click's RL1) was removed on 2026-11-21.
  • Relay timing is measured by a host tool and filed in docs/relay-timing.md; the settle waits change only from such a record.

6.3 The hold is the teardown, and a reset says what it released (0.16.0)

Before 0.16.0 the hold waited for every open capture, so a host that died with a stream open and K1 open left the DUT without its battery for as long as nobody came: the gap A7 of the review was written for. Now the hold is what puts the rig back to its safe state, K1 closed and the bypass open, whatever is running:

  • Every path but the shunt is held. updateHold() arms on path != shunt: the null path, an open lead and a bypass across a closed lead (path=both, released with 115). Any relay order arms it again, one that moves nothing included, so a host that keeps a path past 120 s says so by sending its order again; a capture's or a null window's close re-arms it, as before.
  • Only a sampling null window suspends it. A null assumes one circuit for its whole window, and the window is bounded (600 s), so while one samples serviceHold() keeps pushing the deadline out; once the window stops sampling, by itself or by ABORt, the hold has its whole 120 s. A window that ended by itself and waits for ABORt does not hold the relays: its null rests on the samples already taken, and on the circuit the window's start recorded, so the release cannot spoil it.
  • The release runs under a capture and is marked in it. releaseHeld() drives planNullPath( state, false ), make-before-break from any of the three paths, and when a capture is sampling it marks each move as a LIVE move is marked, labeled hold:k1:closed and hold:k2:open, through Sampler::addHoldMark(), which writes into two slots beyond TRACe:MARK's sixteen. It counts the release in the capture (hold_teardowns= in FETCh:STATistics?, QUEStionable bit 10 for the open or last capture) and queues 113, 114 or 115 with under a capture, marked hold: in the detail. A capture that ended by itself is not marked: no sample follows the move.
  • A reset says what it released. A reset drops every coil at once, which is safe by wiring but can open K2 before K1 recloses, and the capture it fell in ends with the stream. Bank::drive() writes every commanded state into a ResetRecord in RTC slow memory (RTC_NOINIT_ATTR: a software reset, a panic and a watchdog reset leave it, a power-on leaves noise), with a magic number and an inverted copy. Bank::begin() reads it once every pin is released, keeps it unless the chip powered on, and records the released state; announce() queues 116 naming the reset, the coils and their path, and SYSTem:HEALth? reports them as reset_released.
  • What stays out of the hold's reach. An acquisition (MEASure, READ, CALibration:SHUNt) holds the console for its whole window, at most twice 600 s plus one, and the hold runs right after it; an acquisition is refused off the shunt's whole current, so only an open lead can be under one. A dump holds it for seconds. *RST is an order: it closes the window, then releases make-before-break, and queues nothing.

7. Self-test, health and status (0.12.0)

  • *TST? reads, never assumes. The bring-up's three verdicts stay, and the self-test adds what a running instrument can lose: the INA228's identity and SHUNT_CAL read back against the bring-up's, MEMSTAT, the ALE wire probed with STATE's own pacing probe (Sampler::probeAlert(), two periods after its writes since 0.16.4, §3.3), each relay pad read back against its drive, the stored calibration read back from the flash without touching the one in RAM (CalibrationStore::storedReadable(), §3.7), and both tasks' stack high-water marks against a 512-byte floor. It is refused under an open window because it reads registers and reprograms the conversion.
  • SYSTem:HEALth? reads nothing of the device: esp_reset_reason(), the uptime, the ELF hash, the stacks, the heap counts, the hold's releases and the queue's length, so it is safe under a capture and is the one query a host polls to see that the instrument it talks to has not rebooted.
  • QUEStionable bits for what used to reach only the closing statistics: TIME (bit 2) for a fallen-back pace, a failed read or a missed period, data lost (bit 9) for dropped=. They describe the open capture or, once it is closed, the last one, and the transition filters (:PTRansition, :NTRansition) let a host latch a fall as well as a rise.
  • An asynchronous error has one way to the host, the queue: the hold's release of a null path queues 113 with the ESR's device-dependent bit, so a host that reads *ESR? or the queue between its own messages learns of it (and from 0.16.0 114, 115 and 116 the same way, §6.3).

8. The LED goes dark

The carrier's addressable RGB LED latches: a WS2812-class part keeps its last frame for as long as its 3.3 V supply stays up, so a reset, an esptool auto-reset or a flash leaves the previous firmware's color lit, and holding the data line low is a reset code, not a color. led::blankAll() (firmware/src/status_led.h), the second step of app_main() after the relays, writes an all-zero frame of four pixels to both candidate data lines, GPIO48 (this board, the vendor's table) and GPIO38 (where Espressif's DevKitC v1.1 moved it), and then holds both low. The LED is never lit again: a refresh is a current burst on the 3.3 V rail the INA228's front end shares, for no measurement benefit (carrier-board.md §4). Status goes over the serial line, where it can be parsed. Narrowing the two lines to the one confirmed pin is open (carrier-board.md).

On the RMT's registers, with no driver (FW-10). The frame is written through ESP-IDF's low-level layer (hal/rmt_ll.h, inline functions on the registers), not its RMT driver, which allocated a channel, a transaction queue, a group, an encoder and an interrupt for a frame sent once and freed them again (docs/misra.md D1). The RMT's bus clock goes on (and its reset is pulsed) under ESP-IDF's peripheral clock lock; transmit channel 0 runs on the 80 MHz APB clock divided by 4, so a tick is 50 ns, owns one memory block and idles low; its RAM holds one 0 bit (6 ticks high, 19 low) and an end marker; and the channel sends it in loop mode, counting 96 passes (four pixels of 24 bits) and stopping by itself. Each line in turn is given to the channel through the GPIO matrix while it idles low, which holds the leading reset code for 1 ms; the end of the count is polled in the raw interrupt status (no interrupt is enabled), with a budget of 1 ms after which the channel is stopped by hand; the idle level holds the trailing reset code for 1 ms; and only then does the matrix give the line back to the GPIO's output register, already low. The RMT is left as the driver left it: group clock off, memory in low power, bus clock gated. Each line costs about 2.1 ms, once, at boot.

The loop-count path keeps the waveform SYSTem:LED? reports (t0h_ns=300 t0l_ns=950, the same as 0.16.6's driver): on the meter, on 2026-11-22, a temporary build looped each line back into RMT receive channel 4 through the matrix and captured the frame at 12.5 ns (the APB clock, undivided): on both lines 96 high halves of exactly 24 ticks (300 ns) and 95 lows between them of exactly 76 ticks (950 ns), so a pass's end marker adds nothing between two bits. The cycle-counted bit-bang the plan kept as a fallback was not needed. The host harness models the registers (firmware/test/native/harness/sim.h sim::Rmt): it plays the channel's RAM onto the pads routed to it and fails a case that reached the RMT unclocked or outside the clock lock, or left a line it drives at no defined level.


9. Serial-only, and the hardware it does not use parked (0.16.6)

The file the build reads is firmware/sdkconfig.defaults, each line with its reason beside it (§10); this section is what 0.16.6 changed there and in the bring-up, after the owner's ruling of 2026-11-21: the meter is serial-only (the NW-00 radio A/B failed, calibration/records/radio-ab-2026-11-21.md; a transmit-power sweep showed a null shift of about −0.06 µV even at 2 dBm, radio-tx-sweep-2026-11-21.md), and every piece of hardware it does not use is parked. The panel runs on the host, over the cable, never on the meter: kleidos-meter serve (the panel's guide, its HTTP API the HTTP API's reference) is one opener of the port like any other, the firmware has no command, session or lock for it, and a panel that dies is the case the hold was made for (§6.3).

  • Wi-Fi, Bluetooth, the PHY, coexistence: not linked, and from FW-16 not built: the project's component list holds only the firmware's component and what it requires (firmware/CMakeLists.txt, COMPONENTS), so esp_wifi, bt, esp_phy and esp_coex are not in the build and their options not in the generated config (CONFIG_BT_ENABLED=n stays in sdkconfig.defaults as the statement of what an absent symbol means). ESP-IDF's esp_perip_clk_init() gates the Wi-Fi, Bluetooth and SDIO clocks at a power-on reset. Until FW-16 the image kept one symbol of theirs, include_esp_phy_override, an empty link anchor (esp_phy's CMakeLists passed -u for it); it is gone with the component.
  • The USB-Serial-JTAG: off. CONFIG_ESP_CONSOLE_SECONDARY_NONE=y and CONFIG_USJ_ENABLE_USB_SERIAL_JTAG=n (from FW-16 its driver's component is not in the build, and the option is absent, which esp_perip_clk_init() reads as off just the same). Until 0.16.5 the secondary console defaulted to it, so its pad and bus clock stayed on, its VFS and connection monitor were linked, and the monitor's start-of-frame hook ran from every FreeRTOS tick (1 kHz). Flashing is the ROM's download mode over UART0 and the CH343, and the console is UART0, so nothing is lost but the native port's console and JTAG, which the rig never used (its native port is unplugged, carrier-board.md §7).
  • The unused GPIOs: parked once at boot, inputs with the internal pull-down, by relay::Bank::begin() after it has released every relay: every free or caution pin of the board's table (firmware/board/pins.toml) that no role of the live map holds (pinmap::parkedSet() in firmware/src/pinmap.h, from FW-04). For the default map that set is relay.h's kParkedPins, GPIO1, 2, 8 to 14, 16, 17, 18, 21, 39 to 42 and 47, and a static_assert holds the two equal, pin for pin. GPIO16 and GPIO17 are the unwired spares K3 and K4, which reach nothing since the temporary load NW-00 wired to GPIO16 was removed (2026-11-21). Left alone, with the reasons in relay.h: the strapping pins (0, 3, 45, 46), the flash and PSRAM lines (26 to 37), UART0 (43, 44), the native USB pair (19, 20: ESP-IDF disables its pad, and a gpio_config() on them writes the USB-Serial-JTAG's registers with its clock gated), the INA228's 4, 5 and 6, the relays' 7 and 15 and the LED lines 38 and 48 (held low by status_led.cpp). static_asserts in relay.h and pinmap.h refuse a table that parks a reserved pin, an LED line or a pin of the default map. When a boot falls back to the default bus (§2.6), the pads the stored bus had are parked the same way before the default bus is opened (relay::Bank::park()). Under a stored map the rig's own pins are parked like any other no role holds, GPIO7 among them: an HW-316 input still wired to it would meet a pull-down, which sinks current through its LEDs, so move the wire before the map (§6.1).

The gate (scripts/check_radio_absent.py, CI's firmware job, after the IRAM gate): nm over the linked firmware.elf, failing on any defined symbol, code or data, of Wi-Fi, Bluetooth, the PHY, coexistence or the USB-Serial-JTAG; the ROM's absolute aliases (A), which the ROM linker scripts give every image, are not counted, and an allowed name the image no longer holds fails as a stale exception. On 0.16.6's image it reports 0 in every family; on 0.16.5's, 28 USB-Serial-JTAG symbols; on the NW-00 spike's, 1,104. tests/firmware/test_radio_absent_gate.py holds its parsing and its verdicts, and --selftest runs the same checks with no toolchain.


10. The project

firmware/
├── platformio.ini # [env:meter], the one image; the toolchain pins (tests/firmware/test_project_pins.py)
├── CMakeLists.txt # project( kleidos-meter ), the instrument's own version, the warnings as errors
├── sdkconfig.defaults # every option with its reason beside it
├── partitions.csv # §3.7, §2.5: the record logs' calib and pins partitions and the image
├── version.txt # the instrument's version (CHANGELOG.md, "The version rule")
├── scripts/ # the build's own helpers
├── src/
│ ├── main.cpp # app_main(): read the pin map, release the relays, blank the LED, the calibration, the bring-up and the sampler on Core 1, the console
│ ├── relay.h/.cpp # §6: the four circuits, the planned orders, the hold, the parking, on the map's pins
│ ├── pinmap.h # the pin map: the roles' pins, the default map, validate() and parkedSet() (FW-01)
│ ├── pin_table.h # the board's pins, generated from firmware/board/pins.toml by scripts/gen_pin_table.py
│ ├── pin_boot.h/.cpp # §2.6: the map the boot runs, its bus brought up, the fallback to the default bus
│ ├── pin_apply.h/.cpp # §2.7: the move to another map and back, relays first, ALERT and the bus on Core 1
│ ├── pinmap_store.h/.cpp # §2.5: the pin map's record in the pins log, the store's judgment of one, load() and save()
│ ├── status_led.h/.cpp # §8
│ ├── ina228_regs.h # the register map, one comment per register citing [DS]
│ ├── ina228.h/.cpp # the bus, its core, the bring-up, the transactions (§2)
│ ├── i2c_bus.h/.cpp # §2.4: the INA228's bus, I2C0 on its registers, polled, nothing allocated
│ ├── scale.h, calmath.h, wide.h # the integer conversions and the 128-bit sums (§3.6, §3.8)
│ ├── sampler.h/.cpp # §3.2 to §3.9, §4.1: profiles, pacing, the loop, the ring, anchors, marks, statistics
│ ├── calibration.h/.cpp # §3.7: the calibration's record, the store's judgment of one, and the quality token
│ ├── flash_log.h/.cpp # §3.7, §2.5: the record logs, the calibration's and the pin map's, two sectors of raw flash each
│ ├── flash_port.h/.cpp # §3.7: the logs' places (the calib and pins partitions), their port on esp_flash, the static region check
│ ├── console.h/.cpp, console_commands.cpp # the UART0 console, the command table kCommands, the hold's service
│ ├── scpi.h/.cpp # the SCPI parser, the error queue, the status registers (docs/scpi.md)
│ ├── bits.h # flag tests and register fields on std::uint32_t (misra.md, 7.0.5)
│ ├── chars.h # character classes, case and digits from a compile-time table (misra.md, 7.0.3)
│ ├── text.h/.cpp # the bounded writer: typed appends on std::to_chars, no format string (misra.md, 21.10.1 and 30.0.1; FW-24 to FW-26)
│ ├── identity.h/.cpp, sha256.h # the instrument serial and the image's ELF hash
│ ├── heap_monitor.h/.cpp # the heap hooks behind DIAGnostic:HEAP?, and the census build's ring
│ ├── interrupt.h/.cpp # §5.1: the ALERT pin's and UART0's interrupts routed to CPU lines, nothing allocated
│ ├── uart0.h/.cpp # §4.2: the console's UART0 on its registers, its receive ring, the polled transmit
│ ├── watchdog.h/.cpp # §5.1: Timer Group 0's MWDT, fed once every party checked in
│ └── crc32.h # the dump's CRC-32
└── test/native/ # the host tests and their fake ESP-IDF (docs/testing.md)

Nothing here includes anything from the Kleidos firmware repository. Build from the repository root, with the PlatformIO virtualenv active: pio run --project-dir firmware -e meter (on the Kleidos bench, through that repository's scripts/pio-job); the build tree is firmware/.pio/. The upload names the CH343 port (KLEIDOS_METER_PORT, README.md "Flash").

firmware/sdkconfig.defaults is the configuration of record, every option with its reason beside it; tests/firmware/test_meter_sdkconfig_reaches_the_build.py holds that each one reaches the build. In short: silence on UART0 (CONFIG_ESP_CONSOLE_NONE, no log, no bootloader log), because a log line inside a dump corrupts a capture; no Bluetooth and no USB-Serial-JTAG (§9); CONFIG_FREERTOS_HZ=1000; ESP-IDF's task watchdog off for the instrument's own on the same timer, 5 s, a system reset, without Core 1's idle task (§5.1); the IPC task's stack at 4 KiB for the boot on Core 1 (§2.2); FreeRTOS and the I2C master's shared path in IRAM (§5.2); PSRAM on (CONFIG_SPIRAM=y, octal at 80 MHz, tested at boot, with .bss allowed in it for the ring, §4.1), in the memory map only and never a heap (CONFIG_SPIRAM_USE_MEMMAP, FW-18: no 32 KiB internal reserve, and free_spiram reads 0); ESP-IDF's brownout handling off for the firmware's own arming of the detector, a hardware reset at ESP-IDF's 2.44 V (CONFIG_ESP_BROWNOUT_DET=n, firmware/src/brownout.h, FW-18); no VFS; the heap hooks (DIAGnostic:HEAP?, misra.md) with light poisoning and a watchpoint at the end of each task's stack; 16 MB of flash with the meter's own partition table and ESP-IDF's flash write check left to the firmware's static one (§3.7), 240 MHz, -O2 (CONFIG_COMPILER_OPTIMIZATION_PERF, §3.4); and the RTC slow clock on the internal RC (§6.1). The project restates the strict warning set and the toolchain pins itself (firmware/platformio.ini, firmware/CMakeLists.txt), and AGENTS.md lists the gates that hold them.

No dynamic memory in our code. Every object of the instrument is static (constinit in app_main()); every task the firmware creates, every queue and every semaphore is made over static storage (xTaskCreateStaticPinnedToCore, xQueueCreateStatic, xSemaphoreCreateBinaryStatic), the console runs on the main task ESP-IDF created before app_main() (§5.1), over a static stack and control block its creation is linked wrapped onto (firmware/src/startup_memory.h), as the IPC tasks', the flash locks' (the flash operations' recursive mutex and, from ESP-IDF 6.1.1, the SPI1 flash API's two mutexes and its mmap lock's two semaphores) and the system interrupts' are, and a queue or semaphore both tasks reach exists before either task does. The gates (tests/firmware/test_no_dynamic_memory.py, scripts/check_heap_objects.py, and from FW-19 scripts/check_heap_reachability.py, which walks the linked image's call graph from every function of ours, read from the relocations the link keeps with -Wl,--emit-relocs, and fails when any allocator is reachable, ESP-IDF's code and the wraps included) and the device's own count (DIAGnostic:HEAP?, held at allocs_since_main=0 frees_since_main=0 after every command: on the host by a session that gives every header of the command table, firmware/test/native/test_heap.cpp, and on the meter by the bench suite) hold it; what ESP-IDF still allocates, all of it before app_main(), is registered row by row in misra.md (D1); no operation is maintenance since FW-16, which took the last (a calibration save, NVS) off. The count runs from the first allocation of ESP-IDF's startup and is split at app_main()'s first line (heap::arm(), which from FW-17 also starts the 0.7.0 steady state's count, so nothing after that line is exempt): 39 allocations before it and 79 since on 0.16.6's image once the boot has settled (76 from FW-09, which routes the ALERT pin's interrupt without the GPIO ISR service; 52 since from FW-10, the LED without the RMT driver; 35 before and 50 since from FW-11, the own watchdog; 35 before and 35 since from FW-12, the console's UART without its driver; 23 since from FW-14, the own I2C master; 31 before and 0 since from FW-16, the calibration in the flash log and a build of the firmware's components alone, with the idle task's two frees of the main task the only events since; from FW-17, which keeps the main task as the console, no allocation and no free since app_main()'s first line; and from FW-18 16 allocations and 4 frees before it, with PSRAM out of the heap, PSA's initialization and the idle tasks' memory linked wrapped onto static answers (firmware/src/startup_memory.h) and the brownout detector armed by the firmware), held by the bench suite (tests/bench, heap_expectations.toml). A census build (-DMETER_HEAP_CENSUS through PLATFORMIO_BUILD_SRC_FLAGS, no environment of its own) keeps every event's size, capabilities and call sites in a static ring of 384 in internal RAM, read by its two DIAGnostic:HEAP:CENSus queries and named by scripts/heap_census.py (misra.md, "What allocates, and where").


11. What the instrument deliberately does not do

Left out Why
ENERGY POWER integrated, and the instrument reports voltage and current at full rate; the host integrates them, and the capture's own energy is its mean power times its duration (§3.8)
Triggered conversions (MODE 0h–7h) The accumulators are invalid in triggered mode ([DS] §7.3.4) and each sample would cost a write. The one use is deliberate: the boundary temperature of TRACE and BURST (§3.2)
Threshold alerts (BOVL, BUVL, TEMP_LIMIT, PWR_LIMIT, SOVL/SUVL as limits) The limit registers are 16× coarser than the measurements ([DS] §7.6.1.13–18): 50 µA a step in range 0, a quarter of the whole sleep band. Verdicts belong on the host. The one use kept is the clip detector: SOVL = 7FF8h, SUVL = 8008h, eight limit counts inside each end of the field, written at every capture and null (ina228_regs.h kShuntOverLimitClip), with ALATCH = 1 so SHNTOL and SHNTUL reach flags=. The instrument's own threshold (SENSe:CURRent:THReshold) is a comparison in the loop (§3.8)
Auto-ranging One range does both jobs (§3.1); a switch mid-capture costs a discarded period, an RSTACC, the other range's null and a 4× scale
SHUNT_TEMPCO / TEMPCOMP The shunt's tempco is unmarked, the compensation follows the die, centimeters from the shunt, and can under-report at high shunt voltage ([DS] §7.3.5). The die temperature tells the host when the null has gone stale instead (§3.7)
CONVDLY It aligns several monitors in time ([DS] §7.3.4); there is one
High-speed I²C ESP-IDF has no master code for it (6.0.3, nor 6.1.1) (§2.1)
A radio Never: the NW-00 A/B failed, and the meter is serial-only (§9)
A panel of its own, sessions, a lock One opener holds a serial port, so there is nobody to share it with: the panel is the host's (kleidos-meter serve, the panel's guide), and lends the line to one client at a time
The LED as a status light §8

11.1 CHARGE stays, as a probe

CHARGE is out of the sampling path, but SENSe:CHARge? and SENSe:CHARge:RESet stay, and every capture carries the pair of boundary reads (§3.5). The accumulator sums every conversion regardless of AVG ([DS] §7.3.2), so over a long window it would integrate away quantization, which makes it the natural number for a long sleep; but whether it accumulates at all at 10 µA, where one conversion contributes 0.0132 counts, is not stated by [DS] (ina228-reference.md §10 q1). So no number the protocol reports depends on it: every current comes from the VSHUNT path, and CHARGE is the hardware's independent check, its mean reported beside the samples' (§3.8). SENSe:CHARge? reports the raw count, the nominal conversion and of= (CHARGEOF, read in the same breath because reading CHARGE clears it); SENSe:CHARge:RESet writes RSTACC.

Back to the top