Skip to content

Commit

Permalink
cmsis-dap: Increase USB timeout for v2 to 1s (#2205)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiwalun authored Feb 18, 2024
1 parent 9f2ae82 commit d54e584
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog/fixed-increas-cmsis-dap-usb-timeout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmsis-dap: Increase USB timeout to 1s.
24 changes: 12 additions & 12 deletions probe-rs/src/probe/cmsisdap/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::io::ErrorKind;
use std::str::Utf8Error;
use std::time::Duration;

const USB_TIMEOUT: Duration = Duration::from_millis(1000);

#[derive(Debug, thiserror::Error)]
pub enum CmsisDapError {
#[error("Error handling CMSIS-DAP command {command_id:?}")]
Expand Down Expand Up @@ -95,17 +97,16 @@ impl CmsisDapDevice {
/// Read from the probe into `buf`, returning the number of bytes read on success.
fn read(&self, buf: &mut [u8]) -> Result<usize, SendError> {
match self {
CmsisDapDevice::V1 { handle, .. } => match handle.read_timeout(buf, 1000)? {
// Timeout is not indicated by error, but by returning 0 read bytes
0 => Err(SendError::Timeout),
n => Ok(n),
},
CmsisDapDevice::V2 { handle, in_ep, .. } => {
let timeout = Duration::from_millis(100);
handle
.read_bulk(*in_ep, buf, timeout)
.map_err(SendError::UsbError)
CmsisDapDevice::V1 { handle, .. } => {
match handle.read_timeout(buf, USB_TIMEOUT.as_millis() as i32)? {
// Timeout is not indicated by error, but by returning 0 read bytes
0 => Err(SendError::Timeout),
n => Ok(n),
}
}
CmsisDapDevice::V2 { handle, in_ep, .. } => handle
.read_bulk(*in_ep, buf, USB_TIMEOUT)
.map_err(SendError::UsbError),
}
}

Expand All @@ -114,10 +115,9 @@ impl CmsisDapDevice {
match self {
CmsisDapDevice::V1 { handle, .. } => Ok(handle.write(buf)?),
CmsisDapDevice::V2 { handle, out_ep, .. } => {
let timeout = Duration::from_millis(100);
// Skip first byte as it's set to 0 for HID transfers
handle
.write_bulk(*out_ep, &buf[1..], timeout)
.write_bulk(*out_ep, &buf[1..], USB_TIMEOUT)
.map_err(SendError::UsbError)
}
}
Expand Down

0 comments on commit d54e584

Please sign in to comment.