Repository navigation
Description
Context
During #4887 native CDC link-map review, Arduino USB/USBMSC/USBCDC/TinyUSB HAL archive roots were eliminated, but modern P4 still retained HardwareSerial and String through an independent framework root.
Verified in Arduino-ESP32 3.3.11 cores/esp32/main.cpp:61-63: unless NO_GLOBAL_INSTANCES or NO_GLOBAL_SERIAL is defined, startup directly calls Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0)). The P4 map shows main.o -> Serial0/HardwareSerial -> Stream::readString -> WString. Removing FastLED's console references cannot remove this root by itself.
Proposal
Investigate an upstream framework-compatible weak or lazy initialization boundary that configures UART0 only when a real application user links/initializes it. Determine whether the correct fix belongs in Arduino-ESP32 and whether fbuild packaging needs a version update. Preserve application Serial functionality and board pin defaults.
Acceptance criteria
- RED -> GREEN: record a minimal modern P4 native-console ELF/map retaining Serial0 solely through startup, then demonstrate removal of that root with a concrete fix.
- Normal Serial0.begin/write, default pins and explicitly selected pins continue to work; verify both native-first and Arduino-first order on supported hardware.
- Compare matched no-Serial, explicitly-used Serial0, and native USB cases, reporting live symbol roots, flash/static RAM/runtime heap and SDK/core versions.
- Check weak reference/archive extraction and global-constructor behavior; a weak declaration alone is not proof of elimination.
- Link the upstream patch/issue and downstream package integration where needed. Document affected SDK/core/board scope rather than assuming all variants share this startup path.
Decisions
- Do not force NO_GLOBAL_SERIAL or NO_GLOBAL_INSTANCES to manufacture a saving: those change application APIs.
- Keep this framework-root work separate from fix(esp32): remove Arduino console retention with native SDK backends #4887's already removed FastLED/TinyUSB callback roots.
- Weak/lazy initialization is a candidate, not a predetermined fix; choose only after preserving startup semantics.
Related issues
#4887 supplies the native P4 probe and link-map finding. Baseline integrated probe: IDF 5.5.5 / Arduino 3.3.11, 375,584 flash and 72,624 static RAM bytes; not a matched D32 size comparison.
Tracked under #4888.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Oct 22, 2026
Current-source experiment confirms a concrete weak boundary can remove the startup root while preserving explicit Serial linkage. Core source is Arduino3.3.11 / IDF5.5.5, P4, current FastLED c1747a3.
The candidate replaces main.cpp's direct Serial0.setPins call with a guarded weak undefined C hook. HardwareSerial.cpp supplies the strong hook with the original setPins operation. The hook does not extract the Serial archive member by itself; explicit application Serial use still extracts it and restores the same startup call. No NO_GLOBAL_SERIAL/NO_GLOBAL_INSTANCES setting or installed-SDK mutation was used.
Matched pristine/candidate framework archives differ only by this two-file patch. Equal-length archive and build paths; real builds and
bash bloat:Native-only candidates exclude sized Serial0, HardwareSerial methods and Stream::readString. The explicit Serial0 candidate retains them and the strong default-pin hook. The actual symbol-report verifier is RED before and GREEN after for the Serial root.
One residual root remains independently: main -> chip-debug-report -> Esp.cpp -> WString retains a String constructor. An initial overly broad verifier correctly failed on it; this is not a claim that every Arduino String symbol disappeared. Existing #2886 tracks chip-debug-report suppression and its still-projected savings.
Not complete: physical startup/default pins/explicit pins/native-first/Arduino-first/heap checks and durable production integration. Current fbuild honors framework HTTP(S) archive pins, but its native ESP32 build does not consume source replacement middleware. Scratch HTTP package serving proves the experiment, not a production integration. I am keeping this issue and parent #4888 open while completing those requirements.
zackees commentedon Oct 22, 2026
Implementation is integrated locally through an immutable framework source pin,
paired with IDF 5.5.5 for esp32dev/esp32s3/esp32p4. Upstream patch:
espressif/arduino-esp32#13010.
Six matched P4 public-archive controls confirm build-summary savings of 22,040 B
flash / 1,096 B static RAM for native UART and 28,418 / 1,128 B for native USB.
Explicit Serial0 costs 26 B flash and unchanged static RAM. All six
bash bloatreports independently confirm removal/preservation of the intended live owners;
full totals and accounting differences are documented in the forthcoming PR.
Physical classic ESP32 matched native-only AutoResearch recovers 612 B free heap
(71,512 → 72,124). Explicit Serial0 retains the same 71,468 B free heap before and
after. Both pairs pass five cold/settling/warm cycles with no retained per-cycle
heap and valid integrity. Default pins, explicit GPIO16/17 changes/restoration,
both initialization orders and exact alternating records pass the device probes.
Full Python is green: 2,022 passed, 47 skipped, 2 expected failures, 3,280 subtests.
Full lint passes. Final consolidated fixture verification is finishing before PR
publication. Physical native USB runtime/heap remains explicitly unverified and
will be handled under #4893; compile/link evidence is not a substitute for it.
zackees commentedon Oct 22, 2026
Published in PR #4898 (commit 1a32907). All three final consolidated AutoResearch modes passed five physical cycles each, normal S3/P4 Blink builds pass, full lint passes, and full Python reports 2,022 passed. Bloat/runtime details and upstream patch linkage are in the PR. Full stack/master CI and the separately tracked physical USB matrix #4893 remain pending.
fix(serial): Avoid linking unused UART0 from framework startup
zackees commentedon Oct 22, 2026
Closed: the Serial0 startup root lives in stock Arduino-ESP32 main.cpp and cannot be removed from FastLED with stock, unpatched SDKs (see #4898 closure). Tracked upstream at espressif/arduino-esp32#13010; revisit when a released core includes it.
zackees commentedon Oct 23, 2026
Reopened: a stock-SDK fix exists after all; see #4911 and PR #4913.
fix(esp32): gate lazy Serial0 on a multi-header Arduino-ESP32 canary,…
fix(esp32): keep unused Serial0 out of stock Arduino-ESP32 images (#4892
fix(serial): avoid retaining unused HardwareSerial from startup (#13010)