cancel
Showing results for 
Search instead for 
Did you mean: 

LPTIM2 not counting when clocked from PLL2P on STM32H563

andy
Associate II

Hi

I'm doing a new design using an STM32H563 and would like to use LPTIM2 to measure elapsed time.

Ideally I'd like its clock source to be PLL2P, which means RCC->CCIPR2.LPTIM2SEL = 0b001 according to RM0481 page 545.

However, if I select this clock source then LPTIM2 appears not to be clocked at all. In my code snippet below, ARROK is never set and the code hangs waiting for it.

If I set LPTIM2SEL = 0b000 (rcc_pclk1) then it works fine, and so does 0b101 (per_ck). If I then break into the code using a debugger, and manually set LPTIM2SEL back to 0b001, then LPTIM2 stops counting.

I've confirmed that PLL2P is definitely enabled and running at the expected frequency, which in this case happens to be 4 MHz. I have MCO2 set to output PLL2P on a physical pin and I can see it on my scope, so PLL2P is definitely OK. It just appears not to actually connect to LPTIM2 through its kernel clock multiplexer.

I know I can work around the problem by using rcc_pclk1 or per_ck as my clock source instead, but I don't like leaving bugs unexplained.

Can anyone please let me know what I'm doing wrong, or confirm it's not my code that's at fault? Thanks!

Andy.

__LPTIM2_CLK_ENABLE();

LPTIM2->CR = 0;
LPTIM2->CFGR = (1 << LPTIM_CFGR_PRESC_Pos); // Internal clock, 1:2 prescaler

LPTIM2->CR = LPTIM_CR_ENABLE;
LPTIM2->ARR = 65535; // Full 16 bit count range

while ((LPTIM2->ISR & LPTIM_ISR_ARROK) == 0);

LPTIM2->CR = LPTIM_CR_CNTSTRT | LPTIM_CR_ENABLE;

 

0 REPLIES 0