cancel
Showing results for 
Search instead for 
Did you mean: 

Clear pending interrupts

jwoolston
Associate II
Posted on August 15, 2014 at 02:03

I know for a fact that this question has been asked before (I've seen it) but for the life of me I cannot find it, so I appologize.

I am unable to get some of my EXTI interrupts to clear their pending status. I remember reading in the previously mentioned post that the clear is buffered and that a read should force the write to complete. This is also mentioned in this

/public/Faq/Lists/faqlst/DispForm.aspx?ID=143&level=1&objectid=141&type=product&Source=/public/Faq/Tags.aspx?tags=%20interrupt

. The CMSIS library is useless for this as the NVIC_GetPendingIRQ reads from ISPR register and the clear obviously goes to ICPR register. So I tried using NVIC_ClearPendingIRQ() followed by a direct read of NVIC->ICPR, but it still stays set. I know there is no signal on the EXTI line which would be asserting it at the time. I configure the interrupt as follows:

GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOA clock */
HOST_SPI_ACTIVE_CLK_ENABLE();
/* Configure PA2 pin as input floating */
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Pin = HOST_SPI_ACTIVE_PIN;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(HOST_SPI_ACTIVE_PORT, &GPIO_InitStructure);
/* Enable and set EXTI Line7 Interrupt to the lowest priority */
HAL_NVIC_SetPriority(HOST_SPI_ACTIVE_EXTI_IRQn, HOST_SPI_ACTIVE_IRQ_PREEMPT_PRI, HOST_SPI_ACTIVE_IRQ_SUB_PRI);
HAL_NVIC_EnableIRQ(HOST_SPI_ACTIVE_EXTI_IRQn);

My attempts to clear the interrupt prior to re-enabling it after I had previous disabled it follow:

uint32_t pending = HAL_NVIC_GetPendingIRQ(HOST_SPI_ACTIVE_EXTI_IRQn);
printf(''SPI Active interrupt pending? %'' PRIu32 ''\n\r'', pending);
HAL_NVIC_ClearPendingIRQ(HOST_SPI_ACTIVE_EXTI_IRQn);
pending = NVIC->ICPR[0];
pending = HAL_NVIC_GetPendingIRQ(HOST_SPI_ACTIVE_EXTI_IRQn);
printf(''SPI Active interrupt post clear pending? %'' PRIu32 ''\n\r'', pending);
HAL_NVIC_EnableIRQ(HOST_SPI_ACTIVE_EXTI_IRQn);

After the enable call the interrupt is immediately fired, even though the GPIO line in question is logic low (confirmed by logic analyzer) #interrupt #stm32 #stm32f4 #exti
2 REPLIES 2
jwoolston
Associate II
Posted on August 15, 2014 at 02:04

I neglected to mention, the line in question is EXTI2 which is interrupt 8 (hence the 0 index on trying to access ICPR directly).

jwoolston
Associate II
Posted on August 15, 2014 at 20:04

Based on the info at

http://blog.frankvh.com/2011/11/21/stm32f2xx-dma-controllers-part-2/

web page I implemented the following code which has resolved the problem:

while (HAL_NVIC_GetPendingIRQ(HOST_SPI_ACTIVE_EXTI_IRQn)) {
__HAL_GPIO_EXTI_CLEAR_IT(HOST_SPI_ACTIVE_PIN);
HAL_NVIC_ClearPendingIRQ(HOST_SPI_ACTIVE_EXTI_IRQn);
}
HAL_NVIC_EnableIRQ(HOST_SPI_ACTIVE_EXTI_IRQn);