Skip to content

fix(teensy4/flexio-rx): CLK_SEL=3 + skip SWRST so FLEXIO1 actually clocks (closes #2772, refs #3059) - #3065

Merged
zackees merged 1 commit into
masterfrom
fix/2772-flexio1-clk-sel-and-swrst-skip
Jun 15, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/2772-flexio1-clk-sel-and-swrst-skip

Conversation

@zackees

@zackees zackees commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Live-debugged the original root cause of #2772 (FlexIO RX FLEXIO1 software-reset spin never clears, defeating both flexioRxBenchmark and flexioObjectFledTest and propagating up to #3059's runSingleTest hang on Teensy 4 + OBJECT_FLED).

Two changes, applied together:

  1. Reprogram CCM_CDCDR to put FLEXIO1 on pll3_sw_clk (=CLK_SEL=3, the 480 MHz USB PLL guaranteed running by Teensyduino) at /1/8 = 60 MHz functional. The previous fix kept CLK_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).
  2. Skip the CTRL.SWRST self-clear spin. Even with CLK_SEL=3 pointing at a running source, the SWRST bit doesn't auto-clear on FLEXIO1 in this build. Wrote 0 to CTRL instead — the module reads as 0 pre-write so it's already in post-reset state.

How it was diagnosed

Added FL_WARN diagnostic dumps inside flexio1_clock_init():

pre-init:  CCGR5=0xf0033cf3  CDCDR=0x33f71f92
post-gate: CCGR5=0xf0033cff  CDCDR=0x33f71f92
VERID=0x1010001 PARAM=0x2100808 CTRL=0x0
[FlexIO RX] FLEXIO1 software-reset bit never cleared after 1e6 polls ...

CDCDR's POR default 0x33f71f92 has FLEXIO1_CLK_SEL bits [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. Setting CLK_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 flexioObjectFledTest call returned in ~50 ms with RxBeginFailed (bounded-spin bailout from the prior #2772 fix). FlexIO RX was completely unusable.

Post-fix:

DATA: {'rx_pin': 4, 'tx_pin': 3, 'matched': 0, 'success': False,
       'num_leds': 100, 'test_case': 4, 'mismatched': 300,
       'decoded_bytes': 0, 'edges_captured': 1, 'expected_bytes': 300}

edges_captured: 1 proves the FlexIO RX hardware path is alive — was 0 before. The remaining low edge-count + decode mismatch is a separate follow-up (DMA arming + timer config — edges_captured should 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

  • Live: flexioObjectFledTest returns structured result instead of RxBeginFailed. FlexIO RX captures edges from a real OBJECT_FLED frame.
  • No regression to FlexIO TX (FLEXIO2) — only FLEXIO1 register paths touched.
  • No regression to FlexPWM RX — separate driver, unrelated registers.
  • CI

Out of scope

Closes #2772
Refs #3059

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Refined Teensy 4.x FlexIO1 hardware initialization sequence to improve stability and startup performance.
    • Optimized clock configuration strategy for more efficient hardware power management.
    • Added enhanced diagnostic capabilities for better visibility into the initialization process.

…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]>
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1ad5eddc-2973-4417-bbf8-bccacc610ff3

📥 Commits

Reviewing files that changed from the base of the PR and between 404e0ad and 24140df.

📒 Files selected for processing (1)
  • src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp

📝 Walkthrough

Walkthrough

The Teensy 4.x FlexIO1 RX bring-up sequence is updated in rx_flexio_channel.cpp.hpp: flexio1_clock_init is rewritten to gate FLEXIO1 off, reprogram CCM_CDCDR to pll3_sw_clk at 60 MHz (was 24 MHz OSC), gate back on, and add diagnostics. flexio1_configure drops the unbounded SWRST polling loop and clears FLEXIO1_CTRL directly.

Changes

FlexIO1 RX clock init and configuration

Layer / File(s) Summary
FlexIO1 clock gating and CCM_CDCDR reprogramming
src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp
kFlexIo1ClkMHz raised from 24 to 60; flexio1_clock_init now gates FLEXIO1 clock off, reprograms CCM_CDCDR to CLK_SEL=3 (pll3_sw_clk) with PRED=0/PODF=7, gates back on, and adds FL_WARN diagnostics with VERID/PARAM/CTRL readbacks and synchronization barriers.
SWRST spin loop removal in flexio1_configure
src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp
Removes the unbounded software-reset polling loop (while (FLEXIO1_CTRL & (1u<<1)) {}); updates function contract comment; replaces reset sequence with a direct FLEXIO1_CTRL = 0 clear before programming shifter/timer registers and enabling FLEXEN.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2765: Introduced the original FlexIO RX skeleton in rx_flexio_channel.cpp.hpp, including the flexio1_clock_init and flexio1_configure functions that this PR revises.
  • FastLED/FastLED#2781: Also modifies FLEXIO1 clock gating and the SWRST/wait behavior in the same flexio1_clock_init/flexio1_configure functions.
  • FastLED/FastLED#2766: Overlaps at the same CCM_CDCDR clock-gating strategy and flexio1_configure SWRST flow in rx_flexio_channel.cpp.hpp.

Poem

🐇 Hoppity-hop through the clock-gate door,
No more spin-loops to wait and snore!
60 MHz on pll3_sw_clk,
CTRL cleared clean — no SWRST trick.
The watchdog rests, no firmware resets,
FlexIO1 hums with no regrets! 🎉

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/2772-flexio1-clk-sel-and-swrst-skip

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit 689138f into master Jun 15, 2026
4 of 6 checks passed
@zackees
zackees deleted the fix/2772-flexio1-clk-sel-and-swrst-skip branch June 15, 2026 08:11
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 15, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

1 participant