Skip to content

fix(teensy-flexio): TRGSEL=3 for Timer 1/Timer 3 + emit FlexPWM RX diag for FlexIO - #3413

Merged
zackees merged 1 commit into
masterfrom
fix/flexio-trgsel-timer1-timer3
Jun 26, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/flexio-trgsel-timer1-timer3

Conversation

@zackees

@zackees zackees commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

#3410 Round 3

Two changes:

1. Timer 1 + Timer 3 TRGSEL encoding fix

Per i.MX RT1062 RM 47.4.10, TRGSEL = 4*M + pattern. For "Timer M output" pattern is 3, so for Timer 0 output the value is 3 (NOT 0). Driver had Timer 1 + Timer 3 set to TRGSEL=0 which encodes "Pin 0 input" — they were waiting for an external rising edge on pin 0 that never came, so the WS2812 low-bit PWM never fired.

2. FlexPWM RX diagnostics emitted for ALL Teensy drivers

Previously only ObjectFLED runs got the FlexPWM RX state dump. FlexIO TX → pin 22 RX needs it too. Now emits unconditionally on Teensy 4.x; context.py renders regardless of TX driver.

Hardware result

bash autoresearch teensy41 --flex-io --tx-pin 8 --rx-pin 22 --timeout 30 --skip-lint
TEST FLEX_IO lanes=1 leds=100 FAIL 460 ms class=zero_capture

