From f920c73ff3f855a8b52cae07bffef752cc496c64 Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Thu, 6 Mar 2014 11:28:07 +0100 Subject: commandline: Fix up that may have caused to patch two pages --- commandline/library/micronucleus_lib.c | 6 ++++-- commandline/library/micronucleus_lib.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'commandline') diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index c92f11f..601b190 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -70,6 +70,8 @@ micronucleus* micronucleus_connect(int fast_mode) { nucleus->pages = (nucleus->flash_size / nucleus->page_size); if (nucleus->pages * nucleus->page_size < nucleus->flash_size) nucleus->pages += 1; + nucleus->bootloader_start = nucleus->pages*nucleus->page_size; + if ((nucleus->version.major>=2)&&(!fast_mode)) { // firmware v2 reports more aggressive write times. Add 2ms if fast mode is not used. nucleus->write_sleep = buffer[3]+2; @@ -172,7 +174,7 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz } } - if ( address >= deviceHandle->flash_size - deviceHandle->page_size ) { + if ( address >= deviceHandle->bootloader_start - deviceHandle->page_size ) { // move user reset vector to end of last page // The reset vector is always the last vector in the tinyvectortable unsigned int user_reset_addr = (deviceHandle->pages*deviceHandle->page_size) - 4; @@ -195,7 +197,7 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz // always write last page so bootloader can insert the tiny vector table - if ( address >= deviceHandle->flash_size - deviceHandle->page_size ) + if ( address >= deviceHandle->bootloader_start - deviceHandle->page_size ) pagecontainsdata = 1; // ask microcontroller to write this page's data diff --git a/commandline/library/micronucleus_lib.h b/commandline/library/micronucleus_lib.h index 0accc59..9031d2f 100644 --- a/commandline/library/micronucleus_lib.h +++ b/commandline/library/micronucleus_lib.h @@ -67,6 +67,7 @@ typedef struct _micronucleus { micronucleus_version version; unsigned int flash_size; // programmable size (in bytes) of progmem unsigned int page_size; // size (in bytes) of page + unsigned int bootloader_start; // Start of the bootloader unsigned int pages; // total number of pages to program unsigned int write_sleep; // milliseconds unsigned int erase_sleep; // milliseconds -- cgit v1.2.3