Skip to main content
Rob.Riggs
Senior
July 2, 2017
Question

STM32L4 HAL_PCDEx_BCD_VBUSDetect() Broken for (non-OTG) USB

  • July 2, 2017
  • 1 reply
  • 650 views
Posted on July 02, 2017 at 03:41

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 #pcd
This topic has been closed for replies.

1 reply

ST Technical Moderator
July 3, 2017
Posted on July 03, 2017 at 11:50

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

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks