Repository navigation
feat(platform): LPC845 PWM+DMA-to-GPIO clockless driver (#2842) - #2850
Conversation
|
Wondering what really moved? Review this PR in Change Stack to inspect semantic changes, definitions, and references. 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 a gated LPC845 clockless WS2812 driver using SCT events plus DMA to write GPIO SET/CLR sequences and wires the driver into the platform header when ChangesLPC845 PWM+DMA Clockless Driver
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Adds Stage 2c of the NXP LPC8xx FastLED port: a CPU-free WS2812 clockless driver for LPC845 that uses the State Configurable Timer (SCT) to generate three match events at WS2812 timing positions (T0_RISE, T0_FALL, T1_FALL) and chains them to three DMA channels that write GPIO SET/CLR masks. The CPU is free during transmission; only the encode-pass runs on the M0+. Novel pattern in FastLED. Closest analogues: - src/platforms/arm/rp/rpcommon/clockless_rp_pio.h (RP2040 PIO+DMA) - src/platforms/arm/teensy/teensy4_common/drivers/flexio/ (NXP FlexIO) Stage 2a bit-bang remains default. Opt-in via FASTLED_LPC_PWM_DMA=1 because the driver claims the SCT plus 3 contiguous DMA channels (base FASTLED_LPC_PWM_DMA_BASECH default 0) — global resources users may want for other peripherals. New file: src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h - SCT init (UM11029 16.6.6 MATCH, 16.6.21 EVx_CTRL) - DMA setup (UM11029 17.4 channel descriptor, 17.5 XFERCFG) - Chunked stream encoder (default 64-bit chunks, ~768 B working set) - Forward-declared CMSIS peripheral struct shims so the file parses in IDE-introspection environments without <LPC845.h>; real CMSIS device-header definitions win when present. Updated: src/platforms/arm/lpc/fastled_arm_lpc.h - Routes fl::ClocklessController to the PWM+DMA driver when FL_LPC845 and FASTLED_LPC_PWM_DMA are both set; bit-bang otherwise. Resources consumed: - SCT: MATCH0..3, EV0..3, claimed for driver lifetime - 3 contiguous DMA channels (base FASTLED_LPC_PWM_DMA_BASECH) - GPIO0 output direction on data pin Host build is inert because FASTLED_LPC_PWM_DMA is never defined there. All TODOs tagged TODO(2842) in-source for hardware-validation phase: SYSAHBCLKCTRL0 bit positions, EVx_CTRL bit layout, DMAREQ0 mapping, SCT CONFIG layout, DMA CFG.HWTRIGEN, INMUX wiring, descriptor table SRAMBASE allocation, RGBW pixel path, busy-wait to WFI+IRQ. Refs #2842, #2836, #2831. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
706dfe2 to
856ab6b
Compare
…Phase A.3) (#3529) The classic `ClocklessController<>` template that supplied the LPC845 SCT+DMA fast path is now `clockless_channel_lpc.h` (landed in #3527), which routes through `ChannelEngineLpcSctDma` via `BusTraits<Bus::BIT_BANG>`. Nothing in the tree still `#include`s the legacy header: $ grep -rn '#include.*clockless_arm_lpc_pwm_dma' src/ examples/ tests/ (no results) Safe to delete. Keeping two code paths for the same peripheral risked: 1. Divergent register-programming choices (the legacy template still had `TODO(2842)` markers that got moved into the channels-API runtime `lpc_sct_dma_runtime.cpp.hpp`). 2. Confusion for users about which path they get when `FASTLED_LPC_PWM_DMA=1` is set. Also updates `src/platforms/arm/lpc/README.md`: - Supported-platforms row for LPC845 replaces "PWM+DMA legacy template (#2850)" with the channels-API engine + `addLeds<>` route (#3527). - Files section marks `clockless_arm_lpc_pwm_dma.h` as retired with an explanation. Historical / provenance comment references inside `drivers/sct_dma/channel_engine_lpc_sct_dma.{h,cpp.hpp}` and `drivers/sct_dma/lpc_sct_dma_runtime.{h,cpp.hpp}` are kept — those narrate the design derivation, they're not `#include` breakage risks. ## Verification - `bash test --cpp` — 345/345 pass (unchanged from master) - `bash bloat lpc845 --allow-overflow` — vanilla LPC845 build still 53.29 KB (the retired header was never linked in vanilla anyway; users had to opt into it, and #3527 already routed that opt-in through the channels adapter) - With `-DFASTLED_LPC_PWM_DMA=1` build still overflows by 236 B — that budget gap needs the `FL_AUTORESEARCH_LITE_RPC` implementation (from #3522) to close. Refs: #3517 (meta issue), #3527 (Phase A.2 addLeds routing), #3522 (tier define), #2850 (original PR that shipped this file). Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Closes #2842
Summary
Stage 2c of the NXP LPC8xx FastLED port: a CPU-free WS2812 clockless driver for LPC845 that uses the State Configurable Timer (SCT) to generate three match events at WS2812 timing positions and chains them to three DMA channels writing GPIO SET/CLR masks. The CPU is free during transmission; only the encode-pass runs on the M0+.
Novel pattern in FastLED. No existing port drives PWM->DMA->GPIO for LED bit timing. Closest analogues used as architectural references:
src/platforms/arm/rp/rpcommon/clockless_rp_pio.h(RP2040 PIO + DMA)src/platforms/arm/teensy/teensy4_common/drivers/flexio/(NXP/Freescale FlexIO)Design
SCT timing (UM11029 §16.6.6 MATCH, §16.6.21 EVx_CTRL)
SCT runs in 16-bit unified counter mode driven by the system clock (F_CPU = 30 MHz). At 30 MHz the tick is 33.33 ns; WS2812 positions land at:
GPIO->SET[0]for every bitGPIO->CLR[0]for '0' bitsGPIO->CLR[0]for '1' bitsFor other chipset timings the ticks come from
TimingTraits<TIMING>::T1/T2/T3(ns) at compile time using(ns * F_CPU + 5e8) / 1e9round-to-nearest.DMA descriptor format (UM11029 §17.4 / §17.5)
Each of the three channels has a linear 32-bit-word source stream, one word per WS2812 bit:
GPIO->SET[0]GPIO->CLR[0]GPIO->CLR[0]Writing 0 to
GPIO->CLRis a documented no-op (UM11029 §12.4.2.6), so "skip this bit" entries cost only one DMA word in RAM.Stream chunking
A full 144-LED encoding is 41 KB which exceeds the 16 KB SRAM of LPC845. The driver stream-encodes in chunks (default
FASTLED_LPC_PWM_DMA_CHUNK_BITS=64, ~768 B working set), kicking the SCT per-chunk and reloading the source between chunks.Resources consumed
FASTLED_LPC_PWM_DMA_BASECH, default 0)Build opt-in
The Stage 2a bit-bang driver remains the default. Activate via:
On host builds the macro is never set, so the entire driver file compiles to empty and Stage 2a continues to serve
fl::ClocklessController.Files changed
src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h(new, 585 lines)src/platforms/arm/lpc/fastled_arm_lpc.h(+11 lines, dispatch hook)TODOs left for hardware-validation phase
All tagged
TODO(2842)in-source. None of these block compile on host or on a real LPC845 build that supplies a complete<LPC845.h>from the MCUXpresso SDK; they call out bit-positions the author wants verified against UM11029 chapter-and-verse before scoping a hardware-bring-up PR:SYSAHBCLKCTRL0bit positions for SCT / DMA clock-gate (UM11029 §4.6.13)EVx_CTRLbit layout for MATCHSEL / COMBMODE (UM11029 §16.6.21)SCT->DMAREQ0bit mapping (UM11029 §16.6.18)SCT->CONFIGbit layout (UM11029 §16.6.1)CFG.HWTRIGENbit position (UM11029 §17.6.2)SRAMBASEwiring (UM11029 §17.4)loadAndScaleRGBW)DMA->ACTIVE0with WFI + DMA-done IRQHardware validation
Not done in this PR. Requires Stage 1 fbuild LPC845 toolchain (separate FastLED/fbuild PR) plus a physical LPC845 board with WS2812 strip and scope. Drafted as a follow-up per the meta-issue (#2836) plan.
Test plan
Host-side (this PR):
bash lint --cpppassesFASTLED_LPC_PWM_DMAwhich is never set on hostHardware-gated (follow-up PR, blocked on fbuild Stage 1):
bash compile lpc845 --examples Blinksucceeds with-DFASTLED_LPC_PWM_DMA=1🤖 Generated with Claude Code
Summary by CodeRabbit