cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WBA65 example logic wrong in HAL_PCD_MspInit()?

JFisher-Legato
Associate II

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

2 REPLIES 2
STTwo-32
ST Employee

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 will escalate this internally to be updated on the future. 
Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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.