cancel
Showing results for 
Search instead for 
Did you mean: 

Is HAL_Delay() implemented with Interrupts?

Karan 123
Senior

Hi,

Is HAL_Delay() implemented with SysTick() interrupt ?

Is ​it safe to use HAL_Delay() in while loop main.c

with other ( low priorities ) interrupts?

​Thanks

--

Karan​

15 REPLIES 15

I do not use HAL_Delay() in interrupts . I want to use HAL_Delay() in main with interrupts

What is it that still prevents you from using it?

Hi,

If I use HAL_Delay() in main and other high priority interrupts ?

Got below errors..

https://community.st.com/s/question/0D53W00000AbLseSAF/stm32g0-variable-corruptmemory-fault-hardfault-inside-the-interrupts

As Pavel A. (Community Member) Said :

"As @berendi (Community Member)​ replied, in main just call HAL_Delay. Unless you need delay while interrupts are disabled. Or unless you want more precise delay (microseconds). Just try it. Do not change the systick priority."

I don't want to disable my high priority interrupts.

--

Karan

> If I use HAL_Delay() in main and other high priority interrupts ?

> Got below errors..

Fix them, integer overflow and array indexing problems, have nothing to do with interrupts, delays, or priorities.

> I don't want to disable my high priority interrupts.

Then what is the problem?

S.Ma
Principal

Take a step back and ask yourself: where are the time critical actions (that needs to kick in within 1 msec)

Interrupts should remain very brief. If you do things that take time within an interrupt, something is wrong in the implementation.

HAL_Delay has "1 msec jitter" to be very brief

Timer Output Compare can be used to generate any period measurement. The finer the time granularity, the higer frequency the timer runs.

If you need to drive LED Segment, why not use TIMER to generate a burst of clock pulses, and use another output compare channel(s) (interrupts?) to flip the data GPIOs if the LED clock frequency is few kHz ? The implementation depends on the timing constrains of the system and the timing/latency constrains within the microcontroller. This is what SW tools won't help much. It's called SW profiling.

Quote: This is why HAL_Delay() should not be used in an interrupt routine.

A blocking call have to be avoided in ANY interrupt routine in any circumstances!