diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index fe660fc4..b967a37d 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -310,6 +310,7 @@ static void usbh_hubport_release(struct usbh_hubport *child) } child->config.config_desc.bNumInterfaces = 0; usbh_kill_urb(&child->ep0_urb); + usb_osal_mutex_delete(child->mutex); } } @@ -598,6 +599,7 @@ static void usbh_hub_events(struct usbh_hub *hub) child->connected = true; child->port = port + 1; child->speed = speed; + child->mutex = usb_osal_mutex_create(); USB_LOG_INFO("New %s device on Hub %u, Port %u connected\r\n", speed_table[speed], hub->index, port + 1); diff --git a/core/usbh_core.c b/core/usbh_core.c index 33dc7b5f..91d79f71 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -673,11 +673,16 @@ int usbh_control_transfer(struct usbh_hubport *hport, struct usb_setup_packet *s urb = &hport->ep0_urb; + usb_osal_mutex_take(hport->mutex); + + memset(urb, 0, sizeof(struct usbh_urb)); usbh_control_urb_fill(urb, hport, setup, buffer, setup->wLength, CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT, NULL, NULL); ret = usbh_submit_urb(urb); if (ret == 0) { ret = urb->actual_length; } + + usb_osal_mutex_give(hport->mutex); return ret; } diff --git a/core/usbh_core.h b/core/usbh_core.h index 7cc1eace..c56953b9 100644 --- a/core/usbh_core.h +++ b/core/usbh_core.h @@ -111,6 +111,7 @@ struct usbh_hubport { #endif struct usb_endpoint_descriptor ep0; struct usbh_urb ep0_urb; + usb_osal_mutex_t mutex; }; struct usbh_hub {