Skip to content

LPC845 SPI+DMA driver wedges on first use — control flow jumps into harnessDriver()::drv static (PC=0x100018BC) #3580

Closed

Description

@zackees

Summary

The ARMHardwareSPIOutputDMA<> driver (src/platforms/arm/lpc/spi_arm_lpc_dma.h, #3454) wedges the LPC845 on the first dmaSpiTransferOnce RPC. With the new WWDT + NMI backtrace tooling (landed on feat/delegate-flash-to-fbuild), the wedge is now precisely located:

FAULT: HardFault PC=0x100018BC LR=0xFFFFFFF9 xPSR=0x40058000

firmware.map symbolication:

0x100018b4  autoresearch::dma_spi::harnessDriver()::inited
0x100018b8  guard variable for autoresearch::dma_spi::harnessDriver()::drv
0x100018bc  autoresearch::dma_spi::harnessDriver()::drv        ← PC lands HERE
0x100018c0  autoresearch::dma_spi::harnessBuffer()::buf

The CPU was executing the driver's static object as code — control flow jumped into .bss. The stacked frame is the wedged (thread-mode) context, and the fault line is emitted by the watchdog warning-NMI hook 3.0 s after the wedge, after which the chip resets and answers RPC echo again (self-recovery verified).

Repro

On the feat/delegate-flash-to-fbuild branch with an LPC845-BRK attached (and fbuild ≥ 2.3.18 + probe-rs in ~/.fbuild/prod/tools/):

bash autoresearch lpc845 --dma-spi --skip-lint

Build: 56.42 KB flash / 10.60 KB RAM (the FASTLED_LPC_SPI_DMA=1 + FASTLED_LPC_SPI_DMA_MAX_BYTES=512 defines are injected by the harness — at the driver-default 2048 the build was at 94% static RAM and HardFaulted at PC=0 on any RPC; that separate issue is fixed). Deploy succeeds via probe-rs SWD; echo works; first dmaSpi* call wedges.

Where to look

The wedge is in the lazy-init path of the harness (harnessDriver() → first-call construction + drv.init()) or the first kickDmaStream():

  1. DMA descriptor table (SRAMBASE) placement — the LPC845 DMA controller reads channel descriptors from RAM at DMA0->SRAMBASE, which must be 512-byte aligned and point at a properly laid-out descriptor table. If SRAMBASE is misprogrammed (or the descriptor block overlaps other statics), the DMA engine can scribble on .bss near the driver's statics — consistent with control flow later diving into drv's address.
  2. Vendor-PAL migration state of spi_arm_lpc_dma.h — audit any remaining hand-rolled offsets against <LPC845.h> the same way Meta: Replace all hand-rolled LPC register maps with vendor CMSIS PAL headers #3437 did elsewhere. The WWDT MOD/TC swap (fixed in the same branch) shows this class of bug ships silently.
  3. FASTLED_LPC_SPI_DMA_CHANNEL default vs the fixed DMA request map — SPI0_TX = DMA ch 6, SPI1_TX = ch 8 (UM11029 §12). A wrong channel with HWTRIGEN can fire on the wrong peripheral's request line.

Why this wasn't visible before

Three masking layers, all removed this week: (a) pyocd HID wedge blocked any flash; (b) at default buffer sizes the firmware RAM-exhausted and HardFaulted at PC=0 on any RPC; (c) the WWDT never armed (MOD/TC register swap) so a wedge looked like "device dead, no output" instead of a backtrace line.

Refs: #3456 (bench), #3453 (bring-up meta), #3454 (driver), #3300 (the empty-RX blocker this explains), #3437 (vendor PAL policy).

Activity

  1. added a commit that references this issue on Jul 2, 2026
    7f4f912
  2. zackees commented on Jul 2, 2026

    @zackees
    MemberAuthor

    Fixed in commit 7f4f912ee9 on feat/delegate-flash-to-fbuild (PR #3550's branch). The single reported wedge turned out to be six stacked silicon bugs, each masking the next — bisected live on the LPC845-BRK with the WWDT NMI backtrace, breadcrumb prints, and bounded-spin register snapshots:

    1. DMA0->SRAMBASE never programmed → descriptors fetched from the flash vector table (the original PC-in-.bss wedge). Fixed with a shared FL_ALIGNAS(512) descriptor table (lpc_dma_descriptor_table.h).
    2. SPI peripheral never clocked on the AHB → first spi->STAT read stalled the bus forever. init() now owns SYSAHBCLKCTRL0 + PRESETCTRL0 + SWM routing.
    3. Wrong DMA channel: 4 (USART2_RX) vs 11 = SPI0_TX per UM11029 §16.3.3 Table 296 (the "Table 80" the old comment cited does not exist).
    4. XFERCFG.SWTRIG missing — PERIPHREQEN requests only pace a channel; it must first be triggered (snapshot showed CFGVALID=1, TXRDY=1, TRIG=0, XFERCOUNT frozen).
    5. SYSCON->FCLKSEL[9] resets to "none" — the SPI shift engine had no function clock and froze mid-byte with STAT=0.
    6. No frame closure after a DMA stream → MSTIDLE never re-asserted → every subsequent call wedged in waitFully() (bench alternated PASS/WEDGE through watchdog reboots). Fixed with a one-time software STAT.ENDTRANSFER after the stream drains (per-byte EOT was tried and rejected: measured 39% throughput loss).

    Acceptance (LPC845-BRK, 2026-07-02), bash autoresearch lpc845 --dma-spi end-to-end:

    dmaSpiTransferOnce(32)   PASS — 109 us (theoretical 64)
    dmaSpiTransferOnce(256)  PASS — 716 us (theoretical 512)
    dmaSpiTransferOverlap    PASS — 1411 us, 978 CPU toggles during DMA  ← async proof
    dmaSpiMeasureSck         PASS — 2.894 MHz effective (FIFO-less+DMA model: 2.76 MHz)
    PASS — #3456 SPI+DMA async bench green.
    

    Note on the SCK number: the LPC845 SPI is FIFO-less, so each byte costs 8/SCK shift + ~0.76 µs DMA refill. Wire SCK is a true 4 MHz; ~2.9 MHz is the physically attainable effective throughput at divider 6, and the bench now models it that way.

    This closes #3517 Phase B.1's silicon acceptance for real.

  3. moved this from Triage to Done in FastLED Trackeron Jul 2, 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