Skip to main content
Robert Ritchey
Senior
September 8, 2026
Solved

STM32G051C8 TIM2 Not Initializing

  • September 8, 2026
  • 5 replies
  • 54 views

STM32G051C8 TIM2 is not initializing using LL_TIM_Init().  After I call the function and look at the registers they are all zero.  All the other TIM seem to work.  

Best answer by Robert Ritchey

Cancel this, I forgot to enable the clock. DUH

5 replies

Robert Ritchey
Senior
September 9, 2026

I tried this bit of code and it returned 0 for the prescaler.

    LL_TIM_SetPrescaler (TIM2, 0X0F);
    uint32_t Pre = LL_TIM_GetPrescaler (TIM2);

 

Robert Ritchey
Robert RitcheyAuthorBest answer
Senior
September 9, 2026

Cancel this, I forgot to enable the clock. DUH

Ozone
Principal
September 9, 2026

That’s a common mistake.
Or trying the wrong peripheral bus and RCC register ...

Kelvintavarez
Visitor II
September 9, 2026

Have you checked whether the TIM2 peripheral clock is enabled before calling LL_TIM_Init()?

On STM32G051, make sure the APB clock for TIM2 is enabled through RCC before initializing the timer. If the peripheral clock is not active, the registers may remain at their reset values even after the init function call.

I would also verify:

  • LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); is executed before LL_TIM_Init()

  • The timer instance passed to LL_TIM_Init() is actually TIM2

  • GPIO alternate function configuration is correct if you are using an external pin

  • Timer reset state is cleared after enabling the clock

A quick test is to manually write/read a TIM2 register (for example PSC or ARR) after enabling the clock. If it stays at zero, the issue is likely clock enable or peripheral access rather than LL_TIM_Init() itself.

passaicemergencyroof.com
Robert Ritchey
Senior
September 9, 2026

Thanks for the answers.  I wish the ST products acted like the NXP products and gave you a bus error when you tried to access a peripheral where the clock was not enabled.  That is about the only thing I like about NXP vs ST.