From ab3da9f87ca57153e6ffed5551e1f554b5953391 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Fri, 30 Dec 2022 21:05:57 +0000 Subject: [PATCH 1/3] Guard urclock_getsync() against initial spurious input --- src/avrdude.1 | 2 +- src/doc/avrdude.texi | 2 +- src/urclock.c | 25 ++++++++++--------------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/avrdude.1 b/src/avrdude.1 index 2365a161..8e3603a3 100644 --- a/src/avrdude.1 +++ b/src/avrdude.1 @@ -1270,7 +1270,7 @@ frame is programmed. .It Ar delay= Add a ms delay after reset. This can be useful if a board takes a particularly long time to exit from external reset. can be negative, -in which case the default 110-140 ms delay after issuing reset will be +in which case the default 80 ms delay after issuing reset will be shortened accordingly. .It Ar strict Urclock has a faster, but slightly different strategy than -c arduino to diff --git a/src/doc/avrdude.texi b/src/doc/avrdude.texi index a901b04b..a4c66d6c 100644 --- a/src/doc/avrdude.texi +++ b/src/doc/avrdude.texi @@ -1066,7 +1066,7 @@ frame is programmed. @item @samp{delay=} Add a ms delay after reset. This can be useful if a board takes a particularly long time to exit from external reset. can be negative, -in which case the default 110-140 ms delay after issuing reset will be +in which case the default 80 ms delay after issuing reset will be shortened accordingly. @item @samp{strict} Urclock has a faster, but slightly different strategy than -c arduino to diff --git a/src/urclock.c b/src/urclock.c index 7f32d88e..b582d049 100644 --- a/src/urclock.c +++ b/src/urclock.c @@ -1919,8 +1919,9 @@ static int urclock_recv(const PROGRAMMER *pgm, unsigned char *buf, size_t len) { rv = serial_recv(&pgm->fd, buf, len); if(rv < 0) { - if(!ur.sync_silence) - pmsg_error("programmer is not responding; try -xstrict and/or vary -xdelay=100\n"); + if(ur.sync_silence < 2) + pmsg_warning("programmer is not responding%s\n", + ur.sync_silence? "; try -xstrict and/or vary -xdelay=100": ""); return -1; } @@ -1960,7 +1961,8 @@ static int urclock_getsync(const PROGRAMMER *pgm) { */ autobaud_sync = part && part->autobaud_sync? part->autobaud_sync: Cmnd_STK_GET_SYNC; - ur.sync_silence = 1; + ur.sync_silence = 2; + serial_drain_timeout = 20; // ms for(attempt = 0; attempt < MAX_SYNC_ATTEMPTS; attempt++) { /* @@ -1985,6 +1987,7 @@ static int urclock_getsync(const PROGRAMMER *pgm) { if(!ur.gs.seen || iob[0] != ur.gs.stk_insync || iob[1] != ur.gs.stk_ok || iob[0] == iob[1]) { ur.gs.stk_insync = iob[0]; ur.gs.stk_ok = iob[1]; + serial_drain(&pgm->fd, 0); // Drain periodically to guard against initial line noise ur.gs.seen = 1; } else break; @@ -1994,7 +1997,8 @@ static int urclock_getsync(const PROGRAMMER *pgm) { usleep(slp*1000); } if(attempt > 5) { // Don't report first six attempts - ur.sync_silence = 0; + if(attempt == MAX_SYNC_ATTEMPTS-1) + ur.sync_silence = 1; pmsg_warning("attempt %d of %d: not in sync\n", attempt - 5, MAX_SYNC_ATTEMPTS-6); } } @@ -2239,17 +2243,8 @@ static int urclock_open(PROGRAMMER *pgm, const char *port) { // Set DTR and RTS back to high serial_set_dtr_rts(&pgm->fd, 1); -#ifndef WIN32 - if((100+ur.delay) > 0) - usleep((100+ur.delay)*1000); // Wait until board comes out of reset -#else - if((125+ur.delay) > 0) - usleep((125+ur.delay)*1000); // Wait until board starts up accommodating effective drain time -#endif - - // Drain any extraneous input - serial_drain_timeout = 20; // ms - serial_drain(&pgm->fd, 0); + if((80+ur.delay) > 0) + usleep((80+ur.delay)*1000); // Wait until board comes out of reset pmsg_debug("%4ld ms: enter urclock_getsync()\n", avr_mstimestamp()); if(urclock_getsync(pgm) < 0) From ac10272bb690a97ead2164c6ef37cc88eef9bc67 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Sat, 31 Dec 2022 12:27:07 +0000 Subject: [PATCH 2/3] Lengthen delay after reset for benefit of autobaud bootloaders --- src/avrdude.1 | 2 +- src/doc/avrdude.texi | 2 +- src/urclock.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/avrdude.1 b/src/avrdude.1 index 8e3603a3..41e4a6ad 100644 --- a/src/avrdude.1 +++ b/src/avrdude.1 @@ -1270,7 +1270,7 @@ frame is programmed. .It Ar delay= Add a ms delay after reset. This can be useful if a board takes a particularly long time to exit from external reset. can be negative, -in which case the default 80 ms delay after issuing reset will be +in which case the default 120 ms delay after issuing reset will be shortened accordingly. .It Ar strict Urclock has a faster, but slightly different strategy than -c arduino to diff --git a/src/doc/avrdude.texi b/src/doc/avrdude.texi index a4c66d6c..9e2e3116 100644 --- a/src/doc/avrdude.texi +++ b/src/doc/avrdude.texi @@ -1066,7 +1066,7 @@ frame is programmed. @item @samp{delay=} Add a ms delay after reset. This can be useful if a board takes a particularly long time to exit from external reset. can be negative, -in which case the default 80 ms delay after issuing reset will be +in which case the default 120 ms delay after issuing reset will be shortened accordingly. @item @samp{strict} Urclock has a faster, but slightly different strategy than -c arduino to diff --git a/src/urclock.c b/src/urclock.c index b582d049..33338e46 100644 --- a/src/urclock.c +++ b/src/urclock.c @@ -2243,8 +2243,8 @@ static int urclock_open(PROGRAMMER *pgm, const char *port) { // Set DTR and RTS back to high serial_set_dtr_rts(&pgm->fd, 1); - if((80+ur.delay) > 0) - usleep((80+ur.delay)*1000); // Wait until board comes out of reset + if((120+ur.delay) > 0) + usleep((120+ur.delay)*1000); // Wait until board comes out of reset pmsg_debug("%4ld ms: enter urclock_getsync()\n", avr_mstimestamp()); if(urclock_getsync(pgm) < 0) From 90dfee80ba9cb0f7d40339b89f66dc1d82b83573 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Sat, 31 Dec 2022 12:42:12 +0000 Subject: [PATCH 3/3] Change info on libreadline to notice2 level --- src/urclock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/urclock.c b/src/urclock.c index 33338e46..1d613e6a 100644 --- a/src/urclock.c +++ b/src/urclock.c @@ -2590,7 +2590,7 @@ void urclock_initpgm(PROGRAMMER *pgm) { #if defined(HAVE_LIBREADLINE) pmsg_notice2("libreadline is used; avrdude -t -c urclock should work interactively\n"); #else - pmsg_warning("compiled without readline library, cannot use avrdude -t -c urclock interactively\n"); - imsg_warning("but it is still possible to pipe: echo \"d fl 0 32; quit\" | tr \\; \\\\n | avrdude -t -curclock\n"); + pmsg_notice2("compiled without readline library, cannot use avrdude -t -c urclock interactively\n"); + imsg_notice2("but it is still possible to pipe: echo \"d fl 0 32; quit\" | tr \\; \\\\n | avrdude -t -curclock\n"); #endif }