0
votes

I am really new to STM32 world so I came across this while reading:

void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn);

This will cause the interrupt to fire, as it would be generated by the hardware. A distinctive feature of Cortex-M processors it that it is possible to programmatically fire an interrupt inside the ISR routine of another interrupt.

I got this from the book Mastering STM32 (by Carmine Noviello page 208). From this I have understood that If we set this pending bit even from the main function, then the interrupt is generated. So to try this out, I have written this code:

while (1)
  {
      HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
      for(int i = 0; i <10000000; i++);
      HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
      for(int i = 0; i <10000000; i++);
      HAL_NVIC_SetPendingIRQ(EXTI0_IRQn);
  }
}

along with this call back function

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_PIN){
    HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_15);
}

I have programmed GPIO_PIN_0 as source of interrupt and when I press the push button connected to PA0 the Interrupt works perfectly i.e. ISR is executed. To my surprice HAL_NVIC_SetPendingIRQ function doesn't generate interrupt. I don't understand why?

More Info:

  • I am using STM32F411VET6 DISCO board
  • I am using STM32CubeIDE to program the board
1
I have no experience with HAL, but I suspect that there is an additional layer of HAL which prevents execution to reach HAL_GPIO_EXTI_Callback. Probably in that layer, there is some code to detect the GPIO pin causing the interrupt and it fails to detect the pin as the interrupt is generated artificially.Tagli

1 Answers

1
votes

Thank you @Tagli. I have found the function HAL_GPIO_EXTI_IRQHandler inside stm32f4xx_hal_gpio.c file. Defalult definition was like this:

void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
  /* EXTI line interrupt detected */
  if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
  {
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
    HAL_GPIO_EXTI_Callback(GPIO_Pin);
  }
}

I got why the GPIO was not being toggled. It was the same reason you have commented above. I have modified to prove it.

void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
  /* EXTI line interrupt detected */
    HAL_GPIO_EXTI_Callback(GPIO_Pin);
  if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
  {
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
    HAL_GPIO_EXTI_Callback(GPIO_Pin);
  }
}

Now the callback function is called when the HAL_NVIC_SetPendingIRQ(EXTI0_IRQn); is being called