AnsweredAssumed Answered

CubeMX V4.20: VBUS sensing always enabled in FS mode STM32F407

Question asked by Markus Rudolf on Mar 15, 2017
Latest reply on Apr 12, 2018 by Markus Rudolf

I discovered CubeMX 4.20 always generates code where VBUS sensing is enabled, no matter if it is ticked in CubeMX or not. This caused enumeration fails in several projects where PA9 is not used by me (I use it in CDC Virtual Com Port mode)


Affected code file is usbd_conf.c line 299 (line 18 in snippet)


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 = 4;
  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 = DISABLE;
  hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE; // <= IT SHOULD BE DISABLED !!!
  hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)

  HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80);
  return USBD_OK;

Took me a while. Please fix it, also fix the annoying RCC Init Bug and the "does not build in STM32 System Workbench because we forgot to put the "attribute weak" in hypens-bug".

It is really annoying to correct this after each minor change in CubeMX.