Skip to main content
Michal Dubovsky
Associate III
June 9, 2017
Solved

unwanted stop mode wakeup (STM32L052K8)

  • June 9, 2017
  • 3 replies
  • 4143 views
Posted on June 09, 2017 at 16:29

Hello, I am running into a problem while trying to put MCU into a STOP mode. I have tried to comment out all of the 'unnecessary' code but It does not work even if I leave just this in the source:

HAL_Init();

SystemClock_Config();

MX_GPIO_Init();

while(1)

{

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // clear WU FLAG

HAL_PWREx_EnableUltraLowPower(); // Enable Ultra low power mode

HAL_PWREx_EnableFastWakeUp(); // Enable the fast wake up from Ultra low power mode

// Select HSI as system clock source after Wake Up from Stop mode

__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);

// go to sleep with low power regulator ON

// WFI = the device is woken up by any pending interrupt

HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

blink_led();

}

It seems as if the processor never even entered the sleep mode (or woke up immediately after entering it) because the LED just keeps blinking. This happens even if I disable all interrupt sources using HAL_NVIC_DisableIRQ();

    This topic has been closed for replies.
    Best answer by Nesrine M_O
    Posted on June 13, 2017 at 10:52

    Hi

    Try to disable the

    Systick interrupt

    /* Enter Stop Mode */HAL_SuspendTick();HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);HAL_ResumeTick();�?�?�?�?

    -Nesrine-

    3 replies

    Zt Liu
    Senior III
    June 9, 2017
    Posted on June 09, 2017 at 16:57

    How would you like to wake up the MCU?

    Which IRQ did you disable? Did you disable SysTick interrupt?

    Are you still debugging the MCU while it is trying to enter stop mode?

    Michal Dubovsky
    Associate III
    June 10, 2017
    Posted on June 10, 2017 at 09:38

    I have disabled all IRQ (I believe there are 32 of them). I have tried both debug and release build but the problem persists. Once I figure out how to put the processor into stop mode I'd like to wake it up by GPIO EXTI.

    Zt Liu
    Senior III
    June 10, 2017
    Posted on June 10, 2017 at 12:11

    Can't see why the above code can't work! 

    Currently I got no other L0 series except for STM32L011 Nucleo 32 board.

    I tried your code, even though you didn't set up external int source and you didn't turn off other gpio for power saving....

    It just worked, I just add an external int source to make it wake up.

    Guess there is something wrong in your code that it's not seen here.

       /*your code below*/

    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); 

    HAL_PWREx_EnableUltraLowPower(); 

    HAL_PWREx_EnableFastWakeUp(); 

    __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);

       /*Just add an external int source, firstly jumper on D2 and ground then take off jumper to wake up mcu*/

    GPIO_InitTypeDef GPIO_InitStruct;

    GPIO_InitStruct.Pin = GPIO_PIN_12;

    GPIO_InitStruct.Pull = GPIO_PULLUP;

    GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

    __HAL_RCC_GPIOA_CLK_ENABLE();

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    /* Enable and set PA.12 EXTI Interrupt*/

    NVIC_SetPriority((IRQn_Type)(EXTI4_15_IRQn), 0x03);

    HAL_NVIC_EnableIRQ((IRQn_Type)(EXTI4_15_IRQn));

    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

     /*Wake up starts here*/

    SystemClock_Config();

    /*Config LED and flash it*/

    BSP_LED_Init(LED3);

    BSP_LED_On(LED3);

    HAL_Delay(500);

    BSP_LED_Off(LED3);

    HAL_Delay(500)

    BSP_LED_On(LED3);

    HAL_Delay(500);

    BSP_LED_Off(LED3);

    HAL_Delay(500)

    Nesrine M_O
    Associate
    June 12, 2017
    Posted on June 12, 2017 at 17:02

    Hi

    DUBOVSKY.MICHAL

    I am using a custom board.

    Have a look to the getting started hardware of your STM32 related product you find some Recommended PCB routing guidelines:

    http://www.st.com/content/ccc/resource/technical/document/application_note/fd/f4/6b/40/9a/b5/41/a2/DM00112pdf/files/DM00112pdf/jcr:content/translations/en.DM00112pdf

    -Nesrine-

    Michal Dubovsky
    Associate III
    June 12, 2017
    Posted on June 12, 2017 at 18:18

    Thank you, unfortunately the same thing happens to me when I use STM32L053R8 nucleo board.

    Michal Dubovsky
    Associate III
    June 13, 2017
    Posted on June 13, 2017 at 09:08

    UPDATE:

    (Note: This happens only after the first startup. If I power the device down and back up, evetything works)

    1.Program executes 

    HAL_PWR_EnterSTOPMode();

    2.The processor does not go to STOPMode and goes straight to another function which is 

    SystemClock_Config();

    3.I get HAL_TIMEOUT @ stm32l0xx_hal_rcc.c line 695

    while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSI48RDY) == RESET)

    {

       if((HAL_GetTick() - tickstart) > HSI48_TIMEOUT_VALUE)

       {

          return HAL_TIMEOUT;

       }

    }

    Attaching my clock configuration below (supply voltage 2.2V):

    0690X00000607JiQAI.png
    Nesrine M_O
    Nesrine M_OBest answer
    Associate
    June 13, 2017
    Posted on June 13, 2017 at 10:52

    Hi

    Try to disable the

    Systick interrupt

    /* Enter Stop Mode */HAL_SuspendTick();HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);HAL_ResumeTick();�?�?�?�?

    -Nesrine-

    Michal Dubovsky
    Associate III
    June 13, 2017
    Posted on June 13, 2017 at 11:18

    This totally works. I can't find a reason why this isn't mentioned in the example or in a HAL_PWR_EnterSTOPMode() function description.