cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WLE5JB doesnt exit from stop mode with LPTIM.

Anton Chaban
Associate III

I'am using STM32WLE5JB with LOWPOWERMODE_STOP(0,1,2) to deacrease power consumption. Although I configured LPTIM with LSE for 2 sec period to wake up, device doesnt exit from stop mode. I tried LPTIM with LSI the result was same.

Here is My code LPTIM Init:

__HAL_RCC_LPTIM1_CLK_ENABLE();
    __HAL_RCC_LPTIM1_CLK_SLEEP_ENABLE();
 
    __HAL_RCC_LPTIM1_CONFIG(source);
 
    LPTIM1->IER = 0;
    LPTIM1->IER |= LPTIM_IER_ARRMIE; //Autoreload match Interrupt Enable
 
    LPTIM1->CR |= LPTIM_CR_ENABLE;  // Enable LPTIM1
 
    LPTIM1->ARR = autoReload;           // set AutoReloadRegister 32768/65536 = 0.5 Hz
 
    while(LPTIM1->ISR & LPTIM_ISR_ARROK != LPTIM_ISR_ARROK);
 
    LPTIM1->ICR |= LPTIM_ICR_ARROKCF; // clear IRQ flags
                                    // Enable timer counting
    LPTIM1->CR |= LPTIM_CR_CNTSTRT; // Start LPTIM

RCC init

RCC->CR |= (uint32_t)0x00000100;
  RCC->CR &= ~RCC_CR_HSION;
  tmp = RCC->ICSCR;
  tmp &= ~RCC_CR_MSIRANGE;
  tmp |= RCC_CR_MSIRANGE_6; 
  __HAL_RCC_MSI_RANGE_CONFIG(RCC_MSIRANGE_0);
  RCC->ICSCR = tmp;
  HAL_RCCEx_WakeUpStopCLKConfig(RCC_STOP_WAKEUPCLOCK_MSI);
  while((RCC->CR & RCC_CR_MSIRDY)==0);
 
  SET_BIT(RCC->BDCR, RCC_BDCR_LSEON);
 
  while(READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == 0U);
 
  SET_BIT(RCC->BDCR, RCC_BDCR_LSESYSEN);
 
  while (READ_BIT(RCC->BDCR, RCC_BDCR_LSESYSRDY) == 0U);
 
  HAL_RCCEx_EnableLSECSS();

Stop Mode ENTER:

HAL_PWREx_DisableBatteryCharging();
    HAL_PWREx_DisableWPVD();
    HAL_PWREx_DisableBORPVD_ULP();
    HAL_PWREx_DisablePVM3();
    LL_PWR_DisableWakeUpPin(LL_PWR_WAKEUP_PIN2);
    LL_PWR_ClearFlag_WU2();
    HAL_PWREx_DisableInternalWakeUpLine();
    EXTI->PR1 = 0xFFFFFFFF;
    EXTI->PR2 = 0xFFFFFFFF;
    __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(RTC, RTC_FLAG_WUTF);
    __HAL_RTC_ALARM_CLEAR_FLAG(RTC, RTC_FLAG_ALRAF);
    __HAL_RTC_ALARM_CLEAR_FLAG(RTC, RTC_FLAG_ALRBF);
 
    PWR->EXTSCR = 0;    
    
    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);

After device entering STOP mode, next load code begin with such message, choosing NO lets me load new program to the flash

 0693W000001sDrtQAE.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
Remi QUINTIN
ST Employee

​Did you configute the EXTI accordingly?

Please find a simple example demonstrating LPTim in stop mode 2. It toggles the LED any time the MCU is waking up. (consumption below from 3.9mA LEDon to 1.5uA =LEDoff)

The zip could be extracted in \Projects\NUCLEO-WL55JC\Examples\LPTIM.

View solution in original post

9 REPLIES 9
Anton Chaban
Associate III

I've wrote a simple program only HAL used, the problem is same. Device doesn't wake up from stop mode.

