What is the cause of LPTIM_WaitForFlag function resulted HAL_TIMEOUT in STM32WL MCU ?
I modified the LoRaWAN_End_Node sample program for measuring the external pulses input to the COMP1. I register a task in the sequencer and set up the timer in timer server. It is no problem to run a test task by just toggle the LED. When I initialize the lptim1 timer to count the external pulse, the program jump to the while(1) loop in Error_Handler. Checking by breakpoints, it is because the LPTIM_WaitForFlag function resulted HAL_TIMOUT. Below is the code of lptim1 initialization.
void LPTIM1_Init(void)
{
hlptim1.Instance = LPTIM1;
hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
hlptim1.Init.UltraLowPowerClock.Polarity = LPTIM_CLOCKPOLARITY_RISING;
hlptim1.Init.UltraLowPowerClock.SampleTime = LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION;
hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_6;
hlptim1.Init.Trigger.ActiveEdge = LPTIM_ACTIVEEDGE_RISING;
hlptim1.Init.Trigger.SampleTime = LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION;
hlptim1.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
hlptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_EXTERNAL;
hlptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_COMP1;
hlptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)
{
Error_Handler();
}
// Start Counting
if (HAL_LPTIM_Counter_Start(&hlptim1, 0xFFFF)!= HAL_OK)
{
Error_Handler();
}
// lptim1 enable
hlptim1.Instance->CR |= 0x00000001;
// lptim1 continuous mode
hlptim1.Instance->CR |= 0x00000004;
}
I would be grateful if any expert can help to solve the problem.
Thanks
