diff --git a/Downstream/.cproject b/Downstream/.cproject index 1f23b55..befc0b1 100644 --- a/Downstream/.cproject +++ b/Downstream/.cproject @@ -8,6 +8,8 @@ + + @@ -45,7 +47,7 @@ - + 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 f818bbd..a2bc45f 100644 --- a/Downstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_hcd.h +++ b/Downstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_hcd.h @@ -193,6 +193,7 @@ HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, 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); void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, 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 cb659bf..d51ea94 100644 --- a/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c +++ b/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c @@ -570,6 +570,11 @@ __weak void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd) */ } +__weak void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd) +{ + +} + /** * @brief Disconnection Event callback. * @param hhcd: HCD handle @@ -1055,11 +1060,11 @@ static void HCD_HC_OUT_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum) hhcd->hc[chnum].urb_state = URB_NOTREADY; } - /* re-activate the channel */ - tmpreg = USBx_HC(chnum)->HCCHAR; - tmpreg &= ~USB_OTG_HCCHAR_CHDIS; - tmpreg |= USB_OTG_HCCHAR_CHENA; - USBx_HC(chnum)->HCCHAR = tmpreg; +// /* re-activate the channel */ +// tmpreg = USBx_HC(chnum)->HCCHAR; +// tmpreg &= ~USB_OTG_HCCHAR_CHDIS; +// tmpreg |= USB_OTG_HCCHAR_CHENA; +// USBx_HC(chnum)->HCCHAR = tmpreg; } __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH); @@ -1174,7 +1179,7 @@ static void HCD_Port_IRQHandler (HCD_HandleTypeDef *hhcd) USBx_HOST->HFIR = (uint32_t)60000; } } - HAL_HCD_Connect_Callback(hhcd); + HAL_HCD_PortEnabled_Callback(hhcd); if(hhcd->Init.speed == HCD_SPEED_HIGH) { diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h index c0e5487..85c96ae 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h @@ -122,6 +122,7 @@ USBH_StatusTypeDef USBH_LL_Start (USBH_HandleTypeDef *phost); USBH_StatusTypeDef USBH_LL_Stop (USBH_HandleTypeDef *phost); USBH_StatusTypeDef USBH_LL_Connect (USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_LL_PortEnabled (USBH_HandleTypeDef *phost); USBH_StatusTypeDef USBH_LL_Disconnect (USBH_HandleTypeDef *phost); USBH_SpeedTypeDef USBH_LL_GetSpeed (USBH_HandleTypeDef *phost); USBH_StatusTypeDef USBH_LL_ResetPort (USBH_HandleTypeDef *phost); 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 4a5dfa8..4eb2709 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 @@ -24,7 +24,9 @@ * limitations under the License. * ****************************************************************************** - */ + * + * Modifications by Robert Fisk + */ /* Includes ------------------------------------------------------------------*/ #include "usbh_core.h" @@ -401,7 +403,7 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost) switch (phost->gState) { - case HOST_IDLE : + case HOST_IDLE: if (phost->device.is_connected) { @@ -426,7 +428,7 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost) USBH_Delay(100); phost->device.speed = USBH_LL_GetSpeed(phost); - + phost->gState = HOST_ENUMERATION; phost->Control.pipe_out = USBH_AllocPipe (phost, 0x00); @@ -835,18 +837,29 @@ USBH_StatusTypeDef USBH_LL_Connect (USBH_HandleTypeDef *phost) { phost->pUser(phost, HOST_USER_CONNECTION); } - } - else if(phost->gState == HOST_DEV_WAIT_FOR_ATTACHMENT ) + } + else if (phost->gState == HOST_DEV_WAIT_FOR_ATTACHMENT) { - phost->gState = HOST_DEV_ATTACHED ; + //On the first boot after a power cycle with a low-speed device pre-attached, + //we get a second port-connected interrupt!??? + //So go back and do the port reset again... + phost->gState = HOST_IDLE; } -#if (USBH_USE_OS == 1) - osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0); -#endif - return USBH_OK; } + + +USBH_StatusTypeDef USBH_LL_PortEnabled (USBH_HandleTypeDef *phost) +{ + if(phost->gState == HOST_DEV_WAIT_FOR_ATTACHMENT ) + { + phost->gState = HOST_DEV_ATTACHED ; + } + return USBH_OK; +} + + /** * @brief USBH_LL_Disconnect * Handle USB Host disconnection event diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c index dbd03b4..df7f7d5 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c @@ -23,7 +23,10 @@ * limitations under the License. * ****************************************************************************** - */ + * + * Modifications by Robert Fisk + */ + /* Includes ------------------------------------------------------------------*/ #include "usbh_ctlreq.h" @@ -654,7 +657,13 @@ static USBH_StatusTypeDef USBH_HandleControl (USBH_HandleTypeDef *phost) #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0); #endif - } + } + else if (URB_Status == USBH_URB_NOTREADY) + { + //Some mice cause a transaction error interrupt (HCINT_TXERR) at this point, + //so we retry and hope for the best! + phost->Control.state = CTRL_SETUP; + } break; case CTRL_DATA_IN: diff --git a/Downstream/Src/usbh_config.c b/Downstream/Src/usbh_config.c index 8a7b6a7..af812dc 100644 --- a/Downstream/Src/usbh_config.c +++ b/Downstream/Src/usbh_config.c @@ -112,6 +112,13 @@ void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd) USBH_LL_Connect(hhcd->pData); } + +void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd) +{ + USBH_LL_PortEnabled(hhcd->pData); +} + + /** * @brief SOF callback. * @param hhcd: HCD handle diff --git a/Upstream/.cproject b/Upstream/.cproject index e0a67c4..64b5466 100755 --- a/Upstream/.cproject +++ b/Upstream/.cproject @@ -48,7 +48,7 @@ - +