From 4f0568d030fb5d8bcf90ff76c2b01360cc99ce07 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 17 Dec 2013 12:47:19 -0800 Subject: commandline: pretty sure this should be a comparison not an assignment --- commandline/library/micronucleus_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commandline/library/micronucleus_lib.c') diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index 6bbf04c..47a3952 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -102,7 +102,7 @@ int micronucleus_eraseFlash(micronucleus* deviceHandle, micronucleus_callback pr Assertion failed: (res >= 4), function micronucleus_connect, file library/micronucleus_lib.c, line 63. */ if (res == -5 || res == -34 || res == -84) { - if (res = -34) { + if (res == -34) { usb_close(deviceHandle->device); deviceHandle->device = NULL; } -- cgit v1.2.3 From e8fc0bd1c7af9d7018df37876806c8ee5afc7c3c Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 17 Dec 2013 12:48:10 -0800 Subject: commandline: silence a warning since this is used correctly --- commandline/library/micronucleus_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commandline/library/micronucleus_lib.c') diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index 47a3952..8774e25 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -60,7 +60,7 @@ micronucleus* micronucleus_connect() { // get nucleus info unsigned char buffer[4]; - int res = usb_control_msg(nucleus->device, 0xC0, 0, 0, 0, buffer, 4, MICRONUCLEUS_USB_TIMEOUT); + int res = usb_control_msg(nucleus->device, 0xC0, 0, 0, 0, (char *)buffer, 4, MICRONUCLEUS_USB_TIMEOUT); assert(res >= 4); nucleus->flash_size = (buffer[0]<<8) + buffer[1]; -- cgit v1.2.3 From ed8501462ec235d1dd34afd21ef3fbab484055c4 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 17 Dec 2013 12:51:17 -0800 Subject: commandline: use C automatic stringification --- commandline/library/micronucleus_lib.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'commandline/library/micronucleus_lib.c') diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index 8774e25..9b73d46 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -50,10 +50,12 @@ micronucleus* micronucleus_connect() { nucleus->version.minor = dev->descriptor.bcdDevice & 0xFF; if (nucleus->version.major > MICRONUCLEUS_MAX_MAJOR_VERSION) { - fprintf(stderr, "Warning: device with unknown new version of Micronucleus detected.\n"); - fprintf(stderr, "This tool doesn't know how to upload to this new device. Updates may be available.\n"); - fprintf(stderr, "Device reports version as: %d.%d\n", nucleus->version.major, nucleus->version.minor); - return NULL; + fprintf(stderr, + "Warning: device with unknown new version of Micronucleus detected.\n" + "This tool doesn't know how to upload to this new device. Updates may be available.\n" + "Device reports version as: %d.%d\n", + nucleus->version.major, nucleus->version.minor); + return NULL; } nucleus->device = usb_open(dev); -- cgit v1.2.3 From d9e1adda960b22b9571a04b79d1a261983e6e11a Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 17 Dec 2013 12:53:29 -0800 Subject: commandline: whitespace --- commandline/library/micronucleus_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commandline/library/micronucleus_lib.c') diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index 9b73d46..b9bceb2 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -151,7 +151,7 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz // give microcontroller enough time to write this page and come back online delay(deviceHandle->write_sleep); - + if (res != page_length) return -1; } -- cgit v1.2.3 From c76ecfb6151c615cc35774c404b956a16c14085c Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Mon, 30 Dec 2013 13:20:35 +0100 Subject: commandline: do not write to empty pages --- commandline/library/micronucleus_lib.c | 39 ++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'commandline/library/micronucleus_lib.c') diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index b9bceb2..ddcefdd 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -121,38 +121,49 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz unsigned int address; // overall flash memory address unsigned int page_address; // address within this page when copying buffer unsigned int res; - + unsigned int pagecontainsdata; + for (address = 0; address < deviceHandle->flash_size; address += deviceHandle->page_size) { // work around a bug in older bootloader versions if (deviceHandle->version.major == 1 && deviceHandle->version.minor <= 2 && address / deviceHandle->page_size == deviceHandle->pages - 1) { page_length = deviceHandle->flash_size % deviceHandle->page_size; } + + pagecontainsdata=0; // copy in bytes from user program for (page_address = 0; page_address < page_length; page_address += 1) { if (address + page_address > program_size) { page_buffer[page_address] = 0xFF; // pad out remainder with unprogrammed bytes } else { + pagecontainsdata=1; // page contains data and needs to be written page_buffer[page_address] = program[address + page_address]; // load from user program } } + // always write last page so bootloader can insert the tiny vector table + if ( address >= deviceHandle->flash_size - deviceHandle->page_size ) + pagecontainsdata = 1; + // ask microcontroller to write this page's data - res = usb_control_msg(deviceHandle->device, - USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, - 1, - page_length, address, - page_buffer, page_length, - MICRONUCLEUS_USB_TIMEOUT); - - // call progress update callback if that's a thing - if (prog) prog(((float) address) / ((float) deviceHandle->flash_size)); - - // give microcontroller enough time to write this page and come back online - delay(deviceHandle->write_sleep); + if (pagecontainsdata) { + res = usb_control_msg(deviceHandle->device, + USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, + 1, + page_length, address, + page_buffer, page_length, + MICRONUCLEUS_USB_TIMEOUT); + + if (res != page_length) return -1; + + // give microcontroller enough time to write this page and come back online + delay(deviceHandle->write_sleep); + } + + // call progress update callback if that's a thing + if (prog) prog(((float) address) / ((float) deviceHandle->flash_size)); - if (res != page_length) return -1; } // call progress update callback with completion status -- cgit v1.2.3 From e4596e39c7ba51d83f18e8687388e733efb3aa7f Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Tue, 14 Jan 2014 06:33:50 +0100 Subject: commandline: Add cast to prevent warning --- commandline/library/micronucleus_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commandline/library/micronucleus_lib.c') diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index ddcefdd..6e574f5 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -152,7 +152,7 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1, page_length, address, - page_buffer, page_length, + (char*)page_buffer, page_length, MICRONUCLEUS_USB_TIMEOUT); if (res != page_length) return -1; -- cgit v1.2.3