Skip to content

Add 'uart.Port.console' to read input from the console UART.#3091

Merged
floitsch merged 2 commits into
masterfrom
floitsch/uart-console
Jul 19, 2026
Merged

Add 'uart.Port.console' to read input from the console UART.#3091
floitsch merged 2 commits into
masterfrom
floitsch/uart-console

Conversation

@floitsch

Copy link
Copy Markdown
Member

The console UART (the one used for logging and print) can now be opened with uart.Port.console. It keeps the configuration it was given during boot; only the UART driver is installed, so RX becomes interrupt driven while system output continues through the polling VFS path (the same coexistence ESP-IDF's own console REPL uses). A dedicated one-slot pool guards single-open and returns the port on close, and in-flight TX is drained before the driver install since that resets the TX FIFO.

This is the base for driving hardware tests over the serial connection instead of WiFi (following the EC618 tester's serial mini-jag model): the esp-tester now answers UART-INPUT-REQUEST: <payload> marker lines by writing the payload back over the serial port, and the new uart-console-test exercises the full loop (open, double-open rejection, host echo received byte-exact, driver-side write, close/reopen).

Verified on the hardware rig: uart-console-test.toit-esp32 passes, and the remaining 15 uart hardware tests pass on the new firmware (the teardown change touches every UART's close path). Skipped on esp32s3: that rig's board1 is connected through USB-Serial-JTAG, so host writes don't reach UART0 RX — S3 input needs a usb_serial_jtag equivalent as a follow-up.

The console UART (the one used for logging and 'print') can now be
opened with 'uart.Port.console'. It keeps the configuration it was given
during boot; only the UART driver is installed, so RX becomes interrupt
driven while system output continues through the polling VFS path.

This is the base for driving hardware tests over the serial connection
instead of WiFi: the esp-tester now answers 'UART-INPUT-REQUEST: '
marker lines by writing the payload back over the serial port, and a new
hardware test exercises the full loop.
Comment thread src/resources/uart_esp32.cc Outdated
// interrupt driven. System output (logging, `print`) keeps going through
// the polling VFS path and thus doesn't need the driver.
// Installing the driver resets the TX FIFO, so drain in-flight output first.
esp_rom_output_tx_wait_idle(port);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there could be a race condition?
If we wait for idle, and another container prints something we might still drop a few bytes.
If there isn't a good way around that, then we should document that.

Comment thread tests/hw/esp32/fail.cmake Outdated
set(TOIT_SKIP_TESTS
# On the test rig the S3's board1 is connected through the USB-Serial-JTAG
# console, so data written by the tester doesn't reach the UART0 RX pin.
uart-console-test.toit-esp32s3

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's true.

run-test: test

test:
port := uart.Port.console

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a test (or modify this one) that we can change the uart baudrate of the console. (obviously needs to work together with the tester).

@floitsch
floitsch merged commit 4077547 into master Jul 19, 2026
27 checks passed
@floitsch
floitsch deleted the floitsch/uart-console branch July 19, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant