cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476 wake up source detection

XGao.2
Associate II

Set Blue button(wake up 2) as wake up source and shut down. Press blue button will wake up system and print wake up source.

With cube debugging environment, everything is fine. It shows wake up source is 2

But after stop cube debugging, disconnect JP6 on board, and connect JP6 again. Repeat this test, the wake up source is always 0. This is a problem.

Can somebody repeat my test and help me to figure it out please?

Thank you. Attached is main.c and ioc file

STM32CubeIDE1.11.2

nucleo-l476rg board

Demo code in main.c

 printf("--L476 blue button wake up test. wake up source: %ld\r\n", __HAL_PWR_GET_FLAG(PWR_FLAG_WUF2));

 HAL_Delay(3000);

 HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW);

 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);

 printf(" shut down.\r\n");

 HAL_PWREx_EnterSHUTDOWNMode();

1 ACCEPTED SOLUTION

Accepted Solutions
FBL
ST Employee

Hello @XGao.2​ 

Well same behavior in IAR, I have reviewed your code and the issue may be due to the fact that the PWR_FLAG_WUF2 is not being set before entering the shutdown mode. This flag is being used to determine the source of the wakeup. This issue may result from wakeup pin clear flag.

An internal ticket has been submitted.

Internal ticket number: 145152 (This is an internal tracking number and is not accessible or usable by customers).

When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster. 

Firas

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.

View solution in original post

4 REPLIES 4
FBL
ST Employee

Hello @XGao.2​ ,

Would you please precise your use case application? Is it to measure the current consumption in SHUTDOWN mode in order to disconnect JP6?

The WFI instruction to enter the shutdown mode requires an interrupt handler to wake up the system.

However, there is no corresponding interrupt handler to handle the wake up event. You may need to implement an interrupt handler for the user button wake up source and ensure that it is correctly configured in the interrupt controller.

void EXTI15_10_IRQHandler(void)
{
  HAL_GPIO_EXTI_IRQHandler(USER_BUTTON_PIN);
}

This handler should clear the wake up flag and call the appropriate function to exit the shutdown mode.

You can add an EXTI line detection callbacks as referenced in the example provided.

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if (GPIO_Pin == USER_BUTTON_PIN)
  {    
    /* Wait that user release the User push-button */
    while(BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_RESET){}
 
    /* Disable all used wakeup sources: WKUP pin */
    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
    
 
    /* Clear wake up Flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
    
    /* Enable wakeup pin WKUP2 */
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW);
// user code
}
}

Hope this helps!

Firas

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.

XGao.2
Associate II

Hi F.Belaid

Thank you for your help. I understood your point.

But I think I didn't give you more detail description and let you be confused.

Let's explain my demo code again.

Firmware start, print out wake up flag by checking PWR_FLAG_WUF2,

then sleep 3 seconds.

enable wake up source --- wake up pin2 low.

clear wake up flag

print "shut down"

enter shut down mode.

There is no blue button involved during firmware running.

The only function for blue button is wake up source. It is working only under system shutdown mode.

During ST32CubeIDE debugging mode (download to board and run), system will enter shutdown mode after 3 seconds delay. (Without any button touching).

Then press blue button, system starts again and will show below information. It means system was waken up by wake up pin 2(blue button). That is correct.

--L476 blue button wake up test. wake up source: 2

Another test, same code, no STM32CubeIDE environment:

Stop debugging mode on STM32CubeIDE , disconnect board power supply and connect power supply again (disconnect JP6 and connect JP6).

System will enter shutdown mode after 3 seconds delay. (Without any button touching).

Then press blue button, system starts again and will show below information.

--L476 blue button wake up test. wake up source: 0

It doesn't show correct wake up source number. It is the problem.

below is main(), my customized code is only 6 lines in black.

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_USART2_UART_Init();

 /* USER CODE BEGIN 2 */

 printf("--L476 blue button wake up test. wake up source: %ld\r\n", __HAL_PWR_GET_FLAG(PWR_FLAG_WUF2));

 HAL_Delay(3000);

 HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW);

 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);

 printf(" shut down.\r\n");

 HAL_PWREx_EnterSHUTDOWNMode(); // shut down here and can be waken up by pressing blue button.

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

FBL
ST Employee

Hello @XGao.2​ 

Well same behavior in IAR, I have reviewed your code and the issue may be due to the fact that the PWR_FLAG_WUF2 is not being set before entering the shutdown mode. This flag is being used to determine the source of the wakeup. This issue may result from wakeup pin clear flag.

An internal ticket has been submitted.

Internal ticket number: 145152 (This is an internal tracking number and is not accessible or usable by customers).

When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster. 

Firas

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.

XGao.2
Associate II

Thanks for your help.

Please share once get this internal ticket's response or have some work around solution.