#include "stm32wlxx_hal.h"
 
LPTIM_HandleTypeDef hlptim1;
 
void SystemClock_Config(void);
static void LPTIM_IRQHandler_Config();
static void MX_LPTIM1_Init(void);
static void GPIO_Output_Config(void);
void Error_Handler();
 
void LPTIM1_IRQHandler(void)
{
    HAL_LPTIM_IRQHandler(&hlptim1);
}
 
int main(void)
{
  HAL_Init();
 
  SystemClock_Config();
 
  LPTIM_IRQHandler_Config();
 
  MX_LPTIM1_Init();
  
  GPIO_Output_Config();
 
  while (1)
  {
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_SET);
      HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_RESET);
  }
}
 
/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
 
  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
 
}
 
static void LPTIM_IRQHandler_Config()
{
    __HAL_RCC_LPTIM1_CLK_ENABLE();
    __HAL_RCC_LPTIM1_CLK_SLEEP_ENABLE(); // enable clock to LPTIM peripheral also in low power mode
 
    HAL_NVIC_SetPriority(LPTIM1_IRQn, 2, 0);
    HAL_NVIC_EnableIRQ(LPTIM1_IRQn);
}
 
static void MX_LPTIM1_Init(void)
{
  hlptim1.Instance = LPTIM1;
  hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
  hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV128;
  hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
  hlptim1.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
  hlptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
  hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
  if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)
  {
    //_Error_Handler(FILE, LINE);
  }
 
    uint16_t autoReload = -1;
 
    HAL_LPTIM_Counter_Start_IT(&hlptim1, autoReload);
}
 
static void GPIO_Output_Config(void)
{
  GPIO_InitTypeDef   GPIO_InitStructure;
 
  __HAL_RCC_GPIOA_CLK_ENABLE();
 
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
 
  GPIO_InitStructure.Pin = GPIO_PIN_2;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
}
 
/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  while(1) 
  {
  }
}
 
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{ 
 /* Infinite loop */
  while (1)
  {
  }
}
#endif /* USE_FULL_ASSERT */

Remi QUINTIN
ST Employee

​Did you configute the EXTI accordingly?

Please find a simple example demonstrating LPTim in stop mode 2. It toggles the LED any time the MCU is waking up. (consumption below from 3.9mA LEDon to 1.5uA =LEDoff)

The zip could be extracted in \Projects\NUCLEO-WL55JC\Examples\LPTIM.

Yea, your example helped to understand what i missed. Thank you so much! (I have L0x where i test my code and in that series it doesn't need EXTI only NVIC.)

From Table 43. Stop 0 mode

Mode exit: Any EXTI line configured in Interrupt mode (the corresponding EXTI interrupt

vector must be enabled in the NVIC). The interrupt source can be external

interrupts or peripherals with wakeup capability

LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_29); -> __HAL_LPTIM_LPTIM1_EXTI_ENABLE_IT

hi Remi QUINTIN,

How can i get STM32WL cube ?

Thanhks,

Remi QUINTIN
ST Employee

​The STM32WL Cube FW package is not officially available yet. It should be released by a month or two.

rivier
Associate II

how you can make programme on this chip ? don't undestant .

in my side impossible to found Hal driver , i have buy some chip and made prototype , but impossible to programme :s

Remi QUINTIN
ST Employee

​You can't develop any application for now. You have to wait for the official release of the CubeWL FW pacakage.

So some have Hal drivers like Anton Chaban

And other not ?:\

Remi QUINTIN
ST Employee

A few companies have been delivered a beta version of the WL stack ahead of the official delivery date.

These lead customers help mature the stack, solving the last remaining issues based on real use cases.

The goal of this strategy is to improve the quality of the WL stack that is expected to be delivered very soon.

This should also prevent a sudden high level of support as soon as the whole WL ecosystem (Stack, CubeMX, CubeIDE, …) is released.

You can anyhow try to get the WL stack through the local ST FAE or sales covering your region. It is then a business decision.