Skip to content

Commit

Permalink
Trying to call get_status when it fails, resulting in huge speed bump
Browse files Browse the repository at this point in the history
Speeding up DFU
  • Loading branch information
Gregwar committed Dec 16, 2020
1 parent 37a393d commit 4953f7d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
56 changes: 30 additions & 26 deletions src/dfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,32 +133,36 @@ int dfu_get_status( struct dfu_if *dif, struct dfu_status *status )
unsigned char buffer[6];
int result;

/* Initialize the status data structure */
status->bStatus = DFU_STATUS_ERROR_UNKNOWN;
status->bwPollTimeout = 0;
status->bState = STATE_DFU_ERROR;
status->iString = 0;

result = libusb_control_transfer( dif->dev_handle,
/* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
/* bRequest */ DFU_GETSTATUS,
/* wValue */ 0,
/* wIndex */ dif->interface,
/* Data */ buffer,
/* wLength */ 6,
dfu_timeout );

if( 6 == result ) {
status->bStatus = buffer[0];
if (dif->quirks & QUIRK_POLLTIMEOUT)
status->bwPollTimeout = DEFAULT_POLLTIMEOUT;
else
status->bwPollTimeout = ((0xff & buffer[3]) << 16) |
((0xff & buffer[2]) << 8) |
(0xff & buffer[1]);
status->bState = buffer[4];
status->iString = buffer[5];
}
do {
/* Initialize the status data structure */
status->bStatus = DFU_STATUS_ERROR_UNKNOWN;
status->bwPollTimeout = 0;
status->bState = STATE_DFU_ERROR;
status->iString = 0;

result = libusb_control_transfer( dif->dev_handle,
/* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
/* bRequest */ DFU_GETSTATUS,
/* wValue */ 0,
/* wIndex */ dif->interface,
/* Data */ buffer,
/* wLength */ 6,
dfu_timeout );

if( 6 == result ) {
status->bStatus = buffer[0];
if (dif->quirks & QUIRK_POLLTIMEOUT)
status->bwPollTimeout = DEFAULT_POLLTIMEOUT;
else
status->bwPollTimeout = ((0xff & buffer[3]) << 16) |
((0xff & buffer[2]) << 8) |
(0xff & buffer[1]);
status->bState = buffer[4];
status->iString = buffer[5];
} else {
milli_sleep(8);
}
} while (result != 6);

return result;
}
Expand Down
2 changes: 0 additions & 2 deletions src/dfu_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ off_t dfuload_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file
dst.bState == DFU_STATE_dfuERROR)
break;

/* Wait while device executes flashing */
milli_sleep(dst.bwPollTimeout);
if (verbose > 1)
fprintf(stderr, "Poll timeout %i ms\n", dst.bwPollTimeout);

Expand Down
2 changes: 0 additions & 2 deletions src/dfuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ static int dfuse_special_command(struct dfu_if *dif, unsigned int address,
/* wait while command is executed */
if (verbose > 1)
fprintf(stderr, " Poll timeout %i ms\n", polltimeout);
milli_sleep(polltimeout);
if (command == READ_UNPROTECT)
return ret;
/* Workaround for e.g. Black Magic Probe getting stuck */
Expand Down Expand Up @@ -298,7 +297,6 @@ static int dfuse_dnload_chunk(struct dfu_if *dif, unsigned char *data, int size,
errx(EX_IOERR, "Error during download get_status");
return ret;
}
milli_sleep(dst.bwPollTimeout);
} while (dst.bState != DFU_STATE_dfuDNLOAD_IDLE &&
dst.bState != DFU_STATE_dfuERROR &&
dst.bState != DFU_STATE_dfuMANIFEST &&
Expand Down

0 comments on commit 4953f7d

Please sign in to comment.