From 5588abbf68e55f9f9f453b3137d02c77ba8acb3d Mon Sep 17 00:00:00 2001 From: "Brian S. Dean" Date: Wed, 5 Mar 2003 04:30:20 +0000 Subject: [PATCH] Fix stk500 page write (Program Page command). This is supported after all on non-paged-memory parts. The problem was that the page size was defaulting to 256 (maximum for the stk500), but the timeout for a response from the stk500 before declaring it dead was only 0.5 seconds. But it takes much longer than 0.5 seconds to program 256 bytes, so we just weren't waiting long enough. Fix this in two ways - increase the timeout to 5 seconds, and decrease the page size to 16 bytes for non-paged parts. The programming time for 16 bytes is short enough to provide the user with some feedback that something is happening. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@260 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrdude/avr.c | 32 +++++++++++++------------------- avrdude/stk500.c | 10 +++++----- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/avrdude/avr.c b/avrdude/avr.c index 36d21ea5..02207ea0 100644 --- a/avrdude/avr.c +++ b/avrdude/avr.c @@ -677,24 +677,6 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size, pgm->err_led(pgm, OFF); - if ((strcmp(m->desc, "flash")==0) || (strcmp(m->desc, "eeprom")==0)) { - if (pgm->paged_write != NULL) { - /* - * the programmer supports a paged mode write, perhaps more - * efficiently than we can read it directly, so use its routine - * instead - */ - if (m->paged) { - return pgm->paged_write(pgm, p, m, m->page_size, size); - } -#if 0 - else { - return pgm->paged_write(pgm, p, m, 32 /*pgm->page_size*/, size); - } -#endif - } - } - printed = 0; werror = 0; @@ -704,12 +686,24 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size, } else if (size > wsize) { fprintf(stderr, - "%s: WARNING: %d bytes requested, but memory region is only %d bytes\n" + "%s: WARNING: %d bytes requested, but memory region is only %d" + "bytes\n" "%sOnly %d bytes will actually be written\n", progname, size, wsize, progbuf, wsize); } + if ((strcmp(m->desc, "flash")==0) || (strcmp(m->desc, "eeprom")==0)) { + if (pgm->paged_write != NULL) { + /* + * the programmer supports a paged mode write, perhaps more + * efficiently than we can read it directly, so use its routine + * instead + */ + return pgm->paged_write(pgm, p, m, m->page_size, size); + } + } + for (i=0; ibuf[i]; if (verbose) { diff --git a/avrdude/stk500.c b/avrdude/stk500.c index e99bf034..add8c8f1 100644 --- a/avrdude/stk500.c +++ b/avrdude/stk500.c @@ -109,8 +109,8 @@ static int stk500_recv(PROGRAMMER * pgm, char * buf, int n) int nfds; int rc; - timeout.tv_sec = 0; - timeout.tv_usec = 500000; + timeout.tv_sec = 5; + timeout.tv_usec = 0; while (n) { FD_ZERO(&rfds); @@ -511,6 +511,8 @@ static int stk500_initialize(PROGRAMMER * pgm, AVRPART * p) retry: tries++; + memset(buf, 0, sizeof(buf)); + /* * set device programming parameters */ @@ -879,9 +881,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned int n; if (page_size == 0) { - fprintf(stderr, "%s: stk500_paged_write(): invalid page size = %d\n", - progname, page_size); - return -1; + page_size = 16; } if (strcmp(m->desc, "flash") == 0) {