xtensa/esp32s3: Fix CONSOLE_DEV clobbered by USBSERIAL macro. - #20053
Merged
xiaoxiang781216 merged 1 commit intoSep 4, 2026
Merged
Conversation
When a real UART (CONFIG_UARTx_SERIAL_CONSOLE) is selected as the system console while CONFIG_ESP32S3_USBSERIAL is also enabled (e.g. to keep /dev/ttyACM0 available as a secondary device alongside an external console UART), the unconditional #ifdef CONFIG_ESP32S3_USBSERIAL # define CONSOLE_DEV g_uart_usbserial #endif block silently redefines CONSOLE_DEV, clobbering the correct earlier definition that pointed it at the chosen UART device. Confirmed on real hardware (Seeed XIAO ESP32-S3): with UART0 selected as console and USBSERIAL also enabled, the board boot-looped on RTCWDT_RTC_RST every ~8s, never reaching NSH. With this fix, NSH comes up normally over UART0 and /dev/ttyACM0 remains available. Signed-off-by: Felipe Moura <moura.fmo@gmail.com> Assisted-by: Claude:claude-sonnet-5
FelipeMdeO
force-pushed
the
fix/esp32s3-usbserial-console-clobber
branch
from
September 3, 2026 15:32
01d6a73 to
8ededdb
Compare
xiaoxiang781216
approved these changes
Sep 3, 2026
Contributor
Author
|
@acassis , can you review this PR too, please? |
eren-terzioglu
approved these changes
Sep 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hang/reset-loop bug.
arch/xtensa/src/esp32s3/esp32s3_serial.c, theCONSOLE_DEVmacroselection logic used by the ESP32-S3 serial driver.
When
CONFIG_ESP32S3_USBSERIALis enabled at the same time as a realUART is selected as the system console (
CONFIG_UARTx_SERIAL_CONSOLE),an unconditional
#define CONSOLE_DEV g_uart_usbserialsilentlyoverrides the correct earlier definition that pointed
CONSOLE_DEVatthe chosen UART device.
xtensa_earlyserialinit()then callsesp32s3_setup(&CONSOLE_DEV)— a function only valid for astruct esp32s3_uart_s— on what is actuallyg_uart_usbserial, whoseprivpoints to an unrelatedstruct esp32s3_usbserial_s. Readingpriv->idoff the wrong struct returns garbage, which is then used tocompute a UART register address; the resulting access to invalid IO
hangs the CPU until the RTC watchdog resets the board, in a loop,
before NSH ever starts. The fix guards the USBSERIAL assignment with
!defined(CONSOLE_DEV), mirroring the pattern already used a few linesbelow in the same file for
TTYS1_DEV/TTYS2_DEV.Impact
Is existing feature changed? NO — pure bug fix,
no behavior change for any config that was working correctly before
(the only configs affected are ones where
CONSOLE_DEVwas silentlywrong, i.e. already broken).
Testing
I confirm that changes are verified on local setup and works as intended:
xtensa-esp32s3-elftoolchain (esp-elf 14.2.0).
out-of-tree defconfig with
CONFIG_ESP32S3_UART0=y,CONFIG_UART0_SERIAL_CONSOLE=y,CONFIG_ESP32S3_USBSERIAL=y.SERIAL_CONSOLEwhileCONFIG_ESP32S3_USBSERIALis also enabled, andwatch the UART console — it boot-loops instead of reaching NSH.
Testing logs before change:
Testing logs after change: