cancel
Showing results for 
Search instead for 
Did you mean: 

How to reading wakeup flag?

Macun
Associate II

I want to know which Wakeup pin or Reset pin wakes up the microprocessor that enters standby mode. I have 2 wakeup pins.
I am monitoring SR1 and SR2 variables with Live expression in Debug mode, but when I wake up from standby mode, the value of the variables does not change.

Is there a method other than the code block below?

I am grateful in advance.


/* USER CODE BEGIN 2 */

CheckWakeupPins();

/* USER CODE END 2 */


/* USER CODE BEGIN 4 */

void CheckWakeupPins(void) {

// Ensure the PWR clock is enabled

__HAL_RCC_PWR_CLK_ENABLE();

 

// Read the wakeup pin status from PWR_SR1

uint32_t wakeup_status = __HAL_PWR_GET_FLAG(PWR_FLAG_WU);

 

// Check individual wakeup pins - adjust mask as per your device's definitions

SR1 = (wakeup_status & PWR_FLAG_WUF1) ? 1 : 0;

SR2 = (wakeup_status & PWR_FLAG_WUF2) ? 1 : 0;

HAL_Delay(3000);

 

// Clear the wakeup flags after processing to avoid retriggering

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

}

/* USER CODE END 4 */

 

3 REPLIES 3
Hl_st
ST Employee

Hello,

method you are using is correct, but in masking wakeup flag don´t use PWR_FLAG_WUF1 but PWR_SR1_WUF1 and instead of PWR_FLAG_WUF2 use PWR_SR1_WUF2 and it should work fine.

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.

hardrock
Associate II
void EnterStandbyMode(void)
{
    // Enable Power Peripheral
    __HAL_RCC_PWR_CLK_ENABLE();

    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);

    // Clear PWR Wake-up Flag
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

    // Enable WKUP pin
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2);

    // Enter STANDBY Mode
    HAL_PWR_EnterSTANDBYMode();
}

void CheckWakeupReason(void)
{
    if(__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST)) {
        // [Wakeup Reason] Hardware Reset Pin
    }

    if(__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST)) {
        // [Wakeup Reason] Software Reset
    }

    if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB)) {
        // [Wakeup Reason] Standby Mode
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
    }
}

Macun_0-1714571025272.png

You can see the coding in the attached image.

When both WKUP pins are woken up, only the LED named GPIO_PIN_8 lights up.
So WUF2 is never HIGH.

GPIO_PIN_8 when woken up with pin 1,
GPIO_PIN_7 should work when woken up with pin 2, but GPIO_PIN_8 works even when I wake it up with pin 2.