Skip to content

feat(rx/lpc): SCT→DMA RX capture path — closes Phase 2 hardware gate for #3021 - #3034

Merged
zackees merged 1 commit into
masterfrom
feat/3021-followup-sct-dma-rx
Jun 14, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3021-followup-sct-dma-rx

Conversation

@zackees

@zackees zackees commented Jun 14, 2026 •

Copy link
Copy Markdown
Member

Summary

The #3021 follow-up the closing comment on the issue called out: replace LpcSctRxChannel's polling-mode capture with a true SCT→DMA path so the Phase-2 ws2812SctTest actually works on real LPC845 silicon. Polling at ~2 µs/poll on M0+ @ 30 MHz can't keep up with WS2812 sub-pulses (400–850 ns); DMA latches every edge without CPU involvement.

Design

Two DMA channels — one per edge direction:

DMA ch Source Trigger Destination ring
0 SCT->CAP[0] SCT_DMA0 g_dma_rising[512]
1 SCT->CAP[1] SCT_DMA1 g_dma_falling[512]

begin() wires:

  • SCT->DMAREQ0/1 so EV0 (rising) → SCT_DMA0 line and EV1 (falling) → SCT_DMA1 line
  • INPUTMUX->DMA_ITRIG_INMUX[0..1] to route those lines to DMA chs 0/1
  • DMA->CHANNEL[0..1].CFG = HWTRIGEN | TRIGPOL_HI (edge-triggered)
  • DMA->CHANNEL[0..1].XFERCFG = CFGVALID | WIDTH=32 | SRCINC=0 | DSTINC=+1 | XFERCOUNT=511 (single-shot)
  • DMA->SETVALID0 + ENABLESET0 to arm + enable both channels
  • DMA->SRAMBASE = 512-byte-aligned descriptor table

wait() sleeps for the capture window, halts the SCT, reads how many edges each channel captured via XFERCFG.XFERCOUNT residual (handles natural-completion case where CFGVALID drops to 0), then merges the two rings by timestamp into mEdges with an unsigned-subtract wrap-aware compare.

Compile gates

  • FASTLED_LPC_RX_SCT_DMA=1 activates the new path. It implies FASTLED_LPC_RX_SCT=1 automatically.
  • The polling path stays as the default for sketches that only set FASTLED_LPC_RX_SCT — Phase 1 pinToggleRx users don't pay any DMA-setup flash cost.
  • All DMA code is platform-gated behind FL_IS_ARM_LPC_845; host stub + non-LPC builds skip it entirely.
  • In examples/AutoResearchLpc/AutoResearchLpc.ino, FASTLED_LPC_RX_SCT_WS2812 (Phase 2 opt-in) now auto-enables FASTLED_LPC_RX_SCT_DMA — so users who opt into the WS2812 test automatically get the DMA path that makes it work.

Ring sizing

