2013-09-16 03:15 PM
I am trying to use the ISR for TIM1, but it does not want to trigger. I run the following code in debug mode on my IDE, but the TIM1 ISR code never gets executed.
I believe that the problem may have something to do with an extra enable needed for the advanced control timers, but have yet been unable to find it.Also, I would appreciate any tips on how to make the following code more readable for you./* Includes ------------------------------------------------------------------*/&sharpinclude ''stm32f4xx.h''/* Private typedef -----------------------------------------------------------*//* Private define ------------------------------------------------------------*//* Private Variables */uint16_t uhPrescalerValue = 0;NVIC_InitTypeDef NVIC_InitStructure;TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;/* Functions */int main(void){ uhPrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 10000000) - 1; /* TIM clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); /* Enable the TIM4 interrupt */ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; NVIC_Init(&NVIC_InitStructure); /* Time Base configuration */ TIM_TimeBaseStructure.TIM_Prescaler = uhPrescalerValue; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 0xFFFF; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); //Enable TIM1 output TIM_CtrlPWMOutputs(TIM1,ENABLE); /* TIM counter enable */ TIM_Cmd(TIM1, ENABLE); TIM_Cmd(TIM4, ENABLE); //TIM IT Config TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE); TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE); while (1){ }}void TIM4_IRQHandler(void) { TIM_ClearITPendingBit(TIM4, TIM_IT_Update);}void TIM1_CC_IRQHandler(void) { TIM_ClearITPendingBit(TIM3, TIM_IT_Update);}void TIM1_CC_IRQHandler(void);void TIM4_IRQHandler(void); #stm32f4 #stm32f4 #interrupts #tim1 #isr #vector-table2013-09-16 03:42 PM
TIM1 uses multiple interrupts for different sources
For UpdateTIM1_UP_TIM10_IRQHandlerYou'll want to change the NVIC (TIM1_UP_TIM10_IRQn), and have the service routine clear TIM1, not TIM32013-09-16 05:04 PM
Thanks again clive. That works.
In order to use the CC interrupt, would you need to set up one of the IC or OC functions on one of the TIM1 channels?2013-09-16 05:35 PM
Yes, and the other interrupts in NVIC as required. You could however modify the vector table in startup_stm32f4xx.s to all use the same service routine.
2013-10-30 07:28 PM
Ahh good idea. I am finding now that I need to use this technique for other purposes.
2014-01-17 01:41 PM
In order to make two different interrupts use the same ISR is it correct to say:
startup_stm32f4xx.sEXTI9_5_IRQHandler\ PROC EXPORT EXTI9_5_IRQHandler [WEAK] IMPORT EXTI_COM_IRQ_Handler B EXTI_COM_IRQ_Handler ENDPEXTI15_10_IRQHandler\ PROC EXPORT EXTI15_10_IRQHandler [WEAK] IMPORT EXTI_COM_IRQ_Handler B EXTI_COM_IRQ_Handler ENDP;EXTI9_5_IRQHandler;EXTI15_10_IRQHandler---in file.cpp NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_Init(&NVIC_InitStructure); void EXTI_COM_IRQ_Handler__irq(void) { }in file.h:extern ''C'' {void EXTI_COM_IRQ_Handler__irq(void) ;
}2014-01-17 02:05 PM
I'd probably just change them in the vector table and save the unnecessary branch
.. DCD EXTI9_5_IRQHandler ; External Line[9:5]s .. DCD EXTI15_10_IRQHandler ; External Line[15:10]s .. too IMPORT EXTI_COM_IRQ_Handler .. DCD EXTI_COM_IRQHandler .. DCD EXTI_COM_IRQHandler .. NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_Init(&NVIC_InitStructure); void EXTI_COM_IRQHandler(void) // cdecl?! { } in file.h: extern ''C'' { void EXTI_COM_IRQHandler(void) ; }2014-01-17 02:18 PM
Is it true to say that the interrupts vector list in stm32f4xx.h is the mapping for the list in the External Interrupts section of startup_stm32f4xx.s? This would mean that as long as you did not mess with the order, it does not really matter what you call each item is the assembly list?