flash_loader: used timeout in ms

pull/1113/head
anton 2021-03-17 20:32:20 +05:00
rodzic 125cb2d763
commit ebcf04f02b
1 zmienionych plików z 9 dodań i 5 usunięć

Wyświetl plik

@ -3,6 +3,7 @@
#include <unistd.h>
#include <stlink.h>
#include <helper.h>
#include "flash_loader.h"
#define FLASH_REGS_BANK2_OFS 0x40
@ -313,7 +314,7 @@ int stlink_flash_loader_write_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t*
int stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, const uint8_t* buf, size_t size) {
struct stlink_reg rr;
int i = 0;
unsigned timeout;
size_t count = 0;
uint32_t flash_base = 0;
const char *error = NULL;
@ -368,16 +369,19 @@ int stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t targe
* 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 40
// wait until done (reaches breakpoint)
for (i = 0; i < WAIT_ROUNDS; i++) {
timeout = time_ms() + 500;
while (time_ms() < timeout) {
usleep(10000);
if (stlink_is_core_halted(sl)) { break; }
if (stlink_is_core_halted(sl)) {
timeout = 0;
break;
}
}
if (i >= WAIT_ROUNDS) {
if (timeout) {
error = "Flash loader run error";
goto error;
}