cancel
Showing results for 
Search instead for 
Did you mean: 

Long LPTIM values

Jonathan Frech
Associate II

My goal is to wake up an MCU that remains in STOP2 Mode. For this i've sucessfully implemented LPTIM to wake-up from STOP2. Now my problem is, that the LPTIM can only be set to a maximum value of 0xFFFF, which is 2 Seconds if i got the stm32 documentation right

But i need a really long time (like 30s)

I'm using the follwing code

Function:

**
  * @brief  Start the Timeout function in interrupt mode.
  * @note   The first trigger event will start the timer, any successive
  *         trigger event will reset the counter and the timer restarts.
  * @param  hlptim : LPTIM handle
  * @param  Period : Specifies the Autoreload value.
  *         This parameter must be a value between 0x0000 and 0xFFFF.
  * @param  Timeout : Specifies the TimeOut value to rest the counter.
  *         This parameter must be a value between 0x0000 and 0xFFFF.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)

Call:

HAL_LPTIM_TimeOut_Start_IT(&lptim1,  64001, 32000 );

Config:

	  lptim1.Instance = LPTIM1;
	  lptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
	  lptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
	  lptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
	  lptim1.Init.Trigger.ActiveEdge = LPTIM_ACTIVEEDGE_RISING;
	  lptim1.Init.Trigger.SampleTime = LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION;
	  lptim1.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
	  lptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
	  lptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
	  lptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
	  lptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
 
	  /* Initialize LPTIM peripheral according to the passed parameters */
	  if (HAL_LPTIM_Init(&lptim1) != HAL_OK)
	  {
	    Error_Handler();
	  }
 

Source:

  PeriphClkInit.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSI; //32kHz LSI

Does anyone has a solution to implement very long times directly? Not via a function that count interrupts or so, because this will cause a wakeup (current increase) each seconds

1 REPLY 1
berendi
Principal

According to the reference manual, LPTIM has a prescaler that can divide the clock with a factor up to 128.

It can be configured in the PRESC bitfield of LPTIM->CFGR, so

LPTIM->CFGR |= LPTIM_CFGR_PRESC;

would give a maximum interval of 256 seconds when running on a 32 kHz clock.

RTC alarms can be used for even longer delays.