AnsweredAssumed Answered

STM32F411, STM32CubeMX, USB Device for CDC

Question asked by lai.bardeen on Nov 26, 2014
Latest reply on Dec 7, 2014 by pirc.matija

When using STM32CubeMX Ver4.4 to generate USB Device only code for CDC class, initialization is fine but cannot connect to PC (host).

The STM32CubeMX generated code also has same problem as MDK-ARM 5.xx USB device driver. It could be resulting from "power saving mode" or "VBus voltage sensing" for STM32F411.

For example,
      * @file           : usbd_conf.c
      * @date           : 24/11/2014 18:53:54   
      * @version        : v1.0_Cube
      * @brief          : This file implements the board support package for the USB device library
        USBD_StatusTypeDef  USBD_LL_Init (USBD_HandleTypeDef *pdev)
          /* Init USB_IP */
          if (pdev->id == DEVICE_FS) {
          /* Link The driver to the stack */     
          hpcd_USB_OTG_FS.pData = pdev;
          pdev->pData = &hpcd_USB_OTG_FS; 
          hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
          hpcd_USB_OTG_FS.Init.dev_endpoints = 7;
          hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
          hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
          hpcd_USB_OTG_FS.Init.ep0_mps = DEP0CTL_MPS_64;
          hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
          hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
          //hpcd_USB_OTG_FS.Init.low_power_enable = ENABLE;
 hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
          hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
          hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
          hpcd_USB_OTG_FS.Init.use_external_vbus = DISABLE;
          HAL_PCD_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
          HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
          HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80);
          return USBD_OK;

At line 268 of usbd_conf.c, disable the "low_power_enable" flag then USB device can work fine...

I have no idea what is going on USB driver for STM32F411 body. Please address me if you have similar issue.

Thank you!