summaryrefslogtreecommitdiffstats
path: root/commandline
diff options
context:
space:
mode:
authorcpldcpu <cpldcpu@gmail.com>2013-12-30 13:20:35 +0100
committercpldcpu <cpldcpu@gmail.com>2013-12-30 13:20:35 +0100
commitc76ecfb6151c615cc35774c404b956a16c14085c (patch)
treee3e66ad71509067adf2d966a0be82cd16db617a4 /commandline
parent2e067963c4b8d0285a3f70b71d2b438c66c2e40c (diff)
downloadmicronucleus-c76ecfb6151c615cc35774c404b956a16c14085c.tar.gz
micronucleus-c76ecfb6151c615cc35774c404b956a16c14085c.tar.bz2
micronucleus-c76ecfb6151c615cc35774c404b956a16c14085c.zip
commandline: do not write to empty pages
Diffstat (limited to 'commandline')
-rw-r--r--commandline/Makefile2
-rwxr-xr-xcommandline/builds/Windows/micronucleus.exebin26126 -> 26126 bytes
-rw-r--r--commandline/library/micronucleus_lib.c39
-rw-r--r--commandline/micronucleus.c5
-rw-r--r--commandline/micronucleus.exebin26126 -> 0 bytes
5 files changed, 29 insertions, 17 deletions
diff --git a/commandline/Makefile b/commandline/Makefile
index 028f7aa..5d7a410 100644
--- a/commandline/Makefile
+++ b/commandline/Makefile
@@ -41,7 +41,7 @@ $(LWLIBS):
$(EXAMPLES): $(addsuffix .o, $(LWLIBS))
@echo Building command line tool: $@...
$(CC) $(CFLAGS) -o $@$(EXE_SUFFIX) $@.c $^ $(LIBS)
-
+
clean:
rm -f $(EXAMPLES)$(EXE_SUFFIX) *.o *.exe
diff --git a/commandline/builds/Windows/micronucleus.exe b/commandline/builds/Windows/micronucleus.exe
index 4118d0c..e94113b 100755
--- a/commandline/builds/Windows/micronucleus.exe
+++ b/commandline/builds/Windows/micronucleus.exe
Binary files differ
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
diff --git a/commandline/micronucleus.c b/commandline/micronucleus.c
index c6d122a..b7d49ab 100644
--- a/commandline/micronucleus.c
+++ b/commandline/micronucleus.c
@@ -185,9 +185,10 @@ int main(int argc, char **argv) {
// return EXIT_FAILURE;
// }
- printf("> Available space for user application: %d bytes\n", my_device->flash_size);
+ printf("> Device has firmware version %d.%d\n",my_device->version.major,my_device->version.minor);
+ printf("> Available space for user applications: %d bytes\n", my_device->flash_size);
printf("> Suggested sleep time between sending pages: %ums\n", my_device->write_sleep);
- printf("> Whole page count: %d\n", my_device->pages);
+ printf("> Whole page count: %d page size: %d\n", my_device->pages,my_device->page_size);
printf("> Erase function sleep duration: %dms\n", my_device->erase_sleep);
int startAddress = 1, endAddress = 0;
diff --git a/commandline/micronucleus.exe b/commandline/micronucleus.exe
deleted file mode 100644
index c6252cb..0000000
--- a/commandline/micronucleus.exe
+++ /dev/null
Binary files differ