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

1 ACCEPTED SOLUTION

Accepted Solutions

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

 

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.

View solution in original post

3 REPLIES 3
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've escalated this internally to be updated on the future (under internal ticket number 218518).


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.

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

 

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.