cancel
Showing results for 
Search instead for 
Did you mean: 

EXTI Pending Interrupt (EXTI_PR1) still getting serviced even when clearing the pending register

KBako
Associate

I have a system that uses an STM32L476 controller, where we are using EXTI0 to wake up on a falling edge interrupt.

My interrupt service routine used to wake up, contains an IWDG reset, so any time the interrupt gets serviced, we just reset (that's the intended way of waking up)

void EXTI0_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI0_IRQn 0 */
  MX_IWDG_Init();
   // HAL_IWDG_Init();
  /* USER CODE END EXTI0_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
  /* USER CODE BEGIN EXTI0_IRQn 1 */
 
  /* USER CODE END EXTI0_IRQn 1 */
}

The problem seems to be, that once we go to sleep, if there is a pending interrupt, it gets serviced, so we reset.

I tried to clear the pending interrupt, so that it doesn't get serviced, but it doesn't seem to help, only in debug mode.

I tried to clear it like:

while(EXTI->PR1 & 0x01){
        EXTI->PR1 = 0x01;
      }

And also by:

HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn);

(The NVIC function doesn't even clear the bit properly (?!) )

Any suggestions are welcome.

1 ACCEPTED SOLUTION

Accepted Solutions
KBako
Associate

I actually tried that, but it did not help.

What did, however, was this snippet I found on this forum for a similar problem:

  while (HAL_NVIC_GetPendingIRQ(EXTI0_IRQn)) {
  __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
  HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn);
  }

Looks like you need to read the pending interrupt, before you clear it and that will solve your problem for good.

View solution in original post

2 REPLIES 2

It takes time until the change propagates from EXTI into NVIC, especially if the APB bus on which EXTI sits has a clock divided down.

Try to put some a couple of NOPs after the EXTI->PR1 clear.

JW

KBako
Associate

I actually tried that, but it did not help.

What did, however, was this snippet I found on this forum for a similar problem:

  while (HAL_NVIC_GetPendingIRQ(EXTI0_IRQn)) {
  __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
  HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn);
  }

Looks like you need to read the pending interrupt, before you clear it and that will solve your problem for good.