Skip to content

Commit 095e99a

Browse files
committed
Mega2560 bootloader: fix wrong eeprom addressing
1 parent 911e9ac commit 095e99a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

bootloaders/stk500v2/stk500boot.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -1021,13 +1021,14 @@ int main(void)
10211021
else
10221022
{
10231023
//* issue 543, this should work, It has not been tested.
1024-
// #if (!defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega2560__) && !defined(__AVR_ATmega2561__) && !defined(__AVR_ATmega1284P__) && !defined(__AVR_ATmega640__))
1025-
#if (defined(EEARL) && defined(EEARH) && defined(EEMWE) && defined(EEWE) && defined(EEDR))
1024+
#if (defined(EEARL) && defined(EEARH) && defined(EEMWE) && defined(EEWE) && defined(EEDR))
1025+
uint16_t ii = address >> 1;
10261026
/* write EEPROM */
10271027
do {
1028-
EEARL = address; // Setup EEPROM address
1029-
EEARH = (address >> 8);
1030-
address++; // Select next EEPROM byte
1028+
EEARL = ii; // Setup EEPROM address
1029+
EEARH = (ii >> 8);
1030+
address+=2; // Select next EEPROM byte
1031+
ii++;
10311032

10321033
EEDR = *p++; // get byte from buffer
10331034
EECR |= (1<<EEMWE); // Write data into EEPROM
@@ -1036,9 +1037,9 @@ int main(void)
10361037
while (EECR & (1<<EEWE)); // Wait for write operation to finish
10371038
size--; // Decrease number of bytes to write
10381039
} while (size); // Loop until all bytes written
1039-
#endif
1040+
#endif
10401041
}
1041-
msgLength = 2;
1042+
msgLength = 2;
10421043
msgBuffer[1] = STATUS_CMD_OK;
10431044
}
10441045
break;

0 commit comments

Comments
 (0)