Skip to content

Commit f08dd05

Browse files
bugadanijessebraham
authored andcommitted
Allow specifying monitor speed
1 parent 5a7a6f9 commit f08dd05

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

cargo-espflash/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,13 @@ fn flash(
240240

241241
if opts.flash_opts.monitor {
242242
let pid = flasher.get_usb_pid()?;
243-
monitor(flasher.into_serial(), Some(&elf_data), pid).into_diagnostic()?;
243+
monitor(
244+
flasher.into_serial(),
245+
Some(&elf_data),
246+
pid,
247+
opts.connect_opts.monitor_speed.unwrap_or(115200),
248+
)
249+
.into_diagnostic()?;
244250
}
245251

246252
Ok(())

espflash/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ OPTIONS:
4343
--monitor
4444
Open a serial monitor after flashing
4545
46+
--monitor-speed <MONITOR_SPEED>
47+
Baud rate at which to read console output
48+
4649
--partition-table <PARTITION_TABLE>
4750
Path to a CSV file containing partition table
4851

espflash/src/cli/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub struct ConnectOpts {
4141
#[clap(long)]
4242
pub speed: Option<u32>,
4343

44+
/// Baud rate at which to read console output
45+
#[clap(long)]
46+
pub monitor_speed: Option<u32>,
47+
4448
/// Use RAM stub for loading
4549
#[clap(long)]
4650
pub use_stub: bool,
@@ -161,7 +165,14 @@ pub fn board_info(opts: ConnectOpts, config: Config) -> Result<()> {
161165
pub fn serial_monitor(opts: ConnectOpts, config: Config) -> Result<()> {
162166
let flasher = connect(&opts, &config)?;
163167
let pid = flasher.get_usb_pid()?;
164-
monitor(flasher.into_serial(), None, pid).into_diagnostic()?;
168+
169+
monitor(
170+
flasher.into_serial(),
171+
None,
172+
pid,
173+
opts.monitor_speed.unwrap_or(115200),
174+
)
175+
.into_diagnostic()?;
165176

166177
Ok(())
167178
}

espflash/src/cli/monitor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub fn monitor(
8787
mut serial: Box<dyn SerialPort>,
8888
elf: Option<&[u8]>,
8989
pid: u16,
90+
baud: u32,
9091
) -> serialport::Result<()> {
9192
println!("Commands:");
9293
println!(" CTRL+R Reset chip");
@@ -95,7 +96,7 @@ pub fn monitor(
9596

9697
// Explicitly set the baud rate when starting the serial monitor, to allow using
9798
// different rates for flashing.
98-
serial.set_baud_rate(115_200)?;
99+
serial.set_baud_rate(baud)?;
99100
serial.set_timeout(Duration::from_millis(5))?;
100101

101102
let _raw_mode = RawModeGuard::new();

espflash/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ fn flash(opts: Opts, config: Config) -> Result<()> {
177177

178178
if opts.flash_opts.monitor {
179179
let pid = flasher.get_usb_pid()?;
180-
monitor(flasher.into_serial(), Some(&elf_data), pid).into_diagnostic()?;
180+
181+
monitor(
182+
flasher.into_serial(),
183+
Some(&elf_data),
184+
pid,
185+
opts.connect_opts.monitor_speed.unwrap_or(115200),
186+
)
187+
.into_diagnostic()?;
181188
}
182189

183190
Ok(())

0 commit comments

Comments
 (0)