Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

SysTick interrupt priority

Posted by samfpetersen on January 6, 2016

I'm using FreeRTOS V8.2.1 on STM32F4 and my question is about the SysTick interrupt priority. The FreeRTOS source says that it should be the "lowest priority interrupt", and it explicitly sets it to the lowest priority in xPortStartScheduler(). This seems backwards to me, shouldn't it be the highest?

Further complicating things is the STM32's HAL libraries, which have their own systick implementation... It specifies that you should set the systick interrupt to the highest priority.

By the way, I'm referring to logically highest not numerically highest, and I'm aware that they are inverted

Thanks, Sam


SysTick interrupt priority

Posted by rtel on January 6, 2016

The interrupt that absolutely must be the lowest priority is the PendSV interrupt. The SysTick interrupt could be higher, but could interfer with application interrupts if it is.

When the ST HAL is used with FreeRTOS, like it can be with the STM32 Cube software supplied by ST, then ST call the FreeRTOS tick handler from their HAL tick handler. That means you must not install the FreeRTOS handler. However, I do it the other way around - installing the FreeRTOS handler as normal, then calling the HAL tick handler from the FreeRTOS tick hook function.

Regards.


SysTick interrupt priority

Posted by rtel on January 7, 2016

Actually - I would like to correct my previous post. The SysTick handler does need to run at the lowest priority. This is because the critical section within the handler itself assumes it is running at the lowest priority, so saves time by not saving the old priority mask and then restoring the previous priority mask.


SysTick interrupt priority

Posted by samfpetersen on January 8, 2016

The conflict I encounter is that the ST HAL SysTick must be at the highest priority, since there are HAL layer ISRs that wait on a timeout (which is bad, but it is what it is). So to fix this, I'm setting the SysTick interrupt to the highest priority, and in that ISR I'm calling the ST HAL tick function and setting another interrupt at the lowest priority. In the ISR of that interrupt, I'm calling the FreeRTOS tick function.

Seems hacky, but I can't think of a better way to do this at the moment. Thoughts?

Thanks, Sam


SysTick interrupt priority

Posted by janoshnosh on November 9, 2016

@Sam Petersen I totally agree with that strategy. I have no understanding for why the SysTick interrupt should be of lowest priority. In my opinion, FreeRTOS wouldn't have anything to do with a real-time system anymore, if it doesn't keep counting milliseconds. We have the same issue here, that the HAL-ISR-delays make all time calculations based on the FreeRTOS tick invalid. And ridiculous.


SysTick interrupt priority

Posted by owainkopin on December 22, 2017

@Richard Barry

what is logic of having systick as lowest priority isr? Surely systick is used for driving timers on various semaphore/mailbox operations that may time out; and also scheduler is run off the back of the systick. Is not systick kind of the God process controlling just about everything?

I can also see the view that we may have processes run off the back of ISR's that must be serviced in a timely fashion independent of the RTOS; they may be higher priority than systick. But ISR's that are posting semapores etc; should they not run lower than systick?

I am working on a system with around 10 isr sources; these are currently all higher priority than systick and I regularly see the systick being preempted. As a general rule of thumb is it not better to let systick run; do its stuff and then process other isrs?


SysTick interrupt priority

Posted by rtel on December 22, 2017

I think it is only the PenSV that needs to run at the lowest priority, it is just recommended to run SysTick at the lowest too to leave a lot of higher priority interrupts available for applications that require them to be more real time (deterministic). Some libraries (STM32Cube?) poll the tick inside an ISR (not good practice in my humble opinion) in which cases having the tick at the lowest priority can actually cause a deadlock. It is also generally more efficient if the tick is only incremented after other interrupts have completed, rather than intermix ISRs that are using the time and having the time changing.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Meet us at Embedded World. Hall 3A-525.

Hear from Richard Barry at Embedded World. Feb 28, 16:00, Hall 4-428.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS