I've run into some problems with the LPTimer and hope that maybe you can point me the right direction so I can find a fix.
Some context first:
-I have an RTC Alarm interrupt triggering once a second.
-Inside the RTC interrupt I start the LPTimer (nothing else is being done other than start the timer and check LPTimer registers) run it for a while and then stop it.
-Compare and ARR Match interrupts are enabled in the LPTimer.
So, if the code is only this, and the main is a "while(1);", everything works fine. RTC interrupt fires, LPtimer starts, compare and ARR interrupts fire, then LPTimer is stopped. And this goes on and on every second.
However, when I put some extra code doing other stuff in the while(1) I get a very weird behavior by the timer. The timer doesn't start at all.
This is how the timer is stopped:
This is how the timer is started:
This works well for 5-10 seconds, and then it stops working all together.
Under working conditions, printing the CR register yields "0x01", since CNTSTRT is cleared by hardware.
When it stops working if I print the "LPTIM->CR" register I get a 0x05. This means it is enabled, and the count bit has been set, but it's never cleared by hardware and timer is not starting.
What could be stopping the timer from starting? The clock is enabled, and is never touched.
//Enable clock to the Low Power Timer
RCC->APB1ENR |= RCC_APB1ENR_LPTIM1EN;
Do you know of any other conditions that can prevent a timer from starting?