AnsweredAssumed Answered

Enter and Exit STOP Mode with RTC and EXTI

Question asked by yoann.guerin on Jul 27, 2016
Latest reply on Feb 8, 2018 by Jhon Edwin Cordoba Papamija
I have made a previous subject for exit standby mode with WKUP and RTC but no response wet, so i have try to to do the same with STOP mode also problems...
Platfrom is STM32L162
I just want to :
Enter in STOP Mode
Exit if i have RTC timer IT or EXTI IT on PC13 pin
During my tests it's seems that i don't enter in STOP Mode, I am wake up every time with TIM2_IRQHandler even if it's deactivated with HAL_SuspendTick, my code is very simple  :

void system_clock_config(void)
  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInit;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);

  void Configure_PC13(void) {
    /* Set variables used */
    GPIO_InitTypeDef GPIO_InitStruct;
    /* Set pin as input */
    GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
    GPIO_InitStruct.Pin = WAKEUP_TILT_Pin;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
    /* Add IRQ vector to NVIC */
    HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);

void enter_stop_mode(void)
    /* RTC configuration */ 
    RTCHandle.Instance = RTC; 
    RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;
    RTCHandle.Init.AsynchPrediv =0x7F;   // LSE as RTC clock: RTC_ASYNCH_PREDIV
    RTCHandle.Init.SynchPrediv =  0x00FF; // LSE as RTC clock: RTC_SYNCH_PREDIV;
    RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
    RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
    HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 0x000A, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
    HAL_GPIO_WritePin(GPIOE, LED1_Pin, 0);
    HAL_GPIO_WritePin(GPIOE, LED2_Pin, 0);
    HAL_GPIO_WritePin(GPIOE, LED3_Pin, 0);
    /* Enter Stop Mode */
    // STOP MODE
    /* Disable Wakeup Counter */
    /* Configures system clock after wake-up from STOP: enable HSE, PLL and select
    PLL as system clock source (HSE and PLL are disabled in STOP mode) */
    // Blinking LED to mark end of STOP Mode
    HAL_GPIO_TogglePin(GPIOE, LED1_Pin);
    HAL_GPIO_TogglePin(GPIOE, LED1_Pin);