From 1539320a76f6be5f14a426461b1999b5ce401001 Mon Sep 17 00:00:00 2001 From: Jenna Fox Date: Mon, 24 Sep 2012 13:49:41 +1000 Subject: Making progress fixing issue where it never properly erases first page --- firmware/main.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'firmware/main.c') diff --git a/firmware/main.c b/firmware/main.c index 84cc11e..34628c6 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -95,18 +95,32 @@ static addr_t currentAddress; /* in bytes */ /* ------------------------------------------------------------------------ */ +static inline void eraseApplication(void); +static void writeFlashPage(void); +static void writeWordToPageBuffer(uint16_t data); +static void fillFlashWithVectors(void); +static uchar usbFunctionSetup(uchar data[8]); +static uchar usbFunctionWrite(uchar *data, uchar length); +static inline void initForUsbConnectivity(void); +static inline void tiny85FlashInit(void); +static inline void tiny85FlashWrites(void); +static inline __attribute__((noreturn)) void leaveBootloader(void); + static inline void eraseApplication(void) { - // erase all pages starting from end of application section down to page 1 (leaving page 0) - currentAddress = BOOTLOADER_ADDRESS - SPM_PAGESIZE; + // xxxxxx erase all pages starting from end of application section down to page 1 (leaving page 0) + // erase all pages (every last one!) + currentAddress = BOOTLOADER_ADDRESS; + cli(); while (currentAddress) { - cli(); + currentAddress -= SPM_PAGESIZE; + boot_page_erase(currentAddress); boot_spm_busy_wait(); - sei(); - - currentAddress -= SPM_PAGESIZE; } + + fillFlashWithVectors(); + sei(); } static void writeFlashPage(void) { -- cgit v1.2.3