Skip to content

Serial monitor: choose and check the baud rate on a UART - #16

Merged
robdobsn merged 1 commit into
mainfrom
feature/monitor-baud-detect
Nov 8, 2026
Merged

robdobsn merged 1 commit into
mainfrom
feature/monitor-baud-detect

Conversation

@robdobsn

@robdobsn robdobsn commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Summary

The serial monitor now chooses the baud rate itself, and checks it, when -b isn't given. This applies to raft monitor and to the monitor at the end of raft run.

  • Which ports: only a real UART, meaning a USB-UART adapter or a non-USB port. The ESP32's native USB (vendor ID 303a) ignores the rate and isn't checked.
  • -b given: that rate is used and never changed.
  • Starting rate, the first that's known:
    1. the built firmware's console rate (CONFIG_ESP_CONSOLE_UART_BAUDRATE in build/<SysType>/raft/sdkconfig, when the console is on a UART)
    2. the rate last found working on this adapter
    3. the -b from last time (raft.info)
    4. 115200
  • Checking: if the output is unreadable for more than 0.5 s, other rates are tried until log text is readable. Each change is shown in the output and in the log file. Without -b, a rate saved in raft.info is now only a starting point and no longer fixes the rate.
    • "Unreadable" means under 70% text bytes, or 6 or fewer distinct byte values with less than 90% text, and no log lines.
    • The boot ROM's output (always at 115200) is never taken as a sign the rate is right or wrong.
    • Once text has been read, 3 s of unreadable output is needed before trying again, so a burst of binary data doesn't change the rate.
    • If no rate gives readable text, the most readable one is kept and the search repeats after 10 s.
  • Remembering: the rate found is saved per adapter (USB IDs and serial number, or the port name) in monitor_bauds.json in the user's config folder (~/.config/raft, or %APPDATA%\raft on Windows).
  • WSL: -b is passed to raft.exe only when given. Otherwise raft.exe chooses the rate, because only it can identify the adapter.

README: new Monitor baud rate section. The -b help text was updated for monitor and run.

Testing

  • cargo test: 162 passed, 15 of them new. A simulated UART receiving at the wrong rate covers 12 rate pairs, plus the detector, a reset during boot, a binary burst, the starting-rate order, sdkconfig parsing and the adapter store.
  • On hardware: an Axiom (ESP32-S3) with a CH340 adapter on UART0 (COM17), Windows raft.exe built from this branch, and resets through the Axiom's USB port.
    • With firmware at 115200:
      • nothing known: 115200, readable
      • 921600 wrongly remembered: switched to 115200 after about 1 s
      • -b 921600: stayed at 921600, unreadable as expected
      • native USB port: not checked
    • With firmware at 921600:
      • from the project folder: started at 921600 from the build's console setting
      • 115200 remembered, or nothing known: switched to 921600 0.5 s after the unreadable output began
      • three resets while at 921600: no switch
      • WSL hand-off to raft.exe: started at 921600 from the build's console setting

This PR and #15 both change the run handler in main.rs, so whichever merges second needs a small conflict fixed.

🤖 Generated with Claude Code

Without -b, the monitor starts on a UART (a USB-UART adapter or a non-USB port) at the most likely rate: the built firmware's console rate (CONFIG_ESP_CONSOLE_UART_BAUDRATE in build/<SysType>/raft/sdkconfig when the console is on a UART), the rate last found working on the adapter (remembered in the user's config folder, monitor_bauds.json, by USB IDs and serial number), the -b given last time (raft.info), then 115200. While the output is unreadable (the byte patterns a UART gives at the wrong rate, no log lines) for over 0.5 s, other rates are tried until log text is readable; once readable only 3 s of unreadable output changes it, so binary bursts and the boot ROM's 115200 output after a reset don't. Changes are shown in the output and log. -b on the command line is used as it is; the ESP32's native USB (vid 303a) ignores the rate and isn't checked. Under WSL, -b is passed to raft.exe only when given so that raft.exe (which can identify the adapter) chooses the rate. Tests use a simulated UART receiving at the wrong rates. README: Monitor baud rate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@robdobsn
robdobsn merged commit ed3739b into main Nov 8, 2026
6 checks passed
@robdobsn
robdobsn deleted the feature/monitor-baud-detect branch November 8, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant