AnsweredAssumed Answered

[STM32L0] LPTimer failing to start after a while.

Question asked by Andres Cao on May 6, 2018
Latest reply on May 7, 2018 by Andres Cao

Hi all.

 

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:

 

LPTIM1->CR = 0;

This is how the timer is started:

 

LPTIM1->CR = LPTIM_CR_ENABLE;

LPTIM1->CR = LPTIM_CR_ENABLE | LPTIM_CR_CNTSTRT;

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?

 

Thanks!

 

Cheers,

Andrés

Outcomes