Skip to content

fix(lpc): on-board jumper scan; LPC845 pin-toggle-rx passes on silicon - #5262

Merged
zackees merged 4 commits into
masterfrom
fix/autoresearch-lpc-fl-pin-api
Nov 18, 2026
Merged

zackees merged 4 commits into
masterfrom
fix/autoresearch-lpc-fl-pin-api

Conversation

@zackees

@zackees zackees commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Hardware follow-up to #5261 / #5260. On an LPC845-BRK, the --pin-toggle-rx bench now finds its own jumper and passes on silicon. It had never passed on hardware: every capture reported edges=1, whatever the wiring and whichever pin API drove TX.

Evidence (LPC845-BRK on /dev/ttyACM1, bash autoresearch lpc845 --pin-toggle-rx --upload-port /dev/ttyACM1, deployed through fbuild)

Target identity, checked before any flash: the firmware already on the board answered ws2812SctTest, an RPC bound only under FL_IS_ARM_LPC_845.

Jumper scan (the new findConnectedPins; no wiring was assumed):

pairs=10>13od 11>13od ;stuck=4H 7H 23H 30H ;skip=2:debug-swd 3:debug-swd 5:reset 12:isp-entry 24:console-link 25:console-link ;od=10 11
using discovered pair TX=P0_13 RX=P0_10

One net joins P0_10, P0_11 (true open-drain pads) and P0_13.

Run 1 kHz 5 kHz 10 kHz
master (::pinMode/::digitalWrite, same wiring) FAIL edges=1 (n/a: master ran 1/10/100 kHz) FAIL edges=1; 100 kHz: no reply
this PR, TX=P0_13 -> RX=P0_10 (auto-picked) PASS mean 1,000,027 ns, sigma 269 ns, 32 periods PASS mean 200,062 ns, sigma 682 ns PASS mean 100,061 ns, sigma 723 ns
this PR, TX=P0_11 (open-drain, sinks) -> RX=P0_13 (pull-up) PASS mean 1,000,026 ns, sigma 901 ns PASS mean 200,045 ns, sigma 697 ns PASS mean 100,019 ns, sigma 586 ns

summary: 3 pass / 0 fail out of 3 cases, exit 0.

Root causes found on the bench

  • Read-back span of 1: pinToggleRx sized it as sizeof(edges_buf)/sizeof(edges_buf[0]) on a pointer, which is 4/4 = 1. The same bug in pwmDmaClCaptureSelf rejected any frame over 1 LED.
  • LpcSctRxChannel::pollOnce recorded rise before fall when both arrived in one poll, so the delta wrapped and saturated to about 2.1 s. It now records them in capture order.
  • Watchdog wedge in the stats: the linear-search sqrt ran for billions of steps on a wide spread. The one-pass E[x^2] - floor(mean)^2 variance was also off by up to about 1.4 us at a 1 ms period. Replaced with a bitwise isqrt and a two-pass variance.
  • TX timing: delayMicroseconds added each write and poll to the half period (+20% at 1 kHz), and micros() costs about 19 us per call (two soft divides). Edges now run on SysTick deadlines, with the capture polled once per half period.
  • ticksToNs did a 64-bit soft divide per edge. It now uses exact 32-bit math when the value fits.
  • Low-memory JSON: an all-int array with a value > 32767 was packed as vector<float>. Low-memory has no float -> int conversion, so pinToggleRx(..., 100000, ...) and every pwmDmaCl* color argument were rejected. Large ints now stay i64 on low-memory builds.
  • Host benches: test_lpc_pin_toggle_rx / test_lpc_pwm_dma_cl called positional RPCs with RpcBench.call, which wraps params as [args], so even their echo check failed.

