Skip to content

fix(autoresearch): use GPIO18/19 as default TX/RX on classic ESP32 (#3452) - #3455

Merged
zackees merged 3 commits into
masterfrom
fix/3452-classic-esp32-uart0-collision
Jun 30, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/3452-classic-esp32-uart0-collision

Conversation

@zackees

@zackees zackees commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Resolves #3452 — "RPC silence on classic ESP32-WROOM".

The autoresearch sketch defaulted PIN_TX=1 / PIN_RX=0 on classic ESP32 (FL_IS_ESP_32DEV / esp32dev). GPIO 1 is the UART0 TX pin — the Arduino Serial console output that bash autoresearch reads via the USB-Serial bridge — and GPIO 0 is a boot-strap pin. The first loop() iteration calls testRxChannel(rx_channel, PIN_TX, PIN_RX, ...) which toggles PIN_TX as a digital output, instantly killing UART0. That's the "device boots, emits ready, then goes silent" symptom.

Switching the classic-ESP32 defaults to GPIO 18 / 19 — both general-purpose, not muxed to UART0, not on the boot-strap list — restores the console for the lifetime of the sketch. Other platform defaults are untouched.

Also adds a null guard around the GPIO baseline test so a future RX-channel creation failure cannot panic loop() with a nullptr deref.

Diagnostic heartbeat prints that lived briefly on diag/3452-loop-heartbeat are removed; the root cause is fixed, the bisection scaffolding isn't needed.

Validation

Tested on the user's WROOM board (COM11). Pre-fix: device sends RESULT: {... \"ready\":true ... \"pinTx\":1, \"pinRx\":0 ...} and then UART0 stays silent forever. Post-fix:

RESULT: {\"chip\":\"ESP32 (Xtensa)\",\"type\":\"ready\",\"pinRx\":19,\"pinTx\":18,\"ready\":true,\"drivers\":5,...}
RESULT: {\"hz\":40000000,\"type\":\"gpioBaseline\",\"pinRx\":19,\"pinTx\":18,\"success\":false,...}
>>> ping
REMOTE: {\"id\":1,\"error\":{...},\"jsonrpc\":\"2.0\"}     ← RPC alive
RESULT: {\"type\":\"status\",\"ready\":true,\"uptimeMs\":5040}    ← loop running
RESULT: {\"type\":\"status\",\"ready\":true,\"uptimeMs\":10041}

Test plan

  • WROOM board on COM11 boots and serves RPC continuously
  • bash autoresearch end-to-end on classic ESP32 (next PR — separate handler issue tracked locally)
  • Other ESP32 variants (S3, C3, S2, C6, P4) and Teensy 4.x defaults verified not regressed (no behavior change there — only the classic-ESP32 #else branch moved)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved startup reliability by avoiding a GPIO baseline test when no receive channel is available.
    • Updated default UART pin selection on classic ESP32 boards to safer pins, reducing conflicts with boot and console behavior.
  • Documentation
    • Added clearer guidance about avoiding certain GPIO pins on classic ESP32 devices.

zackees and others added 3 commits June 30, 2026 13:51
…#3452)

Adds a once-per-loop heartbeat at the very top of `loop()` that prints
via two parallel paths so we can isolate the failure mode on the
silent-RPC classic ESP32-WROOM described in #3452:

  Path A: fl::println(...)           — through the FastLED IO singleton
                                        (UartEsp32 + EspIO + fl::print).
  Path B: Serial.print/println(...)  — straight to Arduino HardwareSerial.

The heartbeat is non-destructive (never consumes a byte) so the RPC
parser still sees all UART input. Both paths fire on the first
iteration and then every 1 s; each line includes the iteration counter,
millis(), and the live `Serial.available()` / `fl::available()` counts.

First-flash result on the user's COM11 board (#3452 follow-up):

    [ 2.66s] [#3452:raw] iter=1 avail=0          ← Path B (Arduino Serial)
    [ 3.37s] (single space character)              ← Path A (fl::println)?
                                                   nothing else for 15 s.

Two diagnoses fall out of that:

  * `fl::println` is silently failing on this board (Path A produces
    either nothing or a single byte; the full line never lands).
    Suggests the FastLED `EspIO`/`UartEsp32` singleton's
    `mBuffered` / `mPortInt` state is no longer pointing at a healthy
    driver by the time `loop()` runs, even though Arduino's UART path
    still works fine.
  * `loop()` only iterates once. The for-loop in `loop()` that pumps
    `fl::task::run()` 100× wedges on the very first pass — so the
    RPC-polling task (which calls `remote_control.tick()`, which in
    turn pulls via `fl::available()`/`fl::readLine`) blocks forever
    or starves the rest of the loop.

Filed against issue #3452. To delete once the singleton-vs-Arduino
divergence is root-caused.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds before/after Serial.print bookends around the per-loop
`for (i=0; i<100; i++) fl::task::run();` block so we can tell which
side of the pump the device wedges in.

Observed on the user's classic ESP32-WROOM:

  [ 2.67s] [#3452:raw] iter=1 avail=0
  [ 2.67s] [#3452:raw] before for(100) iter=1
  [ 3.37s] [#3                                ← OUTPUT TRUNCATES MID-PRINT

So at 3.37 s (700 ms into the first call to fl::task::run), in the
middle of emitting the "[#3452:raw] after for(100) iter=1" line, the
UART TX path stops working part-way through writing. The chip is still
alive (no reset, no boot message), but `Serial.print` is dropping bytes
on the floor mid-string. The next loop iteration's heartbeat never
makes it onto the wire either.

That's not a "task blocks forever" pattern — that's a "UART driver
gets clobbered while a Serial.print is in progress." Strongly
consistent with one of the FastLED background tasks (the wave8 UART
driver's `UartPeripheralEsp::initialize(UART_NUM_0, …)` is the prime
suspect — it calls `uart_driver_install()` + `uart_set_line_inverse()`
on UART0, which would invalidate Arduino's `HardwareSerial` driver
silently the instant it fires).

Next investigation step: print which tasks the scheduler is currently
running so we can name the culprit, then look at why something is
calling into wave8 UART initialize from a background task without an
RPC trigger.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…3452)

The autoresearch sketch defaulted `PIN_TX=1` / `PIN_RX=0` on classic
ESP32 (FL_IS_ESP_32DEV / esp32dev). GPIO 1 is the UART0 TX pin (the
Arduino `Serial` console output that bash autoresearch reads), and
GPIO 0 is a boot-strap pin. On loop() entry the GPIO baseline test
(`testRxChannel(rx_channel, PIN_TX, PIN_RX, ...)`) toggles PIN_TX as
a digital output, instantly killing UART0 — manifesting as the
"device emits ready event then goes silent" symptom in #3452.

Switch the classic-ESP32 defaults to GPIO 18 / 19, which are
general-purpose pins not muxed to UART0 and not on the boot-strap
list. The rest of the platform-specific defaults stay as-is.

Also harden loop() against a null rx_channel: skip the GPIO baseline
testRxChannel call when `g_autoresearch_state->rx_channel` is null,
which prevents an immediate panic if the RX channel creation in
setup() ever fails on a future platform.

Drops the temporary `#3452` diagnostic heartbeat prints added on
branch `diag/3452-loop-heartbeat`. Validated on the user's WROOM
board (COM11): device boots → emits `ready` (pinRx:19, pinTx:18,
drivers:5) → emits `gpioBaseline` → responds to ping RPC → emits
periodic `status` events. Pre-fix: same boot then UART silence.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit e15a9b2 into master Jun 30, 2026
6 checks passed
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 688cd3ca-6acb-4786-9477-69d997be69a3

📥 Commits

Reviewing files that changed from the base of the PR and between 1874d0f and e9d8685.

📒 Files selected for processing (2)
  • examples/AutoResearch/AutoResearch.ino
  • examples/AutoResearch/AutoResearchPlatform.h

📝 Walkthrough

Walkthrough

Modifies the AutoResearch example for classic ESP32: AutoResearchPlatform.h adds explicit FL_IS_ESP_32DEV pin branches defaulting TX to GPIO18 and RX to GPIO19, with documentation on GPIO0/1/3 caveats. AutoResearch.ino tightens the GPIO baseline test condition to also require a non-null rx_channel.

Changes

AutoResearch ESP32 pin defaults and RX guard

Layer / File(s) Summary
ESP32 classic default TX/RX pin update
examples/AutoResearch/AutoResearchPlatform.h
Adds an explicit FL_IS_ESP_32DEV branch returning GPIO18 for defaultTxPin() and GPIO19 for defaultRxPin(), with new comments documenting GPIO0/1/3 boot-strap/UART0 caveats on classic ESP32.
GPIO baseline test RX channel guard
examples/AutoResearch/AutoResearch.ino
Loop condition now also checks g_autoresearch_state->rx_channel is non-null before running the GPIO baseline test, preventing testRxChannel(...) from being called without a valid RX channel.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

  • FastLED/FastLED#3356: Both PRs adjust AutoResearch to avoid continuing with tests when RX channel setup is invalid or missing.

Poem

Hop, hop, GPIO eighteen and nineteen too,
No more boot-strap pins giving us the blues 🐇
A null rx_channel? Not on my watch—
I check before I let that test catch.
Whiskers twitch, the wires align,
ESP32 classic, now you're fine!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/3452-classic-esp32-uart0-collision

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

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant