Skip to content

Commit 3d06457

Browse files
committed
Deprecate original STK500 v1 protocol in favour of optiboot and Arduino as ISP
For paged read/write early AVRDUDE implementations of the STK500 v1 protocol communicated a word address (below a_div=2) or byte address (a_div=1) based on the following code irrespective of which memories were used: if(m->op[AVR_OP_LOADPAGE_LO] || m->op[AVR_OP_READ_LO]) a_div = 2; else a_div = 1; This turned out to be a bug: it really should have been a_div=2 for flash and a_div=1 for eeprom. At the time presumably no one noted because Atmel was at the cusp of replacing their FW 1.x with FW 2 (and the STK500 v2 protocol). It seems that the world (optiboot, Arduino as ISP, ...) has compensated for the bug by assuming AVRDUDE sends *all* eeprom addresses as word addresses. Actually these programmers overcompensated for the bug because for six out of the 146 known SPI programmable parts with eeprom and page size > 1, AVRDUDE would still send the eeprom addresses as byte addresses (ATmega8 ATmega8A ATmega64 ATmega64A ATmega128 ATmega128A) owing to above code. It makes no sense to correct the bug now seeing that virtually no one uses the old 2005 STK 500 v1 firmware. This commit now follows optiboot, Arduino as ISP and other projects, and simply sends all addresses for paged read or write as word addresses. There are no longer (little known) exceptions for ATmega8 et al that surprised some optiboot etc users.
1 parent 29c6645 commit 3d06457

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/stk500.c

+22-20
Original file line numberDiff line numberDiff line change
@@ -805,27 +805,28 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
805805

806806
if (strcmp(m->desc, "flash") == 0) {
807807
memtype = 'F';
808-
}
809-
else if (strcmp(m->desc, "eeprom") == 0) {
808+
a_div = 2;
809+
} else if (strcmp(m->desc, "eeprom") == 0) {
810810
memtype = 'E';
811-
}
812-
else {
811+
/*
812+
* The STK original 500 v1 protocol actually expects a_div = 1, but the
813+
* v1.x FW of the STK500 kit has been superseded by v2 FW in the mid
814+
* 2000s. Since optiboot, arduino as ISP and others assume a_div = 2,
815+
* better use that. See https://github.com/avrdudes/avrdude/issues/967
816+
*/
817+
a_div = 2;
818+
} else {
813819
return -2;
814820
}
815821

816-
if ((m->op[AVR_OP_LOADPAGE_LO]) || (m->op[AVR_OP_READ_LO]))
817-
a_div = 2;
818-
else
819-
a_div = 1;
820-
821822
n = addr + n_bytes;
822823
#if 0
823824
avrdude_message(MSG_INFO, "n_bytes = %d\n"
824825
"n = %u\n"
825826
"a_div = %d\n"
826827
"page_size = %d\n",
827828
n_bytes, n, a_div, page_size);
828-
#endif
829+
#endif
829830

830831
for (; addr < n; addr += block_size) {
831832
// MIB510 uses fixed blocks size of 256 bytes
@@ -872,7 +873,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
872873
progname, Resp_STK_INSYNC, buf[0]);
873874
return -4;
874875
}
875-
876+
876877
if (stk500_recv(pgm, buf, 1) < 0)
877878
return -1;
878879
if (buf[0] != Resp_STK_OK) {
@@ -899,19 +900,20 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
899900

900901
if (strcmp(m->desc, "flash") == 0) {
901902
memtype = 'F';
902-
}
903-
else if (strcmp(m->desc, "eeprom") == 0) {
903+
a_div = 2;
904+
} else if (strcmp(m->desc, "eeprom") == 0) {
904905
memtype = 'E';
905-
}
906-
else {
906+
/*
907+
* The STK original 500 v1 protocol actually expects a_div = 1, but the
908+
* v1.x FW of the STK500 kit has been superseded by v2 FW in the mid
909+
* 2000s. Since optiboot, arduino as ISP and others assume a_div = 2,
910+
* better use that. See https://github.com/avrdudes/avrdude/issues/967
911+
*/
912+
a_div = 2;
913+
} else {
907914
return -2;
908915
}
909916

910-
if ((m->op[AVR_OP_LOADPAGE_LO]) || (m->op[AVR_OP_READ_LO]))
911-
a_div = 2;
912-
else
913-
a_div = 1;
914-
915917
n = addr + n_bytes;
916918
for (; addr < n; addr += block_size) {
917919
// MIB510 uses fixed blocks size of 256 bytes

0 commit comments

Comments
 (0)