Repository navigation
feat(rx/lpc): SCT→DMA RX capture path — closes Phase 2 hardware gate for #3021 - #3034
Conversation
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.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds an optional SCT→DMA edge-capture path to the LPC845 RX backend, gated by ChangesLPC845 SCT→DMA RX Capture Path
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
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-2ws2812SctTestactually 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:
SCT->CAP[0]g_dma_rising[512]SCT->CAP[1]g_dma_falling[512]begin()wires:SCT->DMAREQ0/1so EV0 (rising) → SCT_DMA0 line and EV1 (falling) → SCT_DMA1 lineINPUTMUX->DMA_ITRIG_INMUX[0..1]to route those lines to DMA chs 0/1DMA->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+ENABLESET0to arm + enable both channelsDMA->SRAMBASE= 512-byte-aligned descriptor tablewait()sleeps for the capture window, halts the SCT, reads how many edges each channel captured viaXFERCFG.XFERCOUNTresidual (handles natural-completion case whereCFGVALIDdrops to 0), then merges the two rings by timestamp intomEdgeswith an unsigned-subtract wrap-aware compare.Compile gates
FASTLED_LPC_RX_SCT_DMA=1activates the new path. It impliesFASTLED_LPC_RX_SCT=1automatically.FASTLED_LPC_RX_SCT— Phase 1pinToggleRxusers don't pay any DMA-setup flash cost.FL_IS_ARM_LPC_845; host stub + non-LPC builds skip it entirely.examples/AutoResearchLpc/AutoResearchLpc.ino,FASTLED_LPC_RX_SCT_WS2812(Phase 2 opt-in) now auto-enablesFASTLED_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:
The
SRC_END_ADDR = start + width*(count-1)formula matches the NXP MCUXpresso SDK'sfsl_dma.c.Test plan
bash lint --cpp src/platforms/arm/lpc/rx_sct_capture.cpp.hppclean.tests/fl/channels/rx_sct_capture.cpppasses (5/5) — DMA path is platform-gated, doesn't affect host build.bash autoresearch lpc845brk --ws2812-loopback --upload-port COM10withFASTLED_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()ofrx_sct_capture.cpp.hpp.🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes