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
Hello,
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;
 
  __HAL_RCC_PWR_CLK_ENABLE();
 
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI
                              |RCC_OSCILLATORTYPE_HSE;
  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_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);
 
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  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;
  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
 
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
 
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 
  /* 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);
     
    __HAL_GPIO_EXTI_CLEAR_FLAG(WAKEUP_TILT_Pin);
    NVIC_ClearPendingIRQ(EXTI15_10_IRQn);
  
    /* Add IRQ vector to NVIC */
    HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);
    HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}

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;
    RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
     
    Configure_PC13();
    HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 0x000A, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
 
    HAL_GPIO_WritePin(GPIOE, LED1_Pin, 0);
    HAL_GPIO_WritePin(GPIOE, LED2_Pin, 0);
    HAL_GPIO_WritePin(GPIOE, LED3_Pin, 0);
     
    HAL_SuspendTick();
     
    /* Enter Stop Mode */
    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
    ////////////////
    // STOP MODE
    ////////////////
 
    HAL_ResumeTick();
     
    /* Disable Wakeup Counter */
    HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
     
    /* 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) */
    system_clock_config();
     
    // Blinking LED to mark end of STOP Mode
    HAL_GPIO_TogglePin(GPIOE, LED1_Pin);
    HAL_Delay(200);
    HAL_GPIO_TogglePin(GPIOE, LED1_Pin);
}

Thanks

Outcomes