Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Allow listing and selecting probe #49

Merged
merged 1 commit into from
Sep 3, 2020
Merged

Conversation

aurelj
Copy link

@aurelj aurelj commented Sep 1, 2020

This provides options similar to cargo-flash to list all connected probes
and to specify which one to use:
probe-run --list-probes
probe-run --probe '1366:0101' --chip nrf52 bin
probe-run --probe '1366:0101:123456' --chip nrf52 bin

This also alows specifying the probe as en env-var:
PROBE_RUN_PROBE='1366:0101:123456' cargo run

It fixes #14.

Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This looks great. I left some comments.

src/main.rs Outdated
let selector: probe_rs::DebugProbeSelector = probe_opt.try_into()?;
probe_rs::Probe::open(selector)?
} else {
probes[0].open()?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you change this to throw an error if there's more than one probe? the error should say something like "more than one probe found; use --probe to specify which one to use"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good idea.

README.md Outdated
@@ -44,6 +44,16 @@ To support multiple devices, or permit overriding default behavior, you may pref
`${PROBE_RUN_CHIP}` environment variable, and set `runner` (or
`CARGO_TARGET_${TARGET_ARCH}_RUNNER`) to `probe-run`.

If you have several probes connected, you can specify which one to use adding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a note here indicating the syntax for the --probe flag? or say that the syntax can be found in the output of the -h command

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

@japaric
Copy link
Member

japaric commented Sep 2, 2020

Additional question: does the selector accept just the serial number (e.g. --probe 123456)? I think that the serial number is usually unique enough to select a probe.

src/main.rs Outdated
let probe = probes[0].open()?;
let probe = if let Some(probe_opt) = opts.probe.as_deref() {
let selector: probe_rs::DebugProbeSelector = probe_opt.try_into()?;
probe_rs::Probe::open(selector)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, it seems that if you pass "$VID:$PID" as the selector and there are two connected probes with that VID PID pair then this will pick the "first one" of those two -- calling probe-run a second time results in a probe-rs error ("probe could not be created"). In that scenario we should throw an error and ask the user to narrow down the selection using the serial number.

Is it possible to use DebugProbeSelector to filter a list of probes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

I don't think probe-rs provides a way to use a DebugProbeSelector to filter a list of probes. But it is easy enough to implement.

Updated version now requires that only 1 probe matches the DebugProbeSelector to continue.

@aurelj
Copy link
Author

aurelj commented Sep 2, 2020

Additional question: does the selector accept just the serial number (e.g. --probe 123456)? I think that the serial number is usually unique enough to select a probe.

No, in DebugProbeSelector, the vendor_id and product_id are not optional.

README.md Outdated
@@ -44,6 +44,17 @@ To support multiple devices, or permit overriding default behavior, you may pref
`${PROBE_RUN_CHIP}` environment variable, and set `runner` (or
`CARGO_TARGET_${TARGET_ARCH}_RUNNER`) to `probe-run`.

If you have several probes connected, you can specify which one to use adding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you have several probes connected, you can specify which one to use adding
If you have several probes connected, you can specify which one to use by adding

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

README.md Outdated
PROBE_RUN_PROBE='1366:0101:123456' cargo run
```

To list all connected probes run `probe-run --list-probes`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To list all connected probes run `probe-run --list-probes`.
To list all connected probes, run `probe-run --list-probes`.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

This provides options similar to cargo-flash to list all connected probes
and to specify which one to use:
  probe-run --list-probes
  probe-run --probe '1366:0101' --chip nrf52 bin
  probe-run --probe '1366:0101:123456' --chip nrf52 bin

This also alows specifying the probe as en env-var:
  PROBE_RUN_PROBE='1366:0101:123456' cargo run

It fixes knurling-rs#14.
Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic. Thank you!

@japaric japaric merged commit 3d7b480 into knurling-rs:main Sep 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add flag / env-var to select the probe by serial number
3 participants