Each ring is 512 × 4 B = 2 KB; two rings = 4 KB total (25 % of LPC845's 16 KB SRAM). Captures up to 1024 edges per window = ~21 WS2812 LEDs. Covers the 1/3-LED test cases comfortably; the 100-LED stress case will be truncated at ~21 LEDs of the alternating R/G/B pattern (still validates the timing path).

Reference cross-check

All register offsets + bit positions verified against UM11029 Rev 1.7:

  • §14 — INPUTMUX (DMA_ITRIG_INMUX layout + SCT_DMA0/1 source IDs 0x2/0x3)
  • §16 — DMA controller (CHANNEL.CFG/XFERCFG bit positions, descriptor format, SRAMBASE alignment)
  • §21 — SCT (DMAREQ0/1 layout, CAP register addresses)

The SRC_END_ADDR = start + width*(count-1) formula matches the NXP MCUXpresso SDK's fsl_dma.c.

Test plan

  • bash lint --cpp src/platforms/arm/lpc/rx_sct_capture.cpp.hpp clean.
  • Host unit test tests/fl/channels/rx_sct_capture.cpp passes (5/5) — DMA path is platform-gated, doesn't affect host build.
  • Hardware bench (next step) — bash autoresearch lpc845brk --ws2812-loopback --upload-port COM10 with FASTLED_LPC_RX_SCT_WS2812=1 (which now implies DMA). Closes the Phase-2 hardware gate from feat(lpc): RX backend for LPC8xx via SCT input-capture — two-phase rollout #3021.

Notes

Code is bench-ready but NOT yet validated on real LPC845 silicon — no hardware attached in this dev environment. The DMA descriptor + channel setup follows UM11029 exactly + SDK conventions, but the first hardware run will inevitably surface small tweaks (descriptor field layout, trigger polarity, etc.). The PR is structured so those tweaks are isolated to begin() of rx_sct_capture.cpp.hpp.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Introduced optional DMA-accelerated capture mechanism for LPC845 microcontrollers, substantially improving overall performance and efficiency of WS2812 LED timing edge detection through advanced hardware-backed acceleration capabilities.
    • Added intelligent automatic configuration that seamlessly enables DMA capture acceleration whenever compatible hardware is available, significantly simplifying setup and eliminating manual intervention requirements for users.

Adds an opt-in DMA-driven capture path to `LpcSctRxChannel` behind a
new `FASTLED_LPC_RX_SCT_DMA` flag. Required for Phase 2 hardware
acceptance — the polling-mode `pollOnce()` from Phase 1 takes ~2 µs
per poll on M0+ @ 30 MHz, which can't keep up with WS2812's 400–850 ns
sub-pulses; DMA latches every edge with no CPU involvement.

Design
------

Two DMA channels, one per edge direction:

  * DMA ch 0 — source = `SCT->CAP[0]` (rising edge timestamps),
               triggered by `SCT_DMA0` (raised by SCT EV0),
               writes into `g_dma_rising[]`
  * DMA ch 1 — source = `SCT->CAP[1]` (falling edge timestamps),
               triggered by `SCT_DMA1` (raised by SCT EV1),
               writes into `g_dma_falling[]`

`begin()` programs:
  * `SCT->DMAREQ0/1` so EV0 → SCT_DMA0 line and EV1 → SCT_DMA1 line
  * `INPUTMUX->DMA_ITRIG_INMUX[0..1]` to route those lines to DMA chs 0/1
  * `DMA->CHANNEL[0..1].CFG` = HWTRIGEN | TRIGPOL_HI (edge-triggered)
  * `DMA->CHANNEL[0..1].XFERCFG` = CFGVALID | WIDTH=32 | SRCINC=0 |
    DSTINC=+1 | XFERCOUNT=kDmaRingSize-1 (single-shot, no auto-reload)
  * `DMA->SETVALID0` / `DMA->ENABLESET0` to arm + enable both channels
  * `DMA->SRAMBASE` = 512-byte-aligned descriptor table base

`wait()` sleeps for the capture window, halts the SCT, reads how many
edges each channel captured via `XFERCFG.XFERCOUNT` residual (treating
the natural-completion case where `CFGVALID` drops to 0 as "ring full"),
then merges the two rings by timestamp into `mEdges` using an
unsigned-subtract wrap-aware compare.

Ring sizing
-----------

Each ring is 512 × 4 B = 2 KB; two rings = 4 KB total (25 % of LPC845's
16 KB SRAM). Captures up to 512 rising + 512 falling = 1024 edges =
~21 WS2812 LEDs per window. The LPC845 cannot do longer single-shot
captures without raising `kDmaRingSize` at the cost of SRAM. For the
WS2812 test cases this covers 1/3-LED patterns comfortably and
under-covers the 100-LED stress case (which is the bound case anyway).

Compile gates
-------------

  * `FASTLED_LPC_RX_SCT_DMA` implies `FASTLED_LPC_RX_SCT` automatically.
  * The DMA code path is only active when both flags are set AND the
    target is `FL_IS_ARM_LPC_845`. Off-target builds (host, other LPC
    chips) skip the path entirely.
  * The polling path stays as the default for `FASTLED_LPC_RX_SCT`
    alone — Phase 1 `pinToggleRx` users don't pay any DMA-setup flash
    cost.

Sketch integration
------------------

In `examples/AutoResearchLpc/AutoResearchLpc.ino`,
`FASTLED_LPC_RX_SCT_WS2812` (Phase 2 WS2812 opt-in) now auto-enables
`FASTLED_LPC_RX_SCT_DMA` — so once a user opts into the WS2812 test
they get the DMA path that's required to make it actually work.

Hardware validation
-------------------

Code is bench-ready but NOT yet validated on real LPC845 silicon —
no hardware attached in this dev environment. All register offsets +
bit positions cross-checked against UM11029 Rev 1.7 §14 (INPUTMUX) +
§16 (DMA) + §21 (SCT). The descriptor table layout and the
SRC/DST_END_ADDR formula `start + width*(count-1)` match the NXP
MCUXpresso SDK's `fsl_dma.c`.

Host unit test `tests/fl/channels/rx_sct_capture.cpp` continues to
pass — the DMA path is platform-gated so `injectEdges()` round-trip
testing on host is unaffected.
@coderabbitai

coderabbitai Bot commented Jun 14, 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: 4429c091-a428-4396-a2e4-700481ea9076

📥 Commits

Reviewing files that changed from the base of the PR and between a85d665 and 386d2bd.

📒 Files selected for processing (2)
  • examples/AutoResearchLpc/AutoResearchLpc.ino
  • src/platforms/arm/lpc/rx_sct_capture.cpp.hpp

📝 Walkthrough

Walkthrough

Adds an optional SCT→DMA edge-capture path to the LPC845 RX backend, gated by FASTLED_LPC_RX_SCT_DMA. The example sketch auto-enables this flag alongside FASTLED_LPC_RX_SCT_WS2812. The core implementation adds INPUTMUX/DMA MMIO constants, DMA ring buffers and descriptor tables, extended begin() wiring, a DMA-aware wait() that merges timestamp rings into mEdges, and destructor teardown for the DMA channels.

Changes

LPC845 SCT→DMA RX Capture Path

Layer / File(s) Summary
Compile-time feature gates
examples/AutoResearchLpc/AutoResearchLpc.ino, src/platforms/arm/lpc/rx_sct_capture.cpp.hpp
Auto-defines FASTLED_LPC_RX_SCT_DMA in the sketch when WS2812 SCT loopback is active; force-enables FASTLED_LPC_RX_SCT inside the header when the DMA path is selected without an explicit SCT opt-in.
MMIO constants and register accessors
src/platforms/arm/lpc/rx_sct_capture.cpp.hpp
Adds INPUTMUX/DMA base addresses, DMA clock/reset bits, SCT DMAREQ offsets, DMA channel register offsets and XFERCFG bitfields, SCT CAP[n] address computation helper, and DMA MMIO read/write accessor.
DMA ring buffers and descriptor table
src/platforms/arm/lpc/rx_sct_capture.cpp.hpp
Defines rising/falling timestamp ring buffers, a DMA descriptor table with LPC845-required alignment, and a helper that derives per-channel captured entry counts from XFERCFG residual and CFGVALID.
begin() power sequencing and DMA wiring
src/platforms/arm/lpc/rx_sct_capture.cpp.hpp
Extends begin() to enable DMA clock and reset, wire SCT DMAREQ outputs through INPUTMUX, initialize the DMA controller SRAM base, populate descriptors for CAP[0]/CAP[1] into the two rings, configure XFERCFG transfer parameters, arm both channels, and release the SCT halt.
wait() DMA merge and destructor cleanup
src/platforms/arm/lpc/rx_sct_capture.cpp.hpp
Reworks wait() to sleep until rings fill or timeout, halt SCT, snapshot counts, disable DMA channels, and merge rising/falling timestamp arrays into mEdges in chronological order. Destructor clears/aborts both DMA channels and SCT DMAREQ triggers under the DMA flag.

Sequence Diagram(s)

sequenceDiagram
    participant sketch as AutoResearchLpc.ino
    participant ch as LpcSctRxChannel
    participant SCT as SCT (MMIO)
    participant INPUTMUX as INPUTMUX (MMIO)
    participant DMA as DMA Controller (MMIO)
    participant rings as Rising/Falling Rings

    sketch->>ch: begin()
    ch->>SCT: enable DMAREQ[0], DMAREQ[1]
    ch->>INPUTMUX: route CAP[0]/CAP[1] to DMA CH0/CH1
    ch->>DMA: set SRAMBASE, populate descriptors
    ch->>DMA: configure XFERCFG, arm channels
    ch->>SCT: release HALT

    sketch->>ch: wait()
    ch->>rings: poll until full or timeout
    ch->>SCT: HALT
    ch->>DMA: snapshot XFERCFG residual counts
    ch->>DMA: disable channels
    ch->>rings: read rising[] / falling[]
    ch->>ch: merge into mEdges[] (chrono order, compute delta/level)

    sketch->>ch: ~LpcSctRxChannel()
    ch->>DMA: clear/abort CH0, CH1
    ch->>SCT: clear DMAREQ triggers
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3016: Scaffolds LpcSctRxChannel with basic begin/wait/decode in the same rx_sct_capture.cpp.hpp file that this PR extends with the DMA capture path.
  • FastLED/FastLED#3024: Targets the LPC845 SCT RX path and adds a pinToggleRx benchmark that relies on the captured period statistics produced by the wait() implementation this PR reworks.

Poem

🐇 Hoppity-hop through registers in a row,
The SCT fires a DMA trigger — go, go, go!
Rising edges, falling edges fill the ring,
Timestamps merge in order — what a beautiful thing.
No polling loops, just descriptors aligned just right,
The bunny bows proudly: hardware captures flight! ✨

✨ 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 feat/3021-followup-sct-dma-rx

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 177db59 into master Jun 14, 2026
7 of 8 checks passed
@zackees
zackees deleted the feat/3021-followup-sct-dma-rx branch June 14, 2026 18:22
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 14, 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