summaryrefslogtreecommitdiffstats
path: root/commandline/library/micronucleus_lib.c
diff options
context:
space:
mode:
authorcpldcpu <cpldcpu@gmail.com>2015-03-15 09:36:49 +0100
committercpldcpu <cpldcpu@gmail.com>2015-03-15 09:36:49 +0100
commit8dab45135ab6aa69db0708776a989a586ff99b50 (patch)
treee10d944ae3bec82a6730c13a4d15b2ae7e7b05c1 /commandline/library/micronucleus_lib.c
parenta6f4163452ad6faf0dfd64f115a15cdde75c39a8 (diff)
downloadmicronucleus-8dab45135ab6aa69db0708776a989a586ff99b50.tar.gz
micronucleus-8dab45135ab6aa69db0708776a989a586ff99b50.tar.bz2
micronucleus-8dab45135ab6aa69db0708776a989a586ff99b50.zip
commandline: Fixed assert when device was unresponsive
Diffstat (limited to 'commandline/library/micronucleus_lib.c')
-rw-r--r--commandline/library/micronucleus_lib.c8
1 files changed, 8 insertions, 0 deletions
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];