2022-10-10 10:09 AM
Hello everyone,
return to the issue of problems that can arise using the HAL_Delay (), within the Interrupt service functions in projects for embedded systems without RTOS.
Briefly: the HAL_Delay (), uses the interrupts thrown every mSec by the system timer SysTick; these interrupts increment a counter and the HAL_Delay () waits within a while for the counter value to reach the desired value.
But in the projects I made in the Cube environment, the SysTick is assigned by the development environment, in the HAL_Init () function, a priority of 15 (the lowest).
You can see this both from the MX environment and from the code.
Obviously an IRQ service function with higher priority (<15) can never be interrupted, and when using the HAL_Delay (), the Systick counter cannot be counted and the HAL_Delay() function is blocked; the system stops advancing.
I use a micro STM32F401 and as some external peripherals I use, they often need small delays , also in some interrupt situation (I think it happened to you too)
I tried to:
a) change the priority of the service function on SystTick interruption to a very high value (1 and sometimes 0),
b) declare ALL the interrupts used and controlled by me, with lower authority (2,3, ..).
The system works, for the tests I have been able to do. But some questions remain:
a) why does the CUBE system by default bring the priority of the SysTick to the minimum value? it was easily foreseeable that problems would arise.
b) what problems will I encounter on systems with more complex code? (I don't think I'm using RTOS).
Thank you.
Luciano
2022-10-10 10:51 AM
Real trick is that it needs to preempt any other usage in interrupt/callbacks. Although those types of uses shouldn't be blocking, or looping in a manner that a timeout is even appropriate. I can't even blame it on interns, this is high-school level stuff.
Foreseeable, yes for sure. The earlier timeout functions also had naive implementation that failed at rollover.
A better solution would have been to use a free running TIM, ideally a 32-bit one, and potentially a sub-millisecond granularity. TIM2, TIM5 or DWT CYCCNT..
2022-10-11 12:20 AM
Many thanks for recognizing me as a student. I am 74 years old with some degree . Do you have a Tesla-car ? wow !! are you Spder Man? WWWWOW!!
2024-05-23 02:04 AM
Good day
Can Anyone tell me if the HAL_Delay function uses it's own timer and registers or is it using a timer that is avaialble to the user. I need to make sure there can be no conflict by using HAL_Delay and for instance Timer 2 to do 2 seperate things.