Repository navigation
Description
Symptom
The FlexIO RX backend brought up across #2765 / #2766 / #2767 / #2769 (the #2764 plan) passes host-stub C++ tests and compiles clean for Teensy 4, but the flexioRxBenchmark RPC hangs the firmware on real Teensy 4.0 silicon and gets reset by the WDOG3 watchdog (15 s).
Hardware-validation session on the dev-bench Teensy 4.0 (COM20, GPIO 3↔4 jumper):
[flexio-rx-bench] opening COM20 @ 115200
[flexio-rx-bench] ping ok: uptime=57263 ms
--- 2.1 / 1 kHz (1000 Hz / 200 ms) ---
FAIL: no response or RPC error: None ← firmware hung mid-call
--- 2.2 / 10 kHz (10000 Hz / 100 ms) ---
serial.serialutil.SerialException: ClearCommError failed
(PermissionError(13, 'The device does not recognize the command.', None, 22))
← USB CDC re-enumerating after reset
Re-probed after the harness exited:
{"id":99,"result":{"message":"pong","uptimeMs":48043,...},"jsonrpc":"2.0"}
Uptime regressed from 57 s → 48 s — the device rebooted between the two probes. With a 15 s WDT timeout, that's consistent with flexioRxBenchmark blocking somewhere in the FlexIO RX setup for ≥15 s, triggering the bare-register WDOG3 reset path landed in #2753.
Most likely culprits (in order of suspected probability)
-
Unbounded software-reset spin in
flexio1_configure()
src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hppdoesFLEXIO1_CTRL = (1u << 1); // software reset while (FLEXIO1_CTRL & (1u << 1)) {} // wait for clear
If the FLEXIO1 clock gate isn't actually on, the reset bit never clears and the CPU spins indefinitely until WDOG3 fires. Either
CCM_CCGR5_FLEXIO1(CCM_CCGR_ON)isn't the right macro/bit combination, the DSB/ISB ordering is wrong, orCCM_CDCDR_FLEXIO1_CLK_SEL(3)is selecting an unsupported source. Add a bounded-spin guard (like the WDOG3 init in feat(watchdog): Teensy 4 bare-register WDOG3 impl, hardware-verified #2753 does withkBoundedSpinLimit) so the failure mode is "RPC reports error" instead of "device resets." -
DMAMUX source for FLEXIO1
mDma.triggerAtHardwareEvent(DMAMUX_SOURCE_FLEXIO1_REQUEST0)— isDMAMUX_SOURCE_FLEXIO1_REQUEST0actually defined in Teensyduino's<DMAChannel.h>/<imxrt.h>? If not, the DMA channel never gets a valid hardware trigger and the channel may go into an error state. Worth confirming the macro exists and resolves to a sensible value (likely 0x0A on iMXRT1062, but verify). -
Missing PRIMASK gate around the unlock-to-write window
The FlexIO TX driver and the WDOG3 init in feat(watchdog): Teensy 4 bare-register WDOG3 impl, hardware-verified #2753 both wrap their register sequences incpsid i/msr primaskto keep the unlock-to-write window within 16 bus cycles. The FlexIO RXbegin()does not. An ISR firing mid-sequence could leave registers half-written. -
mDma.disableOnCompletion()interaction with empty buffer
At 1 kHz with a 200 ms window, only ~400 edges fire but the buffer is sized for 1024 (the floor). The DMA never reports completion. That alone shouldn't crash —wait()would just hitTIMEOUTand return — but combined with one of the above, it could be how the hang manifests.
What hardware-validation data we have
- ✅ Flash succeeded (335 872 bytes via teensy_loader_cli)
- ✅ Firmware boots and serves the JSON-RPC harness (
pingreturns instantly) - ✅ The pre-existing
runSingleTest/findConnectedPins/ GPIO baseline path runs in loop() - ❌ The new
flexioRxBenchmarkRPC reproducibly hangs the firmware
Diagnostic next steps
- Add a bounded spin to every
while (REG & bit)inrx_flexio_channel.cpp.hpp— mirror the WDOG3 fix pattern from feat(watchdog): Teensy 4 bare-register WDOG3 impl, hardware-verified #2753. This converts "device resets" into "RPC returns error" so we can iterate without a hard reset every test. - Instrument with
FL_WARNmarkers at each step ofbegin()so the serial output identifies the line where the hang occurs. Need to be careful about the ordering vs the WDT feed. - Check
<DMAChannel.h>forDMAMUX_SOURCE_FLEXIO1_REQUEST0— confirm it exists. If not, find the right symbol or write the request number explicitly. - Compare with the FlexIO TX driver's clock-init sequence — the FlexIO TX uses CCM_CS1CDR for FLEXIO2; FLEXIO1 lives in CCM_CDCDR. The bit positions and field widths are different between those two registers — verify the FlexIO1 versions are correct against iMXRT1062 RM §14.
References
- Parent issue: [meta] Bootstrap AutoResearch driver development for Teensy 4.0 — FlexIO RX + first LED driver verification #2764
- The four merged PRs in the series: feat(rx): FlexIO RX backend skeleton (Phase 1A of #2764) #2765, feat(rx): FlexIO RX hardware programming (Phase 1B of #2764) #2766, feat(autoresearch): flexioRxBenchmark RPC + Python harness (Phase 2 of #2764) #2767, feat(autoresearch): ObjectFLED → FlexIO RX loopback + WS2812 decoder (Phase 3 of #2764) #2769
- WDOG3 bare-register impl that's catching this hang: feat(watchdog): Teensy 4 bare-register WDOG3 impl, hardware-verified #2753
- Reference clock-init sequence:
src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_driver.cpp.hppflexio_clock_init()for FLEXIO2
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(teensy4/flexio-rx): bounded spin, OSC clock, correct CTRL offset …
fix(autoresearch): wrapper-skip OBJECT_FLED on Teensy 4 with syntheti…
fix(autoresearch): wrapper-skip OBJECT_FLED on Teensy 4 with syntheti…
fix(teensy4/flexio-rx): CLK_SEL=3 (pll3_sw_clk) + skip SWRST so FLEXI…