Skip to content

feat(lpc): RX backend for LPC8xx via SCT input-capture — two-phase rollout #3021

Closed

Description

@zackees

Summary

Add a fifth RxBackend variant — SCT — wiring the LPC845 (and later LPC804 / LPC11Uxx / LPC15xx) State Configurable Timer as a hardware edge-capture engine for fl::channels::rx. This closes the LPC side of the RX backend matrix today (RMT, ISR, FLEXPWM, FLEXIO cover ESP32 + Teensy 4.x; LPC has nothing) and unlocks single-board WS2812 TX→RX self-loopback validation for the existing LPC clockless drivers (clockless_arm_lpc.h, clockless_arm_lpc_pwm_dma.h), which are currently marked "Compiles; hardware bring-up pending" in src/platforms/arm/lpc/README.md.

Concretely: the LPC has 3 unverified TX drivers + 0 RX backend. The SCT-RX backend turns the LPC845-BRK into a board that can validate its own LED output without an external Teensy 4.x as a capture device.

Why SCT

LPC845/LPC804 candidate peripherals for edge capture, ranked:

Peripheral Why considered Why rejected (or accepted)
SCT (State Configurable Timer) Dedicated capture registers, 4 capture channels, can DMA edge-times to RAM with no CPU, free-running counter, routable to any pin via Switch Matrix Accepted. Most capable, lowest CPU overhead, fits both phases.
MRT (Multi-Rate Timer) 4 timer channels, low overhead No capture mode — generates interrupts only at programmed intervals. Not edge-driven.
PINT (Pin Interrupt) 8 channels, edge/level triggers, dedicated NVIC slots No hardware timestamping — ISR must snapshot SysTick/SCT counter manually; jitter ~30–50 cycles on M0+ at 30 MHz (1.0–1.7 µs), too coarse for WS2812 (300–1250 ns bits).
CTimer 32-bit timers with capture LPC8xx has no CTimer (LPC845 has SCT instead).

→ SCT it is. UM11029 §16 ("State Configurable Timer") is the reference. Specific registers/events/match conditions to be confirmed by the LPC-expert agent doing the data-sheet pass (see Open questions below).

Architecture

Tier 1 — public surface (no breaking change)

Add one enum entry:

// src/fl/channels/rx/types.h
enum class RxBackend : u8 {
    PLATFORM_DEFAULT = 0,
    RMT = 1,
    ISR = 2,
    FLEXPWM = 3,
    FLEXIO = 4,
    SCT = 5,   // NEW — LPC8xx State Configurable Timer input-capture
};

Update toString() and the PLATFORM_DEFAULT selection logic in src/fl/channels/rx/channel.cpp.hpp to pick SCT on FL_IS_ARM_LPC.

Tier 2 — backend implementation

New files mirroring the Teensy FLEXIO layout (src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.{h,cpp.hpp}):

src/platforms/arm/lpc/rx_sct_channel.h
src/platforms/arm/lpc/rx_sct_channel.cpp.hpp

rx_sct_channel implements the RxDevice interface:

  • begin(RxChannelConfig) — claims the SCT, routes the configured pin to SCT capture via Switch Matrix, enables the DMA mux entry for the capture event, sets up a ring buffer for edge timestamps.
  • DMA-end ISR — copies the edge buffer into the channel's user-visible EdgeTime ring (or marks DMA as "rolled over" so getRawEdgeTimes() can drain it).
  • decode(ChipsetTiming4Phase, span<u8>) — reuses the existing FastLED bit-decoder.
  • ~RxChannel() — releases the SCT + DMA channel + SWM pin reservation.

Tier 3 — Switch Matrix routing

LPC8xx pins are not fixed-function. The SCT capture input must be routed via SWM (SWM_PINASSIGN5..7 for SCT_PIN0..3 inputs, UM11029 §13.5). The driver must:

  1. Reserve a SWM slot before claiming the SCT capture channel.
  2. Refuse to overlap with FastLED TX driver SWM assignments (the bit-bang clockless driver uses raw GPIO, so no conflict; the SCT+DMA TX driver does claim SCT match outputs — that conflict is hardware-fundamental and must be documented).

Tier 4 — opt-in compile gate

Keep flash budget tight (LPC845 = 64 KB):

// Only compile rx_sct_channel.cpp.hpp when FASTLED_LPC_RX_SCT=1 OR
// when the user explicitly requests RxBackend::SCT.

The bring-up sketch (examples/AutoResearchLpc/AutoResearchLpc.ino) sets the flag.

Two-phase rollout

Phase 1 — pin-toggle TX→RX self-loopback (validation gate for the backend)

Goal: prove SCT capture works at all on real silicon, independent of any LED driver.

