Skip to content

Commit

Permalink
Merge pull request #1506 from stefanrueger/reduce-stk500v2-getsync-ti…
Browse files Browse the repository at this point in the history
…meout

Reduce stk500v2_getsync() timeout
  • Loading branch information
stefanrueger authored Sep 28, 2023
2 parents b76750d + 2c7c12d commit 70e5307
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/stk500v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,9 @@ int stk500v2_getsync(const PROGRAMMER *pgm) {
PDATA(pgm)->pgmtype == PGMTYPE_JTAGICE3)
return 0;

long bak_serial_recv_timeout = serial_recv_timeout;
serial_recv_timeout = 200;

retry:
tries++;

Expand All @@ -749,8 +752,7 @@ int stk500v2_getsync(const PROGRAMMER *pgm) {

// if we got bytes returned, check to see what came back
if (status > 0) {
if ((resp[0] == CMD_SIGN_ON) && (resp[1] == STATUS_CMD_OK) &&
(status > 3)) {
if (resp[0] == CMD_SIGN_ON && resp[1] == STATUS_CMD_OK && status > 3) {
// success!
unsigned int siglen = resp[2];
if (siglen >= strlen("STK500_2") &&
Expand All @@ -775,10 +777,12 @@ int stk500v2_getsync(const PROGRAMMER *pgm) {
PDATA(pgm)->pgmtype = PGMTYPE_STK500;
}
pmsg_debug("stk500v2_getsync(): found %s programmer\n", pgmname[PDATA(pgm)->pgmtype]);
serial_recv_timeout = bak_serial_recv_timeout;
return 0;
} else {
if (tries > RETRIES) {
pmsg_error("cannot communicate with device: resp=0x%02x\n", resp[0]);
serial_recv_timeout = bak_serial_recv_timeout;
return -6;
} else
goto retry;
Expand All @@ -788,6 +792,7 @@ int stk500v2_getsync(const PROGRAMMER *pgm) {
} else if (status == -1) {
if (tries > RETRIES) {
pmsg_error("timeout communicating with programmer\n");
serial_recv_timeout = bak_serial_recv_timeout;
return -1;
} else
goto retry;
Expand All @@ -800,6 +805,7 @@ int stk500v2_getsync(const PROGRAMMER *pgm) {
goto retry;
}

serial_recv_timeout = bak_serial_recv_timeout;
return 0;
}

Expand Down

0 comments on commit 70e5307

Please sign in to comment.