Fix ATMega flash addressing. Add an ATMEGA16 part. Perform sanity

checking on the memory parameters for parts that do bank addressing.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@88 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
bsd 2001-10-16 02:47:55 +00:00
parent 7e0ceec977
commit d899f57fec
5 changed files with 105 additions and 10 deletions

22
avr.c
View File

@ -281,7 +281,8 @@ int avr_read(int fd, AVRPART * p, int memtype)
for (i=0; i<size; i++) { for (i=0; i<size; i++) {
rbyte = avr_read_byte(fd, p, memtype, i); rbyte = avr_read_byte(fd, p, memtype, i);
fprintf(stderr, " \r%4lu 0x%02x", i, rbyte); if (i % 1024 == 0)
fprintf(stderr, " \r%4lu 0x%02x", i, rbyte);
buf[i] = rbyte; buf[i] = rbyte;
} }
@ -299,10 +300,26 @@ int avr_write_bank(int fd, AVRPART * p, int memtype,
{ {
unsigned char cmd[4]; unsigned char cmd[4];
unsigned char res[4]; unsigned char res[4];
unsigned int shift;
LED_ON(fd, pgm->pinno[PIN_LED_PGM]); LED_ON(fd, pgm->pinno[PIN_LED_PGM]);
LED_OFF(fd, pgm->pinno[PIN_LED_ERR]); LED_OFF(fd, pgm->pinno[PIN_LED_ERR]);
/*
* 'bank' indicates which bank is being programmed: 0 for the first
* bank_size block, 1 for the second, up to num_banks-1 for the
* last. The MCU actually wants the high-order bits of what would
* be the actual address instead, shifted left to the upper most
* bits of a 16 bit word. For a 128K flash, the actual address is a
* 17 bits. To get the right value to send to the MCU, we want to
* shift 'bank' left by 16 - the number of bits in the bank
* address.
*/
shift = 16 - p->mem[memtype].bankaddrbits;
bank = bank << shift;
fprintf(stderr, "bank address=%u\n", bank);
cmd[0] = 0x4c; cmd[0] = 0x4c;
cmd[1] = bank >> 8; /* high order bits of address */ cmd[1] = bank >> 8; /* high order bits of address */
cmd[2] = bank & 0x0ff; /* low order bits of address */ cmd[2] = bank & 0x0ff; /* low order bits of address */
@ -457,7 +474,8 @@ int avr_write(int fd, AVRPART * p, int memtype, int size)
/* eeprom or low byte of flash */ /* eeprom or low byte of flash */
data = p->mem[memtype].buf[i]; data = p->mem[memtype].buf[i];
rc = avr_write_byte(fd, p, memtype, i, data); rc = avr_write_byte(fd, p, memtype, i, data);
fprintf(stderr, " \r%4lu 0x%02x", i, data); if (i % 1024 == 0)
fprintf(stderr, " \r%4lu 0x%02x", i, data);
if (rc) { if (rc) {
fprintf(stderr, " ***failed; "); fprintf(stderr, " ***failed; ");
fprintf(stderr, "\n"); fprintf(stderr, "\n");

1
avr.h
View File

@ -50,6 +50,7 @@ typedef struct avrmem {
int size; /* total memory size in bytes */ int size; /* total memory size in bytes */
int bank_size; /* size of memory bank (if bank addressed) */ int bank_size; /* size of memory bank (if bank addressed) */
int num_banks; /* number of banks (if bank addressed) */ int num_banks; /* number of banks (if bank addressed) */
int bankaddrbits; /* number of bits in the bank address */
int min_write_delay; /* microseconds */ int min_write_delay; /* microseconds */
int max_write_delay; /* microseconds */ int max_write_delay; /* microseconds */
unsigned char readback[2]; /* polled read-back values */ unsigned char readback[2]; /* polled read-back values */

View File

@ -120,6 +120,7 @@ part
; ;
; ;
part part
id = "2313"; id = "2313";
desc = "AT90S2313"; desc = "AT90S2313";
@ -308,3 +309,30 @@ part
; ;
; ;
part
id = "16";
desc = "ATMEGA16";
chip_erase_delay = 9000;
eeprom
banked = no;
size = 512;
bank_size = 0;
num_banks = 0;
min_write_delay = 9000;
max_write_delay = 9000;
readback_p1 = 0xff;
readback_p2 = 0xff;
;
flash
banked = yes;
size = 16384;
bank_size = 128;
num_banks = 128;
min_write_delay = 4500;
max_write_delay = 9000;
readback_p1 = 0xff;
readback_p2 = 0xff;
;
;

View File

@ -103,12 +103,60 @@ part_def :
{ current_part = avr_new_part(); } { current_part = avr_new_part(); }
part_parms part_parms
{ {
unsigned int i, j, pagebits;
if (current_part->id[0] == 0) { if (current_part->id[0] == 0) {
fprintf(stderr, fprintf(stderr,
"%s: error at %s:%d: required parameter id not specified\n", "%s: error at %s:%d: required parameter id not specified\n",
progname, infile, lineno); progname, infile, lineno);
exit(1); exit(1);
} }
/*
* perform some sanity checking
*/
for (i=0; i<AVR_MAXMEMTYPES; i++) {
if (current_part->mem[i].banked) {
if (!current_part->mem[i].bank_size) {
fprintf(stderr,
"%s: error at %s:%d: must specify bank_size for banked "
"memory\n",
progname, infile, lineno);
exit(1);
}
if (!current_part->mem[i].num_banks) {
fprintf(stderr,
"%s: error at %s:%d: must specify num_banks for banked "
"memory\n",
progname, infile, lineno);
exit(1);
}
if (current_part->mem[i].size != current_part->mem[i].bank_size *
current_part->mem[i].num_banks) {
fprintf(stderr,
"%s: error at %s:%d: bank size (%u) * num_banks (%u) = "
"%u does not match memory size (%u)\n",
progname, infile, lineno,
current_part->mem[i].bank_size,
current_part->mem[i].num_banks,
current_part->mem[i].bank_size * current_part->mem[i].num_banks,
current_part->mem[i].size);
exit(1);
}
pagebits = 0;
for (j=0; j<32 && !pagebits; j++) {
if ((1 << j) == current_part->mem[i].num_banks)
pagebits = j;
}
if (!pagebits) {
fprintf(stderr,
"%s: error at %s:%d: can't determine the number of bank address bits\n"
" Are you sure num_banks (=%u) is correct?\n",
progname, infile, lineno, current_part->mem[i].num_banks);
}
current_part->mem[i].bankaddrbits = pagebits;
}
}
ladd(part_list, current_part); ladd(part_list, current_part);
current_part = NULL; current_part = NULL;
} }

2
main.c
View File

@ -284,7 +284,7 @@ int read_config(char * file)
f = fopen(file, "r"); f = fopen(file, "r");
if (f == NULL) { if (f == NULL) {
fprintf(stderr, "%s: can't open config file \"%s\": %s\n", fprintf(stderr, "%s: can't open config file \"%s\": %s\n",
progname, infile, strerror(errno)); progname, file, strerror(errno));
return -1; return -1;
} }