Check stk500_recv() actually worked before accepting SYNC byte

This commit is contained in:
Stefan Rueger 2022-07-24 18:48:22 +01:00
parent 4babe183da
commit 7310df030f
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
1 changed files with 3 additions and 5 deletions

View File

@ -91,8 +91,6 @@ int stk500_getsync(PROGRAMMER * pgm)
int attempt;
int max_sync_attempts;
/*
* get in sync */
buf[0] = Cmnd_STK_GET_SYNC;
buf[1] = Sync_CRC_EOP;
@ -119,11 +117,11 @@ int stk500_getsync(PROGRAMMER * pgm)
usleep(50*1000);
stk500_drain(pgm, 0);
}
stk500_send(pgm, buf, 2);
stk500_recv(pgm, resp, 1);
if (resp[0] == Resp_STK_INSYNC){
if(stk500_recv(pgm, resp, 1) >= 0 && resp[0] == Resp_STK_INSYNC)
break;
}
avrdude_message(MSG_INFO, "%s: stk500_getsync() attempt %d of %d: not in sync: resp=0x%02x\n",
progname, attempt + 1, max_sync_attempts, resp[0]);
}