AnsweredAssumed Answered

USB on STm32F411RE

Question asked by Quentin on Apr 7, 2016
Latest reply on Apr 8, 2016 by Quentin
Hi,
I'm trying to handle a printer via USB with my NUCLEO-F411RE but I'm facing a problem. Indeed, when my board send the first request for the enumeration, it goes in a waiting time forever :
phost -> gState                = HOST_ENUMERATION
phost -> EnumState        = ENUM_IDLE
phost -> RequestState     = CMD_WAIT
and
phost -> Control -> state = CTRL_SETUP_WAIT

When I check the DP and DM line, there are indeed communication between my printer and the board but I don't know what the message means.


For the Hardware, I have this (sorry but there is a bug when I try  to put a picture or a code block...). The LP2980-5 is a linear regulator supplied with 10V.

For the Code, I'm inspired by a MSC_HOST application from STM324xG_Eval. Here the main part of usb_conf.c (I attach the complete file just in case):

void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
{
    GPIO_InitTypeDef  GPIO_InitStruct;
  
     /* Configure USB FS GPIOs */
     __HAL_RCC_GPIOA_CLK_ENABLE();
     //__HAL_RCC_GPIOH_CLK_ENABLE();
     
     GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
     GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 
     
     GPIO_InitStruct.Pin = GPIO_PIN_6;
     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 
     
     /* Enable USB FS Clocks */ 
     __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
     
     /* Set USBFS Interrupt to the lowest priority */
     HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0);
     
     /* Enable USBFS Interrupt */
     HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
}

USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost)
{  
  /* Set the LL driver parameters */
  hhcd.Instance = USB_OTG_FS;
  hhcd.Init.Host_channels = 11; 
  hhcd.Init.dma_enable = 0;
  hhcd.Init.low_power_enable = 0;
  hhcd.Init.phy_itface = HCD_PHY_EMBEDDED; 
  hhcd.Init.Sof_enable = 0;
  hhcd.Init.speed = HCD_SPEED_FULL;
  /* Link the driver to the stack */
  hhcd.pData = phost;
  phost->pData = &hhcd;
  /* Initialize the LL Driver */
  HAL_HCD_Init(&hhcd);

  USBH_LL_SetTimer(phost, HAL_HCD_GetCurrentFrame(&hhcd));
  
  return USBH_OK;
}

USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state)
{
    if(state == 0)
   {
        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
    }
    else
   {
        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
    }
   
    HAL_Delay(200);

     return USBH_OK;  
}


Except for the Vbus pin, I didn't change much. I although tried to use the mass storage class with a usb stick to be sur the problem didn't come from my printer class. It didn't change anything as expected.

Has anyone succeed to use this board as USB host ? 
For the others, is there a obvious problem that I don't get ?

Thank you.

Attachments

Outcomes