2022-02-24 08:21 PM
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;
sConfigPVD.Mode = PWR_PVD_MODE_IT_RISING_FALLING;
void HAL_PWREx_PVD_PVM_Rising_Callback(void)
{
/* Turn Off LED1 as voltage is below threshold */
BSP_LED_Off(LED1);
/* 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 */
BSP_LED_On(LED1);
/* Set uwToggleOn global variable to one to disable toggle */
2022-02-25 01:51 AM
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:
We will check this again and correct it in one of the next updates if necessary.
Regards
/Peter
@Imen DAHMEN
@Amel NASRI
2022-02-25 05:58 AM
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.
2022-02-25 05:07 PM
The code which calls those checks the correct flags. Perhaps recheck assumptions.
2022-02-25 05:20 PM
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.
2022-02-25 05:25 PM
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.
2022-02-28 07:31 AM
I tried in different Nucleo Boards and the issue remains so it's not my custom board. I will try to check the flags.