diff --git a/protocol/dfu_hostcmd.c b/protocol/dfu_hostcmd.c index bba984d..1b81f0d 100644 --- a/protocol/dfu_hostcmd.c +++ b/protocol/dfu_hostcmd.c @@ -83,5 +83,6 @@ int libhoth_dfu_update(struct libhoth_device* dev, const uint8_t* image, } // TODO: Wait for chip to come back and confirm version + usleep(LIBHOTH_REBOOT_DELAY_MS * 1000); return libhoth_device_reconnect(dev); } diff --git a/transports/libhoth_device.h b/transports/libhoth_device.h index 0b838b4..b2ee9eb 100644 --- a/transports/libhoth_device.h +++ b/transports/libhoth_device.h @@ -22,6 +22,7 @@ extern "C" { #endif #define LIBHOTH_MAILBOX_SIZE 1024 +#define LIBHOTH_REBOOT_DELAY_MS 1000 typedef enum { LIBHOTH_OK = 0, diff --git a/transports/libhoth_usb.c b/transports/libhoth_usb.c index d6e97b8..20c4860 100644 --- a/transports/libhoth_usb.c +++ b/transports/libhoth_usb.c @@ -105,12 +105,20 @@ static int libhoth_usb_reconnect(struct libhoth_device* dev) { } libhoth_usb_close(dev); - libusb_handle_events_completed(usb_ctx, NULL); uint64_t start_time_ms = libhoth_get_monotonic_ms(); while (1) { - int ret = libhoth_usb_get_device(usb_ctx, &usb_loc, &libusb_dev); + libusb_exit(usb_ctx); + int ret = libusb_init(&usb_ctx); + if (ret != 0) { + fprintf( + stderr, + "libusb_init_context failed while reconnecting (error: %d (%s))\n", + ret, libusb_strerror(ret)); + } + + ret = libhoth_usb_get_device(usb_ctx, &usb_loc, &libusb_dev); if (ret == 0) { // Found the device break; @@ -123,6 +131,7 @@ static int libhoth_usb_reconnect(struct libhoth_device* dev) { stderr, "libhoth_usb_open timed out while reconnecting (error: %d (%s))\n", ret, libusb_strerror(ret)); + libusb_exit(usb_ctx); return ret; // Timeout }