Skip to content

fix(objectfled): BYTES_PER_DMA=120 + TMR4 round-to-nearest - #3408

Merged
zackees merged 1 commit into
masterfrom
fix/objectfled-isr-race-and-tmr4-rounding
Jun 26, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/objectfled-isr-race-and-tmr4-rounding

Conversation

@zackees

@zackees zackees commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

Defensive correctness from #3406 round-2 audit

Both fixes empirically did NOT move the residual 0.5-0.7% byte corruption rate. Landing because both are real defects regardless.

A. BYTES_PER_DMA 60 → 120

Agents 2 + 6 independently arrived at the same hypothesis: the ObjectFLED ISR refill could race with dma2's ESG-chained re-arm because the ~10 µs ISR vs ~1.25 µs inter-trigger gap. Doubling BYTES_PER_DMA doubles the major-loop period (1200 µs instead of 600 µs), giving the ISR 2× safety margin. Memory cost: bitdata grows from 15 KB to 30 KB in DMAMEM (OCRAM2, plenty of room).

B. TMR4 compare round-to-nearest

(uint16_t)(F_BUS_ACTUAL / 1e9 * T0H) was truncating 33.75 → 33 (T0H of 220 ns, 5 ns short of spec). + 0.5f before the cast now rounds to 34 (T0H of 226.67 ns, centered in the WS2812B-V5 215-235 ns window).

Hardware result

Run 1: 0.6 % (5/900)
Run 2: 0.4 % (4/900)
Run 3: 0.7 % (6/900)

Unchanged from baseline. Root cause is in Cluster D (CA0DE vs CA1DE FlexPWM DMA trigger — Agent 4) or deeper. Separate PR to follow.

Test plan

  • bash test --unit → 254/254
  • bash lint --cpp → clean
  • 3× canonical autoresearch → no regression

Refs: #3406 #3359

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved timing accuracy for signal generation by using rounded hardware timing values instead of truncation.
    • Increased the default DMA chunk size, which helps provide more timing headroom and reduces the chance of intermittent output glitches at chunk boundaries.
    • Updated related notes to better reflect the behavior of shared runtime state and DMA timing handling.

…fensive)

Two fixes from the #3406 round-2 multi-agent audit that are correct
in their own right. Empirically neither moves the residual 0.5-0.7%
byte corruption rate (3 consecutive runs after this commit: 0.6%,
0.4%, 0.7%) so the root cause is in Cluster D (CA0DE vs CA1DE) or
deeper. Landing these because they remove real defects.

1. BYTES_PER_DMA 60 -> 120 (ObjectFLEDDmaManager.h fallback). The
   ISR refill race hypothesis (Agents 2 + 6 converged) said the
   ISR's ~10 us memset+fillbits+cache-flush could race with dma2's
   ESG-chained re-arm because the inter-trigger gap was only ~1.25
   us. BYTES_PER_DMA=120 doubles the major-loop period (1200 us
   instead of 600 us), giving the ISR much more headroom. Memory
   cost: bitdata grows from 15 KB to 30 KB in DMAMEM (OCRAM2).
   Empirical: rate didn't change, but the race window is now ~2x
   safer regardless of root cause.

2. TMR4 compare values now round-to-nearest instead of truncating
   (OjectFLED.cpp.hpp:262-267). Previous `(uint16_t)(F_BUS_ACTUAL /
   1e9 * T0H)` truncates 33.75 to 33 (T0H of 220 ns, 5 ns below
   spec). `+ 0.5f` before the cast rounds to 34 (T0H of 226.67 ns,
   centered in the 215-235 ns window).

Also expanded the ObjectFLEDDmaManager comment about why the ISR
shared state stays non-volatile (Agent 5 suggested volatile but
that breaks the memcpy() in showInternal that initializes the
arrays from the local copies).

Validation:
- bash test --unit -> 254/254
- bash lint --cpp -> clean
- bash autoresearch teensy41 --object-fled --tx-pin 22 --rx-pin 8
  --timeout 60 --skip-lint, 3 runs: 0.6%, 0.4%, 0.7% byte corruption
  (no improvement, no regression).

Refs: #3406 #3359
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@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: 6cf1c4cb-3cbc-4349-83bc-9001c3b67738

📥 Commits

Reviewing files that changed from the base of the PR and between 96a9608 and 5b5b853.

📒 Files selected for processing (3)
  • src/third_party/object_fled/src/ObjectFLED.h
  • src/third_party/object_fled/src/ObjectFLEDDmaManager.h
  • src/third_party/object_fled/src/OjectFLED.cpp.hpp

📝 Walkthrough

Walkthrough

This PR increases the default ObjectFLED DMA chunk size to 120, updates related comments about ISR-shared state, and rounds timer compare values before casting in waveform setup.

Changes

ObjectFLED timing and DMA tuning

Layer / File(s) Summary
DMA defaults and shared-state comments
src/third_party/object_fled/src/ObjectFLED.h, src/third_party/object_fled/src/ObjectFLEDDmaManager.h
BYTES_PER_DMA defaults to 120, and the surrounding comments describe the DMA timing margin and ISR-shared state behavior.
Timer compare rounding
src/third_party/object_fled/src/OjectFLED.cpp.hpp
comp1load[0..2] now round bus-clock tick calculations before casting in ObjectFLED::begin().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • FastLED/FastLED issue 3343: The PR changes ObjectFLED DMA sizing and timing behavior in the same area described by this issue.

Possibly related PRs

  • FastLED/FastLED#3358: Adjusts ObjectFLED DMA chunk sizing and timing calculations in the same code path.

Poem

I’m a rabbit with twitchy ears and a bright LED grin,
I hopped through the timings and let the roundings in.
Bigger DMA chunks go thump-thump down the lane,
And phantom flips scurry away in the rain.
🐇✨

✨ 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/objectfled-isr-race-and-tmr4-rounding

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.

@zackees
zackees merged commit 3fc5cf5 into master Jun 26, 2026
7 of 10 checks passed
@zackees
zackees deleted the fix/objectfled-isr-race-and-tmr4-rounding branch June 26, 2026 03:04
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 26, 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.

1 participant