cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32L0] LPTimer failing to start after a while.

Andres Cao
Associate III
Posted on May 06, 2018 at 14:36

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

1 REPLY 1
Andres Cao
Associate III
Posted on May 07, 2018 at 12:51

Hi all,

I managed to reduce the problem a little bit. 

-Removed the RTC interrupt.

-Timer is started and never stopped.

So now I just initialize the timer and start it. Then run the rest of the code and after a couple of seconds the timer stops running. (I can tell because the overflow interrupt is not called anymore and the counter is stuck at a fixed number).

So to rephrase the question: What can stop the timer if it's never disabled?

EDIT: I can also confirm it's not the RCC->APB1ENR clock. If you disable the clock you read '0' from all registers, and reenabling it keeps everything going normally. 

Thanks again!

Cheers,

Andrés