While reading the RM0008 reference manual I got confused about how to use the NVIC to configure interrupts. The manual basically redirects the reader to the PM0056 programming manual which, in my opinion, doesn't do a great job in explaining how to use the NVIC functions provided by CMSIS.
So, I'm trying to set up an interrupt for GPIOA pin 1 using EXTI Line 1 in a NucleoF103 board, and I want to setup priority and subpriority bits, but I'm not sure how to do that. The RM0008 manual states that the NVIC has 4 bits of interrupt priority.
CMSIS provides functions such as "NVIC_SetPriorityGrouping" and "NVIC_SetPriority" to choose priority and subpriority bits, but I can't seem to find a good explanation for what the arguments do in these functions.
It seems that the "NVIC_SetPriorityGrouping" changes some values in the AIRCR register, which does have some bits to configure number of priority and subpriority bits.
So, for instance, is this code correct for setting up and EXTI interrupt on Line 1?
#define RESET_WITH_MASK(reg,mask) reg &= ~(mask) #define SET_WITH_MASK(reg,mask) reg |= (mask) [...] //Configure EXTI Line1 to not be masked SET_WITH_MASK(EXTI->IMR,EXTI_IMR_MR1); //Configure a rising edge to trigger an interrupt SET_WITH_MASK(EXTI->RTSR,EXTI_RTSR_TR1); //Configure EXTI Line1 multiplexer to listen to port A SET_WITH_MASK(AFIO->EXTICR,AFIO_EXTICR1_EXTI1_PA); //Choose type of priority bits: 3bits for priority, 1bit for subpriority NVIC_SetPriorityGrouping(1); //Set priority of EXTI Line1 to 0 (highest priority), subpriority to 1 NVIC_SetPriority(EXTI1_IRQn,0b0001); //Enable EXTI Line 1 interrupt NVIC_EnableIRQ(EXTI1_IRQn); //Enable interrupts __enable_irq();
Here I am assuming that the argument for the "NVIC_SetPriorityGrouping" chooses the number of subpriority bits, and that the "NVIC_SetPriority" takes the priority bits, the most significant being priority and least significant being subpriority.
Obviously pin 1 of GPIOA needs to be configured as an input for this to work, but aside from that, am I missing any configuration stuff? Also, is "__enable_irq()" truly necessary?
Any help would be appreciated as I was not able to find any good examples of this, and I'd like to avoid doing the configurations using all those shifts in the NVIC registers when CMSIS already provides functions for this.