Skip to main content
Pilous Droip
Senior
May 9, 2019
Solved

Timer doesn't work (STM32F767 + TIM3)

  • May 9, 2019
  • 3 replies
  • 839 views

Hello. I have this init TIM3:

void Start_Timer_3(void)
{
	LL_TIM_InitTypeDef TIM_InitStruct;
 
	LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
 
	NVIC_SetPriority(TIM3_IRQn, 3);
	NVIC_EnableIRQ(TIM3_IRQn);
 
 // 50MHz clock
	// 1000 Hz, upcounting 32-bit
	// 1000 = ( 50000000 / (Prescaler+1))
	TIM_InitStruct.Prescaler = (uint16_t)50000 - 1;
	TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
	TIM_InitStruct.Autoreload = 0xFFFFFFFFU;
	TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
	TIM_InitStruct.RepetitionCounter = (uint8_t)0x00U;
 
 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM3);
 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM3);
 
	LL_TIM_Init(TIM3, &TIM_InitStruct);
 
	LL_TIM_ClearFlag_UPDATE(TIM3);
	LL_TIM_EnableIT_UPDATE(TIM3);
 
	LL_TIM_EnableCounter(TIM3);
}

And here is my Handler:

void TIM3_IRQHandler(void)
{
	LL_TIM_ClearFlag_UPDATE(TIM3);
	// breakpoint atc.... here
}

And my handler isn't working. Any idea, why? I try everything.

This topic has been closed for replies.
Best answer by Pilous Droip

It is my mistake....

Solution is in this line:

TIM_InitStruct.Autoreload = 0xFFFFFFFFU;

3 replies

waclawek.jan
Super User
May 9, 2019

How do you know that the "handler isn't working"?

Read out the timer registers in debugger, check if they are set as expected, check if TIMx_CNT is changing, check if the required bit in TIMx_UDR is set. Check in NVIC registers if the proper interrupt is enabled. Check in the disassembler if the IRQ handler's address is inserted at the proper place.

I wouldn't be surprised if you'd need to insert some delay between the reset and setting up the timer registers.

JW

Pilous Droip
Pilous DroipAuthorBest answer
Senior
May 10, 2019

It is my mistake....

Solution is in this line:

TIM_InitStruct.Autoreload = 0xFFFFFFFFU;

waclawek.jan
Super User
May 15, 2019

I don't understand. What solution? It's exactly as you've posted in your initial post. So what did you do to correct the problem?

JW