Skip to main content
DPesk.1
Associate II
May 12, 2020
Solved

WUF flag don't set after shutdown

  • May 12, 2020
  • 3 replies
  • 1196 views

Hi everybody)

I have a problem with exiting after shutdown mode.

Entering code

if( (LL_PWR_IsActiveFlag_C1SB() == 0)
 || (LL_PWR_IsActiveFlag_C2SB() == 0)
 )
 {
 /* Set the lowest low-power mode for CPU2: shutdown mode */
 LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
	 
 }
	HAL_RTCEx_BKUPWrite(&hrtc, 5, 0x0005);
	
	HAL_PWREx_ClearWakeupFlag(PWR_FLAG_WU);
	HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW);
 
	HAL_SuspendTick();
	HAL_PWREx_EnterSHUTDOWNMode();

My board have a button in PA0 with external pullup resistor.

When I press the button MCU exiting from shutdown mode, but my function

if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF1)) ...

return FALSE always.

My starting code:

int main(void)
{
 /* USER CODE BEGIN 1 */
	
 /* USER CODE END 1 */
 
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
	
 /* USER CODE END Init */
 
 /* Configure the system clock */
 SystemClock_Config();
 
 /* USER CODE BEGIN SysInit */
 
 /* USER CODE END SysInit */
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_I2C1_Init();
 MX_SPI1_Init();
 MX_TIM1_Init();
 MX_ADC1_Init();
 MX_RTC_Init();
 MX_RF_Init();
 /* USER CODE BEGIN 2 */
 
 if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF1))
 {
	 reboot = true;
 }

RTC is enable in shutdown, but don't use to wakeup. RTC tampers are disabled.

This topic has been closed for replies.
Best answer by TDK

Per the reference manual:

A power-on reset occurs when exiting from Shutdown mode. All registers (except for the ones in the Backup domain) are reset after wakeup from Shutdown.

This includes the PWR_SR1 register. The WUF1 flag is only set after exiting standby modes.

That's how I read it, at least.

3 replies

TDK
Super User
May 13, 2020

Your code as written checks __HAL_PWR_GET_FLAG before entering shutdown mode. Those bits will be clear after reset. Where in main() do you even enter shutdown?

"If you feel a post has answered your question, please click ""Accept as Solution""."
DPesk.1
DPesk.1Author
Associate II
May 13, 2020

But this is ST example. When I exiting from shutdown mode MCU is reseting (as NRST pin) and start program at the start your code

TDK
TDKAnswer
Super User
May 13, 2020

Per the reference manual:

A power-on reset occurs when exiting from Shutdown mode. All registers (except for the ones in the Backup domain) are reset after wakeup from Shutdown.

This includes the PWR_SR1 register. The WUF1 flag is only set after exiting standby modes.

That's how I read it, at least.

"If you feel a post has answered your question, please click ""Accept as Solution""."
DPesk.1
DPesk.1Author
Associate II
May 13, 2020

Ou, sorry, I misunderstood that phrase) Thanks