cancel
Showing results for 
Search instead for 
Did you mean: 

Systick IRQ priority and HAL_Delay()

LVara.1
Associate II

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

0693W00000UnkBcQAJ.jpg

3 REPLIES 3

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..

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

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!!

SDu T
Associate III

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.