I need to configure a timer in order to get an interrupt every 1ms. So first I need to know which timer I can use. But I also don't know at which point I should configure the timer and where I can define the TIM2_IRQHandler(void). Does anybody know where I can find information about timer used in crazyflie firmware and how to configure them?
I tried to configure TIM2 in the AppLayer even though I don't know if TIM2 is used by the firmware already.
But after NVIC is enabled "NVIC_EnableIRQ(TIM2_IRQn);" the crazyflie reboots and repeats the starting sequence.
Code: Select all
RCC->APB1ENR |=1;               // Enable Timer 2 Clock
TIM2->PSC=15999;                // PSC=15999 
TIM2->ARR=1000; 		// --> interrupt every 1s
TIM2->CR1=0x4;                  // URS=1 (Update Request Source)
TIM2->DIER |=1;                 // UIE=1 (Update Interrupt Enable)
NVIC_ClearPendingIRQ(TIM2_IRQn);
NVIC_SetPriority(TIM2_IRQn, 10); 
NVIC_EnableIRQ(TIM2_IRQn);		
TIM2->CR1 |=0;              
void TIM2_IRQHandler(void)
	{
	    // Clear Update Interrupt Flag UIF
	    TIM2->SR &= ~(1<<0);
		for (i = 0; i < 100000; i++) {
			motorsSetRatio(MOTOR_M2, 2500);	}
	}