Skip to content

FlexIO RX begin() hangs on real Teensy 4.0 silicon — WDOG3 fires (#2764 Phase 5 follow-up) #2772

Description

@zackees

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)

  1. Unbounded software-reset spin in flexio1_configure()
    src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp does

    FLEXIO1_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, or CCM_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 with kBoundedSpinLimit) so the failure mode is "RPC reports error" instead of "device resets."

  2. DMAMUX source for FLEXIO1
    mDma.triggerAtHardwareEvent(DMAMUX_SOURCE_FLEXIO1_REQUEST0) — is DMAMUX_SOURCE_FLEXIO1_REQUEST0 actually 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).

  3. 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 in cpsid i / msr primask to keep the unlock-to-write window within 16 bus cycles. The FlexIO RX begin() does not. An ISR firing mid-sequence could leave registers half-written.

  4. 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 hit TIMEOUT and 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 (ping returns instantly)
  • ✅ The pre-existing runSingleTest / findConnectedPins / GPIO baseline path runs in loop()
  • ❌ The new flexioRxBenchmark RPC reproducibly hangs the firmware

Diagnostic next steps

  1. Add a bounded spin to every while (REG & bit) in rx_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.
  2. Instrument with FL_WARN markers at each step of begin() so the serial output identifies the line where the hang occurs. Need to be careful about the ordering vs the WDT feed.
  3. Check <DMAChannel.h> for DMAMUX_SOURCE_FLEXIO1_REQUEST0 — confirm it exists. If not, find the right symbol or write the request number explicitly.
  4. 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

🤖 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