Merge pull request #945 from mariusgreuel/pr-micronucleus-macos-usb-issue

Fix micronucleus bootloader to check for unresponsive USB devices
This commit is contained in:
Marius Greuel 2022-06-08 21:46:40 +02:00 committed by GitHub
commit fc9d640f0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 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) static int micronucleus_reconnect(pdata_t* pdata)
{ {
struct usb_device* device = usb_device(pdata->usb_handle); struct usb_device* device = usb_device(pdata->usb_handle);
@ -696,6 +712,7 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port)
usb_init(); usb_init();
bool show_retry_message = true; bool show_retry_message = true;
bool show_unresponsive_device_message = true;
time_t start_time = time(NULL); time_t start_time = time(NULL);
for (;;) for (;;)
@ -717,6 +734,19 @@ static int micronucleus_open(PROGRAMMER* pgm, char* port)
pdata->major_version = (uint8_t)(device->descriptor.bcdDevice >> 8); pdata->major_version = (uint8_t)(device->descriptor.bcdDevice >> 8);
pdata->minor_version = (uint8_t)(device->descriptor.bcdDevice >> 0); 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", avrdude_message(MSG_NOTICE, "%s: Found device with Micronucleus V%d.%d, bus:device: %s:%s\n",
progname, progname,
pdata->major_version, pdata->minor_version, pdata->major_version, pdata->minor_version,