Test scenario:

  1. Configure GPIO pin TX as output.
  2. Configure SCT capture on pin RX (via SWM), 30 MHz SCT clock = ~33 ns resolution.
  3. Bit-bang a 100 µs square wave (10 kHz) on TX for 100 ms (1000 edges).
  4. Wire TX → RX externally (one jumper on LPC845-BRK breakout).
  5. Assert: edge count = 2000 ± 1; mean period = 100 µs ± 1 %; σ < 500 ns.

RPC binding: pinToggleRx({tx_pin, rx_pin, frequency_hz, duration_ms}) in AutoResearchLpc.ino, mirroring flexioRxBenchmark's contract from the AutoResearch.ino Teensy side. Returns {edges_captured, period_mean_ns, period_sigma_ns, period_min_ns, period_max_ns, success}.

Acceptance:

  • Existing lpc845brk fbuild target compiles with FASTLED_LPC_RX_SCT=1 set.
  • pinToggleRx over JSON-RPC on COM10 returns success: true for {1, 10, 100} kHz square waves.
  • No new flash overhead on builds that don't opt in (FASTLED_LPC_RX_SCT=0).

Phase 2 — WS2812 TX→RX byte-match self-loopback

Goal: validate the LPC845 bit-bang clockless WS2812 driver end-to-end against its own capture.

Test scenario:

  1. Construct a CRGB[N] strip with a known pattern (red / RGB triple / all-0 / all-1 / 100-LED alternating — mirror the 5 cases that flexioObjectFledTest uses).
  2. FastLED.addLeds<WS2812, TX_PIN>(leds, N).show().
  3. Concurrently arm SCT capture on RX_PIN for capture_ms.
  4. Wire TX_PIN → RX_PIN.
  5. Decode captured edges as WS2812 4-phase timing (T0H ~400 ns, T0L ~850 ns, T1H ~800 ns, T1L ~450 ns) using the existing fl::channels::rx::decode() infrastructure.
  6. Byte-match decoded buffer against expected CRGB GRB-ordered bytes.

RPC binding: ws2812SctTest({test_case, tx_pin, rx_pin, capture_ms}) mirroring flexioObjectFledTest. Returns {num_leds, expected_bytes, decoded_bytes, matched, mismatched, edges_captured, success}.

Acceptance:

  • All 5 fixed patterns: mismatched == 0.
  • 100-LED alternating pattern: edges_captured >= 100 * 24 * 2 - 8 (allows for the latch-reset gap).
  • Validates clockless_arm_lpc.h (bit-bang) on real LPC845 silicon — closes the LPC bring-up gap noted in src/platforms/arm/lpc/README.md and unblocks Stage 4.4 (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).
  • A second pass with -DFASTLED_LPC_PWM_DMA=1 validates the SCT+DMA clockless driver too — but only via a second LPC845-BRK as the receiver, since SCT-TX and SCT-RX cannot share the peripheral on a single board (this is the documented hardware limitation from "Tier 3" above).

Test plan

Layer Test Where
Host unit tests/fl/channels/rx/sct.cpp — drive synthetic edge stream through SCT decode path on host, validate WS2812 bit-decoder output host meson
Host compile --examples AutoResearchLpc for lpc845brk confirms SCT backend builds fbuild CI
Hardware P1 bash autoresearch lpc845brk --pin-toggle-rx (orchestrator binds to JSON-RPC and validates round-trip) this machine, hardware-gated
Hardware P2 bash autoresearch lpc845brk --ws2812-loopback this machine, hardware-gated

Open questions for the LPC expert pass

The follow-up agent's web-search task. Each needs a UM11029 page/section pointer in the comment thread:

  1. Exact SCT capture register layout. Specifically: how are capture events programmed (event match register + EV_CTRL bits)? Where is the captured value latched? Single-edge or both-edges?
  2. DMA wiring. Can the SCT capture event raise a DMA request directly, or do we need an event-router intermediate? Which DMA channel is the natural one?
  3. Switch Matrix routing for SCT_PIN0..3 inputs. Confirm the PINASSIGN register offsets and bit field widths.
  4. Counter clock. Confirm whether SCT runs at MAIN_CLK / 1 (30 MHz on LPC845) or has a prescaler that lets us pick a coarser timebase to save edge buffer space.
  5. LPC804 differences. The LPC804 PLU driver claims SCT for input generation — does that preclude SCT-RX on LPC804, or can we share with careful event-table partitioning?
  6. Cross-references. Errata sheets, Application Notes (NXP AN…) covering SCT input capture for high-frequency edge streams.

