From 94f22b15ee67a15285ea1b21ee738afa07de1180 Mon Sep 17 00:00:00 2001 From: "Brian S. Dean" Date: Sun, 1 Dec 2002 15:05:56 +0000 Subject: [PATCH] The STK500 can perform paged read/write operations even on standard "non-paged" parts. Take advantage of that and use the faster internal routines of the STK500 for those parts as well. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@162 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrdude/avr.c | 42 +++++++++---- avrdude/avrdude.conf.sample | 114 ++++++++++++++++++++---------------- avrdude/main.c | 8 ++- avrdude/pgm.h | 5 +- avrdude/stk500.c | 44 +++++++------- 5 files changed, 124 insertions(+), 89 deletions(-) diff --git a/avrdude/avr.c b/avrdude/avr.c index b1013533..5ea05f9d 100644 --- a/avrdude/avr.c +++ b/avrdude/avr.c @@ -374,12 +374,20 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size, size = mem->size; } - if (mem->paged && pgm->paged_load != NULL) { - /* - * the programmer directly supports writing this memory, perhaps - * more efficiently than we can from here - */ - return pgm->paged_load(pgm, p, mem, size); + if ((strcmp(mem->desc, "flash")==0) || (strcmp(mem->desc, "eeprom")==0)) { + if (pgm->paged_load != NULL) { + /* + * the programmer supports a paged mode read, perhaps more + * efficiently than we can read it directly, so use its routine + * instead + */ + if (mem->paged) { + return pgm->paged_load(pgm, p, mem, mem->page_size, size); + } + else { + return pgm->paged_load(pgm, p, mem, pgm->page_size, size); + } + } } @@ -434,7 +442,7 @@ int avr_write_page(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, * if this memory is word-addressable, adjust the address * accordingly */ - if (mem->op[AVR_OP_LOADPAGE_LO]) + if ((mem->op[AVR_OP_LOADPAGE_LO]) || (mem->op[AVR_OP_READ_LO])) addr = addr / 2; pgm->pgm_led(pgm, ON); @@ -674,12 +682,20 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size, pgm->err_led(pgm, OFF); - if (m->paged && pgm->paged_write != NULL) { - /* - * the programmer directly supports writing this memory, perhaps - * more efficiently than we can from here - */ - return pgm->paged_write(pgm, p, m, size); + 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); + } + else { + return pgm->paged_write(pgm, p, m, pgm->page_size, size); + } + } } printed = 0; diff --git a/avrdude/avrdude.conf.sample b/avrdude/avrdude.conf.sample index 1385c09f..555b908c 100644 --- a/avrdude/avrdude.conf.sample +++ b/avrdude/avrdude.conf.sample @@ -15,6 +15,7 @@ # programmer # id = [, [, ] ...] ; # are quoted strings # desc = ; # quoted string +# type = ppi | stk500 ; # programmer type # vcc = [, ... ] ; # pin number(s) # reset = ; # pin number # sck = ; # pin number @@ -29,6 +30,7 @@ # part # id = ; # quoted string # desc = ; # quoted string +# devicecode = ; # numeric # chip_erase_delay = ; # micro-seconds # pgm_enable = ; # chip_erase = ; @@ -60,6 +62,8 @@ # complain. # # NOTES: +# * 'devicecode' is the device code used by the STK500 (see codes +# listed below) # * Not all memory types will implement all instructions. # * AVR Fuse bits and Lock bits are implemented as a type of memory. # * Example memory types are: @@ -106,6 +110,64 @@ # # See below for some examples. # +# +# The following are STK500 part device codes to use for the +# "devicecode" field of the part. These came from Atmel's software +# section avr061.zip which accompanies the application note +# AVR061 available from: +# +# http://www.atmel.com/atmel/acrobat/doc2525.pdf +# + +#define ATTINY10 0x10 +#define ATTINY11 0x11 +#define ATTINY12 0x12 + +#define ATTINY22 0x20 +#define ATTINY26 0x21 +#define ATTINY28 0x22 + +#define AT90S1200 0x33 + +#define AT90S2313 0x40 +#define AT90S2323 0x41 +#define AT90S2333 0x42 +#define AT90S2343 0x43 + +#define AT90S4414 0x50 +#define AT90S4433 0x51 +#define AT90S4434 0x52 + +#define AT90S8515 0x60 +#define AT90S8535 0x61 +#define AT90C8534 0x62 +#define ATMEGA8515 0x63 +#define ATMEGA8535 0x64 + +#define ATMEGA8 0x70 + +#define ATMEGA161 0x80 +#define ATMEGA163 0x81 +#define ATMEGA16 0x82 +#define ATMEGA162 0x83 +#define ATMEGA169 0x84 + +#define ATMEGA323 0x90 +#define ATMEGA32 0x91 + +#define ATMEGA103 0xB1 +#define ATMEGA128 0xB2 + +#define AT86RF401 0xD0 + +#define AT89START 0xE0 +#define AT89S51 0xE0 +#define AT89S52 0xE1 + + +# +# PROGRAMMER DEFINITIONS +# programmer id = "bsd", "default"; @@ -165,55 +227,9 @@ programmer - - - -#define ATTINY10 0x10 -#define ATTINY11 0x11 -#define ATTINY12 0x12 - -#define ATTINY22 0x20 -#define ATTINY26 0x21 -#define ATTINY28 0x22 - -#define AT90S1200 0x33 - -#define AT90S2313 0x40 -#define AT90S2323 0x41 -#define AT90S2333 0x42 -#define AT90S2343 0x43 - -#define AT90S4414 0x50 -#define AT90S4433 0x51 -#define AT90S4434 0x52 - -#define AT90S8515 0x60 -#define AT90S8535 0x61 -#define AT90C8534 0x62 -#define ATMEGA8515 0x63 -#define ATMEGA8535 0x64 - -#define ATMEGA8 0x70 - -#define ATMEGA161 0x80 -#define ATMEGA163 0x81 -#define ATMEGA16 0x82 -#define ATMEGA162 0x83 -#define ATMEGA169 0x84 - -#define ATMEGA323 0x90 -#define ATMEGA32 0x91 - -#define ATMEGA103 0xB1 -#define ATMEGA128 0xB2 - -#define AT86RF401 0xD0 - -#define AT89START 0xE0 -#define AT89S51 0xE0 -#define AT89S52 0xE1 - - +# +# PART DEFINITIONS +# part diff --git a/avrdude/main.c b/avrdude/main.c index 8e0dd9a8..00afc71d 100644 --- a/avrdude/main.c +++ b/avrdude/main.c @@ -103,9 +103,10 @@ extern char * lists_version; extern char * main_version; extern char * pgm_version; extern char * ppi_version; +extern char * stk500_version; extern char * term_version; -#define N_MODULES 8 +#define N_MODULES 9 char ** modules[N_MODULES] = { &avr_version, @@ -115,10 +116,11 @@ char ** modules[N_MODULES] = { &main_version, &pgm_version, &ppi_version, + &stk500_version, &term_version }; -char * version = "2.1.5"; +char * version = "3.0.0"; char * main_version = "$Id$"; @@ -189,7 +191,7 @@ int parse_cvsid(char * cvsid, char * name, char * rev, char * datetime) { int i, j; - if (strncmp(cvsid,"$Id: ",5) != 0) + if (strncmp(cvsid,"$Id: ", 5) != 0) return -1; name[0] = 0; diff --git a/avrdude/pgm.h b/avrdude/pgm.h index 83e8db55..8674d3c7 100644 --- a/avrdude/pgm.h +++ b/avrdude/pgm.h @@ -53,6 +53,7 @@ typedef struct programmer_t { unsigned int pinno[N_PINS]; int ppidata; int fd; + int page_size; /* page size if the programmer supports paged write/load */ int (*rdy_led) (struct programmer_t * pgm, int value); int (*err_led) (struct programmer_t * pgm, int value); int (*pgm_led) (struct programmer_t * pgm, int value); @@ -72,9 +73,9 @@ typedef struct programmer_t { void (*open) (struct programmer_t * pgm, char * port); void (*close) (struct programmer_t * pgm); int (*paged_write) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, - int n_bytes); + int page_size, int n_bytes); int (*paged_load) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, - int n_bytes); + int page_size, int n_bytes); } PROGRAMMER; diff --git a/avrdude/stk500.c b/avrdude/stk500.c index bd9bd379..462c740a 100644 --- a/avrdude/stk500.c +++ b/avrdude/stk500.c @@ -737,7 +737,8 @@ static int loadaddr(PROGRAMMER * pgm, uint16_t addr) } -int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) +int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, + int page_size, int n_bytes) { unsigned char buf[16]; int memtype; @@ -747,9 +748,6 @@ int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) int tries; unsigned int n; - if (!m->paged) - return -1; - if (strcmp(m->desc, "flash") == 0) { memtype = 'F'; } @@ -760,7 +758,7 @@ int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) return -2; } - if (m->op[AVR_OP_LOADPAGE_LO]) + if ((m->op[AVR_OP_LOADPAGE_LO]) || (m->op[AVR_OP_READ_LO])) a_div = 2; else a_div = 1; @@ -770,26 +768,26 @@ int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) n = m->size; } else { - if ((n_bytes % m->page_size) != 0) { - n = n_bytes + m->page_size - (n_bytes % m->page_size); + if ((n_bytes % page_size) != 0) { + n = n_bytes + page_size - (n_bytes % page_size); } else { n = n_bytes; } } - for (addr = 0; addr < n; addr += m->page_size) { + for (addr = 0; addr < n; addr += page_size) { fprintf(stderr, "\r \r%6u", addr); tries = 0; retry: tries++; loadaddr(pgm, addr/a_div); buf[0] = Cmnd_STK_PROG_PAGE; - buf[1] = (m->page_size >> 8) & 0xff; - buf[2] = m->page_size & 0xff; + buf[1] = (page_size >> 8) & 0xff; + buf[2] = page_size & 0xff; buf[3] = memtype; send(pgm, buf, 4); - for (i=0; ipage_size; i++) { + for (i=0; ibuf[addr + i]; send(pgm, buf, 1); } @@ -830,7 +828,8 @@ int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) } -int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) +int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, + int page_size, int n_bytes) { unsigned char buf[16]; int memtype; @@ -839,9 +838,6 @@ int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) int tries; unsigned int n; - if (!m->paged) - return -1; - if (strcmp(m->desc, "flash") == 0) { memtype = 'F'; } @@ -852,7 +848,7 @@ int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) return -2; } - if (m->op[AVR_OP_LOADPAGE_LO]) + if ((m->op[AVR_OP_LOADPAGE_LO]) || (m->op[AVR_OP_READ_LO])) a_div = 2; else a_div = 1; @@ -862,23 +858,26 @@ int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) n = m->size; } else { - if ((n_bytes % m->page_size) != 0) { - n = n_bytes + m->page_size - (n_bytes % m->page_size); + if ((n_bytes % page_size) != 0) { + n = n_bytes + page_size - (n_bytes % page_size); } else { n = n_bytes; } } - for (addr = 0; addr < n; addr += m->page_size) { + fprintf(stderr, "%s: stk500_paged_load(): n=%d, a_div=%d\n", + progname, n, a_div); + + for (addr = 0; addr < n; addr += page_size) { fprintf(stderr, "\r \r%6u", addr); tries = 0; retry: tries++; loadaddr(pgm, addr/a_div); buf[0] = Cmnd_STK_READ_PAGE; - buf[1] = (m->page_size >> 8) & 0xff; - buf[2] = m->page_size & 0xff; + buf[1] = (page_size >> 8) & 0xff; + buf[2] = page_size & 0xff; buf[3] = memtype; buf[4] = Sync_CRC_EOP; send(pgm, buf, 5); @@ -901,7 +900,7 @@ int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int n_bytes) return -4; } - recv(pgm, &m->buf[addr], m->page_size); + recv(pgm, &m->buf[addr], page_size); recv(pgm, buf, 1); if (buf[0] != Resp_STK_OK) { @@ -1020,6 +1019,7 @@ void stk500_initpgm(PROGRAMMER * pgm) */ pgm->paged_write = stk500_paged_write; pgm->paged_load = stk500_paged_load; + pgm->page_size = 256; }