flexPwmRxDiagnostics (now visible):
  activeMuxValueLive: 17     (pin 22 ALT1 + SION OK)
  activeSelectValueLive: 1   (#3404 fix OK)
  mctrl: 3840, captctrla: 25, dmaen: 96, dmaErq: 24  -- RX armed
  cval2..5: 0, citer: 4096, biter: 4096               -- ZERO edges

So FlexIO TX is still not producing edges on pin 8 even after the TRGSEL fix. The shifter+timer architecture needs deeper auditing — possibly Timer 2's enable condition (currently TRGSEL=1 = shifter status flag, but needs to fire only on data=1 bits) or the shifter SMOD/PINCFG routing.

Test plan

  • bash test --unit → 254/254
  • bash lint --cpp → clean
  • bash autoresearch teensy41 --flex-io ... → completes 460 ms, no crash, RX diag now visible and shows TX is silent on the wire

Refs: #3410, #3411, #3412

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Corrected Teensy diagnostics reporting so FlexPWM RX diagnostics are included for all Teensy 4.x tests, and GPIO pad probe data is only shown when relevant.
    • Fixed timer control settings in FlexIO, improving PWM and latch behavior on affected hardware.
    • Clarified and simplified diagnostics handling so enabled snapshots and register details are shown more reliably.

…M RX diag

#3410 Round 3, two related changes:

1. FlexIO Timer 1 and Timer 3 had TRGSEL=0 -- which encodes
   "Pin 0 input" per i.MX RT1062 RM 47.4.10 -- when the intent
   was "Timer 0 output". The correct encoding is
   TRGSEL = 4*M + pattern; for "Timer M output" pattern is 3,
   so for Timer 0 output the value is 3, not 0. With TRGSEL=0
   Timer 1 was waiting for an external rising edge on pin 0
   that never came, so the WS2812 low-bit PWM never fired and
   no signal appeared on the TX pad.

2. The flexPwmRxDiagnostics JSON block was only emitted when
   `is_object_fled_driver`, but the FlexPWM RX path is useful
   for ANY Teensy driver using a FlexPWM-capable pin as RX --
   e.g. FlexIO TX on pin 8 -> FlexPWM RX on pin 22 during this
   round's bring-up. Now emits on every Teensy 4.x test and
   context.py renders it unconditionally.

Hardware result:
  bash autoresearch teensy41 --flex-io --tx-pin 8 --rx-pin 22 \
      --timeout 30 --skip-lint
  TEST FLEX_IO lanes=1 leds=100 FAIL 460 ms class=zero_capture
  flexPwmRxDiagnostics:
    activeMuxValueLive: 17    (pin 22 ALT1 + SION) OK
    activeSelectValueLive: 1  (#3404 fix) OK
    mctrl: 3840  captctrla: 25  dmaen: 96  dmaErq: 24  -- RX armed
    cval2..5: 0  citer: 4096  biter: 4096  -- ZERO edges captured

So FlexIO TX is still NOT producing edges on pin 8 even after the
TRGSEL fix. The shifter+timer architecture needs deeper auditing
against a known-working WS2812-via-FlexIO reference (cross-check
with NXP AN12491 or similar). At minimum:
 - Timer 2 enable condition (currently TRGSEL=1 = shifter status
   flag; needs to fire only on data=1 bits)
 - Shifter 0 SHIFTCTL pin output routing (SMOD=2 TX, PINCFG=3)
 - Whether the design even works with the current 4-timer
   architecture or needs an alternative

Driver state after this PR:
- No crashes, no hangs, no IMPRECISERR (#3411 + #3412 stable)
- Test classifies cleanly as zero_capture (~460 ms per run)
- RX diagnostic confirms TX is silent on the wire
- Next round = make TX actually drive the pad

Refs: #3410, #3411, #3412
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 26, 2026
@zackees
zackees merged commit 9ec9300 into master Jun 26, 2026
6 of 10 checks passed
@zackees
zackees deleted the fix/flexio-trgsel-timer1-timer3 branch June 26, 2026 06:05
@coderabbitai

coderabbitai Bot commented Jun 26, 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: d233f3ea-59db-46f1-ad07-33358effebcc

📥 Commits

Reviewing files that changed from the base of the PR and between 2a96b2b and 2be638d.

📒 Files selected for processing (3)
  • ci/autoresearch/context.py
  • examples/AutoResearch/AutoResearchRemoteRunSingleTest.cpp
  • src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_driver.cpp.hpp

📝 Walkthrough

Walkthrough

The PR adjusts ObjectFLED diagnostics gating and Teensy 4 response field emission, and corrects two FlexIO timer TRGSEL encodings in the Teensy 4 driver.

Changes

Teensy 4 diagnostics and FlexIO encoding

Layer / File(s) Summary
ObjectFLED diagnostics payload
examples/AutoResearch/AutoResearchRemoteRunSingleTest.cpp, ci/autoresearch/context.py
runSingleTestImpl now emits flexPwmRxDiagnostics for all Teensy 4.x runs, keeps standardGpioPadProbe under OBJECT_FLED, and display_objectfled_diagnostics() uses a combined dict/enabled guard.
FlexIO TRGSEL values
src/platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_driver.cpp.hpp
flexio_configure_hw updates TIMCTL[1] and TIMCTL[3] TRGSEL to 3<<24 and refreshes the inline encoding comments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • FastLED/FastLED issue 3066: The PR changes Teensy 4 AutoResearch diagnostics emission and the FlexIO driver path used in the issue’s bringup flow.
  • FastLED/FastLED issue 3410: The FlexIO trigger-selection correction and diagnostics plumbing align with the issue’s Teensy 4 FlexIO work.

Possibly related PRs

  • FastLED/FastLED#3005: Updates the same Teensy 4 AutoResearch diagnostics fields and FlexIO register encoding path.
  • FastLED/FastLED#3064: Alters the OBJECT_FLED RPC handling flow that this PR’s runSingleTestImpl field emission feeds into.
  • FastLED/FastLED#3070: Changes Teensy 4 FlexIO timer trigger setup, which is the same TRGSEL area adjusted here.

Poem

(_/)
(•ㅅ•) I hopped through diagnostics, bright and neat,
/   づ with ObjectFLED and FlexIO in step.
TRGSEL clicked; the timers purred,
and little pad probes sang sweet.

✨ 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/flexio-trgsel-timer1-timer3

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.

@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 26, 2026
zackees added a commit that referenced this pull request Jun 26, 2026
…12 + SION + primed shifter (#3414)

#3410 Round 5. Substantive rewrite per the whatnick FRDM-K82F WS2812
reference. The previous 4-timer + 1-shifter design with OR-gated
outputs could not work because FlexIO TRGSEL doesn't expose "shifter
data output" as a per-bit gating source -- only pin-input, shifter-
status-flag, and timer-trigger-output. Timer 2 could not be modulated
by the actual shifter bit value.

This rewrite drops Timers 1/2/3 and uses ONE timer + ONE shifter:
- Each WS2812 bit is pre-encoded as 4 FlexIO bits in the DMA buffer
  (`1000` for 0-bit, `1110` for 1-bit) at ~3.16 MHz baud
- Shifter 0 routes its output directly to the pin via PINCFG=3
- Timer 0 generates the shift clock; no PWM gating needed
- 0-bit gets ~317 ns HIGH + ~950 ns LOW (within WS2812 spec)
- 1-bit gets ~950 ns HIGH + ~317 ns LOW (within WS2812 spec)
- DMA writes pre-encoded u32s to SHIFTBUF (not SHIFTBUFBIS so the
  MSB-first shifter naturally matches MSB-first encoding)

Additional fixes inline with the rewrite:
1. Pin mux now ALT4 + SION (0x14) per Teensyduino FlexIO_t4 reference.
   Without SION the IOMUXC input path is gated and FlexIO cannot drive
   the alt-mode pad output -- root cause of all prior `zero_capture`
   results in Rounds 1-4. All other register settings had been correct.
2. Timer 0 TIMENA = trigger rising edge (was trigger high level) so the
   timer re-arms on each SSF transition instead of latching once.
3. SHIFTBUF[0] primed with first encoded word before DMA enable, so
   SSF transitions happen and the initial Timer 0 trigger fires.

Hardware result on this branch:
  bash autoresearch teensy41 --flex-io --tx-pin 8 --rx-pin 22 \
      --timeout 30 --skip-lint
  TEST FLEX_IO lanes=1 leds=100 FAIL 459 ms class=zero_capture
  cval2..5: 0  citer: 4096  -- still no edges on the wire

The architectural rewrite is in place but TX is STILL silent. Without
a logic analyzer or scope to confirm whether FlexIO is driving the pad
at all, further blind register-tweaking is unproductive. The next
investigator should either (a) attach a scope to pin 8 during the test,
or (b) port a verified-working FlexIO WS2812 codebase line-by-line
(e.g. Finomnis/ws2812-flexio Rust impl, or MCUXpresso SDK FlexIO LED
driver) rather than continue iterating against the i.MX RT1062 RM in
isolation. The base infrastructure (no hangs, no crashes, register
offsets correct, clock init correct per Teensyduino, ALT4+SION,
bounded waits, post-test diagnostic visibility) is now solid enough
for that focused effort.

Refs: #3410, #3411, #3412, #3413

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