add --probe like present in cargo-flash
@@ -34,6 +34,12 @@ struct Opt {
config: Option<String>,
#[structopt(name = "chip", long = "chip")]
chip: Option<String>,
+ #[structopt(
+ long = "probe",
+ help = "Use this flag to select a specific probe in the list.\n\
+ Use '--probe VID:PID' or '--probe VID:PID:Serial' if you have more than one probe with the same VID:PID."
+ )]
+ probe_selector: Option<DebugProbeSelector>,
#[structopt(name = "list-chips", long = "list-chips")]
list_chips: bool,
#[structopt(name = "disable-progressbars", long = "disable-progressbars")]
@@ -60,7 +66,7 @@ struct Opt {
features: Vec<String>,
}
-const ARGUMENTS_TO_REMOVE: &[&str] = &["list-chips", "disable-progressbars", "chip="];
+const ARGUMENTS_TO_REMOVE: &[&str] = &["list-chips", "disable-progressbars", "chip=", "probe="];
fn main() {
match main_try() {
@@ -168,13 +174,17 @@ fn main_try() -> Result<()> {
));
// If we got a probe selector in the config, open the probe matching the selector if possible.
- let mut probe = match (config.probe.usb_vid.as_ref(), config.probe.usb_pid.as_ref()) {
+ let mut probe = if let Some(selector) = opt.probe_selector {
+ Probe::open(selector)?
+ } else {
+ match (config.probe.usb_vid.as_ref(), config.probe.usb_pid.as_ref()) {
(Some(vid), Some(pid)) => {
let selector = DebugProbeSelector {
vendor_id: u16::from_str_radix(vid, 16)?,
product_id: u16::from_str_radix(pid, 16)?,
serial_number: config.probe.serial.clone(),
};
+ // if two probes with the same VID:PID pair exist we just choose one
Probe::open(selector)?
}
_ => {
@@ -189,16 +199,22 @@ fn main_try() -> Result<()> {
// a single probe detected.
let list = Probe::list_all();
if list.len() > 1 {
- return Err(anyhow!("More than a single probe was detected. Use the [default.probe] config attribute \
+ return Err(anyhow!("The following devices were found:\n \
+ {} \
+ \
+ Use '--probe VID:PID'\n \
+ \
+ You can also set the [default.probe] config attribute \
(in your Embed.toml) to select which probe to use. \
- For usage examples see https://github.com/probe-rs/cargo-embed/blob/master/src/config/default.toml ."));
+ For usage examples see https://github.com/probe-rs/cargo-embed/blob/master/src/config/default.toml .",
+ list.iter().enumerate().map(|(num, link)| format!("[{}]: {:?}\n", num, link)).collect::<String>()));
}
-
Probe::open(
list.first()
.ok_or_else(|| anyhow!("No supported probe was found"))?,
)?
}
+ }
};
probe
