Repository navigation
Description
Sub-issue of #3066 (Teensy 4 driver bringup ledger).
First identified during the FastLED #3219 session that landed PRs #3341 and #3342.
Status (updated): NEEDS FULL RE-INVESTIGATION.
Original framing called this "not solvable from software" — that was wrong.
PR #3342 (FL_WARN volume audit inAutoResearchTest.cpp) cut the device-side serial output by ~10x.
Device-sideFL_WARN()BLOCKS on a full UART TX FIFO (the Teensy's hardware FIFO is ~4 bytes deep and the
Serial.write() path blocks rather than dropping). While blocked, the CPU isn't servicing other tasks —
including ObjectFLED's DMA refill. The "TX-side DMA jitter" hypothesis below was real, but the
root cause may already have been the printf flood we just fixed. This issue needs to be re-measured
on hardware against the new firmware (post-#3342) before any "bench-only" conclusion stands.
Symptom (pre-#3342 measurements)
On a Teensy 4.0 running examples/AutoResearch/AutoResearch.ino with --object-fled --strip-sizes 100, after the wrapper-side and decoder fixes:
| Driver | 5-LED test | 100-LED test |
|---|---|---|
| OBJECT_FLED | 4/4 patterns PASS in 13 ms ✓ | 1-8 of 100 LEDs corrupt per run, RANDOM per run |
Concrete per-run captures (3 consecutive runs of --object-fled --strip-sizes 100, all run BEFORE #3342 landed):
| Pattern | Run 1 errors | Run 2 errors | Run 3 errors |
|---|---|---|---|
| A (R=0xF0, G=0x0F, B=0xAA) | 1 (LED 98) | 1 (LED 12) | 2 (LED 51, 58) |
| B (R=0x55, G=0xFF, B=0x00) | 4 (LED 7, 43, 93, 95) | 1 (LED 20) | 0 ✓ PASS |
| C (R=0x0F, G=0xAA, B=0xF0) | 0 ✓ PASS | 2 (LED 73, 95) | 4 (LED 8, 9, 10, 51) |
| D (RGB alternating) | 3 (LED 28, 89, 96) | 1 (LED 96) | 0 ✓ PASS |
| Total per run | 8 | 5 | 6 |
Different LEDs failed each run.
What changed post-#3342 that might fix this
PR #3342 cut device-side serial output volume by ~10x via three changes:
- AutoResearchTest.cpp per-byte capture dump: 26 FL_WARN lines/pattern → 1 collated line.
dumpRawEdgeTiming()collated all edges into one FL_WARN instead of one-per-edge.- Decode-failure raw-edge dump callers:
EdgeRange(0, 256)→EdgeRange(0, 32).
Each FL_WARN on Teensy 4 routes through Serial.write() which fills the UART TX FIFO. When the FIFO is full, the call blocks the calling thread until space opens up. During that block, the CPU isn't running other code — including ObjectFLED's TX-DMA refill thread. Pulse widths on the wire can stretch by tens of µs while the CPU is blocked. That stretching would land bits at the midpoint between T0H and T1H, which the decoder then classifies arbitrarily.
If this is the dominant root cause, the post-#3342 firmware should pass 100-LED autoresearch reliably — or at least with dramatically fewer errors per run.
What I had originally written (kept for context)
Four candidate root causes were proposed, requiring bench instrumentation to disambiguate:
- TX-side ObjectFLED DMA jitter — periodic DMA refill preempted by another channel → pulse width widens by tens of ns.
- RX-side FlexPWM capture jitter — input-sample clock phase drifts vs pin-edge phase.
- Cable/signal-integrity — non-impedance-controlled jumper at 5-10 ns slew rates.
- TX-RX clock-domain drift — TX off 600 MHz core, RX off 150 MHz F_BUS.
The original framing said we can't tell which without a logic analyzer. That's still true for hypotheses 2-4, but hypothesis 1 has a software-domain mechanism (printf-blocking starves DMA) that we've just substantially reduced.
Updated acceptance / next steps
- First — re-measure on hardware against post-perf(autoresearch): collapse per-byte + per-edge FL_WARN dumps (fbuild#755) #3342 firmware.
- Run
bash autoresearch teensy40 --object-fled --strip-sizes 10010 times. - Tally per-run error counts.
- If average errors per run dropped from ~6 to <1 → root cause was the printf flood, this issue can close as fixed by perf(autoresearch): collapse per-byte + per-edge FL_WARN dumps (fbuild#755) #3342.
- If errors persist at similar density → the printf-flood hypothesis was secondary, real bench work is needed (proceed to step 2).
- Run
- If hardware re-measurement still shows jitter:
- Capture ground-truth TX waveform with a logic analyzer at GPIO 3.
- Compare to FlexPWM-RX captures emitted by
runSingleTest. - Classify: TX-side / RX-side / cable / clock.
- Pick a targeted fix (raise FlexPWM RX clock, add adaptive midpoint, terminate the cable, etc.).
- 10-run regression threshold: <1 LED error per run average.
Anti-goals (unchanged)
- Do not widen decoder tolerances to mask the symptom. The midpoint classifier eliminates cascading errors; loosening per-bit tolerances any further makes real decode bugs invisible.
- Do not disable patterns that fail more often. Pattern B (R=0x55, G=0xFF, B=0x00) stresses last-bit timing; killing it would hide a real failure mode.
- Do not declare "bench-only" before re-testing against post-perf(autoresearch): collapse per-byte + per-edge FL_WARN dumps (fbuild#755) #3342 firmware. That was the original mistake.
Workaround until resolution
- The 5-LED autoresearch test (
--strip-sizes 5) is fully reliable post-fix(teensy4/autoresearch): honest FlexPWM RX + wrapper deadline + watchdog (closes #3219) #3341/perf(autoresearch): collapse per-byte + per-edge FL_WARN dumps (fbuild#755) #3342 — same code path, less burst pressure. Use for CI gating. - The 100-LED test still produces useful diagnostic data. Keep running it; don't gate CI on it.
Cross-links
- Parent ledger: [INVALIDATED — see body] Teensy 4 FlexIO RX bringup ledger (FL_WARN-overload-confounded; needs fresh investigation) #3066.
- The wrapper-side and decoder fixes that exposed this jitter: fix(teensy4/autoresearch): honest FlexPWM RX + wrapper deadline + watchdog (closes #3219) #3341.
- The FL_WARN volume audit that may already have fixed this: perf(autoresearch): collapse per-byte + per-edge FL_WARN dumps (fbuild#755) #3342.
- Daemon-side fix that unblocked seeing post-Pattern-A traffic at all: perf(serial): split daemon WS handler into reader/writer/inbound (closes #749) fbuild#750.
- Earlier precursor (closed because wrapper-skip hid it): autoresearch: OBJECT_FLED (FlexIO TX) on Teensy 4 reports 'Capture failed' even though the wire shows correct WS2812 timing (decoder tolerance mismatch) #3059.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-][teensy4] OBJECT_FLED 100-LED autoresearch: ~5% per-frame jitter — needs bench characterization[/-][+][teensy4] OBJECT_FLED 100-LED autoresearch: ~5% jitter — re-investigate post-#3342 FL_WARN audit[/+]zackees commentedon Jun 22, 2026
Hardware research update from the ObjectFLED investigation:
ObjectFLED on Teensy 4.x is not using FlexIO for output. The low-level path is:
The vendored ObjectFLED source routes QTIMER4 through XBARA1 like this:
Teensy core confirms those constants in
imxrt.h,xbar_connect()programs XBARA1 selector registers inpwm.c, andDMAChannel::triggerAtHardwareEvent()programsDMAMUX_CHCFGninDMAChannel.h.The three DMA channels have distinct jobs:
dma1: start-of-bit set, writing the collective pin mask toGPIOx_DR_SET.dma2: zero-bit falling edge, writing expanded per-bit clear masks frombitdatatoGPIOx_DR_CLEAR. This channel owns the major-loop interrupt and scatter/gather refill path.dma3: one-bit falling edge, writing the collective pin mask toGPIOx_DR_CLEAR; this is also used as the transfer-complete indicator.BYTES_PER_DMA=20is not a hardware DMA capacity limit. It is the number of LED data bytes expanded per refill block, not the number of DMA bytes:So the expanded transmit buffer is:
At 800 kHz WS2812 timing, one refill block covers roughly:
show()initially fills up toBYTES_PER_DMA * 2, so with 20 there is about 400 us of initial runway. During the rest of the transfer, the ISR must refill a half-buffer about every 200 us.The i.MX RT1060 eDMA engine has 32 DMA channels and DMA_MUX can route up to 128 request sources; PJRC also lists Teensy 4.0/4.1 as having 32 DMA channels. So the value
20is not because the peripheral can only handle 20-ish bytes.The source comment explains the actual tradeoff: larger values tolerate more interrupt latency, but grow the transmit buffer, and the buffer should stay below about half the Cortex-M7 data cache. Teensy 4.x has a 32 KB D-cache, so half is 16 KB.
Comparison:
Why this matters for this issue:
ObjectFLED is advertised upstream as non-blocking DMA output. Locally,
ObjectFLED::show()starts timers/DMA, recordsupdate_begin_micros, and returns while the DMA/ISR pipeline continues. It also providesbusy()andwaitForDmaToFinish().That means code after
FastLED.show()can overlap the active LED waveform unless FastLED's channel wrapper explicitly waits for ObjectFLED completion. Treating ObjectFLED as synchronous can make diagnostics afterFastLED.show()run while DMA refills are still required.For a 100-LED strip, the wire time is about:
With
BYTES_PER_DMA=20, the refill ISR needs service about every 200 us during that transfer. Blocking serial writes, long diagnostics, interrupt masking, or competing DMA/cache/bus activity during that window are therefore plausible software-domain causes of occasional stretched output timing.This strengthens the post-#3342 re-test requirement: if reducing
FL_WARNvolume eliminates the failures, the likely mechanism is not generic "DMA can't do it" but CPU/ISR starvation during ObjectFLED's refill cadence.Source notes captured locally in this branch:
src/third_party/object_fled/README.md.Primary references:
imxrt.h: https://github.com/PaulStoffregen/cores/blob/master/teensy4/imxrt.hDMAChannel.h: https://github.com/PaulStoffregen/cores/blob/master/teensy4/DMAChannel.hpwm.c(xbar_connect): https://github.com/PaulStoffregen/cores/blob/master/teensy4/pwm.cfix(autoresearch): gate FL_WARN sstream construction on log level
zackees commentedon Jun 27, 2026
Closing -- the FL_WARN audit conclusion landed in commit 6a46bb2 on branch
feat/lpuart-ws2812-driver(PR opening as follow-up).Root cause confirmed:
FL_WARNmacro unconditionally constructsfl::sstream() << Xregardless of log level. Under autoresearch'sfl::ScopedLogDisablewrapper, the cumulativefl::sstream/fl::stringheap alloc/free cycles across the test framework's many FL_WARN sites leave the Teensy 4 heap in a state where the function-exit destructor of a heap-backed fl::string hangs indefinitely (~80% of runs).Fix:
AR_FL_WARN/AR_FL_ERRORmacros that checkfl::getLogLevel()before expanding -- when under ScopedLogDisable (level=NONE), the sstream is never constructed and the heap stays clean. Swept all 73 FL_WARN sites inAutoResearchTest.cppand 8 inAutoResearchHelpers.cpp.Validation: LPUART autoresearch went from 1/5 to 5/5 success with the fix. FlexIO improved from 0/5 to 1-2/5 (residual heap pressure outside this file; tracked separately). When tests do complete, byte corruption stays at the documented 0.3-2.0% noise floor matching this issue's ~5% jitter envelope -- so the apparent jitter was the destructor-hang masquerading, not actual signal corruption.
Marker-narrowed investigation transcript and per-marker bisection results captured in the commit message for 6a46bb2.
fix(teensy4): autoresearch framework hang + Teensy 4 USB-CDC DTR race…
docs(lpc/autoresearch): document --auto-discover-pins default (closes #…
feat(simd/arm-dsp): wire UXTB16/PKHBT/PKHTB/USAT16/SEL ops (refs #3425)…