Showing results for 
Search instead for 
Did you mean: 

STM32G0 Programmable Voltage Detector working backwards?


I'm checking the PVD example from STM32G0 repository in CubeMx and something looks backwards to me unless I'm misunderstanding it. I'm expecting the rising callback when the voltage is ABOVE the threshold not below like the code shows. Likewise, I'm expecting the falling callback when the voltage is BELOW threshold. But the code behaves the opposite, that is, the falling callback comes in when the voltage is above ~2.6V and rising callback when is below ~2.5V.

Part of the code:

/* Configure the PVD Level to 3 and generate an interrupt on rising and falling
     edges(PVD detection level set to 2.5V, refer to the electrical characteristics
     of you device datasheet for more details) */
  sConfigPVD.PVDLevel = PWR_PVDLEVEL_3;
void HAL_PWREx_PVD_PVM_Rising_Callback(void)
  /* Turn Off LED1 as voltage is below threshold */
  /* Set uwToggleOn global variable to zero to disable toggle */
  uwToggleOn = 0u;
void HAL_PWREx_PVD_PVM_Falling_Callback(void)
  /* Turn On LED1 as voltage is above threshold */
  /* Set uwToggleOn global variable to one to disable toggle */

ST Employee

Thank you, @XP.1acheco​, for bringing this to our attention. 

In mainc of the examples, the comments have probably been swapped, but the function names are correct:

  • Projects\NUCLEO-G0B1RE\Examples\PWR\PWR_PVDPWR_PVD/src
  • Projects\STM32G0C1E-EV\Examples\PWR\PWR_PVD\Src

We will check this again and correct it in one of the next updates if necessary.




@Amel NASRI​ 

In order 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.

Even if the comments are swapped, for some reason I'm still seeing that void HAL_PWREx_PVD_PVM_Rising_Callback is being called during the falling edge and vice versa.


I will recheck again, but I have done so multiple times and can't understand why the code is behaving backwards. I'm doing real tests varying the supply voltage.

I'd suggest setting a breakpoint in the IRQ handler itself and verifying the correct flags are set. That would avoid any HAL nonsense. It would be weird for the flags to be misdefined in the header file, but possible.

If you feel a post has answered your question, please click "Accept as Solution".

I tried in different Nucleo Boards and the issue remains so it's not my custom board. I will try to check the flags.