Skip to content

Commit

Permalink
Allow specifying monitor speed
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Sep 16, 2022
1 parent 5a7a6f9 commit 345696e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
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

0 comments on commit 345696e

Please sign in to comment.