diff --git a/Downstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_hcd.h b/Downstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_hcd.h index d436361..2241a9c 100644 --- a/Downstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_hcd.h +++ b/Downstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_hcd.h @@ -197,7 +197,7 @@ void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd); void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd); void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd); void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd); -void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd); +HAL_StatusTypeDef HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd); void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state); diff --git a/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c b/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c index 6d8c4ea..e1b9f0b 100644 --- a/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c +++ b/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c @@ -477,14 +477,14 @@ void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd) /* Handle Host Disconnect Interrupts */ if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT)) { - - /* Cleanup HPRT */ - USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\ - USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG ); - /* Handle Host Port Interrupts */ - HAL_HCD_Disconnect_Callback(hhcd); - USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_48_MHZ ); + if (HAL_HCD_Disconnect_Callback(hhcd) == HAL_OK) + { + /* Cleanup HPRT */ + USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\ + USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG ); + USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_48_MHZ ); + } __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT); } @@ -636,7 +636,7 @@ __weak void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd) * @param hhcd: HCD handle * @retval None */ -__weak void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd) +__weak HAL_StatusTypeDef HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd) { /* NOTE : This function Should not be modified, when the callback is needed, the HAL_HCD_Disconnect_Callback could be implemented in the user file diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c index 2f0e71a..8098f3e 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c @@ -871,6 +871,13 @@ USBH_StatusTypeDef USBH_LL_PortEnabled (USBH_HandleTypeDef *phost) */ USBH_StatusTypeDef USBH_LL_Disconnect (USBH_HandleTypeDef *phost) { + //Ignore false disconnect interrupt that sometimes intrudes + //while we are waiting for the port to enable :( + if (phost->gState == HOST_DEV_WAIT_FOR_ATTACHMENT) + { + return USBH_FAIL; + } + /*Stop Host */ USBH_LL_Stop(phost); diff --git a/Downstream/Src/usbh_config.c b/Downstream/Src/usbh_config.c index 439da85..135fbb5 100644 --- a/Downstream/Src/usbh_config.c +++ b/Downstream/Src/usbh_config.c @@ -124,9 +124,13 @@ void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd) * @param hhcd: HCD handle * @retval None */ -void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd) +HAL_StatusTypeDef HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd) { - USBH_LL_Disconnect(hhcd->pData); + if (USBH_LL_Disconnect(hhcd->pData) == USBH_OK) + { + return HAL_OK; + } + return HAL_ERROR; } /**