Improve micronucleus bootloader user experience for unresponsive USB devices

This commit is contained in:
Marius Greuel 2022-05-05 21:42:27 +02:00
parent 3bdf138721
commit c64f2030a1
1 changed files with 30 additions and 13 deletions

View File

@ -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;
}
}
}
}
}