Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom serial monitor baud option #238

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ fn flash(

if opts.flash_opts.monitor {
let pid = flasher.get_usb_pid()?;
monitor(flasher.into_serial(), Some(&elf_data), pid).into_diagnostic()?;
monitor(
flasher.into_serial(),
Some(&elf_data),
pid,
opts.connect_opts.monitor_speed.unwrap_or(115200),
)
.into_diagnostic()?;
}

Ok(())
Expand Down
3 changes: 3 additions & 0 deletions espflash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ OPTIONS:
--monitor
Open a serial monitor after flashing

--monitor-speed <MONITOR_SPEED>
Baud rate at which to read console output

--partition-table <PARTITION_TABLE>
Path to a CSV file containing partition table

Expand Down
13 changes: 12 additions & 1 deletion espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub struct ConnectOpts {
#[clap(long)]
pub speed: Option<u32>,

/// Baud rate at which to read console output
#[clap(long)]
pub monitor_speed: Option<u32>,

/// Use RAM stub for loading
#[clap(long)]
pub use_stub: bool,
Expand Down Expand Up @@ -161,7 +165,14 @@ pub fn board_info(opts: ConnectOpts, config: Config) -> Result<()> {
pub fn serial_monitor(opts: ConnectOpts, config: Config) -> Result<()> {
let flasher = connect(&opts, &config)?;
let pid = flasher.get_usb_pid()?;
monitor(flasher.into_serial(), None, pid).into_diagnostic()?;

monitor(
flasher.into_serial(),
None,
pid,
opts.monitor_speed.unwrap_or(115200),
)
.into_diagnostic()?;

Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion espflash/src/cli/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn monitor(
mut serial: Box<dyn SerialPort>,
elf: Option<&[u8]>,
pid: u16,
baud: u32,
) -> serialport::Result<()> {
println!("Commands:");
println!(" CTRL+R Reset chip");
Expand All @@ -95,7 +96,7 @@ pub fn monitor(

// Explicitly set the baud rate when starting the serial monitor, to allow using
// different rates for flashing.
serial.set_baud_rate(115_200)?;
serial.set_baud_rate(baud)?;
serial.set_timeout(Duration::from_millis(5))?;

let _raw_mode = RawModeGuard::new();
Expand Down
9 changes: 8 additions & 1 deletion espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ fn flash(opts: Opts, config: Config) -> Result<()> {

if opts.flash_opts.monitor {
let pid = flasher.get_usb_pid()?;
monitor(flasher.into_serial(), Some(&elf_data), pid).into_diagnostic()?;

monitor(
flasher.into_serial(),
Some(&elf_data),
pid,
opts.connect_opts.monitor_speed.unwrap_or(115200),
)
.into_diagnostic()?;
}

Ok(())
Expand Down