Skip to content

FreeRTOS

HannesH edited this page Mar 13, 2021 · 6 revisions

FreeRTOS

About FreeRTOS

FreeRTOS is a realtime operating system for embedded devices. It mainly feature is a scheduler that we are using to differentiate between working thread and attacking thread.

Configuration of FreeRTOS for the project

The STM32CubeIDE can auto generate code to use FreeRTOS. To do so, go to the .ioc-file of the project, choose Middleware > FreeRTOS and select the CMSIS version you want to use (your only option should be version 2). After that you can choose to create tasks automatically in the rider "Tasks and Queues" > Add (under Tasks). The GUI is pretty self-explanitory. One pitfall that you need to consider is the size of the stack. We recommend to use a stacksize of at least 512 words, as issues with osDelay may arise. In most cases however you aren't done yet, as there may be an issue with the timebase. If you get a warning regarding a timer while FreeRTOS is enabled. select System Core and SYS (SYS_NS or SYS_S depending on where you have assigned FreeRTOS before, you only need to care about this, if you use TrustZone), there select "TIM6" as Timebase Source (you may use other Timers, but these need to be configured).

Tasks

Many things in this chapter are taken care by the .ioc-file. However, if you have to create tasks manually you may need to know to know something about FreeRTOS and CMSIS respectively.

Scheduler

Before you can start creating tasks, the Scheduler must be initilaized with "osKernelInitialize()". After that you can start adding Tasks to the scheduler. Once "osKernelStart()" is called, the execution is dependent on the decisions of the scheduler. Even after starting the scheduler, tasks can be added.

Creation of tasks

To create a new task, one uses osThreadNew([Starting Function], [(void *) Argument Vector], [Task Attributes]). The Attributes are passed via a struct called osThreadAttr_t([(char*) Name], [(osPriority_t) Priority], [(int) Stack Size]). As far as examples go, there should be one in the automatically generated code in the main.c. (DefaultTask) CMSIS doesn't allow the creation of tasks during an interrupt. However, you may change the code to allow for just that. Go to cmsis_os2.c at line 415 and remove !IS_IRQ(). We only use this option once to create a thread during an interrupt and it doesn't cause any trouble, but you might want to remember that this optoin has been changed.

Possible Attack

As describe here in FreeRTOS version 10.0.1 some vulnerabilities were discovered. Among these we have considered to exploit the one that is based on the wrong handling of a failed connection. If one considers to use this attack, the board must either be changed or one must find a way to establish a connection that can use this API.

Clone this wiki locally