AnsweredAssumed Answered

STOP MODE on STM32L051K6U6

Question asked by Tanomsup.Nathapol on Apr 17, 2017
Latest reply on Apr 17, 2017 by Tanomsup.Nathapol

Hello, I tried to using STOP Mode on STM32L051 but it was not working

 

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32l0xx_hal.h"
#include "rtc.h"
#include "gpio.h"
#include <math.h>
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
void StopMode_Init(void) {

/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPower();

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

//LowPower_GPIO();

/* Select HSI as system clock source after Wake Up from Stop mode */
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

}
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_RTC_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, ceil(5 / (0.000437)), RTC_WAKEUPCLOCK_RTCCLK_DIV16);
//HAL_Delay(10);

StopMode_Init();

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

}
/* USER CODE END 3 */
}

 

but it was working on STM32L053 and STM32L073 so I can't figure out. That is so weird. Now I found another issue I put GPIO_TogglePin in RTC_Interrupt in stm32l0xx_it.c but I never get an interrupt.

 

void RTC_IRQHandler(void)
{
/* USER CODE BEGIN RTC_IRQn 0 */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_5);
/* USER CODE END RTC_IRQn 0 */
HAL_RTCEx_WakeUpTimerIRQHandler(&hrtc);
/* USER CODE BEGIN RTC_IRQn 1 */
/* USER CODE END RTC_IRQn 1 */
}

Outcomes