2015-04-17 08:51 AM
Hello.
I have Using One of the example Program that port UCOS on STM32F4 Devices.I have One problem. When I activate Timer in one the tasks, The Timer is Working in a right way(example is on the blinking LED). but i want to add some code in its interrupt service routin. i cant find where todo that?here is the code that activate timer 2 and its interrupt service routine(that i used).static void timer_init(void){ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_TimeBaseInitTypeDef timerInitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Enable the TIM2 gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 10; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); timerInitStructure.TIM_Prescaler = 40000; timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up; timerInitStructure.TIM_Period = 5000; timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; timerInitStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM2, &timerInitStructure); TIM_Cmd(TIM2, ENABLE);}Thank you for your answers.. #timer-interupt-handler #ucos-ii2015-04-17 11:56 AM
I can think of a couple ways, none of which may be correct.
Does the project have an stm32[something]_it.c file? In it you will find copies of some interrupt handlers. In the .s file you will find the actual vectors so once your interrupt is firing, you need only provide a function similar to what is in the ..._it.c and matches the vector declared in the .s file.I've been using the examples heavily and have not added any ISRs so hopefully this suggestion is correct.Another alternative would be to find an example that uses a timer ISR and see how it is set up and used.HTH,hank2015-04-17 12:04 PM
Hi HankB and thank you for your suggestions.
The First Way. No . the project does not have that file.and second way i have searched for examples but i was unable to find it. I will be appreciate if you found something like that inform me.again thank you for your answer.2015-04-17 01:10 PM
Typically, you will have a startup file that has the vector table with names for the interrupt handler functions, for example: TIM2_IRQHandler.
You can then define a function of your own with that name, for example: void TIM2_IRQHandler(void) { if (TIM2->SR & TIM_IT_CC2) // rising edge capture { TIM2->SR &= (uint16_t)~TIM_IT_CC2; // clear CC interrupt pending bit TIM2_InputCapture1 = TIM2->CCR1; // save captured values TIM2_InputCapture2 = TIM2->CCR2; } else // unexpected interrupt !? { } } Note that you will probably want to clear the interrupt pending bits that you are using.2015-04-17 01:32 PM
2015-04-18 05:35 AM
Hi Chris T.
Your suggestion in the case that we do not use UCOS is working. but when using UCOS This functions is no longer valid(at least i think this is like that). My problem is that i can not run this interrupt service routines in UCOS. thank you for your answer.2015-04-20 06:27 AM
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); // use all 4 bits for pre-emption priority
// (0 bits for subpriority) Then in your timer init function TIM2 channel assignment:NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 12; //
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // subpriority not used Higher IRQChannelPreemptionPriority values have lower actual priority.