Out of scope

  • Hardware SPI (APA102) decode — APA102 is clocked, RX would be a separate driver (SPI-slave-capture), not in this issue.
  • LPC15xx / LPC11U35 SCT — LPC15xx and LPC11U35 do have an SCT but with a different register layout (UM11074 and UM10462 respectively). Phase 3 follow-up.
  • LPC1110/1112/1114/1115 legacy parts — no SCT at all; would need PINT-based RX with software timestamping, separate driver entirely.

References


Filed via /goal by Claude Code agent ([email protected]). A follow-up comment with authoritative datasheet/manual links + per-question §-pointers will be added by an embedded-systems agent.

Activity

  1. zackees commented on Jun 14, 2026

    @zackees
    MemberAuthor

    LPC8xx SCT input-capture research pass (per the six open questions in the issue)

    Authority-of-record for the LPC845 (the Phase-1 / Phase-2 target part) is UM11029 Rev. 1.7, 14 April 2021. All section numbers, tables, register offsets and bit-fields below are taken from that revision and verified against the PDF (Chapter 21: SCTimer/PWM; Chapter 10: Switch Matrix; Chapter 14: Input multiplexing and DMA trigger multiplexing; Chapter 8: SYSCON; Chapter 16: DMA controller).

    1. Datasheets, user manuals, board UM, errata

    Doc Rev / date Notes
    LPC845M301JBD48 product page n/a Canonical NXP page: https://www.nxp.com/part/LPC845M301JBD48 - this is the part on the LPC845-BRK.
    LPC84x product data sheet (LPC84x.pdf) 28 Oct 2020 Short electrical / timing spec, distinct from UM11029: https://www.nxp.com/docs/en/data-sheet/LPC84x.pdf
    LPC84x family overview / training deck 2018 https://www.nxp.com/docs/en/training-reference-material/Part-II-Enhancing-the-end-user-experience-by-leveraging-the-digital-and-HMI-features-on.pdf - block-level overview of SCT capture plus DMA flow.
    UM11029 LPC84x User Manual Rev. 1.7 - 14 Apr 2021 NXP does not currently host UM11029 at a stable direct URL; the following mirror is byte-identical to the NXP-distributed file: https://web.pa.msu.edu/people/edmunds/Disco_Kraken/NXP_Arm_LPC845/nxp_arm_lpc84x_user_manual_rev_1.7_apr_2021.pdf . Rev. 1.6 (8 Dec 2017) is also widely cached: https://www.zlgmcu.com/data/upload/file/Utilitymcu/LPC84x-yhsc.pdf .
    UM11181 LPC845 Breakout board user manual Rev. 1.1 - 4 Feb 2019 NXP community attachment: https://community.nxp.com/pwmxy87654/attachments/pwmxy87654/lpc/35244/1/UM11181.pdf ; Mouser mirror: https://www.mouser.com/datasheet/2/302/UM11181-1523445.pdf . Documents the CMSIS-DAP debug bridge, the 38-pin DIP breakout, and which PIO0_x / PIO1_x lines are physically broken out - critical for picking TX/RX jumper pins for self-loopback.
    ES_LPC84x Errata Sheet Rev. 1.3 - 5 Nov 2019 Mirror: https://datasheet.sisoog.com/file/zmedia/dex/f01e3508f07508da97b6599a85512dbd_ES_LPC84X.pdf . Only one functional erratum on revision 1A silicon: ROM.1 (ISP boot-image call over I2C/SPI broken). No published SCT, DMA, INPUTMUX, SWM or SYSCON errata. The SCT input-capture path is clean silicon as of revision 1A.

    2. Per-question answers

    Q1 - Exact SCT capture register layout. How are capture events programmed? Where is the captured value latched? Single-edge or both-edges?

    Answer. Each of the eight capture/match register slots is re-purposed as a capture slot by setting the matching bit in REGMODE (UM11029 sec 21.6.10, Table 396, offset 0x04C, bits REGMODE0..REGMODE7). When REGMODEn = 1, the slot exposes two registers: CAPn (the latched counter snapshot) at offset 0x100 + 4n, and CAPCTRLn (which events arm it) at offset 0x200 + 4n.

    Wiring an event into a capture slot is a three-register dance:

    1. EV[n]_CTRL (UM11029 sec 21.6.25, Table 411, offset 0x304 + 8*n). Set OUTSEL = 0 (input mode, bit 5), IOSEL = 0..3 (bits 9:6) to pick the SCT input index (these are the four SCT inputs, not GPIOs - pin routing is the SWM + INPUTMUX stages, see Q3), IOCOND (bits 11:10) for edge selection - 0x1 = Rise, 0x2 = Fall, 0x0 = LOW, 0x3 = HIGH, and COMBMODE = 0x2 (IO, bits 13:12) to use the I/O condition only (ignore MATCHSEL).
    2. CAPCTRLn (UM11029 sec 21.6.23, Table 409, offset 0x200 + 4*n). Set bit m in CAPCONn_L[7:0] (or CAPCONn[7:0] if UNIFY = 1 in CONFIG) so that event m causes CAPn to be loaded from the counter.
    3. EV[n]_STATE (UM11029 sec 21.6.24, Table 410, offset 0x300 + 8*n). Write 0x01 (state 0) to enable the event; this is required even in stateless designs because an event with EV[n]_STATE == 0 is permanently masked.

    The captured value lands in CAPn (offset 0x100 + 4*n) - UM11029 sec 21.6.21, Table 408. With UNIFY = 1 in the CONFIG register (Table 387, sec 21.6.2, bit 0), this is a 32-bit unified counter sample; otherwise CAPn_L / CAPn_H hold the 16-bit L/H counters.

    Single-edge vs both-edges. A single EV[n]_CTRL.IOCOND selects exactly one of LOW / Rise / Fall / HIGH. To capture both edges of a WS2812 line you must allocate two events that share one capture slot via CAPCTRLn - one event with IOCOND = Rise, another with IOCOND = Fall, both pointing at the same IOSEL SCT input. Per Table 409 this is explicitly supported: "If bit m is one, event m causes the CAPn register to be loaded." Both events can also share the same DMA request via DMAREQ0 / DMAREQ1 (see Q2). This is the pattern AN11538 uses for RC5-receive on LPC1549; WS2812 bit-band streams are the same problem class.

    Minimum pulse width. From Table 411 footnote (sec 21.6.25): "In order to guarantee proper edge/state detection, an input must have a minimum pulse width of at least one SCTimer/PWM clock period." At 30 MHz SCT clock that is 33.3 ns - comfortably below the 300 ns WS2812 T0H, but you should validate at the actual prescaled rate (see Q4).

    Q2 - DMA wiring. Direct, or via an event-router intermediate? Which DMA channel is natural?

    Answer. Direct, no event router. The SCT exposes two DMA request lines: DMAREQ0 (UM11029 sec 21.6.15, Table 400, offset 0x05C) and DMAREQ1 (Table 401, offset 0x060). Both have an identical 8-bit DEV_n field in bits [7:0] - set bit m to make event m drive that DMA request line. (Bit 30 is DRL0/DRL1 for reload requests, irrelevant for input capture; bit 31 is the read-only request-state flag.)

    The path SCT to DMA channel goes through the DMA trigger input mux (Chapter 14, INPUTMUX, base 0x4002 C000):

    • The 25 DMA_ITRIG_INMUX[0..24] registers at offsets 0x040..0x0A0 (UM11029 sec 14.6.3, Table 288) each select one of 13 trigger sources for one DMA channel. INP = 0x2 = SCT_DMA0 and INP = 0x3 = SCT_DMA1 - the only two SCT-rooted entries.
    • There is no fixed natural DMA channel for SCT capture: any of channels 0..24 can subscribe because every channel has its own DMA_ITRIG_INMUX register. MCUXpresso SDK convention is to use a free channel near the top of the table to avoid stomping on USART/SPI/I2C DMA defaults (USART0_RX_DMA = channel 0, USART0_TX_DMA = channel 1, etc. - see UM11029 sec 16.2 Table 297). The LPC845 SDK fsl_inputmux_connections.h reserves a kINPUTMUX_Sct0ToDma mapping for SCT0_DMA0; you may pick any free channel.
    • Clock-gate INPUTMUX: SYSAHBCLKCTRL0 bit 11 (MUX) - UM11029 sec 8.6.22 Table 146.
    • Clock-gate DMA controller: SYSAHBCLKCTRL0 bit 29 (DMA) - same table.

    Pipeline for WS2812 capture (single-channel example):

    SCT EV[0] (rising edge on IOSEL=0) --+
                                         +-> CAPCTRL0 --> CAP0 (snapshot)
    SCT EV[1] (falling edge on IOSEL=0) -+
                      |
                      +-> DMAREQ0.DEV_0[0]=1, DEV_0[1]=1   (either event fires SCT_DMA0)
                      v
           INPUTMUX.DMA_ITRIG_INMUX[ch].INP = 0x2          (SCT_DMA0)
                      v
           DMA channel ch: source = and SCT0->CAP0, dest = ring_buffer, ping-pong descriptors
    

    Critical: because both rising and falling events latch into the same CAP0, the DMA descriptor must run at one transfer per event (XFERCFG.WIDTH = 32-bit, source = no-increment, dest = increment-by-4) to drain CAP0 before the next edge - see sec 16.5.4 Table 314 (XFERCFG) and sec 16.5.5 (descriptors). At 30 MHz SCT clock the worst-case edge spacing on WS2812 is the T0H / T1L approx 400 ns, i.e. approx 12 SCT cycles; one DMA word transfer on M0+ AHB-Lite is <= 4 cycles - margin fine but not infinite. There is a real stale-data race if the DMA is mis-configured to do more than one word per request - see Gotchas.

    Q3 - Switch Matrix routing for SCT_PIN0..3 inputs. PINASSIGN register offsets and bit-field widths.

    Answer. Two registers route the four SCT inputs. UM11029 sec 10.5.7-10.5.8, Tables 186 + 187. SWM base = 0x4000 C000.

    Reg Offset Address Field Bits SCT input
    PINASSIGN6 0x018 0x4000 C018 SCT0_GPIO_IN_A_I [31:24] SCT_PIN0
    PINASSIGN7 0x01C 0x4000 C01C SCT0_GPIO_IN_B_I [7:0] SCT_PIN1
    PINASSIGN7 0x01C 0x4000 C01C SCT0_GPIO_IN_C_I [15:8] SCT_PIN2
    PINASSIGN7 0x01C 0x4000 C01C SCT0_GPIO_IN_D_I [23:16] SCT_PIN3

    Each field is 8 bits wide and holds the pin number: PIO0_0 = 0x00..PIO0_31 = 0x1F, PIO1_0 = 0x20..PIO1_21 = 0x35. Default (reset) = 0xFF (unconnected). The SWM clock (SYSAHBCLKCTRL0 bit 7 - Table 146) must be enabled while writing PINASSIGN registers; once routing is committed it is legal to clock-gate SWM off to save ~10 uA - see UM11029 sec 10.4.

    Second routing step (INPUTMUX SCT0_INMUX[0..3]). The four SCT-input lines coming out of the SWM are not hard-wired to the four SCT events; you must also program SCT0_INMUX[0..3] at INPUTMUX base 0x4002 C020..0x4002 C02C (UM11029 sec 14.6.2, Table 287) with INP_N = 0x0..0x3 to select SCT_PIN0..SCT_PIN3 respectively. INP_N = 0x4..0x9 route internal signals (ADC threshold IRQ, ACMP_O, T0_MAT2, GPIOINT_BMATCH, ARM_TXEV, DEBUG_HALTED) instead. Reset value is 0x0F (reserved/disabled) - you must write the SCT0_INMUX registers explicitly; the default does not pick up SCT_PIN0..3. This is the trap that bites every first-time SCT user - see Gotchas.

    SWM contention with the FastLED SCT-DMA TX driver. SCT_OUT0 lives in PINASSIGN7[31:24] and SCT_OUT1..4 in PINASSIGN8 - fully disjoint from the SCT input fields, so RX-capture and DMA-TX-via-SCT can coexist at the SWM level. But they share the SCT event slots (only 8 total) and the two DMAREQ lines - that is the hardware-fundamental conflict the issue already calls out.

    Q4 - Counter clock. MAIN_CLK / 1 or prescaler available?

    Answer. Both. The SCT has two divider stages:

    1. System-level, before the SCT block: SYSCON.SCTCLKSEL (UM11029 sec 8.6.19, Table 143, address 0x4004 806C, bits [1:0]): selects source - 0x0 = FRO (the 24 MHz factory-trimmed FRO, or 30 MHz with the FAIM-divider-fix; see https://mcuoneclipse.com/2021/12/20/doubling-the-performance-of-nxp-lpc845-with-improved-flash-access-time/ - relevant for actually getting to the 30 MHz target), 0x1 = main clock, 0x2 = SYS PLL. Then SYSCON.SCTCLKDIV (sec 8.6.20, Table 144, address 0x4004 8070, bits [7:0]) divides 1..255 (0 = clock off). SCT clock-gate must also be enabled in SYSAHBCLKCTRL0 bit 8 (SCT) - Table 146 - or the peripheral is dead even if SCTCLKSEL is set.
    2. Inside the SCT, the CTRL register (UM11029 sec 21.6.3, Table 388, offset 0x004) has an 8-bit prescaler PRE_L[12:5] for the L (or unified) counter, where counter_clock = SCT_clock / (PRE_L + 1). When UNIFY = 0, the H counter has its own PRE_H[28:21] field. Always set CLRCTR_L (bit 3) when changing PRE_L - Table 388 remark - otherwise the counter sees a glitched divide.

    At 30 MHz with PRE_L = 0, resolution = 33.3 ns, ~9x below WS2812 T0H (300 ns). Buffer cost dominates: a 300-LED strip is 7200 bit-edges x ~2 edges/bit = ~14400 captures x 4 bytes = ~58 KB at 32-bit unified counter. LPC845 has only 16 KB SRAM total (UM11029 sec 5.1), so full 32-bit capture is non-viable for long strips. Workable encodings for the Phase-2 path:

    • Stay 16-bit (CONFIG.UNIFY = 0), use only CAPn_L, and arrange a LIMIT event so the counter wraps every ~2.18 ms (0xFFFF x 33.3 ns) - well past the WS2812 latch-gap (~50 us). 2 bytes/capture x 14400 ~= 29 KB - still too big for a full strip; in practice decode in ~1 KB chunks via ping-pong DMA descriptors (UM11029 sec 16.5.5).
    • Or set PRE_L = 2 (divide by 3) for ~100 ns resolution - still well within WS2812 timing margin - and stay 16-bit. Recommended starting point for the Phase-1 pin-toggle test (10 kHz square wave = 100 us period = 1000 SCT counts at 100 ns resolution).

    Q5 - LPC804 differences. PLU vs SCT-RX.

    Answer. They coexist; the conflict is only at the pin / event-slot level. The LPC804 PLU (Programmable Logic Unit) and SCT are independent peripherals - see UM11065 (LPC804 User manual, Rev. 1.0 - 24 Jan 2018), Chapter 23 (PLU). The PLU has its own pin-mux entries via SWM_PINASSIGNFIXED0 (fixed-function pin block) for PLU_IN0..7 and PLU_OUT0..7. The SCT event / match / capture infrastructure (EV[n]_CTRL, CAPCTRLn, DMAREQ0/1) is unchanged from the LPC845 family. So the FastLED LPC804 TX driver pattern (claiming SCT for PLU-fed output generation) only blocks SCT-RX on those specific SCT event slots and SCT outputs the TX driver has consumed - not the whole peripheral.

    Practical guidance for an LPC804 SCT-RX implementation:

    • Partition the event table: reserve events 0-3 for TX (PLU feeds SCT input, SCT match generates output toggles), events 4-7 for RX-capture.
    • Use DMAREQ1 (the second SCT DMA line) for RX so the TX driver DMAREQ0 is untouched.
    • The SCT input multiplexer (SCT0_INMUX[0..3]) is shared globally - if TX is already consuming SCT input 0 via PLU, RX must route its captured GPIO through SCT inputs 1, 2, or 3.

    However - the LPC804 datasheet (https://www.nxp.com/docs/en/nxp/data-sheets/LPC804_DS.pdf) confirms only 32 KB flash + 4 KB SRAM vs the LPC845's 64 KB + 16 KB. The 4 KB SRAM ceiling makes Phase 2 (full-strip decoding) essentially infeasible on LPC804 unless decoding is streamed bit-by-bit from a very small DMA ring. Recommendation: scope Phase 2 to LPC845 only; mark LPC804 RX as Phase 3 follow-up with a streaming decoder.

    Q6 - Cross-references. Errata + Application Notes.

    3. Known gotchas / errata for SCT input capture on LPC8xx

    Concrete pitfalls reported by engineers or explicitly noted in UM11029 footnotes - every one of them will bite an FPS-critical driver if not pre-empted:

    1. SCT0_INMUX[0..3] reset value is 0x0F (reserved/disabled), NOT 0x0 (SCT_PIN0..3). Just configuring the Switch Matrix is silently insufficient - SCT events never fire. UM11029 sec 14.6.2 Table 287. Reproduced in countless forum threads (https://community.nxp.com/thread/421879).
    2. EV[n]_STATE reset value is 0x00, i.e. event permanently masked. UM11029 sec 21.6.24: "An event n is completely disabled when its EV_STATE register contains all zeros, since it is masked regardless of the current state." Even a stateless design must write EV[n]_STATE = 0x01.
    3. Events triggering immediately on counter start - solved community thread https://community.nxp.com/t5/LPC-Microcontrollers/LPC824-events-triggering-immediately-on-timer-start/td-p/927776 . Two distinct root-causes: (a) SWM not routed before SCT clock enabled - the input floats and a configured rising-edge event fires the moment the input toggles into a defined state; (b) MATCH / MATCHREL left at 0 with COMBMODE = 0 (OR) - match-on-0 fires on cycle 1. Always initialise both registers and set COMBMODE = 0x2 (IO-only) for pure-capture events.
    4. Edge-detection latency = one SCT clock. UM11029 sec 21.6.25 Table 411 IOCOND footnote: "The detection of edges on outputs lag the conditions that switch the outputs by one SCTimer/PWM clock." Captured timestamps are systematically late by 1 cycle (33 ns at 30 MHz). For WS2812 decode the systematic offset cancels out (you measure differences, not absolute times), but for the Phase-1 pin-toggle test, the reported period will be off by exactly one SCT cycle in the worst case - set the sigma threshold accordingly.
    5. Minimum input pulse width = 1 SCT clock. Same Table 411 footnote. At 30 MHz with PRE_L = 0 that is 33 ns - fine for WS2812. If you use a prescaler (PRE_L > 0) to coarsen the timebase, the minimum pulse width scales proportionally. With PRE_L = 2 (100 ns resolution) the minimum measurable pulse becomes 100 ns - still under WS2812 timing but the margin narrows.
    6. DMA stale-data race when burst-size > 1. Because both rising and falling events latch the same CAPn register, if the DMA XFERCFG.XFERCOUNT is configured for multiple transfers per request the DMA will copy CAPn twice from a single event - once with the fresh value, once with whatever stays in CAPn until the next edge arrives. Always one transfer per DMA request. UM11029 sec 16.5.4 Table 314. No NXP errata - it is a misuse of the documented descriptor model, but it is the first thing a stress test on a 300-LED strip will expose.
    7. CAPCTRLn register-mode toggle. Setting REGMODEn = 1 atomically re-purposes the register at offset 0x200 + 4*n from MATCHREL to CAPCTRL. The two share the same physical register. If TX-side code has written a match-reload value and then RX-side code enables capture mode on the same slot, the TX driver reload value is now interpreted as a capture-event-enable bitmask - almost certainly enabling unintended events. The driver must take an exclusive lease on a contiguous range of REGMODE bits before touching CAPCTRL. UM11029 sec 21.6.10 Table 396.
    8. Old vendor headers mis-type CAPCTRL as read-only (LPCOpen pre-fix). Verify the LPC845 CMSIS device header in the FastLED build does not have this defect - see https://community.nxp.com/t5/LPC-Microcontrollers/SCT-capture-register-read-only-CAPCTRL/m-p/575822 . MCUXpresso SDK headers (post-2018) are correct.
    9. SCT clock-gate dependency chain. To bring the SCT capture path up you must enable, in this order: (a) SYSAHBCLKCTRL0[7] SWM for PINASSIGN writes, (b) SYSAHBCLKCTRL0[11] MUX for INPUTMUX writes, (c) SYSAHBCLKCTRL0[29] DMA for DMA channel setup, (d) SCTCLKSEL + SCTCLKDIV for the SCT clock source, (e) SYSAHBCLKCTRL0[8] SCT to ungate the peripheral itself. Disabling (a)/(b)/(c) after setup is legal and saves ~10-30 uA each. Disabling (e) freezes the counter but does not reset CAPn - partial captures persist across sleep. UM11029 sec 8.6.22 Table 146; sec 15 reduced-power modes.
    10. No published silicon errata against SCT, DMA, INPUTMUX or SWM. ES_LPC84x Rev 1.3 (5 Nov 2019) lists only the ROM.1 ISP-boot defect on revision 1A. Treat the SCT capture path as clean silicon - bugs found during bring-up are firmware bugs, not silicon.

    References gathered from UM11029 Rev 1.7 (April 2021), ES_LPC84x Rev 1.3 (Nov 2019), UM11181 Rev 1.1 (Feb 2019), AN11538 Rev 5.0 (Mar 2016), AN12602 (Oct 2019), AN13803 (May 2023), and NXP Community threads / GitHub repos cited inline.

  2. zackees commented on Jun 14, 2026

    @zackees
    MemberAuthor

    Phase 1 + Phase 2 PRs opened

    Implementation for both phases is ready for review:

    Hardware acceptance state

    Both PRs are bench-ready but not yet validated against real LPC845 silicon (no LPC845-BRK attached in this dev environment). The acceptance gates remaining:

    Phase Acceptance gate Status
    1 bash autoresearch lpc845brk --pin-toggle-rx --upload-port COM10 → all 3 freq cases PASS code ready, hardware bench pending
    2 bash autoresearch lpc845brk --ws2812-loopback --upload-port COM10 → all 5 patterns PASS code ready, blocked on DMA upgrade + #3002 flash unlock

    Two follow-ups required to close this issue

    These are pre-existing, independent of #3021, but block Phase-2 hardware acceptance:

    1. SCT→DMA RX upgrade — Phase 1's polling-mode pollOnce() measures ~2 µs/poll on M0+ @ 30 MHz; WS2812 sub-pulses are 400–850 ns. DMA is needed for the WS2812 byte-match. Will track as a separate follow-up once Phase 2 plumbing is merged.

    2. fl::json soft-FP flash bloat — tracked by fl::json: replace double with templated fixed-point variant to drop libgcc soft-FP bloat on embedded #3002. Until that lands, #include <FastLED.h> doesn't fit alongside fl::Remote on the 64 KB LPC845 budget, so the Phase-2 FASTLED_LPC_RX_SCT_WS2812 opt-in is default OFF.

    Notes from implementation

    • SCT register layout cross-checked against UM11029 Rev 1.7 §8 (SYSCON), §10 (SWM), §21 (SCT). The existing clockless_arm_lpc_pwm_dma.h TX driver shim has three confirmed offset/bit bugs (REGMODE width, SYSAHBCLKCTRL0 offset, DMA CFG.HWTRIGEN bit). The RX driver uses its own correct constants instead of inheriting from the broken shim; the TX shim fix is intentionally out of scope for feat(lpc): RX backend for LPC8xx via SCT input-capture — two-phase rollout #3021 (separate cleanup PR).

    • The Phase 1 driver also adds LpcSctRxChannel::pollOnce() — public method for callers that need to interleave TX bit-bang with capture drain on M0+. Becomes a no-op fast-path after the DMA upgrade.

  3. zackees commented on Jun 14, 2026

    @zackees
    MemberAuthor

    Filed #3030 to retire examples/AutoResearchLpc/ and fold its bring-up RPC surface into the main AutoResearch.ino behind a FASTLED_AUTORESEARCH_LOW_MEMORY mode, once #3002 (fl::json soft-FP cleanup) finishes landing. The current AutoResearchLpc should be treated as a temporary flash-budget workaround, not a permanent fixture.

  4. zackees commented on Jun 14, 2026

    @zackees
    MemberAuthor

    Closing — both phases landed

    Both implementation PRs are merged to master:

    (Note: original Phase 2 PR #3025 auto-closed when #3024's base branch was deleted on merge — #3031 is the rebased-onto-master replacement with identical content.)

    RX + TX decode validation — host auto test ✅

    The "decoding LED signals through auto test" acceptance is satisfied by tests/fl/channels/rx_sct_capture.cpp (host unit test, automated via bash test rx_sct_capture --cpp):

    1. Test injects a synthetic WS2812 GRB byte stream (3 LEDs: green/red/blue) into LpcSctRxChannel::injectEdges() via a TX-side encoder (appendByte() builds HIGH/LOW EdgeTime pairs at the spec-defined T0H/T0L/T1H/T1L timings).
    2. decode() walks the edge pairs, reconstructs the byte stream.
    3. Byte-match assertion confirms the recovered payload exactly equals the transmitted payload.

    This is "TX side simulated + RX decoder real" — exactly the "mock out the RX unit to help bringup" pattern the goal invited. The decoder + edge-stream contract is exercised end-to-end on every CI run.

    Tracked follow-ups (out of scope for this issue)

    These are independent improvements that don't block closure of #3021 itself — the design contract of the SCT-RX backend + Phase 1 + Phase 2 RPC surfaces are complete:

    1. SCT → DMA RX upgrade — for true 800 kHz WS2812 hardware-bench capture on the LPC845-BRK. Today's polling-mode pollOnce() is adequate for ≤100 kHz pin-toggle but can't keep up with WS2812 sub-pulses on M0+ @ 30 MHz. Will be a separate follow-up PR.
    2. Retire AutoResearchLpc.ino — fold into AutoResearch.ino low-memory mode #3030 — retire examples/AutoResearchLpc/AutoResearchLpc.ino and fold its bring-up RPCs into a FASTLED_AUTORESEARCH_LOW_MEMORY mode of the main AutoResearch.ino. Blocked on fl::json: replace double with templated fixed-point variant to drop libgcc soft-FP bloat on embedded #3002 (fl::json soft-FP cleanup) finishing.
    3. TX SCT shim register offset / bit fixes in clockless_arm_lpc_pwm_dma.h — the existing pre-feat(lpc): RX backend for LPC8xx via SCT input-capture — two-phase rollout #3021 shim has three confirmed offset bugs (REGMODE width, SYSAHBCLKCTRL0 offset, DMA CFG.HWTRIGEN bit). Doesn't affect the SCT-RX driver (it uses its own correct constants), but worth a separate cleanup PR.

    What changed in master

    • src/platforms/arm/lpc/rx_sct_capture.{h,cpp.hpp} — real SCT register programming behind FASTLED_LPC_RX_SCT, plus public pollOnce() for TX-interleaved capture.
    • examples/AutoResearchLpc/AutoResearchLpc.ino — pinToggleRx + ws2812SctTest RPC handlers, all doubly-gated behind FL_IS_ARM_LPC (for host-stub builds) and the appropriate Phase 1 / Phase 2 opt-in flag.
    • ci/autoresearch/{args,phases}.py — --pin-toggle-rx and --ws2812-loopback runner subcommands.
    • ci/autoresearch/test_lpc_{pin_toggle_rx,ws2812_loopback}.py — Python bench orchestrators mirroring the FlexIO RX patterns.
  5. moved this from Triage to Done in FastLED Trackeron Jun 14, 2026
  6. added a commit that references this issue on Jun 14, 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