Skip to content

fix(teensy4/flexio-rx): drive timer via PINSEL+TIMENA=4 path; DMA now fires on pin edges (refs #3066) - #3070

Merged
zackees merged 1 commit into
masterfrom
fix/3066-iter6-timer-pinsel-fires
Jun 15, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3066-iter6-timer-pinsel-fires

Conversation

@zackees

@zackees zackees commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Loop iter 6 of #3066. With IOMUX routing now proven open (PR #3069 gave us FLEXIO1.PIN bit 6 tracking pin 4's pull-up at 0x40), the remaining bug was the timer's trigger source. The original TIMENA=6 + TIMRST=6 + TRGSEL=2*flexio_pin+1 pattern never engaged on this iMXRT1062 build — verified across iters 2/3/5 by TIMSTAT=0 across 8 hand-driven pin transitions.

This change drives the timer from its own PINSEL field instead of TRGSEL:

Field Was Is
TIMCTL.PINSEL 0 flexio_pin (the input pin)
TIMCTL.TRGSEL 2*flexio_pin+1 (= Shifter 3 status, wrong) unused
TIMCFG.TIMENA 6 (Trigger rising + Pin high) 4 (Pin rising)
TIMCFG.TIMRST 6 (Trigger rising) 2 (Pin rising)
TIMCMP 0xFFFF (1.09 ms wrap, never reached between toggles) 1 (immediate compare)
SHIFTCTL.TIMPOL 1 (negative — never fires) 0 (positive)

Live verification on Teensy 4.0 (COM20)

flexioRxLoopbackPing with 8 toggles 50 µs apart on pin 3 (jumpered to pin 4):

pre-fix:  TIMSTAT=0, transfers_done=0
post-fix: TIMSTAT=1, transfers_done=4   ← matches 4 rising edges in 8 toggles

DMA fires once per pin rising edge. The chain from pin → timer → shifter → DMA is finally alive end-to-end.

What this does NOT fix yet

mCaptureBuffer is still all-zero — the shifter is latching a 1-bit value at the timer-compare moment but it reads as 0. That's the next iter's puzzle around SHIFTBUF semantics. Not enough to decode WS2812 frames yet, but the chain is alive and DMA actually moves data per pin transition. Major step forward.

Test plan

  • Live: flexioRxLoopbackPing reports transfers_done matching the requested edge count (rising edges only).
  • CI

Refs #3066

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved FlexIO edge capture triggering on Teensy 4.x by switching to pin-edge detection method for more reliable signal sampling.
  • Chores

    • Added diagnostic logging for FlexIO register states during loopback testing to aid in debugging and validation.

… fires on pin edges (refs #3066 phase 1)

Loop iter 6 of #3066. With IOMUX routing now proven open (PR #3069
gave us FLEXIO1.PIN bit 6 tracking pin 4's pull-up at 0x40), the
remaining bug was the timer's trigger source. The original
`TIMENA=6` + `TIMRST=6` + `TRGSEL=2*flexio_pin+1` pattern never
engaged on this iMXRT1062 build — verified across iters 2/3/5 by
TIMSTAT=0 across 8 hand-driven pin transitions.

This change drives the timer from its own PINSEL field instead of
TRGSEL:

  TIMCTL:  PINSEL = flexio_pin   (was 0)
           TRGSEL = unused        (was 2*flexio_pin+1 → Shifter 3 status)
  TIMCFG:  TIMENA = 4 (Pin rising)  (was 6 = Trigger rising + Pin high)
           TIMRST = 2 (Pin rising)  (was 6 = Trigger rising)
  TIMCMP   = 1                     (was 0xFFFF)
  SHIFTCTL: TIMPOL = 0 (positive)  (was 1 = negative)

Live diagnostic (`flexioRxLoopbackPing` with 8 toggles, 50 µs apart):

  Pre-fix:  TIMSTAT=0, transfers_done=0
  Post-fix: TIMSTAT=1, transfers_done=4 ← matches 4 rising edges in 8 toggles

DMA fires once per pin rising edge. `mCaptureBuffer` is still all-zero
(shifter is latching a 1-bit value at the timer-compare moment but it
reads as 0) — that's the next iter's puzzle around SHIFTBUF semantics.
Not enough to decode WS2812 frames yet, but the chain is alive.

Also adds an iter-6 diagnostic in `flexioRxLoopbackPing` that dumps
FLEXIO1 `PIN`/`SHIFTSTAT`/`TIMSTAT` immediately after the toggles so
the host can see whether the chain reacted in real time.

Refs #3066

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit fecaa2f into master Jun 15, 2026
6 of 8 checks passed
@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: 7b2e33d6-8161-40dd-bf17-f91b3f9f9a2b

📥 Commits

Reviewing files that changed from the base of the PR and between ff5f173 and 295347b.

📒 Files selected for processing (2)
  • examples/AutoResearch/AutoResearchRemote.cpp
  • src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp

📝 Walkthrough

Walkthrough

FlexIO1 Timer 0 in flexio1_configure is reconfigured from TRGSEL-based trigger-rising capture to PINSEL-based pin-rising edge capture, with TIMCMP reduced from 0xFFFFu to 1u for shifter-edge sampling. Separately, a post-toggle diagnostic block is added to flexioRxLoopbackPing that reads and logs FlexIO1 PIN, SHIFTSTAT, and TIMSTAT MMIO registers.

Changes

FlexIO1 Timer 0 PINSEL refactor and diagnostic logging

Layer / File(s) Summary
Timer 0 PINSEL/TIMCFG/TIMCMP reconfiguration
src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp
FLEXIO1_TIMCTL[0] is updated to set PINSEL to the configured flexio_pin and mark TRGSEL unused; FLEXIO1_TIMCFG[0] switches TIMENA/TIMRST from trigger-rising to pin-rising; FLEXIO1_TIMCMP[0] is changed from 0xFFFFu to 1u with comments describing the new pin-edge sampler mode.
Post-toggle MMIO diagnostic logging
examples/AutoResearch/AutoResearchRemote.cpp
After the GPIO toggle loop in flexioRxLoopbackPing, a new block reads FLEXIO1_PIN, FLEXIO1_SHIFTSTAT, and FLEXIO1_TIMSTAT and logs their hex values via FL_WARN before the RX wait and edge capture.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2781: Modifies the same flexio1_configure function in rx_flexio_channel.cpp.hpp, changing FLEXIO1 timer and config register programming on Teensy 4.x.

Poem

🐇 Hop hop, the timer pin is set,
No trigger path to cause regret.
TIMCMP shrunk to just a 1u,
The shifter chain can sample true.
FL_WARN reads the MMIO state,
Debug at last — the edge won't wait! ✨

✨ 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/3066-iter6-timer-pinsel-fires

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 deleted the fix/3066-iter6-timer-pinsel-fires branch June 15, 2026 13:10
@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
zackees added a commit that referenced this pull request Jun 15, 2026
…0 (refs #3066) (#3071)

Loop iter 7 of #3066. Direct `SHIFTBUF[0]` + `SHIFTBUFBIS` (bit-swap) +
`SHIFTBUFBYS` (byte-swap) reads in the `flexioRxLoopbackPing` RPC
confirm: even with PR #3070's working timer/shifter chain
(`transfers_done=4` per pin rising edge), the SHIFTBUF itself reads as
`0x0` post-toggle. The captured 1-bit values reflect the pin as LOW
even though FLEXIO1.PIN reads 0x40 (bit 6 high) right before the
shifter samples.

Also bumps TIMCMP from 1 to 10 (16-tick delay between TIMENA pin-rising
trigger and the timer compare event) so the IOMUX synchroniser has
more time to propagate the pin's new state before the shifter samples.
Did not change behaviour — the bit still reads as 0 — but documents
the trial in case future iters want to sweep larger TIMCMPs.

Out of obvious knobs to twist without bench/scope visibility. Next
iter (1.8) needs to dig into SMOD=1 sample timing semantics OR try
SMOD=3/4 (Match Store / Continuous) to see if a different shifter
mode latches the pin state more reliably at the timer-compare moment.

Refs #3066

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 18, 2026
…iter 9) (#3214)

* docs(flexio-rx): document iMXRT FlexIO architectural mismatch (#3066 iter 9)

Adds a top-of-file warning block to rx_flexio_channel.cpp.hpp capturing the
iter-9 root-cause finding from #3066: iMXRT FlexIO shifters cannot snapshot a
peer timer's count into SHIFTBUF, and SMOD=1+TIMOD=3 collides shift-and-store
on the same compare event per NXP's own documentation ('shift registers
cannot shift and store on the same clock, so input data may be lost').

This explains the all-zero captures that PRs #3067/#3068/#3069/#3070/#3071
chased without success and the loop's pause at the 5-PR cap. Future readers
should know not to twist more knobs on this file — the path forward is
FlexPWM RX (Phase 4 of #3066), which has dedicated SMx_CAPTCTRL input-capture
silicon.

Pure comment change. Verified compiles via 'bash compile teensy40 --examples
AutoResearch'. References issue comment #3066/4740201201 for the full
register-by-register NXP cross-check.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(flexio-rx): drop emoji per C++ style (CodeRabbit on #3214)

Replace the warning-triangle emoji with a 'WARNING:' text prefix per
the FastLED C++ guideline against emoji in source files.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

1 participant