Skip to content

Commit

Permalink
stm32/mboot: Remove the use of timeout in DFU_GETSTATUS.
Browse files Browse the repository at this point in the history
This is treated more like a "delay before continuing" in the spec and
official tools and does not appear to be really needed.  In particular,
downloading firmware is much slower with non-zero timeouts because the host
must pause by the timeout between sending each DFU_GETSTATUS to poll for
download/erase complete.
  • Loading branch information
pi-anl authored and dpgeorge committed Jul 1, 2020
1 parent 332d833 commit 95ec0de
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions ports/stm32/mboot/main.c
Expand Up @@ -800,28 +800,6 @@ static void dfu_init(void) {
dfu_context.addr = 0x08000000;
}

// The DFU_GETSTATUS response before dfu_process_dnload is run should include the needed timeout adjustments
static size_t get_timeout_ms(void) {
if (dfu_context.wBlockNum == 0) {
// download control commands
if (dfu_context.wLength >= 1 && dfu_context.buf[0] == DFU_CMD_DNLOAD_ERASE) {
if (dfu_context.wLength == 1) {
// mass erase command
// It takes 10-12 seconds to erase a 2MB stm part. Extrapolate a suitable timeout from this.
return APPLICATION_FLASH_LENGTH / 170;

} else if (dfu_context.wLength == 5) {
// erase page command
return 500;
}
}
} else if (dfu_context.wBlockNum > 1) {
// write data to memory command
return 500;
}
return 0;
}

static int dfu_process_dnload(void) {
int ret = -1;
if (dfu_context.wBlockNum == 0) {
Expand Down Expand Up @@ -922,11 +900,10 @@ static int dfu_handle_tx(int cmd, int arg, int len, uint8_t *buf, int max_len) {
default:
dfu_context.state = DFU_STATE_BUSY;
}
size_t timeout_ms = get_timeout_ms();
buf[0] = dfu_context.status; // bStatus
buf[1] = (timeout_ms >> 16) & 0xFF; // bwPollTimeout (ms)
buf[2] = (timeout_ms >> 8) & 0xFF; // bwPollTimeout (ms)
buf[3] = timeout_ms & 0xFF; // bwPollTimeout (ms)
buf[1] = 0; // bwPollTimeout_lsb (ms)
buf[2] = 0; // bwPollTimeout (ms)
buf[3] = 0; // bwPollTimeout_msb (ms)
buf[4] = dfu_context.state; // bState
buf[5] = dfu_context.error; // iString
// Clear errors now they've been sent
Expand Down

0 comments on commit 95ec0de

Please sign in to comment.