2025-05-30 1:54 AM
Hello,
I need counter which should wakeup system from stop2 mode at every sequential time.
So currently use below setting and it works fine and wakeup at every ~4.16 minutes. But I want it should wakeup at max time of 30minutes (not fixed but looking for max time it can achieve). So thinking to use Repetition counter so that it can repeat the same counter and once repeat counter complete it will wakeup the system. But it's not affecting with repetition counter value. works same at zero.
void MX_LPTIM1_Init(void)
{
LPTIM_OC_ConfigTypeDef sConfig1 = {0};
// 1. Enable LSI Clock
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
// 2. Select LSI as LPTIM1 clock source
__HAL_RCC_LPTIM1_CONFIG(RCC_LPTIM1CLKSOURCE_LSI);
// 3. Enable LPTIM1 clock
__HAL_RCC_LPTIM1_CLK_ENABLE();
// 4. Configure LPTIM1
hlptim1.Instance = LPTIM1;
hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC; // This is overridden by RCC config
hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV128;
hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
hlptim1.Init.Period = 65535;//63999;
hlptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
hlptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
hlptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
hlptim1.Init.RepetitionCounter = 0;
if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)
{
Error_Handler();
}
// 5. Configure Output Compare (optional, if needed)
sConfig1.Pulse = 65535;//63999;
sConfig1.OCPolarity = LPTIM_OCPOLARITY_HIGH;
if (HAL_LPTIM_OC_ConfigChannel(&hlptim1, &sConfig1, LPTIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
// 6. Start LPTIM in interrupt mode
if (HAL_LPTIM_Counter_Start_IT(&hlptim1) != HAL_OK)
{
Error_Handler();
}
//Priority(LPTIM1_IRQn, 0, 0);
//HAL_NVIC_EnableIRQ(LPTIM1_IRQn);
}
I just want to know does it support this feature, if yes then what I'm missing.
Also suggest me the callback which expect to call after the completion of the repetition counter.
Currently testing it just blinking led after stop2 wakeup statement.
Thanks,
Nitin
2025-05-30 3:34 AM
Hello @npatil15,
The repetition counter is not used for extending the wakeup time!
The LPTIM's maximum period is determined by the Period register, which is set to 65535 in your configuration. With the LSI clock and the prescaler set to LPTIM_PRESCALER_DIV128, the maximum achievable interval is as you have observed!
For longer wakeup interval you may use RTC as it's designed for such purposes, or, another solution, is to implement a software-based counter in the HAL_LPTIM_AutoReloadMatchCallback to count multiple LPTIM periods
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-05-30 3:55 AM
Ok got it.
Its clear that I cant use repetition counter to block wakeup until counter reset to zero.
But can you help me to understand how/when repetition counter used?
So can I use repetition counter feature to wakeup and use that count in the specific callback to take decision.
If yes, then can you please guid me which interrupt function (HAL_LPTIM_Counter_Start_IT() or HAL_LPTIM_TimeOut_Start_IT()) should I use and in which handler I expect to check this counter to take my decision.
Thanks,
Nitin