cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U585 PWR_WKUP from STOP Mode

bjackson96
Associate II

Hello,

I am using the STM32U585 along with two sensors in a project and I need some help. I want to run my MCU in stop 3 mode primarily and have one of the sensors generate an interrupt on the PWR_WKUP pin of the MCU to return to normal mode and start polling data from the other sensor. I am not very experienced in programming and I'm finding it hard to find the functions needed in the IDE or information in the reference manual to do what I want. Any help would be greatly appreciated.

Thanks.

4 REPLIES 4
Hl_st
ST Employee
Hello,
 
there is one of the simplest way how to do it.
At first generate default code by STM32CubeMX for your IDE
and use there in infinite loop the code below. There 
MCU enters into STOP3 mode and stay there until rising
edge on PA0 pin occurs and then MCU wake up and executes 
your code. After your code will be executed MCU enters
back into STOP3 mode.
 
 
/* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {   
  /* Enable Power Control clock */
  __HAL_RCC_PWR_CLK_ENABLE();
 
  /* Clear all flags from all Wake up pins */
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF);
 
  /* Enable Wake up pin 1 (PA0) with rising edge detection */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);
 
  /* Enter into STOP3 mode and stay there
   * until rising edge on PA0 is detected */
  HAL_PWREx_EnterSTOP3Mode(PWR_STOPENTRY_WFI);
 
  /* Rising edge on PA0 was detected MCU wakes up */
 
 
  /* Time to start polling data from the other sensor
   * ...
   * ... YOUR CODE
   * ...
   * */
 
 
  /* After the end of polling data from other sensor enter back
   * into STOP3 mode in the beginning of while cycle */
 
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */

 

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.

Thank you for your response I will give this solution a try!

Ok, I am trying to run the code you sent and it's not working as expected. Through debugging it seems that it enters into stop 3 mode and immediately exits.

The reference manual has the following note: To enter Stop 3 mode, all WUFx, and the RTC/TAMP flags generating wake-up interrupts must be cleared. Otherwise, the Stop 3 mode entry procedure is completed but the Stop 3 is exited immediately after entry.

I cleared all the power flags so maybe one of the RTC/TAMP flags are set. I have all the timers disabled so they should not be setting any of the flags. Do I also need to clear all timer flags even if they are disabled?

I think it should works without clearing any other flags if you don´t use RTC or TIM,...

Sorry I didn´t mentioned that there have to be connected an external PULL-DOWN resistor to WAKEUP_PIN1 (PA0), so if you connect for example 10 kOhm from GND to PA0 it should solve the problem. Without this resistor is MCU woken up by every noise signal inducted on the pin PA0.

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.