cancel
Showing results for 
Search instead for 
Did you mean: 

STOP MODE on STM32L051K6U6

Nathapol Tanomsup
Associate II
Posted on April 17, 2017 at 09:28

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 */
}�?�?�?�?�?�?�?�?�?�?

4 REPLIES 4
Nesrine M_O
Lead II
Posted on April 17, 2017 at 10:41

Hi

Tanomsup.Nathapol

,

-Nesrine-

Posted on April 17, 2017 at 11:06

I already looked at that example but it seems like stm32l051 never did this command

HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);�?

I tried to use without RTC but it is still not working. Do I need to do something special when I use STM32L051?

Posted on April 17, 2017 at 11:19

I don't think it does not work because of my circuit. It use only internal circuit in your chip and I used LSI to wake chip up.

Nathapol Tanomsup
Associate II
Posted on April 17, 2017 at 16:32

Refer to

https://community.st.com/0D50X00009XkY68SAF

Just add

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

It works like a charm. So why it must use that command. It is that bug ?