Skip to content

[meta] Bootstrap AutoResearch driver development for Teensy 4.0 — FlexIO RX + first LED driver verification #2764

Closed as not planned

Description

@zackees

Important

SUPERSEDED BY #3023 — see that meta for the current status of Teensy 4 channels-API driver work.

This issue's Phase 1-4 (FlexIO RX backend) all shipped on master:

Phase 5-8 (verify the rest of the TX driver matrix) are now reframed in #3023 with the post-#3005 understanding that FLEX_IO wasn't even reachable from AutoResearch until that PR landed, plus the new Bus::LPUART workstream that replaces what would have been a separate Phase 6.

Closed for history; body preserved below.


Goal

Unblock high-fidelity driver development for Teensy 4 by adding a FlexIO-based RX backend and using it to verify a first end-to-end TX↔RX driver path. After this lands, AutoResearch on Teensy 4 has a true bit-exact loopback fixture and the rest of the driver matrix (FLEX_IO, OBJECT_FLED, SPI variants, BIT_BANG) can be qualified against it incrementally.

Why FlexIO RX specifically

The current RxBackend::PLATFORM_DEFAULT on Teensy 4 resolves to FlexPWM RX (per src/fl/channels/rx/types.h:9). FlexPWM works for the gap-aware decoder path but lives in a different peripheral clock domain than the FlexIO TX driver, which means symbol-rate verification of FlexIO output is doing a cross-peripheral capture. A FlexIO RX backend lets us:

  • Capture FlexIO TX into FlexIO RX in the same peripheral clock domain → no DMAMUX cross-routing skew
  • Use FLEXIO1 or FLEXIO3 (both free; FastLED's TX uses FLEXIO2 only, per flexio_driver.h:2)
  • Drive eDMA from the FlexIO RX shifter status flag, mirroring the TX-side design

Hardware can do it. Software doesn't yet.

Verified preconditions (already true on master)

Phase 1 — FlexIO RX backend implementation

Files to add:

  • src/fl/channels/rx/types.h — extend RxBackend enum with FLEXIO, extend RxDeviceType accordingly
  • src/fl/channels/rx/channel.cpp.hpp — wire the new RxBackend::FLEXIO case in createBackendDevice()
  • src/platforms/arm/teensy/teensy4_common/flexio_rx_channel.{h,cpp.hpp} — driver itself

Driver work:

  • Pick host peripheral — FLEXIO1 (FLEXIO2 is owned by TX, FLEXIO3 has fewer mapped pins on Teensy 4.0)
  • Configure 1 shifter in RX mode + 1 timer in dual-8-bit-counter / edge-capture mode
  • Pin-mux configuration table (Teensy 4 GPIO → FLEXIO1 pin index)
  • eDMA channel + DMAMUX source for the RX shifter status flag
  • Implement RxDevice interface: begin(config), wait(timeout_us), read(out_span), stop()
  • Lint clean + bash test --cpp passes
  • Compile-only test on host stub (mock the FLEXIO1 register addresses)

Phase 2 — Bench-verify FlexIO RX with known square-wave signals

Need an independent (non-FlexIO) reference signal generator on the dev board. Easiest: drive a third GPIO via the Teensy core's analogWriteFrequency(pin, hz) + analogWrite(pin, 128) — that gives a 50% duty PWM up to several MHz. Patch that signal pin to the RX pin via jumper wire and measure.

New RPC: flexioRxBenchmark({ frequency_hz: int, duration_ms: int }) → returns { edges_captured, period_mean_ns, period_sigma_ns, period_min_ns, period_max_ns }.

Acceptance pass criteria:

Test Period Tolerance (σ) Tolerance (mean)
2.1 — 1 kHz 1 000 000 ns < 1 000 ns ±1 %
2.2 — 10 kHz 100 000 ns < 500 ns ±1 %
2.3 — 100 kHz 10 000 ns < 100 ns ±1 %

Each test is a separate RPC call driven by the autoresearch Python harness. 100 kHz is intentionally just above WS2812 bit-cell rate (~800 kHz / 1.25 µs per bit) to prove the capture path can resolve the symbol times we'll need in Phase 3.

  • Add flexioRxBenchmark RPC binding in AutoResearchRemote.cpp
  • Add Python test driver in ci/autoresearch/test_flexio_rx_squarewave.py
  • All three rates pass on real Teensy 4.0 hardware
  • Document peripheral resource use (which DMA channel, which DMAMUX source)

Phase 3 — End-to-end driver verification (ObjectFLED)

Picking ObjectFLED over the SPI/Serial driver for the first end-to-end verification because:

  • One TX wire (WS2812 self-clocked) — no clock-line capture needed
  • Already registered + tested as a working TX driver on Teensy 4
  • Uses the same WS2812 bit-cell timing the FlexIO RX is being designed to resolve in Phase 2.3
  • Smaller blast radius if Phase 1/2 has bugs — only one peripheral to bring up on the RX side

Test matrix (each is a separate runSingleTest RPC call):

# Pattern Verifies
3.1 CRGB::Red single LED Basic 24-bit GRB pattern (0x00FF00 in wire order), T1H/T1L on 8 bits
3.2 [Red, Green, Blue] three LEDs Inter-LED bit alignment, no missing reset gap
3.3 All zeros (24 × 0x00) T0H/T0L timing fidelity at zero-density bit cells
3.4 All ones (24 × 0xFF) T1H/T1L timing fidelity at one-density bit cells
3.5 100 LEDs, alternating R/G/B Long-duration capture, RAM/DMA sizing, watchdog safety

Acceptance: each captured bit sequence decodes byte-for-byte to the transmitted CRGB array, with bit-cell timing variance < ±10 % of WS2812 nominal.

  • Wire runSingleTest to set RX_BACKEND = FLEXIO for these test cases
  • Add bit-decoder for captured edge timestamps → CRGB bytes
  • All 5 test cases pass via bash autoresearch teensy40 --object-fled --rx-backend=flexio (or equivalent)
  • Add to CI dispatch list once it's stable

Phase 4 — Documentation + CI integration

  • Update src/fl/channels/rx/types.h:9 comment to mention FLEXIO option on Teensy 4
  • Update agents/docs/hardware-autoresearch.md with: new --rx-backend=flexio flag, GPIO pin restrictions for FlexIO1 mapping, peripheral resource budget
  • Decide policy on RxBackend::PLATFORM_DEFAULT for Teensy 4 — stay on FlexPWM (safe default), or switch to FlexIO once Phase 3 is stable. Default change is separate PR to keep blast radius small.
  • Add bash autoresearch teensy40 --object-fled --rx-backend=flexio to the nightly hardware test matrix once the dev-bench Teensy 4.1 (see Teensy 4.1 hardware verification deferred (RTV-silicone interference) #2760) is back online

Follow-up phases (not in scope of this issue, but unlocked by it)

Once Phase 3 is green, the same pattern extends to:

  • Phase 5 — Verify SPI_UNIFIED (APA102/SK9822, two-wire DATA+CLK; needs FlexIO RX to capture both lines or move to 2-channel capture)
  • Phase 6 — Verify FLEX_IO clockless TX driver (same FlexIO peripheral family on TX and RX — the headline win of this work)
  • Phase 7 — Verify BIT_BANG fallback driver (sanity check that BIT_BANG output is also bit-accurate)
  • Phase 8 — Verify ParallelIO multi-lane drivers (when present)

Each becomes its own issue / PR once the FlexIO RX backend is proven.

References

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions