Permalink
Browse files

Pre-buffer page data to prevent data loss

boot_page_fill() may take too long to complete causing data to be
lost if the UART is running at high speeds (115200 is fast for an
AVR!).
  • Loading branch information...
blastur committed Mar 1, 2011
1 parent 827c005 commit fb7a0264d7daace7dc40726cd244f381119afbdb
Showing with 15 additions and 11 deletions.
  1. +15 −11 magboot.c
View
@@ -70,22 +70,26 @@ static bool cmd_write_page(uint16_t *addr)
{
uint16_t i;
uint16_t page = *addr;
uint8_t buf[SPM_PAGESIZE];
eeprom_busy_wait();
eeprom_busy_wait();
boot_page_erase(page);
boot_spm_busy_wait();
boot_page_erase(page);
for (i = 0; i < SPM_PAGESIZE; i += 2) {
uint16_t w = uart_getc();
w += uart_getc() << 8;
boot_page_fill(page + i, w);
}
for(i = 0; i < SPM_PAGESIZE; i++)
buf[i] = uart_getc();
boot_page_write(page);
boot_spm_busy_wait();
boot_spm_busy_wait();
for (i = 0; i < SPM_PAGESIZE; i += 2) {
uint16_t w = buf[i];
w += buf[i+1] << 8;
boot_page_fill(page + i, w);
}
boot_page_write(page);
boot_spm_busy_wait();
boot_rww_enable();
boot_rww_enable();
/* Auto-increment address */
*addr += SPM_PAGESIZE;

0 comments on commit fb7a026

Please sign in to comment.