cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_Delay and interrupts?

jagauthier
Associate III

Hello,

If I am using an external interrupt on a GPIO pin HAL_Delay() in my program's main() does not work.

  while (1)
  {
	  serprintf("Before HAL Delay");
	  HAL_Delay(500);
	  serprintf("After HAL Delay");
 
  }

 "After HAL Delay" never happens. I've read a few threads that indicate that you should not use HAL_Delay() in the interrupt function, which is fine. I am not doing that.

If I disable the interrupt, the main loop works as expected.

4 REPLIES 4

>>If I disable the interrupt, the main loop works as expected.

Suggests that the EXTI IRQ handler doesn't satisfactorily clear the interrupting state, and it continuously re-enters.

Or something else going on in your unspecified STM32 system more generally.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
void EXTI4_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI4_IRQn 0 */
  VL53L3CX_SimpleRanging_Int();
  /* USER CODE END EXTI4_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
  /* USER CODE BEGIN EXTI4_IRQn 1 */
 
  /* USER CODE END EXTI4_IRQn 1 */
}

Should I be doing more than the this? This function is generated code from CubeMX.

It's all very superficial.

Perhaps have a count so you can see how often it passes. If it enters several hundred thousand times a second then nothing else will likely run.

The tail-chaining methods will basically block execution of foreground code. You basically get an "interrupt storm", and saturate the processor.

You should check the reporting in the NVIC/EXTI to ensure nothing is pending as you leave.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Good point. Sorry, I should have indicated the interrupt is driven by a piece of hardware of 30Hz. So it's not very fast.

The last statement you made was interesting "You should check the reporting in the NVIC/EXTI to ensure nothing is pending as you leave."

I would like to learn how to do this either way.