cancel
Showing results for 
Search instead for 
Did you mean: 

Battery Charge Detection Fails after First Time

Rob.Riggs
Senior III

I am having a similar problem to this post: https://community.st.com/s/question/0D50X00009XkewvSAB/battery-charging-detectorusbbcdr-of-stm32f04-only-works-one-time

This is on an STM32L433 using L4 HAL 1.13.0.

Initially, all subsequent BCD checks after the first failed, resulting in PCD_BCD_ERROR. I discovered that HAL_PCDEx_BCD_VBUSDetect() calls HAL_PCDEx_DeActivateBCD() when complete, but never calls HAL_PCDEx_ActivateBCD(). Calling that manually before calling HAL_PCDEx_BCD_VBUSDetect() allows the subsequent calls to continue without PCD_BCD_ERROR. However, it now detects the wrong port type on subsequent attempts, always returning PCD_BCD_STD_DOWNSTREAM_PORT, when it properly detected the port as a PCD_BCD_DEDICATED_CHARGING_PORT the first time through.

Yes, I am using the HAL. I have looked at the sample code, but the BCD stuff is trivial and would hit the first problem immediately. The HID_Standalone_BCD example does not appear to be designed to demonstrate a battery powered device that will remain powered on after a USB disconnect.

It is not obvious which bits would cause the BCD circuitry to detect a dedicated port as a standard port.

Two things:

  1. What would cause HAL_PCDEx_BCD_VBUSDetect() to misbehave in this manner, detecting the incorrect port type on subsequent connection events?
  2. It seems that HAL_PCDEx_BCD_VBUSDetect() should call HAL_PCDEx_ActivateBCD() if it calls HAL_PCDEx_DeActivateBCD(). This needs to be fixed in the HAL.
1 REPLY 1
Rob.Riggs
Senior III

It seems that setting

hpcd_USB_FS.Instance->BCDR = 0;

Before calling HAL_PCDEx_ActivateBCD() resolves the issue with the HAL detecting the wrong USB port type. It seems like the HAL PCD library is not properly managing the BCD state.

Is there an application note on the proper care and feeding of the STM32L4 BCD subsystem and the corresponding HAL library? I looked but did not find one. The example code is too trivial to provide the detailed guidance needed by anyone developing a battery powered device.