Skip to content

LPC8xx: async DMA output drivers — Phase 1 SPI, Phase 2 clockless bring-up #3453

Closed as not planned

Description

@zackees

Goal

Move the LPC8xx output drivers from CPU-driven to DMA-driven, in two phases:

  1. Phase 1 (async SPI): extend src/platforms/arm/lpc/spi_arm_lpc.h from polled (STAT.RXRDY + per-word TXDATCTL writes) to a DMA0-driven TX stream so show() returns immediately and the CPU is free during pixel transmission.
  2. Phase 2 (clockless DMA): finish the path that already exists at src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h — bench-validate Stage 2c on real LPC845-BRK silicon (feat(platform): LPC845 PWM+DMA-to-GPIO clockless driver (Stage 2c of #2836) #2842) and bring the same SCT+DMA-to-GPIO engine to LPC804 and to multi-strip parallel output (feat(platform/lpc): multi-strip parallel output for LPC845 (SCT + DMA) — Stage 4.4 from #2845, gated on Stage 2c hardware validation #2879).

Both phases share the same LPC_DMA0 controller and the same opt-in pattern (FASTLED_LPC_*_DMA build macro, polled / bit-bang remains the default).

Current state (inventory, 2026-06-30)

Clockless (TX):

SPI (TX):

  • spi_arm_lpc.h — LPC845/804 hardware SPI (UM11029 §"SPI"). Polled STAT.RXRDY + TXDATCTL per word. SPI0 @ 0x40058000, SPI1 @ 0x4005C000 (LPC845 only).

DMA controller:

  • LPC845: DMA0 with 25 channels, peripheral triggers from SPI0/SPI1, USART0/1/2, I2C0/1/2/3, SCT (match events), ADC, MRT, capt sense. UM11029 Chapter 12.
  • LPC804: subset, 4 channels (UM11065 Chapter 12).

Phase 1 — Async SPI via DMA (the new work)

Scope

Add a DMA-capable peer to spi_arm_lpc.h, keeping the polled implementation as the default fallback. Gate is FASTLED_LPC_SPI_DMA. Header file naming should mirror the existing pattern: either spi_arm_lpc_dma.h as a sibling header, or an #if defined(FASTLED_LPC_SPI_DMA) branch inside spi_arm_lpc.h. (The _pwm_dma clockless precedent has a sibling header — keep that.)

Acceptance criteria

  • New file src/platforms/arm/lpc/spi_arm_lpc_dma.h (or DMA branch in spi_arm_lpc.h).
  • Gated on FL_IS_ARM_LPC_845 && FASTLED_LPC_SPI_DMA initially. LPC804 follow-up tracked under meta: LPC dev roadmap — Stages 3 + 4 (port completion, family expansion) #2845 Stage 4 (LPC804 has only 4 DMA channels — needs allocation review before enabling).
  • ARMHardwareSPIOutput (or DMA-variant template) exposes the same template surface as today: <_DATA_PIN, _CLOCK_PIN, _SPI_CLOCK_DIVIDER, pSPIX>. No user-facing API change.
  • writePixels() / writeBytes() programs a single TX DMA descriptor at the SPI0/SPI1 TX trigger, returns immediately, exposes done() / wait() so show() can be async.
  • show() returns ASYNC: caller can run pixel preparation for the next frame while the DMA stream completes the current one.
  • DMA-IRQ end-of-transfer marks the frame complete and (if present) signals the channel manager's completion future.
  • No partial-frame writes on early show() re-entry — either drop the new frame or wait, documented and tested.
  • FastPin / SWM routing matches existing polled driver (assumes the user's SystemInit has routed SPIx_MOSI / SPIx_SCK).
  • Polled fallback (spi_arm_lpc.h) untouched and remains the default when FASTLED_LPC_SPI_DMA is not set.
  • Host / WASM compile-only smoke (DMA branch compiles out cleanly when FL_IS_ARM_LPC is not set).
  • LPC845-BRK bench validation: APA102 / SK9822 / WS2801 200 LEDs, scope-verified SCK frequency vs. requested divider, scope-verified end-of-frame timing, no CPU-stall during transmission (measure GPIO toggle on a free pin from a tight loop during show()).

Implementation notes

  • The LPC8xx SPI block has separate TX and RX FIFOs and supports DMA on both via INTENSET.TXRDYEN / INTENSET.RXRDYEN redirected to DMA triggers (UM11029 §15.6.6 + DMA mux table). For clocked-strip output we only need TX DMA — RX is ignored (TXCTL.RXIGNORE = 1, already set in the polled driver at FL_LPC_SPI_TXCTL_RXIGNORE).
  • DMA channel selection: prefer a single channel for SPI TX. Channel allocation overlaps with the clockless PWM-DMA driver (3 channels starting at FASTLED_LPC_PWM_DMA_BASECH), so document a default channel that doesn't collide. Suggested default: channel 12 (well clear of channel 0–2 used by the clockless driver).
  • DMA descriptor layout: TXDATCTL word with LEN=7 for 8-bit, EOT bit set on the last byte of the frame, source = pixel buffer, destination = SPIx->TXDATCTL, width = 16-bit (the lower half of TXDATCTL carries data; the upper half is control). Verify the SPI block accepts back-to-back DMA writes without manual control bit re-injection (UM11029 figure in §15.6.6).
  • ChannelEngine integration: this driver is a peripheral-level SPI driver, not a parallel-IO multi-mode engine, so the "one engine for both clockless and SPI modes" rule in src/fl/channels/README.md does NOT apply here — it's SPI-only.

Phase 2 — Clockless DMA bring-up

Phase 2 is the existing clockless_arm_lpc_pwm_dma.h engine, not new code:

  • feat(platform): LPC845 PWM+DMA-to-GPIO clockless driver (Stage 2c of #2836) #2842 bench validation on LPC845-BRK — scope-verify WS2812 bit timing (T0H, T0L, T1H, T1L, RES) against the data sheet on real silicon. Specifically validate that the 24 MHz F_CPU correction landed in led_sysdefs_arm_lpc.h produces correct SCT match values (the same constants that historically drifted ~25% under the prior 30 MHz default).
  • feat(platform/lpc): multi-strip parallel output for LPC845 (SCT + DMA) — Stage 4.4 from #2845, gated on Stage 2c hardware validation #2879 multi-strip parallel output — extend the engine to drive N strips in parallel from a single SCT timing pass + N pre-encoded DMA streams. LPC845 has 25 DMA channels; budget 3-per-strip plus 1 for SPI = ~7 strips feasible.
  • LPC804 port (subject to feasibility) — LPC804 has only 4 DMA channels. A 3-channel single-strip engine just fits; multi-strip is infeasible. Decision: either ship single-strip LPC804 DMA clockless gated on FL_IS_ARM_LPC_804 && FASTLED_LPC_PWM_DMA_LIGHT (slightly different topology), or skip and leave LPC804 on PLU + bit-bang.

Phase 2 does not start until Phase 1 ships and the AutoResearch bring-up (#3300) is green on hardware — otherwise we have no way to validate DMA timing on the bench.

Dependencies / order

  1. Blocker: LPC compile path on master is currently broken at the toolchain level — see meta [META] LPC8xx compile + autoresearch + channels API end-to-end restoration — all blockers #3450 (fbuild matcher PR fix(core): match nxp-lpc (hyphenated GitHub form) in platform parser fbuild#900, framework-arduino-lpc8xx tarball checksum). Phase 1 lands cleanly in source but needs the compile path restored for CI to gate it.
  2. Soft blocker: AutoResearch echo bring-up ([BLOCKER] LPC845-BRK AutoResearch bring-up echo returns empty RX (suspected HardFault) — blocks #3102 #3300) needs to land so device-side scope-validation work has an RPC harness.

Relationships

Out of scope

  • LPC11Uxx / LPC15xx SPI DMA — different register layouts, tracked under meta: LPC dev roadmap — Stages 3 + 4 (port completion, family expansion) #2845 Stage 4.
  • Async monitoring / Tx FIFO underrun recovery beyond what the SPI block already reports via STAT.TXUR — Phase 1 just blocks the next show() on the previous frame's completion.
  • Replacing the polled driver. Polled stays as the default; DMA is opt-in.

Activity

  1. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Status snapshot (2026-07-01)

    Cross-linking recent work that shipped against this meta's Phase 1 + Phase 2 acceptance:

    Phase 1 — Async SPI (all code items delivered, silicon pending):

    Phase 2 — Clockless DMA (channels-API path delivered, silicon pending):

    ⚠️ Update the LPC804 line in this issue's text. The current text says:

    LPC804 port (subject to feasibility) — LPC804 has only 4 DMA channels. A 3-channel single-strip engine just fits...

    This is now empirically wrong. LPC804 has zero DMA channels. NXP's own mcux-sdk/devices/LPC804/LPC804.h has no DMA_Type typedef, no DMA0_BASE macro, no FSL_FEATURE_SOC_DMA_COUNT in features; UM11065 has no DMA chapter (only 3 copy-paste leftovers); 0x50008000 is a reserved AHB slot. Diagnosed by @phatpaul on #3499. #3513 reverted the phantom-DMA cascade. Preventive guardrail: #3506/#3507 (agents/docs/peripheral-existence.md).

    Recommend closing the LPC804 line-item of Phase 2 as OUT OF SCOPE — silicon does not support the peripheral. LPC804 stays on PLU + bit-bang exclusively. Non-blocker for closing this meta.

    Compile-path blocker resolved

    The issue text notes "LPC compile path on master is currently broken at the toolchain level." That block cleared — #3450 is closed, fbuild is pinned to a working release (2.3.16), and ci/bloat.py lpc845 --example AutoResearch succeeds at 53.3 KB / 64 KB in this session.

    Remaining scope for closing this meta: (a) silicon bench validation, or (b) maintainer decision to close as "code complete, silicon validation split" — same disposition as #3517.

  2. zackees commented on Jul 6, 2026

    @zackees
    MemberAuthor

    Closing this roll-up to consolidate active LPC board work under #3348.

    The remaining local hardware validation should be tracked through #3348 and its sub-issues #3300 and #3302. Historical DMA implementation details remain in this issue for reference.

  3. moved this from Triage to Done in FastLED Trackeron Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions