cancel
Showing results for 
Search instead for 
Did you mean: 

STM32C031C6T6 : wakeup from shutdown mode

ouss_mans
Associate II

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.

7 REPLIES 7
Sarra.S
ST Employee

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.

ouss_mans
Associate II

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 

Sarra.S
ST Employee

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.

Hello @Sarra.S ,

here is my code :

ouss_mans_0-1718975504498.png

And this is what I get when I am in debug mode :

ouss_mans_1-1718975681297.png

when i am not in debug mode : 

ouss_mans_2-1718975715168.png

and this is my shutdown function : 

ouss_mans_3-1718975769183.png

 

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 

 

 

ouss_mans
Associate II
So, we added a delay before going to shutdown to see what we get :
ouss_mans_0-1718982651758.png

 

 
This is what we get:
- When I do a short press, the PWR_SR1 equals 0 and the device goes to shutdown.
- When I press the button and keep it pressed, the PWR_SR1 equals 0. After 1 second, it goes to shutdown, and after that, the device wakes up, and PWR_SR1 equals 258.
 
 
ouss_mans_1-1718982651760.png

 

Thank you.
 

Primary you cant activate WUpin when is LOW, then add chcek to release before ...

ouss_mans
Associate II

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