Index: arduino.c =================================================================== --- arduino.c (revision 1391) +++ arduino.c (working copy) @@ -80,6 +80,22 @@ return 3; } +static void arduino_frob_reset(PROGRAMMER * pgm) +{ + static bool dtr = 0; + + avrdude_message(MSG_INFO, "%s: arduino_frob_reset(): DTR is %sheld\n", + progname, dtr ? "" : "not "); + /* Clear DTR and RTS to unload the RESET capacitor + * (for example in Arduino) */ + serial_set_dtr_rts(&pgm->fd, 1 ^ dtr); + usleep(250*1000); + /* Set DTR and RTS back to high */ + serial_set_dtr_rts(&pgm->fd, 0 ^ dtr); + usleep(50*1000); + dtr = dtr ^ 1; +} + static int arduino_open(PROGRAMMER * pgm, char * port) { union pinfo pinfo; @@ -89,13 +105,7 @@ return -1; } - /* Clear DTR and RTS to unload the RESET capacitor - * (for example in Arduino) */ - serial_set_dtr_rts(&pgm->fd, 0); - usleep(250*1000); - /* Set DTR and RTS back to high */ - serial_set_dtr_rts(&pgm->fd, 1); - usleep(50*1000); + arduino_frob_reset(pgm); /* * drain any extraneous input @@ -129,4 +139,5 @@ pgm->read_sig_bytes = arduino_read_sig_bytes; pgm->open = arduino_open; pgm->close = arduino_close; + pgm->frob_reset = arduino_frob_reset; } Index: libavrdude.h =================================================================== --- libavrdude.h (revision 1391) +++ libavrdude.h (working copy) @@ -650,6 +650,7 @@ unsigned char *res, int count); int (*open) (struct programmer_t * pgm, char * port); void (*close) (struct programmer_t * pgm); + void (*frob_reset) (struct programmer_t * pgm); int (*paged_write) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes); Index: pgm.c =================================================================== --- pgm.c (revision 1391) +++ pgm.c (working copy) @@ -134,6 +134,7 @@ pgm->parseextparams = NULL; pgm->setup = NULL; pgm->teardown = NULL; + pgm->frob_reset = NULL; return pgm; } Index: stk500.c =================================================================== --- stk500.c (revision 1391) +++ stk500.c (working copy) @@ -99,13 +99,13 @@ * First send and drain a few times to get rid of line noise */ - stk500_send(pgm, buf, 2); - stk500_drain(pgm, 0); - stk500_send(pgm, buf, 2); - stk500_drain(pgm, 0); for (attempt = 0; attempt < MAX_SYNC_ATTEMPTS; attempt++) { stk500_send(pgm, buf, 2); + stk500_drain(pgm, 0); + stk500_send(pgm, buf, 2); + stk500_drain(pgm, 0); + stk500_send(pgm, buf, 2); stk500_recv(pgm, resp, 1); if (resp[0] == Resp_STK_INSYNC){ break; @@ -112,6 +112,7 @@ } 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]); + if(pgm->frob_reset) pgm->frob_reset(pgm); } if (attempt == MAX_SYNC_ATTEMPTS) { stk500_drain(pgm, 0);