From 8dab45135ab6aa69db0708776a989a586ff99b50 Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Sun, 15 Mar 2015 09:36:49 +0100 Subject: commandline: Fixed assert when device was unresponsive --- commandline/library/micronucleus_lib.c | 8 ++++++++ commandline/library/micronucleus_lib.h | 2 +- commandline/micronucleus.exe | Bin 0 -> 27662 bytes 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 commandline/micronucleus.exe (limited to 'commandline') diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c index e2f6791..0569dbe 100644 --- a/commandline/library/micronucleus_lib.c +++ b/commandline/library/micronucleus_lib.c @@ -66,6 +66,10 @@ micronucleus* micronucleus_connect(int fast_mode) { // get nucleus info unsigned char buffer[6]; int res = usb_control_msg(nucleus->device, USB_ENDPOINT_IN| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, 0, 0, (char *)buffer, 6, MICRONUCLEUS_USB_TIMEOUT); + + // Device descriptor was found, but talking to it was not succesful. This can happen when the device is being reset. + if (res<0) return NULL; + assert(res >= 6); nucleus->flash_size = (buffer[0]<<8) + buffer[1]; @@ -97,6 +101,10 @@ micronucleus* micronucleus_connect(int fast_mode) { // get nucleus info unsigned char buffer[4]; int res = usb_control_msg(nucleus->device, USB_ENDPOINT_IN| USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, 0, 0, (char *)buffer, 4, MICRONUCLEUS_USB_TIMEOUT); + + // Device descriptor was found, but talking to it was not succesful. This can happen when the device is being reset. + if (res<0) return NULL; + assert(res >= 4); nucleus->flash_size = (buffer[0]<<8) + buffer[1]; diff --git a/commandline/library/micronucleus_lib.h b/commandline/library/micronucleus_lib.h index 2db7b62..b691fa4 100644 --- a/commandline/library/micronucleus_lib.h +++ b/commandline/library/micronucleus_lib.h @@ -60,7 +60,7 @@ typedef struct _micronucleus_version { unsigned char minor; } micronucleus_version; -#define MICRONUCLEUS_COMMANDLINE_VERSION "Commandline tool version: 2.0a4" +#define MICRONUCLEUS_COMMANDLINE_VERSION "Commandline tool version: 2.0a5" // handle representing one micronucleus device typedef struct _micronucleus { diff --git a/commandline/micronucleus.exe b/commandline/micronucleus.exe new file mode 100644 index 0000000..c5aeedc Binary files /dev/null and b/commandline/micronucleus.exe differ -- cgit v1.2.3