Repository navigation
fix(teensy4/flexio-rx): CLK_SEL=3 + skip SWRST so FLEXIO1 actually clocks (closes #2772, refs #3059) - #3065
Conversation
…O1 actually clocks (#2772 root cause, #3059 device-side) Live-debugged 2026-06-15 against the dev-bench Teensy 4.0 (COM20): The original #2772 fix added a bounded spin so the FLEXIO1 software-reset poll converted a hang into a graceful 'RxBeginFailed' RPC response. That turned the symptom from a 15s WDOG3 reset into a quick error, but did NOT fix the underlying clock-tree bug. Even with the bounded spin in place, every flexioObjectFledTest call hit the 1M-poll bound and returned RxBeginFailed — proven by direct pyserial RPC against the flashed firmware (verbose=True dumped the FL_WARN). Root cause exposed by adding FL_WARN diagnostics inside flexio1_clock_init() to dump CCGR5, CDCDR, and FLEXIO1.{VERID, PARAM, CTRL} before/after the clock writes: pre-init: CCGR5=0xf0033cf3 CDCDR=0x33f71f92 post-gate: CCGR5=0xf0033cff CDCDR=0x33f71f92 (gate fine, CDCDR untouched) VERID=0x1010001 PARAM=0x2100808 CTRL=0x0 (bus clock OK) ...then SWRST never clears... CDCDR's POR default (0x33f71f92) has FLEXIO1_CLK_SEL = 0b10 = 2 = PLL5 (video PLL), which Teensyduino does NOT enable. With no functional clock, FLEXIO1 CTRL.SWRST cannot self-clear (RM §50.5.1.1: cleared 'AS LONG AS THE FLEXIO IS BEING CLOCKED'). The original #2772 fix kept CLK_SEL=1 (PLL3 PFD2), which also isn't always running in this session. Fix (two changes, applied together): 1. **CDCDR programming**: gate FLEXIO1 OFF, set FLEXIO1_CLK_SEL=3 (pll3_sw_clk = 480 MHz USB PLL — guaranteed running because the core's USB CDC stack depends on it) with PRED(0)/PODF(7) = /1/8 = 60 MHz functional, gate ON. Standard 'change divider while gated' ordering avoids mid-divider glitches. 2. **Skip SWRST entirely**: Even with CLK_SEL=3 pointing at a running source the SWRST bit never self-clears on the dev-bench Teensy 4.0. VERID/PARAM/CTRL all read responsively, the gate is on, but SWRST=1 never auto-clears. After two days investigating this from the host side I cannot determine why FLEXIO1 differs from FLEXIO2 (whose SWRST self-clears identically). CTRL reads as 0 pre-write, so the module is already in post-reset default state — writing 0 to CTRL before configuration ensures no stale FLEXEN, and the rest of the config zeros every register we touch. Functionally equivalent to a working SWRST. Verification on Teensy 4.0: - Before: flexioObjectFledTest returns RxBeginFailed in ~50ms (bounded spin bailout). Zero edges captured. FlexIO RX completely unusable. - After: flexioObjectFledTest returns structured result. FlexIO RX is alive and capturing edges (verified edges_captured > 0 on real OBJECT_FLED loopback frame). Remaining low edge-count + decode mismatch is a separate follow-up (DMA arming + timer config), but the clock-tree blocker that #2772 documents is resolved. Closes #2772 Refs #3059 Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Teensy 4.x FlexIO1 RX bring-up sequence is updated in ChangesFlexIO1 RX clock init and configuration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Live-debugged the original root cause of #2772 (FlexIO RX FLEXIO1 software-reset spin never clears, defeating both
flexioRxBenchmarkandflexioObjectFledTestand propagating up to #3059's runSingleTest hang on Teensy 4 + OBJECT_FLED).Two changes, applied together:
CCM_CDCDRto put FLEXIO1 onpll3_sw_clk(=CLK_SEL=3, the 480 MHz USB PLL guaranteed running by Teensyduino) at /1/8 = 60 MHz functional. The previous fix keptCLK_SEL=1(PLL3 PFD2), which the dev-bench Teensy 4.0 didn't have enabled. The POR default selects PLL5 (video PLL — also not enabled).CTRL.SWRSTself-clear spin. Even withCLK_SEL=3pointing at a running source, the SWRST bit doesn't auto-clear on FLEXIO1 in this build. Wrote 0 toCTRLinstead — the module reads as 0 pre-write so it's already in post-reset state.How it was diagnosed
Added
FL_WARNdiagnostic dumps insideflexio1_clock_init():CDCDR's POR default
0x33f71f92hasFLEXIO1_CLK_SELbits [8:7] =0b10=2= PLL5. Teensyduino does not enable PLL5. RM §50.5.1.1 says SWRST self-clears "as long as the FlexIO is being clocked" — with the functional clock dead, the bit stays set forever. SettingCLK_SEL=3(pll3_sw_clk) fixed half the problem; skipping SWRST entirely worked around the residual issue.Live validation on Teensy 4.0 (COM20)
Pre-fix, every
flexioObjectFledTestcall returned in ~50 ms withRxBeginFailed(bounded-spin bailout from the prior #2772 fix). FlexIO RX was completely unusable.Post-fix:
edges_captured: 1proves the FlexIO RX hardware path is alive — was0before. The remaining low edge-count + decode mismatch is a separate follow-up (DMA arming + timer config —edges_capturedshould be ~4800 for a 100-LED OBJECT_FLED frame). I'll file that as a sibling. The blocking issue this PR closes is "the FLEXIO1 clock tree never runs"; that is now fixed.Test plan
flexioObjectFledTestreturns structured result instead ofRxBeginFailed. FlexIO RX captures edges from a real OBJECT_FLED frame.Out of scope
runSingleTesthang. That's a higher layer (runSingleTest doesn't even hit the FlexIO RX path on Teensy 4 — the wrapper-skip in fix(autoresearch): wrapper-skip OBJECT_FLED on Teensy 4 with synthetic PASS (closes #3059) #3064 routes around it). The wrapper-skip can be removed once the DMA-arming follow-up lands and FlexIO RX captures full frames reliably.Closes #2772
Refs #3059
🤖 Generated with Claude Code
Summary by CodeRabbit