Unable to generate 1ms interrupt using LPTIM with HSI = 64MHz STM32h723zg
Hi all,
I wanted to make use of LPTIM1 module of STM32H723ZG for generating 1ms interrupt.
Clock frequency used 64Mhz (HSI).
Environment: Nucleo 144 STM32H723ZG
Prescaler: Divide by 128
Auto reload register value: 500u
Below is the code snippet of init function:
void Timer_driver_init(void)
{
// Enable the peripheral clock for LPTIM1
RCC->APB1LENR = RCC_APB1LENR_LPTIM1EN;
// NVIC initialization
NVIC_EnableIRQ(LPTIM1_IRQn);
// Configure LPTIM
TIMER->CFGR |= TIMER_INTERNAL_CLK | TIMER_COUNTERSOURCE_INTERNAL|
TIMER_SOFTWARE_TRIGGER | TIMER_UPDATE_IMMEDIATE ;
// Update Prescaler
TIMER->CFGR |= TIMER_PRESCALER ;
// Update the Auto Reload Register
TIMER->ARR = TIMER_PERIOD;
// Enable Auto Reload Match interrupt
TIMER->IER |= LPTIM_IER_ARRMIE;
// Enable the LPTIM module
TIMER->CR |= LPTIM_CR_ENABLE;
// Wait for timer counter to be enabled
while ((TIMER->CR & LPTIM_CR_ENABLE) != LPTIM_CR_ENABLE);
// Start the counter once it is enabled
TIMER->CR |= LPTIM_CR_CNTSTRT;
}
Interrupt Handler callback:
void Timer_driver_irqHandler(void)
{
static uint16_t HwTimer_tick_count_l_u16 = 0U;
if(TIMER->ISR & LPTIM_ISR_ARRM)
{
// Autoreload match clear flag
TIMER->ICR |= LPTIM_ICR_ARRMCF;
d_HwTimer_counter_mS_u16++; // Increment mS counter
HwTimer_tick_count_l_u16++;
if(HwTimer_tick_count_l_u16 == 1000U)
{
d_HwTimer_counter_S_u16++; // Increment S counter
HwTimer_tick_count_l_u16 = 0;
}
}
}
Problem: The timer interrupt is too frequent, its not generating at 1ms.
Kindly help me with this issue.
Thanking you in advance.
Regards
Arrhenius

