diff options
| author | cpldcpu <cpldcpu@gmail.com> | 2014-03-06 11:28:07 +0100 | 
|---|---|---|
| committer | cpldcpu <cpldcpu@gmail.com> | 2014-03-06 11:28:07 +0100 | 
| commit | f920c73ff3f855a8b52cae07bffef752cc496c64 (patch) | |
| tree | 852505b4e2c4200b7b9389d4f5705d4c6109200f | |
| parent | e41772b00b450ecb67a6d2e1eaf28647a9df4a54 (diff) | |
| download | micronucleus-f920c73ff3f855a8b52cae07bffef752cc496c64.tar.gz micronucleus-f920c73ff3f855a8b52cae07bffef752cc496c64.tar.bz2 micronucleus-f920c73ff3f855a8b52cae07bffef752cc496c64.zip  | |
commandline: Fix up that may have caused to patch two pages
| -rw-r--r-- | commandline/library/micronucleus_lib.c | 6 | ||||
| -rw-r--r-- | commandline/library/micronucleus_lib.h | 1 | 
2 files changed, 5 insertions, 2 deletions
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  | 
