Repository navigation
Description
Symptom
On LPC845-BRK (16 KB SRAM) the pinToggleRx RPC handler in
examples/AutoResearch/AutoResearchLowMemory.h declares an 8 KB
stack-allocated buffer:
// examples/AutoResearch/AutoResearchLowMemory.h:187
fl::EdgeTime edges_buf[2048];fl::EdgeTime is 4 bytes, so this is 2048 * 4 = 8192 bytes on the stack
inside one lambda. The ws2812SctTest handler at line 286 has a similar
1024-element probe (~4 KB).
.bss for the unified LowMemory build on LPC845-BRK already sits at ~8.5 KB
(measured today against current master with arm-none-eabi-size + nm).
The default LPC845 stack lives at the top of SRAM and grows down. When
pinToggleRx is invoked, the stack frame demand spikes by 8 KB on top of
.bss + Arduino core static + libc reentrancy state. We are over the 16 KB
SRAM ceiling the moment the handler executes.
Reproduction (verified today)
Tested against current master (post-#3084 / #3085 / #3087 / #3088 / #3089
bloat fixes, with FASTLED_LPC_RX_SCT_WS2812=1 enabled by default on
lpc845brk):
bash autoresearch lpc845brk --pin-toggle-rx --upload-port COM10
[lpc-pin-toggle-rx] opening COM10 @ 115200
[lpc-pin-toggle-rx] echo ok # <-- the device boots; echo RPC works
--- 1.1 / 1 kHz (1000 Hz / 200 ms) ---
FAIL: no response or RPC error: None
--- 1.2 / 10 kHz (10000 Hz / 100 ms) ---
FAIL: no response or RPC error: None
--- 1.3 / 100 kHz (100000 Hz / 100 ms) ---
FAIL: no response or RPC error: None
The device is alive (echo round-trips). The moment a pinToggleRx
request lands, the device goes silent and never replies. Consistent with
a runtime stack overflow into the watchdog-fed live region.
Why this is the natural reading
- LPC845-BRK enumerated as a NXP CMSIS-DAP CDC interface (VID 1FC9 /
PID 0132); board hardware is fine. bash autoresearchecho round-trip succeeds -- provesfl::Remote,
the watchdog feed, the JSON-RPC parser, and the CDC transport are all
wired correctly under the LowMemory build.- The very next RPC --
pinToggleRx-- silently never replies. The
handler does its first work before writing any response back to the
serial, and the first work is to allocate 8 KB on the stack. If the
stack pointer crosses the bottom of SRAM the device traps before any
reply is sent. - The
ws2812SctTesthandler at line 286 (when reached via the
FASTLED_LPC_RX_SCT_WS2812path) has the same shape with a 4 KB +
300-byte chain plus a 1024-entry probe -- so the symptom persists
beyond just the pin-toggle bench.
Fix shape
Three obvious ways to land this. (1) is the smallest, (2) is the
architecturally-right answer:
- Move the buffer to
staticstorage (static fl::EdgeTime edges_buf[2048];).- One-line change. Adds the 8 KB to
.bsspermanently which is fine on
a target that already runs 1-2 RPC handlers serially. - Pulls
ws2812SctTest'sprobe[1024]anddecoded_buf[300]/
expected_buf[300]along the same way.
- One-line change. Adds the 8 KB to
- Right-size the buffer to what the bench actually needs. Phase 1's
1 kHz / 100 ms case captures2 * 1000 * 0.1 = 200edges plus a 50%
headroom = 300 edges. Even the 100 kHz / 100 ms case is at most
20,000 edges total -- and a 2048-element ring already truncates that
on the high end. The handler logic already enforces a
cap = expected_edges + headroom; if (cap > 2048u) cap = 2048u;
ceiling, so the captured edge count is at most 2048; declaring an
over-sized stack buffer to match the cap is symmetric with what
cfg.buffer_sizealready controls. A tighter cap (e.g. 512 edges =
2 KB stack) would still satisfy the Phase 1 acceptance window. - Heap-allocate via
fl::unique_ptr<EdgeTime[]>with a size chosen
fromcap. Smallest dynamic footprint per call, but introduces malloc
pressure on the Low-memory bring-up which we're otherwise trying to
avoid.
I lean (1)+(2) together: static fl::EdgeTime edges_buf[512]; (and the
matching change on the ws2812SctTest side), with the cap clamp updated
to match.
Acceptance
This issue closes when:
-
bash autoresearch lpc845brk --pin-toggle-rx --upload-port COM10
on hardware returns three non-Noneresults (one per frequency case)
with at least the 1 kHz case showingsuccess=1. -
bash autoresearch lpc845brk --ws2812-loopback --upload-port COM10
doesn't silently hang. - The handler is documented as carrying at most a bounded static
buffer; no future change pushes a multi-KB stack allocation back in.
Refs
- This issue surfaced as part of the FastLED#3102
bench-validation meta -- Section 1 (lpc21isp deploy validation)
succeeds up through echo but the next-step pin-toggle is wedged. - LPC845 bloat: 8.3 KB of soft-FP / integer-div leaks past the no-soft-FP invariant on LowMemory + RX_SCT_WS2812 #3076 closed today with the bloat-side fixes that made the
build fit 64 KB flash. This is the runtime sibling: now that flash
fits, RAM is the next ceiling that the handler trips. - feat(autoresearch): retire AutoResearchLpc.ino, fold into AutoResearch.ino low-memory mode (closes #3030) #3041 --
AutoResearchLpc.inoretirement folded the bring-up
intoAutoResearch.ino; the over-sized stack buffer came along with
it from the original sketch.
🤖 Filed via Claude Code.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity