2017-07-01 06:41 PM
I am using STM32CubeMX 4.0 and STM32L4 HAL version 1.8.1.
TheHAL_PCDEx_BCD_VBUSDetect() function for 'USB' and 'USB_OTG_FS' differ and the 'USB' version is buggy.
TheHAL_PCDEx_BCD_VBUSDetect() function
is supposed to callHAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DISCOVERY_COMPLETED) when the BCD discovery is complete. However, the way the 'USB' version of thefunction is written, it will only be called when a 'Charging Downstream Port' is detected and not for the other port types.The code as written looks likethis:
/* If Charger detect ? */
if (USBx->BCDR & USB_BCDR_PDET)
{
/* Start secondary detection to check connection to Charging Downstream
Port or Dedicated Charging Port */
USBx->BCDR &= ~(USB_BCDR_PDEN);
USBx->BCDR |= (USB_BCDR_SDEN);
HAL_Delay(300);
/* If CDP ? */
if (USBx->BCDR & USB_BCDR_SDET)
{
/* Dedicated Downstream Port DCP */
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DEDICATED_CHARGING_PORT);
}
else
{
/* Charging Downstream Port CDP */
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CHARGING_DOWNSTREAM_PORT);
/* Battery Charging capability discovery finished
Start Enumeration*/
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DISCOVERY_COMPLETED);
}
}
else /* NO */
{
/* Standard Downstream Port */
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_STD_DOWNSTREAM_PORT);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
The code should look like this (which is essentiallythe same as the USB_OTG_FS version in the same file):
/* If Charger detect ? */
if (USBx->BCDR & USB_BCDR_PDET)
{
/* Start secondary detection to check connection to Charging Downstream
Port or Dedicated Charging Port */
USBx->BCDR &= ~(USB_BCDR_PDEN);
USBx->BCDR |= (USB_BCDR_SDEN);
HAL_Delay(300);
/* If CDP ? */
if (USBx->BCDR & USB_BCDR_SDET)
{
/* Dedicated Downstream Port DCP */
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DEDICATED_CHARGING_PORT);
}
else
{
/* Charging Downstream Port CDP */
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CHARGING_DOWNSTREAM_PORT);
}
}
else /* NO */
{
/* Standard Downstream Port */
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_STD_DOWNSTREAM_PORT);
}
/* Battery Charging capability discovery finished
Start Enumeration*/
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DISCOVERY_COMPLETED);�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
HAL_PCDEx_BCD_VBUSDetect() must call
HAL_PCDEx_BCD_Callback()
withPCD_BCD_DISCOVERY_COMPLETED without regard tothe port type detected.Please fix this.
#stm32cubemx #stm32l4 #hal #usb #bcd #pcd2017-07-03 02:50 AM
Hello
Riggs.Rob
,I will raise your reported issue internally for further investigation and wewill keep you informed about the taken actions/explanation if needed.
Regards
Imen