ESP32 Arduino: Using FreeRTOS functions

The objective of this post is to introduce some basic concepts of FreeRTOS on the ESP32.


The objective of this post is to introduce some basic concepts of FreeRTOS on the ESP32.

First of all, it’s important to take in consideration that we can use functions from the FreeRTOS libraries when coding for the ESP32 with the Arduino IDE. This can easily be seen by this example provided in the libraries, which uses semaphores and mutexes.

The FreeRTOS libraries are available here in the GitHub repository.

So, the possibility of using FreeRTOS functionalities opens a very powerful set of tools that extend beyond the capabilities of the Arduino support.

Nevertheless, as we will in future posts, we can still use Arduino functions. For example, we will use our regular Serial.begin and Serial.print to handle the printing of messages to the serial port.

The concepts of tasks and multi tasking in a operating system are too complex for explaining in this introductory post. Nevertheless, there are lots of good material available around the web that explain these concepts. Also, FreeRTOS as a very good set of explanation pages.

So, I will try to provide some context on future posts, but there will be some things that are going to be left out. I will also leave some links in the related content section that can help you getting started.

For now, we will start by a brief explanation of what is FreeRTOS and what are tasks.


What is FreeRTOS?

FreeRTOS is a real time operating system designed to run on microcontrollers [1]. Naturally, since microcontrollers are resource constrained, any operating system to run on them needs to be adequately designed.

Nevertheless, as mentioned, FreeRTOS is a real time operating system, which is a particular type of operating systems. To understand what a real time operating system is, we need to take a look at the regular operating systems that we are used to.

For example, when we are using Windows or Linux, we can have multiple processes and applications open at the same time, and it seems that they are all running at the same time. For the end user, this is transparent.

Nevertheless, for a computer with a single core (things changed a bit with multi core systems, but let’s stick to a simple example) only one process can be executing at the same time [2]. So, what computers do is changing the execution between tasks very rapidly, so the the end user has the sensation that things are occurring in parallel [2].

Naturally, these changing of processes may occur accordingly to different algorithms but typically it ensures that each process gets a fair amount of CPU to execute. The specifics will depend on the operating system in question. But typically, one cannot predict the flow of execution of the multiple processes, which are not deterministic.

On the other hand, a scheduler in a Real Time Operating System is built to have a deterministic execution pattern [1], which is needed for applications with real time requirements. Note that real time execution means meeting every defined deadline [3], it doesn’t necessarily mean executing fast.

So, we can have parallelism, so we don’t need to execute each task sequentially, as we are used to, for example, in an Arduino environment. On top of that, we have a lot of control over these tasks, since we can predict the flow of execution accordingly to their priorities.

What are tasks?

Tasks are typically the building blocks of Real Time Operating Systems [4]. They execute on their own context and the scheduler is responsible for deciding which task is executing at a given moment [5] in a single core.

Nevertheless, as said before, we can run multiple tasks in parallel (only one executes at each time, but there may be many instantiated) so our programs are easier to code.

In FreeRTOS tasks are implemented as C functions and follow a pre-defined prototype [6], as can be seen bellow.

void taskImplementingFunction( void * parameter )

So tasks will be a very important concept that we need to analyse in future tutorials.

Related content








6 thoughts on “ESP32 Arduino: Using FreeRTOS functions”

  1. Pingback: ESP32 Arduino Bluetooth classic: Getting started | techtutorialsx

  2. Pingback: ESP32 Arduino Bluetooth classic: Getting started | techtutorialsx

Leave a Reply