@@ -7,7 +7,12 @@ use std::{
7
7
use cargo_metadata:: { Message , MetadataCommand } ;
8
8
use clap:: { Args , CommandFactory , Parser , Subcommand } ;
9
9
use espflash:: {
10
- cli:: { self , config:: Config , monitor:: monitor, * } ,
10
+ cli:: {
11
+ self ,
12
+ config:: { Config , PortConfig } ,
13
+ monitor:: monitor,
14
+ * ,
15
+ } ,
11
16
flasher:: FlashSize ,
12
17
logging:: initialize_logger,
13
18
targets:: { Chip , XtalFrequency } ,
@@ -225,24 +230,27 @@ fn main() -> Result<()> {
225
230
// Load any user configuration, if present.
226
231
let config = Config :: load ( ) ?;
227
232
233
+ // Load any user ports configuration, if present.
234
+ let ports_config = PortConfig :: load ( ) ?;
235
+
228
236
// Execute the correct action based on the provided subcommand and its
229
237
// associated arguments.
230
238
match args {
231
- Commands :: BoardInfo ( args) => board_info ( & args, & config) ,
232
- Commands :: ChecksumMd5 ( args) => checksum_md5 ( & args, & config) ,
239
+ Commands :: BoardInfo ( args) => board_info ( & args, & config, & ports_config ) ,
240
+ Commands :: ChecksumMd5 ( args) => checksum_md5 ( & args, & config, & ports_config ) ,
233
241
Commands :: Completions ( args) => completions ( & args, & mut Cli :: command ( ) , "cargo" ) ,
234
- Commands :: EraseFlash ( args) => erase_flash ( args, & config) ,
235
- Commands :: EraseParts ( args) => erase_parts ( args, & config) ,
236
- Commands :: EraseRegion ( args) => erase_region ( args, & config) ,
237
- Commands :: Flash ( args) => flash ( args, & config) ,
238
- Commands :: HoldInReset ( args) => hold_in_reset ( args, & config) ,
239
- Commands :: ListPorts ( args) => list_ports ( & args, & config ) ,
240
- Commands :: Monitor ( args) => serial_monitor ( args, & config) ,
242
+ Commands :: EraseFlash ( args) => erase_flash ( args, & config, & ports_config ) ,
243
+ Commands :: EraseParts ( args) => erase_parts ( args, & config, & ports_config ) ,
244
+ Commands :: EraseRegion ( args) => erase_region ( args, & config, & ports_config ) ,
245
+ Commands :: Flash ( args) => flash ( args, & config, & ports_config ) ,
246
+ Commands :: HoldInReset ( args) => hold_in_reset ( args, & config, & ports_config ) ,
247
+ Commands :: ListPorts ( args) => list_ports ( & args, & ports_config ) ,
248
+ Commands :: Monitor ( args) => serial_monitor ( args, & config, & ports_config ) ,
241
249
Commands :: PartitionTable ( args) => partition_table ( args) ,
242
- Commands :: ReadFlash ( args) => read_flash ( args, & config) ,
243
- Commands :: Reset ( args) => reset ( args, & config) ,
250
+ Commands :: ReadFlash ( args) => read_flash ( args, & config, & ports_config ) ,
251
+ Commands :: Reset ( args) => reset ( args, & config, & ports_config ) ,
244
252
Commands :: SaveImage ( args) => save_image ( args, & config) ,
245
- Commands :: WriteBin ( args) => write_bin ( args, & config) ,
253
+ Commands :: WriteBin ( args) => write_bin ( args, & config, & ports_config ) ,
246
254
}
247
255
}
248
256
@@ -253,7 +261,7 @@ struct BuildContext {
253
261
pub partition_table_path : Option < PathBuf > ,
254
262
}
255
263
256
- pub fn erase_parts ( args : ErasePartsArgs , config : & Config ) -> Result < ( ) > {
264
+ pub fn erase_parts ( args : ErasePartsArgs , config : & Config , ports_config : & PortConfig ) -> Result < ( ) > {
257
265
if args. connect_args . no_stub {
258
266
return Err ( EspflashError :: StubRequired ) . into_diagnostic ( ) ;
259
267
}
@@ -263,7 +271,7 @@ pub fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
263
271
. as_deref ( )
264
272
. or ( config. partition_table . as_deref ( ) ) ;
265
273
266
- let mut flasher = connect ( & args. connect_args , config, false , false ) ?;
274
+ let mut flasher = connect ( & args. connect_args , config, ports_config , false , false ) ?;
267
275
let chip = flasher. chip ( ) ;
268
276
let partition_table = match partition_table {
269
277
Some ( path) => Some ( parse_partition_table ( path) ?) ,
@@ -280,13 +288,14 @@ pub fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
280
288
Ok ( ( ) )
281
289
}
282
290
283
- fn flash ( args : FlashArgs , config : & Config ) -> Result < ( ) > {
291
+ fn flash ( args : FlashArgs , config : & Config , ports_config : & PortConfig ) -> Result < ( ) > {
284
292
let metadata = PackageMetadata :: load ( & args. build_args . package ) ?;
285
293
let cargo_config = CargoConfig :: load ( & metadata. workspace_root , & metadata. package_root ) ;
286
294
287
295
let mut flasher = connect (
288
296
& args. connect_args ,
289
297
config,
298
+ ports_config,
290
299
args. flash_args . no_verify ,
291
300
args. flash_args . no_skip ,
292
301
) ?;
0 commit comments