cancel
Showing results for 
Search instead for 
Did you mean: 

WUF flag don't set after shutdown

DPesk.1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

4 REPLIES 4
TDK
Guru

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
Associate II

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
Guru

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".

Ou, sorry, I misunderstood that phrase) Thanks