If you have any experience in developing software for a microcontroller, have been interested in the topic, or have ever been around an embedded developer, you should be familiar with the concept of a real-time operating system (RTOS).
According to Aspencore market research, 65% of IoT projects use a RTOS. The name "real-time operating system" implies that the primary task of such an OS is to ensure the performance of the tasks designed by the system within a strict time frame. The first release of the RTOS took place in 1972 and was called Data General RDOS. It could process up to 32 tasks, which was an enormous breakthrough at that time.
Currently, we have two most widespread OSs of this type — FreeRTOS and Zephyr Project — which have specific differences in characteristics. In this article, our embedded engineer Oleksandr Zozulia will introduce what embedded engineering needs they cover and provide a clearer perspective on which to select in order to make your embedded project work.
What is FreeRTOS?
At the moment, the most popular real-time operating system is FreeRTOS, which was originally developed as an open-source project. FreeRTOS is all the rage thanks to its high integration with the most popular hardware development platforms (STM32, ESP32, and AVR), reliability, ease of use, and low hardware requirements. Also, this OS includes convenient and understandable APIs for timers and interrupts.
The FreeRTOS scheduler runs on the combination of two algorithms — the Prioritized Preemptive and the Time Slicing Scheduling algorithm – and manages Tasks and Co-routines concurrently. However, you can choose only one of them in the configuration file. For communication and synchronization of the tasks, FreeRTOS supports semaphores (both binary and counting), queues, and mutexes (direct and recursive). This OS can also use separated event flags and event groups. For FreeRTOS tasks, there are five ready-made heap implementations, such as heap_1, heap_2, heap_3, heap_4, and heap_5, with the fourth being used the most.
Why use FreeRTOS?
FreeRTOS is supported by Amazon, which leads to a legitimate modification of FreeRTOS — Amazon FreeRTOS, created for IoT projects with integrated Amazon Web Services. This modification immensely simplifies project development for engineers.
FreeRTOS is built into many IDEs and supports a wide range of chips and architectures.
The widespread popularity of FreeRTOS allows you to fix any occurring problem that you may have in the process of software development since, as an open source product, it has been constantly improved. In addition, there are many FreeRTOS assemblies, and you can find a customized assembly for practically any popular chip.
FreeRTOS has many IoT-oriented libraries such as FreeRTOS libraries (Core, Labs, Plus, and AWS).
FreeRTOS is basically an OS that is manageable if you’ve just started to work with real-time operating systems and need to understand its work principles.
What is Zephyr OS?
The second RTOS we will explore in this article, Zephyr Project, was originally developed for the Virtuoso RTOS, which was intended for DSP processors. In 2016, this RTOS was named Zephyr, and development continued in collaboration with the entire Linux Foundation. In 2022, Zephyr OS became the largest open-source RTOS project by the number of commits and developers.
Zephyr RTOS is an extremely flexible system with a tiny core primarily designed to ensure energy efficiency, which corresponds to its development concept. Its core is tickless by default, meaning that Zephyr software is an event-driven system. However, you can change this since this OS is highly configurable. Event-driven means that the scheduler will be called not just once in a certain period of time (like in FreeRTOS), but only for specific events that change the state of the thread (also known as "tasks"), which are referred to as rescheduling points.
As for the scheduler itself, it supports all well-known flow scheduling algorithms. There are two mandatory system threads: the Main thread and the Idle thread. The kernel can create additional system threads if required by system configurations. Another of the Zephyr program’s advantages lies in its flexibility, which makes it possible to exclude multithreading in its configuration. Additionally, you can use the same semaphores, mutexes, event objects, and queues for synchronization.
Why use Zephyr Project RTOS?
Zephyr operating system is often integrated into various SDKs, including nRF SDK, which was produced by Nordic Semiconductor with a strong Zephyr RTOS integration. This company also made significant contributions to the development of this OS.
Useful debug features
Zephyr RTOS has several very convenient and useful features that make life easier when debugging RTOS software. Personally, I like the thread analyzer the most. You can add it to the project by specifying one additional parameter to the build command in the west environment.
Another useful feature is the GDB Stub, which enables you to control Zephyr via GDB remotely.
It's worth mentioning the СMAKE build system and a hierarchical system of devicetree data used for hardware configuration that make it easy to develop a custom device compatible with Zephyr operating system.
I also find the west meta-utility (something like git or docker) very convenient since, in addition to git functions, it can start the build process and many more.
The Zephyr operating system greatly simplifies the development of many implementations not directly related to the main functionality of the RTOS.
So which should you choose?
More often than not, the choice of a real-time operating system is based on the already-selected hardware, cloud platform, development environment, and developer's experience. I would recommend learning and using FreeRTOS if you've just started to learn the concept of RTOS. However, if you take on a task to develop a low-power solution or embedded software for a low-memory controller, or you simply want to try using something other than FreeRTOS, turn your attention to the Zephyr Project.
If you still doubt which OS to use, contact our experts, and we’ll be happy to provide our embedded development services to help you move your project forward.