2019-10-04 12:19 AM
I am having problems running LPTIM1 off the LSE. When I set up and interrupt it is firing ever clock cycle and does not seem to be clearing. RCC_BDCR_LSERDY bit is active before selecting the LPTIM1 clock source. I have also tried disabling the interrupt and just enabling a PWM output. This results in a toggle every clock cycle on the output pin instead of the expected duty cycle and period.
Is this related to the issue mentioned in this errata (2.7.2)?
static void LPTIM_Init(void)
{
/* Disable LPTIM1 */
RCC->APB1ENR1 &= ~RCC_APB1ENR1_LPTIM1EN;
/* Change Clock Source */
RCC->CCIPR &= ~RCC_CCIPR_LPTIM1SEL;
RCC->CCIPR |= RCC_CCIPR_LPTIM1SEL_0 | RCC_CCIPR_LPTIM1SEL_1; // Select LSE as source
/* Reset LPTIM1 */
RCC->APB1RSTR1 |= RCC_APB1RSTR1_LPTIM1RST;
RCC->APB1RSTR1 &= ~RCC_APB1RSTR1_LPTIM1RST;
/* Enable During Sleep */
RCC->APB1SMENR1 |= RCC_APB1SMENR1_LPTIM1SMEN; //Enable During Sleep
RCC->C2APB1SMENR1 |= RCC_C2APB1SMENR1_LPTIM1SMEN; //Enable During CPU2 CSleep mode
/* Enable LPTIM1 */
RCC->APB1ENR1 |= RCC_APB1ENR1_LPTIM1EN;
RCC->BDCR |= RCC_BDCR_LSCOSEL; // Select LSE for LSCO
RCC->BDCR |= RCC_BDCR_LSCOEN; // Enable LSCO
LPTIM1->CFGR = 0;
LPTIM1->CMP = 49;
LPTIM1->ARR = 199;
LPTIM1->IER = LPTIM_IER_ARRMIE;
/* System interrupt init*/
HAL_NVIC_SetPriority(LPTIM1_IRQn, 7, 0);
HAL_NVIC_EnableIRQ(LPTIM1_IRQn);
LPTIM1->CR |= LPTIM_CR_ENABLE;
LPTIM1->CR |= LPTIM_CR_CNTSTRT;
}
void LPTIM1_IRQHandler(void)
{
if(isr & LPTIM_IT_ARRM)
{
LPTIM1->ICR = LPTIM_ICR_ARRMCF;
Toggle_Pin();
}
}
Thanks,
Daniel
Solved! Go to Solution.
2019-10-04 12:44 AM
Just found out that LPTIM works differently to normal Timers as the CMP and ARR Registers need to be set after the Enable.
LPTIM1->CR |= LPTIM_CR_ENABLE;
LPTIM1->CMP = 49;
LPTIM1->ARR = 199;
LPTIM1->CR |= LPTIM_CR_CNTSTRT;
2019-10-04 12:44 AM
Just found out that LPTIM works differently to normal Timers as the CMP and ARR Registers need to be set after the Enable.
LPTIM1->CR |= LPTIM_CR_ENABLE;
LPTIM1->CMP = 49;
LPTIM1->ARR = 199;
LPTIM1->CR |= LPTIM_CR_CNTSTRT;
2019-10-04 12:45 AM
Dear @Daniel L ,
You can check inside the STM32Cube_FW_WB_V1.2.0, there is an example demonstrating the PWM generation from LPTIM clocked from LSE:
This example seems the best fit for your problem.
You can also checks:
If you prefer low level driver, you can also refer to:
Pierre.