@@ -142,15 +142,12 @@ pub struct FlashArgs {
142142 /// Erase specified data partitions
143143 #[ arg( long, value_name = "PARTS" , value_enum, value_delimiter = ',' ) ]
144144 pub erase_data_parts : Option < Vec < DataType > > ,
145- /// Logging format.
146- #[ arg( long, short = 'L' , default_value = "serial" , requires = "monitor" ) ]
147- pub log_format : LogFormat ,
148145 /// Open a serial monitor after flashing
149146 #[ arg( short = 'M' , long) ]
150147 pub monitor : bool ,
151- /// Baud rate at which to read console output
152- #[ arg ( long , requires = "monitor" , value_name = "BAUD" ) ]
153- pub monitor_baud : Option < u32 > ,
148+ /// Monitor configuration
149+ #[ clap ( flatten ) ]
150+ pub monitor_args : MonitorConfigArgs ,
154151 /// Load the application to RAM instead of Flash
155152 #[ arg( long) ]
156153 pub ram : bool ,
@@ -162,9 +159,6 @@ pub struct FlashArgs {
162159 pub no_skip : bool ,
163160 #[ clap( flatten) ]
164161 pub image : ImageArgs ,
165- /// External log processors to use (comma separated executables)
166- #[ arg( long, requires = "monitor" ) ]
167- pub processors : Option < String > ,
168162}
169163
170164/// Operations for partitions tables
@@ -255,22 +249,36 @@ pub struct ImageArgs {
255249 pub min_chip_rev : u16 ,
256250}
257251
258- /// Open the serial monitor without flashing
259252#[ derive( Debug , Args ) ]
260253#[ non_exhaustive]
261254pub struct MonitorArgs {
262255 /// Connection configuration
263256 #[ clap( flatten) ]
264257 connect_args : ConnectArgs ,
265- /// Optional file name of the ELF image to load the symbols from
258+ /// Monitoring arguments
259+ #[ clap( flatten) ]
260+ monitor_args : MonitorConfigArgs ,
261+ }
262+
263+ /// Open the serial monitor without flashing
264+ #[ derive( Debug , Args ) ]
265+ #[ non_exhaustive]
266+ pub struct MonitorConfigArgs {
267+ /// Baud rate at which to communicate with target device
268+ #[ arg( short = 'r' , long, env = "MONITOR_BAUD" , default_value = "115_200" , value_parser = parse_u32) ]
269+ pub baud_rate : u32 ,
270+ /// File name of the ELF image to load the symbols from
266271 #[ arg( short = 'e' , long, value_name = "FILE" ) ]
267- elf : Option < PathBuf > ,
272+ pub elf : Option < PathBuf > ,
268273 /// Avoids asking the user for interactions like resetting the device
269274 #[ arg( long) ]
270275 non_interactive : bool ,
276+ /// Avoids restarting the device before monitoring
277+ #[ arg( long, requires = "non_interactive" ) ]
278+ no_reset : bool ,
271279 /// Logging format.
272280 #[ arg( long, short = 'L' , default_value = "serial" , requires = "elf" ) ]
273- pub log_format : LogFormat ,
281+ log_format : LogFormat ,
274282 /// External log processors to use (comma separated executables)
275283 #[ arg( long) ]
276284 processors : Option < String > ,
@@ -292,6 +300,7 @@ pub struct ChecksumMd5Args {
292300
293301/// Parses an integer, in base-10 or hexadecimal format, into a [u32]
294302pub fn parse_u32 ( input : & str ) -> Result < u32 , ParseIntError > {
303+ let input: & str = & input. replace ( '_' , "" ) ;
295304 let ( s, radix) = if input. len ( ) > 2 && matches ! ( & input[ 0 ..2 ] , "0x" | "0X" ) {
296305 ( & input[ 2 ..] , 16 )
297306 } else {
@@ -437,7 +446,7 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
437446 let mut flasher = connect ( & args. connect_args , config, true , true ) ?;
438447 let pid = flasher. get_usb_pid ( ) ?;
439448
440- let elf = if let Some ( elf_path) = args. elf . clone ( ) {
449+ let elf = if let Some ( elf_path) = args. monitor_args . elf . clone ( ) {
441450 let path = fs:: canonicalize ( elf_path) . into_diagnostic ( ) ?;
442451 let data = fs:: read ( path) . into_diagnostic ( ) ?;
443452
@@ -449,26 +458,18 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
449458 let chip = flasher. chip ( ) ;
450459 let target = chip. into_target ( ) ;
451460
461+ let mut monitor_args = args. monitor_args ;
462+
452463 // The 26MHz ESP32-C2's need to be treated as a special case.
453- let default_baud = if chip == Chip :: Esp32c2
464+ if chip == Chip :: Esp32c2
454465 && target. crystal_freq ( flasher. connection ( ) ) ? == XtalFrequency :: _26Mhz
466+ && monitor_args. baud_rate == 115_200
455467 {
456468 // 115_200 * 26 MHz / 40 MHz = 74_880
457- 74_880
458- } else {
459- 115_200
460- } ;
469+ monitor_args. baud_rate = 74_880 ;
470+ }
461471
462- monitor (
463- flasher. into_serial ( ) ,
464- elf. as_deref ( ) ,
465- pid,
466- args. connect_args . baud . unwrap_or ( default_baud) ,
467- args. log_format ,
468- !args. non_interactive ,
469- args. processors ,
470- args. elf ,
471- )
472+ monitor ( flasher. into_serial ( ) , elf. as_deref ( ) , pid, monitor_args)
472473}
473474
474475/// Convert the provided firmware image from ELF to binary
@@ -892,6 +893,9 @@ mod test {
892893 // Decimal
893894 assert_eq ! ( parse_u32( "1234" ) , Ok ( 1234 ) ) ;
894895 assert_eq ! ( parse_u32( "0" ) , Ok ( 0 ) ) ;
896+ // Underscores
897+ assert_eq ! ( parse_u32( "12_34" ) , Ok ( 1234 ) ) ;
898+ assert_eq ! ( parse_u32( "0X12_34" ) , Ok ( 0x1234 ) ) ;
895899 // Errors
896900 assert ! ( parse_u32( "" ) . is_err( ) ) ;
897901 assert ! ( parse_u32( "0x" ) . is_err( ) ) ;
0 commit comments