2018-04-26 12:34 AM
Hello all. My problem is as follows.
I would like to set an event in the future, lets say 950ms, at one specific point in the code. Then I would like to set the STM32L432 in Stop2 mode, wake up the MCU near the event, lets say at 750 ms so it can wake up another device, and then do the task at 950ms.
I thought that LPTIM can fire two interrupts, one related to HAL_LPTIM_CompareMatchCallback, and the other related to HAL_LPTIM_AutoReloadMatchCallback.
I setup an example to see how it would work.
In CubeMX I configure LPTIM1 as 'Counts internal clock events', and choose LSE as the LPTIM1 clock mux. LSE frequency is 32768 Hz, and set div2 as preescaler. So each time interval is 61.035 us. In the setup I set 'update at the end of the period' and software as trigger.
In the main function after setup all the peripherals, I call to HAL_LPTIM_TimeOut_Start_IT(&hlptim1, 65535, 16383);
So I set up the period as 65535, so the autoreload should occur at 4s, and the timeout to 16383, so the compare match event should occur at 1s.
I wrote a
HAL_LPTIM_CompareMatchCallback, and a HAL_LPTIM_AutoReloadMatchCallback.
When I run the program I get the HAL_LPTIM_CompareMatchCallback called each 4 secs, and HAL_LPTIM_AutoReloadMatchCallback is never called. Strange behaviour because I though that CompareMatchCallback should be called at 1 sec.
I suppose that I made some mistakes and I have misconceptions as well, so please can anybody tell me what should I do to setup two events in the future so one of them is used to wake up the MCU, and the other to make some transmission to other device?
Thanks in advance, best regards.
Solved! Go to Solution.
2018-04-26 07:57 AM
Ok, now it's working. It was my fault. I set
LPTIM_IT_ARROK, when I should have set
LPTIM_IT_ARRM.
Thanks
2018-04-26 07:08 AM
I've seen what is written in HAL_LPTIM_TimeOut_Start_IT(), and saw that only activates the interrupt related to 'Enable Compare match interrupt'. I've copied that function and added the activation to 'Autoreload register interrupt', so the function results in:
HAL_StatusTypeDef DPM_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
{ /* Check the parameters */ assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); assert_param(IS_LPTIM_PERIOD(Period)); assert_param(IS_LPTIM_PULSE(Timeout));/* Set the LPTIM state */
hlptim->State= HAL_LPTIM_STATE_BUSY;/* Set TIMOUT bit to enable the timeout function */
hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;/* Enable Compare match interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);/* Enable Autoreload register interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);/* Load the Timeout value in the compare register */
__HAL_LPTIM_COMPARE_SET(hlptim, Timeout);/* Start timer in continuous mode */
__HAL_LPTIM_START_CONTINUOUS(hlptim);/* Change the TIM state*/
hlptim->State= HAL_LPTIM_STATE_READY;/* Return function status */
return HAL_OK;}Even though
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK); is set, I can not get the second interrupt fired, and the compare interrupt is fired at 4 seconds.
Anybody has a clue of what is happening?
Thanks in advance.
2018-04-26 07:57 AM
Ok, now it's working. It was my fault. I set
LPTIM_IT_ARROK, when I should have set
LPTIM_IT_ARRM.
Thanks
2024-07-31 04:40 PM
For anyone else's reference, if you're trying to get that periodic behavior with HAL_LPTIM_AutoReloadMatchCallback like OP, you can use `HAL_LPTIM_Counter_Start_IT`. which does activate the interrupt related to autoreload register and makes it so you can use `HAL_LPTIM_AutoReloadMatchCallback` without modifying their code.