Skip to content

Commit

Permalink
Fixed long wait when the loader refuses to run. Fixes #290
Browse files Browse the repository at this point in the history
  • Loading branch information
rewolff committed Mar 19, 2020
1 parent 13c6211 commit b8813fa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/flash_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,20 @@ int stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t targe
/* run loader */
stlink_run(sl);

#define WAIT_ROUNDS 10000
// This piece of code used to try to spin for .1 second by waiting
// doing 10000 rounds of 10 microseconds. But because this usually runs
// on Unix-like OSes, the 10 microseconds get rounded up to the "tick"
// (actually almost two ticks) of the system. 1 milisecond. Thus, the
// ten thousand attempts, when "something goes wrong" that requires
// the error message "flash loader run error" would wait for something
// like 20 seconds before coming up with the error.
// by increasing the sleep-per-round to the same order-of-magnitude as
// the tick-rounding that the OS uses, the wait until the error message is
// reduced to the same order of magnitude as what was intended. -- REW.
#define WAIT_ROUNDS 100
/* wait until done (reaches breakpoint) */
for (i = 0; i < WAIT_ROUNDS; i++) {
usleep(10);
usleep(1000);
if (stlink_is_core_halted(sl))
break;
}
Expand Down

0 comments on commit b8813fa

Please sign in to comment.