Add serial number readout to stlink handling
@@ -5,6 +5,7 @@ use crate::probe::{DebugProbeInfo, DebugProbeType};
use super::usb_interface::USB_PID_EP_MAP;
use super::usb_interface::USB_VID;
+use std::time::Duration;
fn is_stlink_device<T: UsbContext>(device: &Device<T>) -> bool {
// Check the VID/PID.
@@ -22,18 +23,24 @@ pub fn list_stlink_devices() -> Vec<DebugProbeInfo> {
devices
.iter()
.filter(is_stlink_device)
- .map(|d| {
- let descriptor = d
- .device_descriptor()
- .expect("This is a bug. Please report it.");
- DebugProbeInfo::new(
- "STLink ".to_owned()
- + &USB_PID_EP_MAP[&descriptor.product_id()].version_name,
+ .filter_map(|device| {
+ let timeout = Duration::from_millis(100);
+ let descriptor = device.device_descriptor().ok()?;
+ let handle = device.open().ok()?;
+ let language = handle.read_languages(timeout).ok()?[0];
+ let sn_str = handle
+ .read_serial_number_string(language, &descriptor, timeout)
+ .ok();
+ Some(DebugProbeInfo::new(
+ format!(
+ "STLink {}",
+ &USB_PID_EP_MAP[&descriptor.product_id()].version_name
+ ),
descriptor.vendor_id(),
descriptor.product_id(),
- None,
+ sn_str,
DebugProbeType::STLink,
- )
+ ))
})
.collect::<Vec<_>>()
} else {
