cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup interrupts correctly

martingrimm9
Associate
Posted on October 10, 2015 at 17:31

Hello,

I've the following configuration on my STM32F4: - ADC with DMA triggered from TIM3 - EXTI0 triggered fromGPIO PA00 - EXTI1 triggered from GPIO PA01 The interrupt EXTI0 and EXTI1 should have the highes priority. Which means that it should called even if the MCU handles e.g. the ADC or the SysTick(). The standard configuration is a bit weired for me. In the CubeMX examples there is a configuration of the SysTick_IRQn of priority to 1. But actually in the HAL_Init() it is set to: /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */ HAL_InitTick(TICK_INT_PRIORITY); /*Configure the SysTick IRQ priority */ HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); with: #define TICK_INT_PRIORITY ((uint32_t)0x0F) /*!< tick interrupt priority */ which seems a Preempt Priority of 15 ?! Sometimes I get an HardFault error with my configuration. My code is in .cpp. There could be some HAL_Delay() issues I've read. Can anybody give me a hint with a correct interrupt configuration? Thanks

//HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); // Is actually already done in HAL_Init()
/* System interrupt init */
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
/* Timer 3 for ADC - Start */
HAL_NVIC_SetPriority(TIM3_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(TIM3_IRQn);
/* ADC */ 
HAL_NVIC_SetPriority(ADC_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(ADC_IRQn);
/* DMA-Stream */
HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
/* Enable and set EXTI Line0 Interrupt */
HAL_NVIC_SetPriority(EXTI0_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
/* Enable and set EXTI Line1 Interrupt */
HAL_NVIC_SetPriority(EXTI1_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(EXTI1_IRQn);

#stm32f4-nvic-interrupts
2 REPLIES 2
Posted on October 10, 2015 at 19:09

With C++ make sure to use extern ''C'' on the IRQ Handlers so the names don't get mangled and you lose linkage with the Vector Table. Most typical result otherwise is a Hard Fault, or ploughing into the Default Handler.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
thomasrl
Associate
Posted on October 22, 2015 at 04:57

I have noticed that ''NVIC_PriorityGroupConfig(NVIC_PriorityGroup_x); '' is left out of some programs. Is there a library that has a default that it falls back on. One site says it defaults to NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); But I can't find that in any libraries. Can you tell me why you don't always have to use priority group config and show me the library that has the default please.

Thank you