Skip to content

Commit 8fa7d94

Browse files
committed
Mega2560 bootloader: use avr library functions for writing into EEPROM
1 parent 1066766 commit 8fa7d94

File tree

2 files changed

+471
-419
lines changed

2 files changed

+471
-419
lines changed

hardware/arduino/bootloaders/stk500v2/stk500boot.c

100755100644
+5-14
Original file line numberDiff line numberDiff line change
@@ -1020,24 +1020,15 @@ int main(void)
10201020
}
10211021
else
10221022
{
1023-
//* issue 543, this should work, It has not been tested.
1024-
#if (defined(EEARL) && defined(EEARH) && defined(EEMWE) && defined(EEWE) && defined(EEDR))
1023+
//* issue 543, this should work, It has not been tested.
10251024
uint16_t ii = address >> 1;
10261025
/* write EEPROM */
1027-
do {
1028-
EEARL = ii; // Setup EEPROM address
1029-
EEARH = (ii >> 8);
1026+
while (size) {
1027+
eeprom_write_byte((uint8_t*)ii, *p++);
10301028
address+=2; // Select next EEPROM byte
10311029
ii++;
1032-
1033-
EEDR = *p++; // get byte from buffer
1034-
EECR |= (1<<EEMWE); // Write data into EEPROM
1035-
EECR |= (1<<EEWE);
1036-
1037-
while (EECR & (1<<EEWE)); // Wait for write operation to finish
1038-
size--; // Decrease number of bytes to write
1039-
} while (size); // Loop until all bytes written
1040-
#endif
1030+
size--;
1031+
}
10411032
}
10421033
msgLength = 2;
10431034
msgBuffer[1] = STATUS_CMD_OK;

0 commit comments

Comments
 (0)