2024-06-19 05:36 AM
Hello,
I'm contacting you regarding a support request concerning the wakeup from shutdown mode of the STM32C031C6T6:
The issue we're facing is that __HAL_PWR_GET_FLAG(PWR_FLAG_WUF2) returns True when I power up my STM32, even though I haven't triggered the wakeup flag (which is tied to a button).
I solve this issue by adding a delay of at least 5 ms before calling this macro.
Does anyone know if this delay is always necessary?
Thank you.
Best regards.
2024-06-19 06:43 AM - edited 2024-06-19 06:45 AM
Hello @ouss_mans,
Please note that the wake up from shutdown mode generates a system reset and all instructions after HAL_PWREx_EnterSHUTDOWNMode() function are not executed, to see if the flag is set or not you need to read it before entering shutdown mode.
And I propose to try this sequence( clearing the flag before entering shutdown mode):
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
HAL_PWREx_EnterSHUTDOWNMode();
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.
2024-06-19 06:59 AM
hello @Sarra.S ,
Thank you for your response. My issue is that when I turn the power off and then turn it back on, the WKUP flag is set to true, even though I haven't triggered the wakeup pin.
Normally, the wakeup flag should only be true when I press the button (WKUP pin 2).
thank you
2024-06-19 07:43 AM
Hello again @ouss_mans,
To investigate more, I need you to perform this sequence and share with us the value of PWR-> SR1 everytime
monitor PWR-> SR1 in run mode-> enter shutdown-> trigger wkup pin2-> re-monitor (PWR-> SR1)-> power cycle-> RUN-> re-monitor (PWR-> SR1)-> Again Trigger wakeup pin 2-> re-monitor (PWR-> SR1)
Please let me know if that's clear!
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.
2024-06-21 06:23 AM
Hello @Sarra.S ,
here is my code :
And this is what I get when I am in debug mode :
when i am not in debug mode :
and this is my shutdown function :
The first thing is that it seems like everything is working right in debug mode, but in non-debug mode, when I press the button (a short press), the device goes to shutdown and wakes up whith just one press.
However, when I do a very, very short press, the wakeup flag is false (PWR->SR1 = 0).
thank you in advance
2024-06-21 08:11 AM
2024-06-21 08:46 AM
Primary you cant activate WUpin when is LOW, then add chcek to release before ...
2024-06-24 08:08 AM
hello @MM..1 ,
I changed my shutdown function to this:
int8_t thsthal_shutdown()
{
LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_C, PWR_GPIO_BIT_13); // BTN wkup pin 2
HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_B, PWR_GPIO_BIT_5); // LED
HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_B, PWR_GPIO_BIT_8); // I2C_SCL
HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_B, PWR_GPIO_BIT_9); // I2C_SDA
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
HAL_SuspendTick();
HAL_PWREx_EnterSHUTDOWNMode();
return THSTHAL_ERROR;
}
and when I retrieve the value of `PWR->SR1`, it's always 0 when I press the button, although it should be 2.
thank you