2015-07-19 03:05 PM
Hello all,
I tried searching for a bit but couldn't find anything pertaining to my question.I'm trying to set up an external interrupt but I don't understand why exactly we clear the pending bit in EXTI->PR and not in the NVIC_ICPRx (interrupt clear pending registers). Also on the STM32f4 do I need to set any special clocks for EXTI or just the Portx clock? #!stm32f4-disco2015-07-19 06:08 PM
You'd need the SYSCFG clock.
The NVIC handles the Cortex-M4 side of the interrupt generation, but as their are often multiple sources the peripheral is where you look for what actually caused the interrupt, and where you clear it as an acknowledgement.STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\Project\STM32F4xx_StdPeriph_Examples\EXTI\EXTI_Example\main.c2015-07-19 07:47 PM
So if I'm understanding correctly, the NVIC handles interrupts internal to the MPU. Since I'm interrupting external to the Cortex m4, at the periph, the NVIC isn't set up for that. I go to the peripheral and clear the bit?
2015-07-20 08:39 AM
Simple example:
void EXTI_Int(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOE, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource13);
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x10;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
extern uint32_t program_counter;
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
//todo
EXTI_ClearITPendingBit(EXTI_Line13);
}
}
2015-07-20 10:36 AM
The NVIC is responsible to getting code execution to your IRQHandler. You need to identify and clear the source. For EXTI this is by clearing it on the EXTI peripheral, for things like the USART or ADC reading the data registers can clear the source, ie RXNE or EOC
If things aren't cleared, then the NVIC will cause the IRQHandler to be continuously tail-chained, and your foreground code with never get control again.