cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U585 - Wakeup reason detection when exiting shutdown

DHečk.1
Associate

Hi,

Im trying to get WUP reason after the MCU exited the shutdown. I'm using pushbutton connected to PC5 pin to wake up the MCU. I cannot get the WUP flag to behave correctly. Sometimes it is present, sometimes not. This feature is part of bigger project where I use WUP by two alarms and pushbutton. I have no problem detecting that the WUP happend due to alarmA or alarmB, but I'm struggling with the pushbutton.

Here is code snippet from test app where I am debugging behaviour of WUP:

	__HAL_RCC_GPIOC_CLK_ENABLE();
 
	HAL_UART_Transmit(&hlpuart1, "Hello\r\n", 7, 300);
 
	if(PWR->WUSR & PWR_WUSR_WUF5)
	{
		PWR->WUSCR &= PWR_WUSCR_CWUF5;	//clear flag
		HAL_UART_Transmit(&hlpuart1, "Button WUP!\r\n", 13, 300);
	}
 
	char buff[32]="";
	sprintf(buff, "WUSR:%08X, CSR:%08X\r\n",PWR->WUSR,RCC->CSR);
	HAL_UART_Transmit(&hlpuart1, buff, strlen(buff), 300);
 
	HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN5);
	__HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_FLAG5);
	HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN5_HIGH_0);
	HAL_PWREx_EnterSHUTDOWNMode();

If I attach the debugger everything starts to work just fine. Is there something I am doing wrong ? Are the registers reseted upon exiting shutdown ?

4 REPLIES 4
Sarra.S
ST Employee

Hello @David He�?ko​ and welcome to the Community :smiling_face_with_smiling_eyes:,

The Wake up flag WUF5 is cleared by writing 1 in the CWUF5 bit of PWR_WUSCR,

to do so, this is the right instruction : PWR->WUSCR |= PWR_WUSCR_CWUF5;

Thank you!

Sarra.

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.

DHečk.1
Associate

Hi @Sarra.S​ , thank you for quick response. I've tried this fix and it unfortunately does not seems to help.

Sarra.S
ST Employee

Hello again @David He�?ko​,

I am not sure if the if statement is even being executed

if(PWR->WUSR & PWR_WUSR_WUF5)

{

PWR->WUSCR &= PWR_WUSCR_CWUF5; //clear flag

HAL_UART_Transmit(&hlpuart1, "Button WUP!\r\n", 13, 300);

}

To make sure, is the "Button WUP!" string being displayed ?

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.

No, the correct code is:

PWR->WUSCR = PWR_WUSCR_CWUF5;

Take a note that it doesn't use an OR instruction and is not a RMW (Read-Modify-Write) operation.