Fix for occasional problem when attaching mouse after powerup.

It turned out we were getting a "device disconnected" interrupt while
waiting for the port to enable following reset. Simply ignoring the
disconnect interrupt allows everything to work! WTF...
USG_1.0
Robert Fisk 8 years ago
parent 975f2d00af
commit 8aec6a6ca3

@ -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);

@ -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

@ -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);

@ -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;
}
/**

Loading…
Cancel
Save