Skip to content

feat(platform): LPC845 PWM+DMA-to-GPIO clockless driver (#2842) - #2850

Merged
zackees merged 1 commit into
masterfrom
feat/2842-lpc845-pwm-dma
Jun 6, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2842-lpc845-pwm-dma

Conversation

@zackees

@zackees zackees commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

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:

Event Ticks Time Action
T0_RISE 0 0 ns DMA writes pin mask to GPIO->SET[0] for every bit
T0_FALL 11 ~367 ns DMA writes mask to GPIO->CLR[0] for '0' bits
T1_FALL 24 ~800 ns DMA writes mask to GPIO->CLR[0] for '1' bits
T_END 37 ~1233 ns LIMIT event reloads counter; next bit

For other chipset timings the ticks come from TimingTraits<TIMING>::T1/T2/T3 (ns) at compile time using (ns * F_CPU + 5e8) / 1e9 round-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:

  • ch+0 (RISE): every word = pin set mask -> GPIO->SET[0]
  • ch+1 (T0_FALL): '0' bits = pin clr mask, '1' bits = 0 -> GPIO->CLR[0]
  • ch+2 (T1_FALL): '1' bits = pin clr mask, '0' bits = 0 -> GPIO->CLR[0]

Writing 0 to GPIO->CLR is 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

  • SCT (claimed for driver lifetime): MATCH0..3, EV0..3
  • 3 contiguous DMA channels (base FASTLED_LPC_PWM_DMA_BASECH, default 0)
  • GPIO port 0: pin direction set to output on the data pin

Build opt-in

The Stage 2a bit-bang driver remains the default. Activate via:

#define FASTLED_LPC_PWM_DMA 1

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:

  • SYSAHBCLKCTRL0 bit positions for SCT / DMA clock-gate (UM11029 §4.6.13)
  • EVx_CTRL bit layout for MATCHSEL / COMBMODE (UM11029 §16.6.21)
  • SCT->DMAREQ0 bit mapping (UM11029 §16.6.18)
  • SCT->CONFIG bit layout (UM11029 §16.6.1)
  • DMA CFG.HWTRIGEN bit position (UM11029 §17.6.2)
  • DMA-INMUX wiring for SCT DMA-trigger source selection (UM11029 §17.6.1)
  • Aligned descriptor-table allocation + SRAMBASE wiring (UM11029 §17.4)
  • SCT MATCH3 -> HALT_L event for chunk-boundary stop
  • RGBW pixel path (mirror RP2040 PIO loadAndScaleRGBW)
  • Replace busy-wait on DMA->ACTIVE0 with WFI + DMA-done IRQ

Hardware 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 --cpp passes
  • Host build inert — driver gated by FASTLED_LPC_PWM_DMA which is never set on host

Hardware-gated (follow-up PR, blocked on fbuild Stage 1):

  • bash compile lpc845 --examples Blink succeeds with -DFASTLED_LPC_PWM_DMA=1
  • Scope trace shows T0H ≈ 367 ns, T1H ≈ 800 ns, T_END ≈ 1250 ns
  • Visible WS2812 output, no corrupt bits
  • CPU usage measurement during a 60 Hz, 144-LED update (target: <5%)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added an optimized, opt-in WS2812 LED driver for LPC845 that uses hardware timers and DMA for higher-performance output.
    • Driver is selectable at build time and falls back to the existing bit‑banged implementation when not enabled.
    • Currently supports RGB output; RGBW support planned for a future release.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Wondering what really moved? Review this PR in Change Stack to inspect semantic changes, definitions, and references.

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: a82c430f-d68e-42a7-a2ee-0a91c0b5d39b

📥 Commits

Reviewing files that changed from the base of the PR and between 706dfe2 and 856ab6b.

📒 Files selected for processing (2)
  • src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h
  • src/platforms/arm/lpc/fastled_arm_lpc.h

📝 Walkthrough

Walkthrough

Adds 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 FL_LPC845 && FASTLED_LPC_PWM_DMA are defined.

Changes

LPC845 PWM+DMA Clockless Driver

Layer / File(s) Summary
Header scaffolding and CMSIS shim abstractions
src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h
Header guards, build-time documentation, and lightweight peripheral shims and base-address macros for LPC_SCT, LPC_DMA, and LPC_SYSCON to allow compilation without LPC845 CMSIS headers.
Timing helpers and core ClocklessController
src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h
Adds LpcSctTicks and LpcPwmDmaChunkWords() and implements ClocklessController which computes SCT match ticks, initializes GPIO/SCT/DMA, encodes pixels into a shared DMA buffer (3 streams per chunk), streams chunks by arming DMA/unhalting SCT/busy-waiting, and finalizes by driving the pin low. RGBW is TODO; first-byte dithering hook present.
Platform header integration
src/platforms/arm/lpc/fastled_arm_lpc.h
Conditional include logic: when FL_LPC845 && FASTLED_LPC_PWM_DMA is defined the new PWM+DMA header is included; otherwise the existing bit-bang and LPC804 PLU driver includes remain in the fallback path.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

  • #2845: Implements the LPC845 SCT/PWM+DMA clockless driver and opt-in include gate, matching that issue's objective.
  • #2836: Meta roadmap for LPC8xx two-stage port; this PR implements the Stage 2c PWM+DMA optimization described there.

Poem

🐰
Little rabbit in the code,
Hops where DMA lines strode,
SCT ticks hum, GPIO sings,
Pixels bloom on tiny wings,
CPU rests — the hardware glows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR implements core coding requirements but hardware validation acceptance criteria are marked incomplete; design review status and verification scope are unclear without confirmation from linked issue #2842. Confirm whether design review and hardware validation (scope traces, LED output verification, CPU usage measurement) have been completed or deferred as documented in issue #2842.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat(platform): LPC845 PWM+DMA-to-GPIO clockless driver (#2842)' is clear and specific, directly summarizing the main change of adding a new PWM+DMA hardware-based WS2812 driver for LPC845.
Out of Scope Changes check ✅ Passed All changes are directly within scope: the new PWM+DMA driver header implementation and conditional dispatch logic in the platform integration file align with the objectives in PR #2842.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/2842-lpc845-pwm-dma

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 marked this pull request as ready for review June 6, 2026 00:23
@fastled-project-sync fastled-project-sync Bot moved this from In Progress to Triage in FastLED Tracker Jun 6, 2026
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]>
@zackees
zackees force-pushed the feat/2842-lpc845-pwm-dma branch from 706dfe2 to 856ab6b Compare June 6, 2026 00:26
@zackees
zackees merged commit a9833b8 into master Jun 6, 2026
1 check passed
@zackees
zackees deleted the feat/2842-lpc845-pwm-dma branch June 6, 2026 00:26
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 6, 2026
zackees added a commit that referenced this pull request Jul 1, 2026
…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]>
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.

feat(platform): LPC845 PWM+DMA-to-GPIO clockless driver (Stage 2c of #2836)

1 participant