2024-05-31 7:03 AM - edited 2024-05-31 7:12 AM
I am using a STM32U031 part with register level configuration (no Cube libraries). The Timer should be straight forward to start in a single-shot mode but when I set the LPTIM_CR_SNGSTRT flag in the CR register, the CNT register never increments and the SNGSTART flag never shows up in the SFRs window when debugging.
If I run the timer in continuous mode, it works okay.
I know the reference manual talks about a delay after enabling the timer. I've tried adding a 100us delay as a test after enabling it and it didn't work. Besides the code below works with continuous mode and it also doesn't work when stepping through with the debugger.
// I also tried just clearing LPTIM_CR_ENABLE which didn't work. This was another approach that I think I saw in the reference manual. It doesn't work either.
RCC->APBRSTR1 |= RCC_APBRSTR1_LPTIM1RST;
RCC->APBRSTR1 &= ~RCC_APBRSTR1_LPTIM1RST;
// Only modify CFGR register when disabled
LPTIM1->CFGR &= ~LPTIM_CFGR_PRESC_Msk;
LPTIM1->CFGR |= (prescale_powers_of_2 << LPTIM_CFGR_PRESC_Pos);
// Tried with and without WAVE and TIMOUT as a test, no mix would work.
LPTIM1->CFGR|= (LPTIM_CFGR_WAVE | LPTIM_CFGR_TIMOUT);
/* enable the LPTMR and start single shot counting. Timer must be enabled before setiing registers*/
LPTIM1->CR |= LPTIM_CR_ENABLE;
__NOP();
(void)LPTIM1->CR;
LPTIM1->ARR = timer_counts;
LPTIM1->ICR = LPTIM_FLAG_DIEROK;
LPTIM1->DIER |= (LPTIM_DIER_ARRMIE | LPTIM_DIER_UEIE);
while((LPTIM1->ISR & LPTIM_FLAG_DIEROK) == 0 ); // Wait for flagt to be set indicating DIER has been updated.
LPTIM1->CR |= LPTIM_CR_SNGSTRT; // Start counting in single shot mode
//LPTIM1->CR |= LPTIM_CR_CNTSTRT);
Am I missing something? These are brand new parts but I don't see anything in the errata.
FYI, I can't find a ST Library function to run a single-shot lptimer without setting it up in compare mode to control one of the channel's pins. HAL_LPTIM_SetOnce_Start_IT and HAL_LPTIM_OnePulse_Start_IT both assume I want to set the GPIO on a counter match.
2024-06-03 11:37 AM
Hi Nick
This post has been escalated to the ST Online Support Team for additional assistance. We'll contact you directly.
Kind Regards
Joe WILLIAMS
STMicro Support
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.