cancel
Showing results for 
Search instead for 
Did you mean: 

LPTIM fires unexpected CMPM interrupts

aritec
Associate III

I struggled with the CMPM interrupt and made a small test programm to reproduce the bug.

To see whats going on I use an oscilloscope with 2 GPIO pins called A and B.

Pseudo Code:​

LPTIM_IRQHandler()
{
 setGpioA;
 clearFlag_CMPM;
 resetGpioA;
}
​
main()
{
 uint16 cmpVal = 0;
​
 Init LPTIM with 32kHz clock, update mode immediate ;
 EnableLPTIM;
 setAutoReload(0xffff);
 enableIT_CMPM;
 startCounter(Continouse mode);
 
 while(1)
 {
 setGpioB;
 cmpVal += 1000;
 setCompare(cmpVal);
 // to show the bug, we do it again ....
 cmpVal += 1000;
 setCompare(cmpVal);
 resetGpioB;
 
 wfi();
 }
}

I would expect to get an CMPM interrupt every 2000 ticks and most the time this happens. But if an overflow of the CMP register happens at the second writting, a CMP interrupt is raised just after calling wfi();

GpioA ____/\____/\_________

GpioB _____/°°°\__/°°°\_____

​If I write CMP only once, I get a interrupt every 1000 ticks even if the new CMP values is overflowed and set to a smaller value than CNT.

GpioA ____/\______ 1000 ticks _/\______ 1000 ticks _/\__

GpioB _____/°°°\____ ___/°°°\__ ___/°°°\__

I made an check in the interrupt routine as a bugfix, but I think this is ugly and I wonder why this is not mention in the errata and if someone else experienced the same.

Best regards

Armin

2 REPLIES 2
Bob S
Principal

I've never used LPTIM except for "set once and let it run" periodic interrupts. But... maybe this is related to issues here

https://community.st.com/s/question/0D53W000004J0srSAC/stm32l0-lptim-generating-random-compare-match-interrupt-when-changing-compare-match-value

and specifically as documented in @Jeff Tenney​ github page (linked in that post)

aritec
Associate III

Thanks Bob, the very last comment in your link explains the same behavior.