cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_PCDEx_BCD_Callback in usb_device.c does not start USB device

i-am-groot
Associate

In version v2.0_Cube of usb_device.c , the provided code is the following:

void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
{
  USBD_HandleTypeDef usbdHandle = hUsbDeviceFS;
 
  /* USER CODE BEGIN 7 */
  if (hpcd->battery_charging_active == ENABLE)
  {
    switch(msg)
    {
      case PCD_BCD_CONTACT_DETECTION:
 
      break;
 
      case PCD_BCD_STD_DOWNSTREAM_PORT:
 
      break;
 
      case PCD_BCD_CHARGING_DOWNSTREAM_PORT:
 
      break;
  
      case PCD_BCD_DEDICATED_CHARGING_PORT:
 
      break;
 
      case PCD_BCD_DISCOVERY_COMPLETED:
        USBD_Start(&usbdHandle);
      break;
 
      case PCD_BCD_ERROR:
      default:
      break;
    }
  }
  /* USER CODE END 7 */
}

So it looks like when Battery Charging Detection BCD discovery is completed, no matter what the result is (SDP, CDP, or DCP), the USB device should always start with USBD_Start(&usbdHandle);

However this is not the case. In HAL_PCDEx_BCD_VBUSDetect , we see this

  /* Battery Charging capability discovery finished Start Enumeration */
  (void)HAL_PCDEx_DeActivateBCD(hpcd);
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
  hpcd->BCDCallback(hpcd, PCD_BCD_DISCOVERY_COMPLETED);
#else
  HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DISCOVERY_COMPLETED);
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */

which deactivates BCD before calling the Callback function with PCD_BCD_DISCOVERY_COMPLETED.

Since HAL_PCDEx_BCD_Callback checks if (hpcd->battery_charging_active == ENABLE) before entering switch statement, case PCD_BCD_DISCOVERY_COMPLETED is never reached and USB device does not get started.

1 REPLY 1
eBirdman
Senior

I have the same problem. Is it not solved yet? Does STM development team read these posts?