Skip to content

Commit 4953f7d

Browse files
committed
Trying to call get_status when it fails, resulting in huge speed bump
Speeding up DFU
1 parent 37a393d commit 4953f7d

3 files changed

Lines changed: 30 additions & 30 deletions

File tree

src/dfu.c

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,32 +133,36 @@ int dfu_get_status( struct dfu_if *dif, struct dfu_status *status )
133133
unsigned char buffer[6];
134134
int result;
135135

136-
/* Initialize the status data structure */
137-
status->bStatus = DFU_STATUS_ERROR_UNKNOWN;
138-
status->bwPollTimeout = 0;
139-
status->bState = STATE_DFU_ERROR;
140-
status->iString = 0;
141-
142-
result = libusb_control_transfer( dif->dev_handle,
143-
/* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
144-
/* bRequest */ DFU_GETSTATUS,
145-
/* wValue */ 0,
146-
/* wIndex */ dif->interface,
147-
/* Data */ buffer,
148-
/* wLength */ 6,
149-
dfu_timeout );
150-
151-
if( 6 == result ) {
152-
status->bStatus = buffer[0];
153-
if (dif->quirks & QUIRK_POLLTIMEOUT)
154-
status->bwPollTimeout = DEFAULT_POLLTIMEOUT;
155-
else
156-
status->bwPollTimeout = ((0xff & buffer[3]) << 16) |
157-
((0xff & buffer[2]) << 8) |
158-
(0xff & buffer[1]);
159-
status->bState = buffer[4];
160-
status->iString = buffer[5];
161-
}
136+
do {
137+
/* Initialize the status data structure */
138+
status->bStatus = DFU_STATUS_ERROR_UNKNOWN;
139+
status->bwPollTimeout = 0;
140+
status->bState = STATE_DFU_ERROR;
141+
status->iString = 0;
142+
143+
result = libusb_control_transfer( dif->dev_handle,
144+
/* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
145+
/* bRequest */ DFU_GETSTATUS,
146+
/* wValue */ 0,
147+
/* wIndex */ dif->interface,
148+
/* Data */ buffer,
149+
/* wLength */ 6,
150+
dfu_timeout );
151+
152+
if( 6 == result ) {
153+
status->bStatus = buffer[0];
154+
if (dif->quirks & QUIRK_POLLTIMEOUT)
155+
status->bwPollTimeout = DEFAULT_POLLTIMEOUT;
156+
else
157+
status->bwPollTimeout = ((0xff & buffer[3]) << 16) |
158+
((0xff & buffer[2]) << 8) |
159+
(0xff & buffer[1]);
160+
status->bState = buffer[4];
161+
status->iString = buffer[5];
162+
} else {
163+
milli_sleep(8);
164+
}
165+
} while (result != 6);
162166

163167
return result;
164168
}

src/dfu_load.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ off_t dfuload_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file
141141
dst.bState == DFU_STATE_dfuERROR)
142142
break;
143143

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

src/dfuse.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ static int dfuse_special_command(struct dfu_if *dif, unsigned int address,
259259
/* wait while command is executed */
260260
if (verbose > 1)
261261
fprintf(stderr, " Poll timeout %i ms\n", polltimeout);
262-
milli_sleep(polltimeout);
263262
if (command == READ_UNPROTECT)
264263
return ret;
265264
/* Workaround for e.g. Black Magic Probe getting stuck */
@@ -298,7 +297,6 @@ static int dfuse_dnload_chunk(struct dfu_if *dif, unsigned char *data, int size,
298297
errx(EX_IOERR, "Error during download get_status");
299298
return ret;
300299
}
301-
milli_sleep(dst.bwPollTimeout);
302300
} while (dst.bState != DFU_STATE_dfuDNLOAD_IDLE &&
303301
dst.bState != DFU_STATE_dfuERROR &&
304302
dst.bState != DFU_STATE_dfuMANIFEST &&

0 commit comments

Comments
 (0)