2020-06-27 06:11 AM
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
2020-06-27 06:51 AM
Yes. By default it uses a counter which is incremented by the SysTick interrupt handler once every millisecond.
2020-06-27 11:54 AM
Thanks for update..
Do I need to change (lower) SysTick priority if I have HAL_Delay() in while (1). ?
Where other high priority interrupts?
--
Karan
2020-06-28 03:40 AM
The HAL_Delay() use the counter register of SysTick, but not the SyStick iterrupt.
The HAL_Delay() is an active polling loop waiting for SysTick interrupts.
This is why HAL_Delay() should not be used in an interrupt routine.
2020-06-28 05:12 AM
Hi,
@Nikita91 (Community Member)
Thanks for update .. How to use HAL_Delay() in main.c while(1) with other interrupts but not inside the interrupts ?
I have gone through below link..
https://stackoverflow.com/questions/53899882/hal-delay-stuck-in-a-infinite-loop/53903790#53903790
https://community.st.com/s/question/0D50X00009XkYLP/haldelay-causes-infinite-loop-in-some-cases
https://community.st.com/s/feed/0D50X00009XkW2MSAV
By Below Priorities setup , the code stuck in infinite loop and then hardfault
Should I avoid HAL_Delay and use dummy delay as below ?
void __delay_ms(int32_t k)
{
int32_t i,j ;
for(i=0;i<k;i++)
for(j=0;j<3000;j++)
{
}
}
Please advice..
--
Karan
2020-06-28 06:12 AM
As @berendi 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.
--pa
2020-06-29 11:27 PM
Hi,
@berendi (Community Member) and Pavel A. (Community Member)
But Why below type of delay can't produce constant delay every time ?
void __delay_ms(int32_t k)
{
int32_t i,j ;
for(i=0;i<k;i++)
for(j=0;j<3000;j++)
{
}
}
--
Karan
2020-06-29 11:32 PM
Execution time depends on lots of factors, e.g. interrupt activity, code alignment in flash. It can never be relied upon. Use a timer or a counter derived from a timer, like HAL_Delay().
2020-06-30 12:11 AM
Ok ..Thanks .. But I also want to use high priority interrupt with HAL_Delay() and don't want to disable that like Pavel A. (Community Member) said ..
--
Karan
2020-06-30 12:29 AM
Do not use HAL_Delay() or any other kind of delay in interrupts.