cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_HCD_Disconnect_Callback called usb host stm32f429disco 1

SGasp.1
Senior

Hi community.. I am working with stm32f429disco1 (the one with display) I created the code with cube mx and you can find it here in the attachments.. The usb host function it is not working..

I am able to get just at the beginning one connection

phost->device.is_connected = 1

USBH_StatusTypeDef  USBH_Process(USBH_HandleTypeDef *phost)
{
  __IO USBH_StatusTypeDef status = USBH_FAIL;
  uint8_t idx = 0U;
 
  /* check for Host pending port disconnect event */
  if (phost->device.is_disconnected == 1U)
  {
    phost->gState = HOST_DEV_DISCONNECTED;
  }
 
  switch (phost->gState)
  {
    case HOST_IDLE :
 
      if ((phost->device.is_connected) != 0U)
      {
        USBH_UsrLog("USB Device Connected");
 
        /* Wait for 200 ms after connection */
        phost->gState = HOST_DEV_WAIT_FOR_ATTACHMENT;
        USBH_Delay(200U);
        (void)USBH_LL_ResetPort(phost);
 
        /* Make sure to start with Default address */
        phost->device.address = USBH_ADDRESS_DEFAULT;
        phost->Timeout = 0U;
 
#if (USBH_USE_OS == 1U)
        phost->os_msg = (uint32_t)USBH_PORT_EVENT;
#if (osCMSIS < 0x20000U)
        (void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
        (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif
#endif
      }

then if i leave the usb stick without removing i have immediatly the call to this function

/**
  * @brief  SOF callback.
  * @param  hhcd: HCD handle
  * @retval None
  */
void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd)
{
  USBH_LL_Disconnect(hhcd->pData);
}

So it seems that i am getting an interrupt that i am removing the usb key..

Can you please help me to understand why always I get the disconnection?

Thanks a lot

8 REPLIES 8
Pavel A.
Evangelist III

What is your USBH_UsrLog? Please don't tell that it is slow.

SGasp.1
Senior

Hi @Pavel A.​ ..

#define USBH_UsrLog(...) do {} while (0)

I am able to enter inside the instruction USBH_UsrLog("USB Device Connected");

just once.

I am not conidnt that the ioc file i have uploaded here it is correct.

Any ideas ?

Thanks

Do you see another connect after this disconnect?

In one project with STM32F4 USB host I've seen that after connecting a flash drive and the connect event, very soon it disconnects - but then connects again and then stays connected.

I was in hurry and never got to the root reason of it.

Hi @Pavel A.​ .. no just one connection then immediatly a disconnection and then never connects again..

It is always here

 __IO USBH_StatusTypeDef status = USBH_FAIL;

Then I'm afraid you need a USB bus sniffer, software or better hardware.

Hi @Pavel A.​ .. the hardware it is the evaluation board stm32f429disco1 provided from ST.

It is not clear why they din't provide an ioc file for the usb host for this popular board.

SGasp.1
Senior

@Pavel A.​  i have found this ..

https://community.st.com/s/question/0D53W00002FY6i2SAD/stm32f4-another-usb-host-msc-problem

What do you think?

Thanks

The most recent USBH library in the STM32F4 package is v 3.4.0 (April 2021) as can be seen in the release notes.

The latest release on the library is 3.5.1 (Jan 2023). Worth to try.

If it won't work you can request your money back ... but the lost time won't be compensated ((