From 3bdf138721bd4a08ed743312e11a95aa8a2ee892 Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Thu, 5 May 2022 20:45:47 +0200 Subject: [PATCH 1/3] Fix micronucleus bootloader to check for unresponsive USB devices --- src/micronucleus.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/micronucleus.c b/src/micronucleus.c index b3c25341..b8d9d7ee 100644 --- a/src/micronucleus.c +++ b/src/micronucleus.c @@ -744,6 +744,19 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) { avrdude_message(MSG_INFO, "%s: ERROR: Failed to open USB device: %s\n", progname, usb_strerror()); } + else + { + // Send a dummy request to check for a unresponsive USB device. + int result = micronucleus_get_bootloader_info(pdata); + if (result < 0) + { + avrdude_message(MSG_NOTICE, "%s: WARNING: Failed to probe device (error %d), skipping...\n", + progname, result); + + usb_close(pdata->usb_handle); + pdata->usb_handle = NULL; + } + } } } } From c64f2030a175341ee8943757d12dcf91f5af829c Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Thu, 5 May 2022 21:42:27 +0200 Subject: [PATCH 2/3] Improve micronucleus bootloader user experience for unresponsive USB devices --- src/micronucleus.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/micronucleus.c b/src/micronucleus.c index b8d9d7ee..28dac2cb 100644 --- a/src/micronucleus.c +++ b/src/micronucleus.c @@ -139,6 +139,22 @@ static int micronucleus_check_connection(pdata_t* pdata) } } +static bool micronucleus_is_device_responsive(pdata_t* pdata, struct usb_device* device) +{ + pdata->usb_handle = usb_open(device); + if (pdata->usb_handle == NULL) + { + return false; + } + + int result = micronucleus_check_connection(pdata); + + usb_close(pdata->usb_handle); + pdata->usb_handle = NULL; + + return result >= 0; +} + static int micronucleus_reconnect(pdata_t* pdata) { struct usb_device* device = usb_device(pdata->usb_handle); @@ -696,6 +712,7 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) usb_init(); bool show_retry_message = true; + bool show_unresponsive_device_message = true; time_t start_time = time(NULL); for (;;) @@ -717,6 +734,19 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) pdata->major_version = (uint8_t)(device->descriptor.bcdDevice >> 8); pdata->minor_version = (uint8_t)(device->descriptor.bcdDevice >> 0); + if (!micronucleus_is_device_responsive(pdata, device)) + { + if (show_unresponsive_device_message) + { + avrdude_message(MSG_INFO, "%s: WARNING: Unresponsive Micronucleus device detected, please reconnect....\n", + progname); + + show_unresponsive_device_message = false; + } + + continue; + } + avrdude_message(MSG_NOTICE, "%s: Found device with Micronucleus V%d.%d, bus:device: %s:%s\n", progname, pdata->major_version, pdata->minor_version, @@ -744,19 +774,6 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) { avrdude_message(MSG_INFO, "%s: ERROR: Failed to open USB device: %s\n", progname, usb_strerror()); } - else - { - // Send a dummy request to check for a unresponsive USB device. - int result = micronucleus_get_bootloader_info(pdata); - if (result < 0) - { - avrdude_message(MSG_NOTICE, "%s: WARNING: Failed to probe device (error %d), skipping...\n", - progname, result); - - usb_close(pdata->usb_handle); - pdata->usb_handle = NULL; - } - } } } } From 01a9e42d7d43bb4329740f9d72b1c3591e342726 Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Thu, 5 May 2022 22:08:46 +0200 Subject: [PATCH 3/3] Fix typo in micronucleus message --- src/micronucleus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/micronucleus.c b/src/micronucleus.c index 28dac2cb..c3dd007d 100644 --- a/src/micronucleus.c +++ b/src/micronucleus.c @@ -738,7 +738,7 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port) { if (show_unresponsive_device_message) { - avrdude_message(MSG_INFO, "%s: WARNING: Unresponsive Micronucleus device detected, please reconnect....\n", + avrdude_message(MSG_INFO, "%s: WARNING: Unresponsive Micronucleus device detected, please reconnect...\n", progname); show_unresponsive_device_message = false;