Skip to main content
Associate II
September 28, 2025
Solved

STM32WBA65 example logic wrong in HAL_PCD_MspInit()?

  • September 28, 2025
  • 1 reply
  • 461 views

Hello,

I'm chasing a problem where my project is having its configuration of SMPS mode switch back to LDO, and I was realizing that the settings are reset when USB is enabled. Digging into this, I came across this:

 /* Enable VDDUSB */
 if(__HAL_RCC_PWR_IS_CLK_ENABLED())
 {
 __HAL_RCC_PWR_CLK_ENABLE();
 HAL_PWREx_EnableVddUSB();
 HAL_PWREx_EnableUSBPWR();
 __HAL_RCC_PWR_CLK_DISABLE();
 }
 else
 {
 HAL_PWREx_EnableVddUSB();
 }

At a glance, the logic appears incorrect -- why would you enable PWR_CLK when you just checked and it was already enabled? I looked through the v1.7.0 SDK example projects, and saw that most other projects, the line is `if (__HAL_RCC_PWR_IS_CLK_ENABLED() != 1U)`. This only appears here:

./Projects/NUCLEO-WBA65RI/Applications/USBX/Ux_Device_CDC_ACM/Core/Src/stm32wbaxx_hal_msp.c: if(__HAL_RCC_PWR_IS_CLK_ENABLED())
./Projects/NUCLEO-WBA65RI/Applications/USBX/Ux_Device_CDC_ACM/Core/Src/stm32wbaxx_hal_msp.c: if(__HAL_RCC_PWR_IS_CLK_ENABLED())
./Projects/NUCLEO-WBA65RI/Applications/USBX/Ux_Host_HID/Core/Src/stm32wbaxx_hal_msp.c: if(__HAL_RCC_PWR_IS_CLK_ENABLED())
./Projects/NUCLEO-WBA65RI/Applications/USBX/Ux_Host_HID/Core/Src/stm32wbaxx_hal_msp.c: if(__HAL_RCC_PWR_IS_CLK_ENABLED())
./Projects/NUCLEO-WBA65RI/Applications/USBX/Ux_Device_HID_Standalone/Core/Src/stm32wbaxx_hal_msp.c: if(__HAL_RCC_PWR_IS_CLK_ENABLED())
./Projects/NUCLEO-WBA65RI/Applications/USBX/Ux_Device_HID_Standalone/Core/Src/stm32wbaxx_hal_msp.c: if(__HAL_RCC_PWR_IS_CLK_ENABLED())
./Projects/NUCLEO-WBA65RI/Applications/USBX/Ux_Host_HID_Standalone/Core/Src/stm32wbaxx_hal_msp.c: if(__HAL_RCC_PWR_IS_CLK_ENABLED())
./Projects/NUCLEO-WBA65RI/Applications/USBX/Ux_Host_HID_Standalone/Core/Src/stm32wbaxx_hal_msp.c: if(__HAL_RCC_PWR_IS_CLK_ENABLED())

Is this indeed a bug?

Thank you,
Jonathan

Best answer by STTwo-32

Hello @JFisher-Legato 

After checking internally, I think the following changes should be made both in HAL_PCD_MspInit and HAL_PCD_MspDeinit:

  1. "if(__HAL_RCC_PWR_IS_CLK_ENABLED())" -> "if(__HAL_RCC_PWR_IS_CLK_ENABLED() != 1U)"
  2. add HAL_PWREx_EnableUSBPWR or HAL_PWREx_DisableUSBPWR in if and else sections.
  3. add HAL_PWREx_EnableUSBBooster or HAL_PWREx_DisableUSBBooster in if and else sections.

This should be solved on the same internal ticket i've already created.

Best Regards.

STTwo-32

 

1 reply

STTwo-32
Technical Moderator
September 28, 2025

Hello @JFisher-Legato 

I think this is a typo. It must be:

(__HAL_RCC_PWR_IS_CLK_ENABLED() != 1U)

And not:

__HAL_RCC_PWR_IS_CLK_ENABLED()

 I've escalated this internally to be updated on the future (under internal ticket number 218518).


Best Regards.

STTwo-32

Associate II
September 28, 2025

Thank you - that does appear to help a bit. Then the next question I have is why there seems to be a missing call to

HAL_PWREx_EnableUSBPWR();

I have enabled this and things seem to be better.

Additionally, the logic is also backwards in the HAL_PCD_DeInit() call.

STTwo-32
STTwo-32Best answer
Technical Moderator
September 29, 2025

Hello @JFisher-Legato 

After checking internally, I think the following changes should be made both in HAL_PCD_MspInit and HAL_PCD_MspDeinit:

  1. "if(__HAL_RCC_PWR_IS_CLK_ENABLED())" -> "if(__HAL_RCC_PWR_IS_CLK_ENABLED() != 1U)"
  2. add HAL_PWREx_EnableUSBPWR or HAL_PWREx_DisableUSBPWR in if and else sections.
  3. add HAL_PWREx_EnableUSBBooster or HAL_PWREx_DisableUSBBooster in if and else sections.

This should be solved on the same internal ticket i've already created.

Best Regards.

STTwo-32