cancel
Showing results for 
Search instead for 
Did you mean: 

wakeup from stop2 nucleo 144

ran haber
Associate
Posted on June 23, 2018 at 12:13

Hi,

I'm trying to use the example code from cubeV.10           PWR-?PWR_STOP2_RTC.

The only code I added was after the  SYSCLKConfig_STOP() function I added Init for LED 2 and turning it ON till the 5 sec delay then OFF.

The only thing happens is that LED1 blinks, I think that the system never reaches the code after entering STOP 2 mode and just resets itself.

Why doen't it work?

int main(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

 

  /* STM32L4xx HAL library initialization:

       - Configure the Flash prefetch

       - Systick timer is configured by default as source of time base, but user

         can eventually implement his proper time base source (a general purpose

         timer for example or other time source), keeping in mind that Time base

         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and

         handled in milliseconds basis.

       - Set NVIC Group Priority to 4

       - Low Level Initialization

     */

  HAL_Init();

  /* Configure LED1, and LED2 */

  BSP_LED_Init(LED1);

  BSP_LED_Init(LED2);

  /* Configure the system clock to 80 MHz */

  SystemClock_Config();

  /* Enable Power Clock */

  __HAL_RCC_PWR_CLK_ENABLE();

 

  /* Ensure that MSI is wake-up system clock */

  __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI);

  /* Configure the system Power */

  SystemPower_Config();

  while (1)

  {

    /* Insert 5 second delay */

    HAL_Delay(5000);

/* LED2 off before entering STOP 2 */

  BSP_LED_Off(LED2);   

    /* Enable GPIOs clock */

  __HAL_RCC_GPIOA_CLK_ENABLE();

  __HAL_RCC_GPIOB_CLK_ENABLE();

  __HAL_RCC_GPIOC_CLK_ENABLE();

  __HAL_RCC_GPIOD_CLK_ENABLE();

  __HAL_RCC_GPIOE_CLK_ENABLE();

  __HAL_RCC_GPIOF_CLK_ENABLE();

  __HAL_RCC_GPIOG_CLK_ENABLE();        

  __HAL_RCC_GPIOH_CLK_ENABLE();

  __HAL_RCC_GPIOI_CLK_ENABLE();

  /* Configure all GPIO port pins in Analog Input mode (floating input trigger OFF) */

  /* Note: Debug using ST-Link is not possible during the execution of this   */

  /*       example because communication between ST-link and the device       */

  /*       under test is done through UART. All GPIO pins are disabled (set   */

  /*       to analog input mode) including  UART I/O pins.           */

  GPIO_InitStructure.Pin = GPIO_PIN_All;

  GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;

  GPIO_InitStructure.Pull = GPIO_NOPULL;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

  HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);

  HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);

  HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);

  HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);

  HAL_GPIO_Init(GPIOF, &GPIO_InitStructure);

  HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);    

  HAL_GPIO_Init(GPIOH, &GPIO_InitStructure);

  HAL_GPIO_Init(GPIOI, &GPIO_InitStructure);

  /* Disable GPIOs clock */

  __HAL_RCC_GPIOA_CLK_DISABLE();

  __HAL_RCC_GPIOB_CLK_DISABLE();

  __HAL_RCC_GPIOC_CLK_DISABLE();

  __HAL_RCC_GPIOD_CLK_DISABLE();

  __HAL_RCC_GPIOE_CLK_DISABLE();

  __HAL_RCC_GPIOF_CLK_DISABLE();  

  __HAL_RCC_GPIOG_CLK_DISABLE();  

  __HAL_RCC_GPIOH_CLK_DISABLE();

  __HAL_RCC_GPIOI_CLK_DISABLE();

 

  /* Disable all used wakeup source */

  HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);

 

 

  /* Re-enable wakeup source */

  /* ♯♯ Setting the Wake up time ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

  /* RTC Wakeup Interrupt Generation:

    the wake-up counter is set to its maximum value to yield the longuest

    stop time to let the current reach its lowest operating point.

    The maximum value is 0xFFFF, corresponding to about 33 sec. when

    RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16

    Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI))

    Wakeup Time = Wakeup Time Base * WakeUpCounter

      = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI)) * WakeUpCounter

      ==> WakeUpCounter = Wakeup Time / Wakeup Time Base

 

    To configure the wake up timer to 60s the WakeUpCounter is set to 0xFFFF:

    Wakeup Time Base = 16 /(~32.000KHz) = ~0.5 ms

    Wakeup Time = 0.5 ms  * WakeUpCounter

    Therefore, with wake-up counter =  0xFFFF  = 65,535

       Wakeup Time =  0,5 ms *  65,535 = 32,7675 s ~ 33 sec. */

  HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 0x0FFFF, RTC_WAKEUPCLOCK_RTCCLK_DIV16);

 

    /* Enter STOP 2 mode */

    HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

    

    /* ... STOP2 mode ... */

    /* Re-configure the system clock to 80 MHz based on MSI, enable and

       select PLL as system clock source (PLL is disabled in STOP mode) */

    SYSCLKConfig_STOP();

    

  /* Re-configure and turn on LED1  */

  BSP_LED_Init(LED1 );

  BSP_LED_On(LED1 );   

/* Check if we wakeup */

  BSP_LED_Init(LED2);

  BSP_LED_On(LED2);   

  }

}

Thanks,

Ran

#stm32l4-low-power-stop2 #wake-up
1 REPLY 1
OChen
Associate

Change PWR_STOPENTRY_WFI to PWR_STOPENTRY_WFE and try again