Skip to main content
Visitor II
June 19, 2024
Question

STM32C031C6T6 : wakeup from shutdown mode

  • June 19, 2024
  • 5 replies
  • 2180 views

Hello,

I'm contacting you regarding a support request concerning the wakeup from shutdown mode of the STM32C031C6T6:

 

The issue we're facing is that __HAL_PWR_GET_FLAG(PWR_FLAG_WUF2) returns True when I power up my STM32, even though I haven't triggered the wakeup flag (which is tied to a button).

 

I solve this issue by adding a delay of at least 5 ms before calling this macro.

Does anyone know if this delay is always necessary?

 

Thank you.

Best regards.

    This topic has been closed for replies.

    5 replies

    ST Employee
    June 19, 2024

    Hello @ouss_mans

    Please note that the wake up from shutdown mode generates a system reset and all instructions after HAL_PWREx_EnterSHUTDOWNMode() function are not executed, to see if the flag is set or not you need to read it before entering shutdown mode.

    And I propose to try this sequence( clearing the flag before entering shutdown mode):

     

    __HAL_RCC_PWR_CLK_ENABLE();
    HAL_PWR_EnableBkUpAccess(); 
    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
    HAL_PWREx_EnterSHUTDOWNMode();
    
    

     

     

    ouss_mansAuthor
    Visitor II
    June 19, 2024

    hello @Sarra.S , 

    Thank you for your response. My issue is that when I turn the power off and then turn it back on, the WKUP flag is set to true, even though I haven't triggered the wakeup pin.

    Normally, the wakeup flag should only be true when I press the button (WKUP pin 2).

    thank you 

    ST Employee
    June 19, 2024

    Hello again @ouss_mans

    To investigate more, I need you to perform this sequence and share with us the value of PWR-> SR1 everytime 

    monitor PWR-> SR1 in run mode-> enter shutdown-> trigger wkup pin2-> re-monitor (PWR-> SR1)-> power cycle-> RUN-> re-monitor (PWR-> SR1)-> Again Trigger wakeup pin 2-> re-monitor (PWR-> SR1)

    Please let me know if that's clear! 

     

     

     

    ouss_mansAuthor
    Visitor II
    June 21, 2024

    Hello @Sarra.S ,

    here is my code :

    ouss_mans_0-1718975504498.png

    And this is what I get when I am in debug mode :

    ouss_mans_1-1718975681297.png

    when i am not in debug mode : 

    ouss_mans_2-1718975715168.png

    and this is my shutdown function : 

    ouss_mans_3-1718975769183.png

     

    The first thing is that it seems like everything is working right in debug mode, but in non-debug mode, when I press the button (a short press), the device goes to shutdown and wakes up whith just one press.

    However, when I do a very, very short press, the wakeup flag is false (PWR->SR1 = 0).

     

    thank you in advance 

     

     

    ouss_mansAuthor
    Visitor II
    June 21, 2024
    So, we added a delay before going to shutdown to see what we get :
    ouss_mans_0-1718982651758.png

     

     
    This is what we get:
    - When I do a short press, the PWR_SR1 equals 0 and the device goes to shutdown.
    - When I press the button and keep it pressed, the PWR_SR1 equals 0. After 1 second, it goes to shutdown, and after that, the device wakes up, and PWR_SR1 equals 258.
     
     
    ouss_mans_1-1718982651760.png

     

    Thank you.
     
    Graduate II
    June 21, 2024

    Primary you cant activate WUpin when is LOW, then add chcek to release before ...

    ouss_mansAuthor
    Visitor II
    June 24, 2024

    hello @MM..1 ,

    I changed my shutdown function to this: 

     

    int8_t thsthal_shutdown()
    {
    	LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
    	__HAL_RCC_PWR_CLK_ENABLE();
    
    	HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_C, PWR_GPIO_BIT_13); // BTN wkup pin 2
    	HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_B, PWR_GPIO_BIT_5); // LED
    	HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_B, PWR_GPIO_BIT_8); // I2C_SCL
    	HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_B, PWR_GPIO_BIT_9); // I2C_SDA
    
    	HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
    	HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH);
    
    	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
    
    	HAL_SuspendTick();
    	HAL_PWREx_EnterSHUTDOWNMode();
    
    	return THSTHAL_ERROR;
    }

     

    and when I retrieve the value of `PWR->SR1`, it's always 0 when I press the button, although it should be 2.

     

    thank you