Skip to content

LPC845-BRK: WS2812 loopback validation via SCT-capture RX channel #3015

Closed

Description

@zackees

Motivation

The LPC845-BRK bring-up is functionally complete on three transports — Serial.println, JSON-RPC echo, and the FastLED log pipeline (FL_WARN_LIT) all round-trip through bash autoresearch lpc845brk --upload-port COM10 (verified on real hardware in #3014). The next gate is closed-loop WS2812 validation: drive a known frame on one GPIO, capture it on a bridged GPIO via an RX channel, decode the timing, and confirm the bit pattern matches what the driver intended to send.

The pin-bridge probe (probePair RPC added in #3014) already identifies which two pins the user has shorted with a jumper. The natural test wiring is P0_10 ↔ P0_11 — both GPIO-capable, both on the LPC845-BRK header.

What blocks this today

Component Status
LPC8xx WS2812 TX driver ✅ Exists — src/platforms/arm/lpc/clockless_arm_lpc.h (bit-banged via shared m0clockless.h); SCT+DMA variant in clockless_arm_lpc_pwm_dma.h behind FASTLED_LPC_PWM_DMA.
Bring-up sketch flash budget ❌ 97% full (63 060 / 65 536 B after the probePair binding). Adding #include <FastLED.h> + FastLED.addLeds<WS2812, P, GRB>(leds, 1) costs 2–4 KB on this platform — does not fit.
LPC8xx RxDevice implementation ❌ Does not exist. The current RxBackend enum only knows RMT (ESP32), ISR (ESP32-C6 MCPWM), FLEXPWM/FLEXIO (Teensy 4). Nothing for Cortex-M0+.
LPC845 RX hardware capability ✅ SCT input-capture + DMA can timestamp edges at ~42 ns resolution (24 MHz SCT) — sufficient for WS2812 T0H/T1H discrimination (0.4 µs vs 0.8 µs).

Why software-only RX won't work on LPC845

Approach Why it fails
GPIO ISR + software timestamp Cortex-M0+ @ 24 MHz: ~16–46 cycles ISR latency (~1 µs). WS2812 T0H is 0.4 µs — every short-pulse edge gets missed.
Polled GPIO sampling Achievable rate ~4–6 MHz, marginal vs the ≥ 3.2 MHz Nyquist on 0.4/0.8 µs pulses. Burns the CPU; no margin for ISR jitter.
SCT input-capture + DMA The only viable path.

Success criteria

The validation is complete when:

  1. Flash margin restored on the bring-up sketch. The fl::json fixed-point refactor tracked in fl::json: replace double with templated fixed-point variant to drop libgcc soft-FP bloat on embedded #3002 (and partially landed in perf(fl/math): gate libm behind SKETCH_HAS_LARGE_MEMORY; polynomial impls on Low-memory (closes most of #3002) #3012 / feat(lint): ban bare libm calls in src/; route power_mgt through fl:: #3013) frees enough flash that examples/AutoResearchLpc/AutoResearchLpc.ino can #include <FastLED.h> and add a WS2812 controller alongside the existing JSON-RPC + watchdog + probe machinery — within the 64 KB-flash budget with ≥ 1 KB headroom.

  2. src/platforms/arm/lpc/rx_sct_capture.h ships, implementing the FastLED RxDevice interface against LPC845 SCT input-capture + DMA:

    • Register-level SCT setup: pick an input event (EV_n tied to a CTIN/GPIO), program a capture register, route the event into the DMA-trigger mux.
    • DMA channel manages the capture buffer (edge timestamp + polarity per entry).
    • WS2812 frame decoder: convert edge-timestamp stream → 24-bit GRB pixels by classifying each T1-T0 low-time against the T0H/T1H midpoint (0.6 µs nominal).
    • Plumbed through a new RxBackend::LPC_SCT_CAPTURE enum + dispatch in src/fl/channels/rx/channel.cpp.hpp::createBackendDevice.
    • Effort comparable to the existing clockless_arm_lpc_pwm_dma.h TX driver (Stage 2c of meta: port FastLED to NXP LPC8xx (LPC804 + LPC845) — two-stage plan #2836) plus the decoder on top.
  3. Loopback test passes via autoresearch. With both above, the LPC bring-up sketch adds:

    CRGB leds[1];
    FastLED.addLeds<WS2812, P0_10, GRB>(leds, 1);
    
    remote.bind("ws2812Loopback", [](int color) -> int {
        leds[0] = CRGB(color);
        FastLED.show();
        auto rx = fl::RxChannel::create({P0_11, fl::RxBackend::LPC_SCT_CAPTURE});
        auto frame = rx->capture(/*timeout_ms=*/10);
        return frame.equals(leds[0]) ? 1 : 0;
    });

    and bash autoresearch lpc845brk sends {\"method\":\"ws2812Loopback\",\"params\":[0x010203],\"id\":1} and expects result:1 — confirming the WS2812 driver emits valid frames that round-trip the LPC845's own capture peripheral.

  4. Pin-bridge auto-detect. The autoresearch harness should use the existing probePair RPC to pick the loopback pin pair automatically (e.g., expect a bridge between two GPIO-capable pins not on the UART or SWD bus) rather than hard-coding P0_10/P0_11. The probe results in feat(lpc845): WWDT watchdog driver + FL_WARN_LIT enabled on Low-memory #3014 already give the building block.

Related

Session evidence

End-to-end verification of the existing three transports on real LPC845-BRK on COM10:

TX: {"jsonrpc":"2.0","method":"echo","params":[4242],"id":1}
RX: b'FL_WARN: echo invoked\r\nREMOTE: {"id":1,"result":4242,"jsonrpc":"2.0"}\r\n'

✅ Serial.println — REMOTE: response received
✅ JSON-RPC echo — sentinel 4242 round-trip verified
✅ FL_WARN_LIT — FastLED warn pipeline reached host

And the pin-bridge probe correctly identified the jumper:

Bidirectional hits: 1
  P0_10  <->  P0_11

🤖 Filed via Claude Code during the LPC845 WS2812 bring-up attempt that hit the RX gate.

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