Skip to main content
Visitor II
May 31, 2024
Question

STM32U031 LPTIM1 not starting with Single Start mode

  • May 31, 2024
  • 1 reply
  • 781 views

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);

 

 

  • LPTIM1 is clocked from the LSI.
  • Yes, the LSI is enabled and selected as the clock for LPTIM1.
  • Yes, the peripheral clock for LPTIM1 is enabled.
  • No, the system is not currently running in low power modes.

 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.

    This topic has been closed for replies.

    1 reply

    ST Employee
    June 3, 2024

    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