cancel
Showing results for 
Search instead for 
Did you mean: 

Timer doesn't work (STM32F767 + TIM3)

Pilous Droip
Senior

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Pilous Droip
Senior

It is my mistake....

Solution is in this line:

TIM_InitStruct.Autoreload        = 0xFFFFFFFFU;

View solution in original post

3 REPLIES 3

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
Senior

It is my mistake....

Solution is in this line:

TIM_InitStruct.Autoreload        = 0xFFFFFFFFU;

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