Skip to content

Commit

Permalink
Outputs an error message within send_recv, giving details of the fail…
Browse files Browse the repository at this point in the history
…ure.
  • Loading branch information
galexander1 committed Jun 4, 2016
1 parent e4a66cc commit 51b03e7
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,47 @@ ssize_t send_recv(struct stlink_libusb* handle, int terminate,
unsigned char* rxbuf, size_t rxsize) {
/* note: txbuf and rxbuf can point to the same area */
int res = 0;
int t;

if (libusb_bulk_transfer(handle->usb_handle, handle->ep_req,
t = libusb_bulk_transfer(handle->usb_handle, handle->ep_req,
txbuf,
txsize,
&res,
3000))
3000);
if (t) {
printf("[!] send_recv send request failed: %s\n", libusb_error_name(t));
return -1;
} else if ((size_t)res != txsize) {
printf("[!] send_recv send request wrote %d bytes (instead of %d).\n",
res, txsize);
}

if (rxsize != 0) {
if (libusb_bulk_transfer(handle->usb_handle, handle->ep_rep,
t = libusb_bulk_transfer(handle->usb_handle, handle->ep_rep,
rxbuf,
rxsize,
&res,
3000))
return -1;
3000);
if (t) {
printf("[!] send_recv read reply failed: %s\n",
libusb_error_name(t));
return -1;
}
}

if ((handle->protocoll == 1) && terminate) {
/* Read the SG reply */
unsigned char sg_buf[13];
if (libusb_bulk_transfer(handle->usb_handle, handle->ep_rep,
t = libusb_bulk_transfer(handle->usb_handle, handle->ep_rep,
sg_buf,
13,
&res,
3000))
3000);
if (t) {
printf("[!] send_recv read storage failed: %s\n",
libusb_error_name(t));
return -1;
}
/* The STLink doesn't seem to evaluate the sequence number */
handle->sg_transfer_idx++;
}
Expand Down

0 comments on commit 51b03e7

Please sign in to comment.