Jumper discovery

  • findConnectedPins on the LPC low-memory build tests every pin against every other through fl::pinMode/digitalWrite/digitalRead (the fix(lpc): native LPC845/LPC804 pin backend; honor forced software pins #5261 backend, not the core's pinMode, pinMode() indexes IOCON by GPIO bit; pull mode is applied to the wrong pin on LPC845/LPC804 framework-arduino-lpc8xx#40). For each pair: a control read with TX released, then TX Low against the RX pull-up, then TX High against the RX pull-down. It reports every pair, plus stuck pins.
  • LPC845 P0_10/P0_11 are true open-drain pads (UM11029 Tables 207/208). The scan tests them only as drivers. The pair picker drives from the push-pull end.
  • pin_probe_lpc.hpp: the probe skips SWD (PIO0_2/3), RESET (PIO0_5), ISP entry (PIO0_12) and the console USART0 (PIO0_24/25).
  • --pin-toggle-rx and --pwm-dma-cl take the pair from the scan unless --tx-pin/--rx-pin are given.
  • pin_lpc.hpp: no IOCON MODE write for LPC845 P0_10/P0_11, where bits 5:0 are reserved.

Bench changes

Cases are now 1/5/10 kHz, all with a 1 us sigma budget. 100 kHz was never reachable: with a captured edge, one half period costs about 36 us on the 24 MHz M0+ (fl::digitalWrite 5.2 us plus pollOnce recording the edge), which caps the polled bench near 13 kHz. The remaining sigma (0.3-0.9 us) is TX scheduling granularity; masking interrupts did not change it. The SCT timestamps themselves are hardware captures. The mean stays at +/-2% and measures within 0.01%.

Known limitations, not fixed here

  • --pwm-dma-cl can run now (its color args used to be rejected), but pwmDmaClCaptureSelf wedges in the ChannelEngineLpcSctDma poll() spin after show(), and the watchdog resets the board. That's a separate engine/capture SCT-sharing problem.
  • --ws2812-loopback is unchanged: edges 0/1 on every case, the same output fix(lpc): interrupt-driven USART0 RX ends LPC845 RPC loss; SCT RX capture stops wedging the console #4676 recorded.
  • LPC804 AutoResearch already overflows on master (flash +17,364 B, RAM +2,176 B). This PR adds about 2.3 KB.
  • The LPC8xx core HardFault_Handler pushes 6 words before MRS MSP, so its printed PC= is really the stacked R0 (framework-arduino-lpc8xx).

Tests

  • bash lint green.
  • uv run pytest ci/tests/test_lpc_pin_scan.py ci/tests/test_autoresearch_phases.py -k lpc: 20 passed.
  • bash compile lpc845 --examples AutoResearch OK; the ws2812-loopback (RX-DMA) build fits and deploys.

Summary by CodeRabbit

  • New Features
    • LPC hardware tests can now scan for connected jumper pins and use a discovered pair when pins aren’t specified. Scan results report detected connections and pins that can’t be tested.
  • Bug Fixes
    • Improved edge capture and timing measurements during LPC tests, including cases where multiple edges occur between reads.
    • Improved pin handling on LPC845 open-drain pads and array-size checks in clockless capture.
  • Documentation
    • Updated hardware-testing guidance with jumper scanning details, pin limitations, and current measurement frequencies.

…n-drain pads skip IOCON MODE

- pinToggleRx drives TX through fl::pinMode/fl::digitalWrite (#5260
  backend) instead of the Arduino core's ::pinMode/::digitalWrite.
- test_lpc_pin_toggle_rx / test_lpc_pwm_dma_cl call positional-parameter
  RPCs with RpcBench.call_flat; RpcBench.call wraps params as [args], so
  every RPC (including the echo health check) failed.
- pin_lpc.hpp: LPC845 PIO0_10/PIO0_11 are true open-drain I2C pads with
  no pull resistors; IOCON bits 5:0 are reserved there (UM11029 Tables
  207/208), so setPull no longer writes MODE for them.

NOT hardware-validated: the P0_10->P0_11 loopback read edges=1 on both
master and this build (see branch notes).
The LPC845 --pin-toggle-rx bench had never passed on hardware. Every
capture reported edges=1 whatever the wiring. Fixed on LPC845-BRK:

- pinToggleRx sized its read-back span from a pointer
  (sizeof(ptr)/sizeof(EdgeTime) == 1), so it returned one edge.
  The same bug in pwmDmaClCaptureSelf rejected any frame over 1 LED.
- LpcSctRxChannel::pollOnce now records a rise and a fall seen in one
  poll in capture order. Rise-first made the delta wrap to ~2.1 s.
- The bench's period stats: the linear-search sqrt ran for billions of
  steps on a wide spread and tripped the watchdog. The one-pass
  E[x^2]-floor(mean)^2 variance was off by up to ~1.4 us. Both are
  replaced (bitwise isqrt, two-pass variance).
- TX edges run on SysTick deadlines and the capture is polled once per
  half period. delayMicroseconds + micros() (~19 us per call) added
  +20% to the period at 1 kHz and lost edges above ~7 kHz.
- ticksToNs uses 32-bit math when it is exact. A 64-bit soft divide per
  edge stalled the poll loop.
- Low-memory JSON: an int array with a value > 32767 was packed as
  vector<float>, and low-memory has no float -> int conversion, so
  pinToggleRx(..., 100000, ...) and every pwmDmaCl color argument were
  rejected. Large ints now stay i64 on low-memory builds.
- Bench cases are 1/5/10 kHz with a 1 us sigma budget. A polled toggle
  plus polled capture tops out near 13 kHz on the 24 MHz M0+.

Jumper discovery instead of assumed wiring:
- findConnectedPins on the LPC low-memory build tests every pin against
  every other with fl::pinMode/digitalWrite/digitalRead: a control read
  with TX released, then TX Low against the RX pull-up and TX High
  against the RX pull-down. It reports every pair, stuck pins, skipped
  pads, and the LPC845 open-drain pads (P0_10/P0_11 are only drivers).
- pin_probe_lpc.hpp: LPC845 probe skips SWD (PIO0_2/3), RESET (PIO0_5),
  ISP entry (PIO0_12) and the console USART0 (PIO0_24/25).
- --pin-toggle-rx and --pwm-dma-cl pick the pair from the scan unless
  --tx-pin/--rx-pin are given (ci/autoresearch/lpc_pin_scan.py).
- pinToggleRx drives TX through fl::pinMode/digitalWrite (the #5260
  backend), not the LPC8xx core's pinMode (framework-arduino-lpc8xx#40).
- pin_lpc.hpp: no IOCON MODE write on LPC845 PIO0_10/PIO0_11, where
  bits 5:0 are reserved (UM11029 Tables 207/208).
- test_lpc_pin_toggle_rx / test_lpc_pwm_dma_cl call positional RPCs
  with call_flat; RpcBench.call wraps params as [args], so even the
  echo health check failed.
…e user what is wired

Agents must scan for loopback pairs (findConnectedPins, both internal
pulls) and add the scan where a build lacks it. Documents the LPC
low-memory scan reply and the LPC845 open-drain P0_10/P0_11 pads.
@github-actions github-actions Bot added the sanitized Title, body and conversation screened; review text requires separate screening. label Nov 17, 2026
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The changes add LPC845 pin probing and firmware-based loopback discovery, connect scan results to autoresearch benches, and update low-memory capture timing and buffer handling. They also change integer-array classification in low-memory builds.

Changes: LPC Autoresearch

Layer / File(s) Summary
LPC pin probing and pull handling
src/platforms/arm/lpc/pin_lpc.hpp, src/platforms/arm/lpc/pin_probe_lpc.hpp, src/platforms/pin_probe.h, src/fl/system/pin_probe.h
The LPC845 pin backend identifies pins that cannot be probed or lack internal pulls. The platform probe implementation supplies skip reasons and is selected by the platform trampoline.
Low-memory pin discovery
examples/AutoResearch/AutoResearchLowMemory.h, agents/docs/hardware-autoresearch.md
The LPC low-memory firmware adds the findConnectedPins RPC. It scans pin pairs and reports connected pairs, stuck pins, skipped pins, and open-drain pins.
Scan parsing and pin resolution
ci/autoresearch/lpc_pin_scan.py, ci/tests/test_lpc_pin_scan.py
The Python scan client parses firmware replies, chooses a usable pair, handles explicit pins and scan failures, and formats results. Tests cover parsing, pair selection, and error reporting.
Bench pin selection and guidance
ci/autoresearch/phases.py, ci/autoresearch/test_lpc_pin_toggle_rx.py, ci/autoresearch/test_lpc_pwm_dma_cl.py, ci/tests/test_autoresearch_phases.py, CLAUDE.md, agents/docs/*
The LPC benches resolve pin pairs when overrides are omitted and pass explicit overrides when supplied. The workflow guidance directs agents to scan wiring rather than ask users about jumpers.
Capture timing and low-memory corrections
examples/AutoResearch/*, src/platforms/arm/lpc/rx_sct_capture.cpp.hpp, src/platforms/arm/lpc/README.md, ci/autoresearch/test_lpc_pin_toggle_rx.py
The low-memory pin-toggle loop uses SysTick deadlines. SCT capture orders simultaneous edge events by timestamp. The changes also adjust period statistics, buffer-capacity handling, and documented test rates.

Low-memory JSON classification

Layer / File(s) Summary
Integer array classification
src/fl/stl/json.cpp.hpp
The integer-to-float classification for values in the specified range now applies only to large-memory builds.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Bench as Autoresearch bench
  participant RpcBench
  participant Firmware as LPC low-memory firmware
  participant GPIO as LPC GPIO pins
  Bench->>RpcBench: request findConnectedPins
  RpcBench->>Firmware: invoke scan RPC
  Firmware->>GPIO: probe pin pairs and pull states
  GPIO-->>Firmware: return pin readings
  Firmware-->>RpcBench: return scan results
  RpcBench-->>Bench: return scan reply
  Bench->>Bench: resolve TX/RX pins
Loading

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#4729 — This PR extends the pin-probe skip-reason contract and uses its platform skip rules in the LPC845 scan.
Merge Risk: Moderate · up to 855d8

The change makes the LPC845 pin-toggle bench discover its jumper pair and capture edges correctly. It adds platform-specific code under AutoResearch without the markers the repository requires. This should be fixed or explicitly excepted before merge. No functional failure is established.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 17, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Memory usage (this PR vs. its merge base)

Change in examples/Blink per target. The left number is this PR's image flash / attributed RAM in bytes; the colored delta is the change from the merge base (red ↑ is larger, green ↓ is smaller, Same is unchanged).

Target FLASH [bytes] RAM [bytes]
attiny85 2,460 (Same) 136 (Same)

- Bind findConnectedPins on LPC845 only, the LPC with a pin-probe skip
  table; on LPC804 it would drive SWD/RESET/ISP/console pads.
- resolve_pins rejects a lone --tx-pin or --rx-pin instead of dropping it.
- run_scan tells 'not bound' apart from 'did not answer'.
- LowMemTickClock starts SysTick via millis() before reading it.
- Two-pass variance saturates instead of wrapping on clamped edges.
@zackees
zackees enabled auto-merge November 17, 2026 23:59
@zackees
zackees added this pull request to the merge queue Nov 17, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 18, 2026
Merged via the queue into master with commit d378e84 Nov 18, 2026
130 of 131 checks passed
@zackees
zackees deleted the fix/autoresearch-lpc-fl-pin-api branch November 18, 2026 00:09
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Nov 18, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 18, 2026
sutaburosu pushed a commit to sutaburosu/FastLED that referenced this pull request Nov 18, 2026
…d; skip IOCON-identity pins (FastLED#5274)

* fix(autoresearch): LPC corePullCheck only in the --pin-toggle-rx build; skip IOCON-identity pins (FastLED#5270)

- phases.py passes FASTLED_AUTORESEARCH_LPC_CORE_PULL_CHECK with
  --pin-toggle-rx; the sketch compiles corePullCheck only under it. The
  default lpc845 image drops from 60472 to 59684 bytes.
- Platform-neutrality markers on the remaining LPC lines from FastLED#5262/FastLED#5264.
- The pull check skips P0_4 and P0_24 (IOCON slot == GPIO bit, so they
  cannot detect framework-arduino-lpc8xx#40), and a missing binding in
  the --pin-toggle-rx build now fails instead of skipping.

Refs FastLED#5268

* fix: address CodeRabbit review feedback

- check_core_pulls probes the corePullCheck binding (four -1 slots) before
  scanning, so a missing RPC fails even when no idle pin qualifies or the
  scan fails
- test_lpc_pin_toggle_rx documents that it requires the --pin-toggle-rx build
- lowMemCorePullCheck reads back via lowMemSettledHigh (fl::digitalRead);
  only the vendor ::pinMode calls under test stay platform specific

* fix(autoresearch): an unanswered corePullCheck probe fails instead of skipping
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanitized Title, body and conversation screened; review text requires separate screening.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant