Skip to content

Commit

Permalink
dfuse: Add "will-reset" option to download
Browse files Browse the repository at this point in the history
Some DFU downloads on STM32 MCUs (writing options bytes) require
system reset and will not change DFU status to dfuDNLOAD-IDLE.
This is describe in an ST document AN3156 section 5.1.

This commit allows such operations by adding -s :will-reset option.

https://sourceforge.net/p/dfu-util/tickets/36/
  • Loading branch information
Ievgenii Meshcheriakov authored and tormodvolden committed Jun 3, 2017
1 parent a23f1d7 commit 3332f92
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/dfuse.c
Expand Up @@ -46,6 +46,7 @@ static int dfuse_force = 0;
static int dfuse_leave = 0;
static int dfuse_unprotect = 0;
static int dfuse_mass_erase = 0;
static int dfuse_will_reset = 0;

unsigned int quad2uint(unsigned char *p)
{
Expand Down Expand Up @@ -103,6 +104,11 @@ void dfuse_parse_options(const char *options)
options += 10;
continue;
}
if (!strncmp(options, "will-reset", endword - options)) {
dfuse_will_reset = 1;
options += 10;
continue;
}

/* any valid number is interpreted as upload length */
number = strtoul(options, &end, 0);
Expand Down Expand Up @@ -275,7 +281,8 @@ int dfuse_dnload_chunk(struct dfu_if *dif, unsigned char *data, int size,
milli_sleep(dst.bwPollTimeout);
} while (dst.bState != DFU_STATE_dfuDNLOAD_IDLE &&
dst.bState != DFU_STATE_dfuERROR &&
dst.bState != DFU_STATE_dfuMANIFEST);
dst.bState != DFU_STATE_dfuMANIFEST &&
!(dfuse_will_reset && (dst.bState == DFU_STATE_dfuDNBUSY)));

if (dst.bState == DFU_STATE_dfuMANIFEST)
printf("Transitioning to dfuMANIFEST state\n");
Expand Down Expand Up @@ -677,7 +684,9 @@ int dfuse_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file,
}
free_segment_list(mem_layout);

dfu_abort_to_idle(dif);
if (!dfuse_will_reset) {
dfu_abort_to_idle(dif);
}

if (dfuse_leave) {
dfuse_special_command(dif, dfuse_address, SET_ADDRESS);
Expand Down

0 comments on commit 3332f92

Please sign in to comment.