What Are the Advantages of RTOS in Embedded Development?

Potential Issues in Embedded Development

1 Concurrency Issues

The efficiency of concurrent program execution is low when writing bare-metal software. Inevitably, there will be a massive while(1) loop in the main program, which contains almost all the business logic of the project. Since each business logic contains delay functions that cause loop waiting, this leads to all business logic working almost serially. At this point, the CPU wastes a lot of time in the delay functions, running in idle, resulting in very poor software concurrency efficiency.

2 Modularity: High Cohesion, Low Coupling Principle

From a software engineering perspective, we emphasize the principle of high cohesion and low coupling in software development. However, modular development in bare-metal programming is very challenging, with heavy coupling between modules, making it impossible to use bare-metal for large projects. Taking the earlier example of the main function’s large while(1), one can imagine that so many functions are tightly packed into one function, making it impossible to split, leading to significant difficulties in modular development.What Are the Advantages of RTOS in Embedded Development?

5 Reusability: Poor Software Reusability, Always Reinventing the Wheel

Reusability is directly related to the degree of modularity. Everyone wants to avoid repetitive work, and similarly, when writing code, we aim to write as little similar functionality as possible. However, in this era of severe fragmentation in embedded systems, with various chips, making the same code adapt to different hardware in a bare-metal environment is very challenging. This leads to bare-metal code being overly dependent on the underlying hardware, making the process of reinventing the wheel unavoidable.

Advantages Brought by RTOS

My first encounter with operating systems was around 2010 when STM32 began to gain popularity. This powerful microcontroller had many people running operating systems on it, and I also ported ucos, running ucgui on it. Writing applications at that time was a completely new experience, much more enjoyable. After a year with ucos, I later encountered our domestic RT-Thread, which has many ready-to-use components. After trying it out, I found it even more enjoyable, and I have been using it ever since, for about 8 years. Let me share the advantages of operating systems: Thread-based concurrent task processing solves modularity issues while ensuring real-time performance.1 Modularity With the use of an operating system, the entire software work is divided into multiple tasks (also referred to as threads), each with its own independent execution space, i.e., thread stack. At this point, each thread can operate independently, enhancing the degree of modularity significantly.2 Concurrency From a concurrency perspective, when various threads use delay/event wait functions, they automatically yield the CPU to other threads that need it. This not only reduces the burden of writing delay functions but also improves overall CPU utilization, ultimately enhancing concurrency.3 Real-time Performance Regarding real-time performance, RTOS like ucos/RT-Thread are designed as real-time operating systems, where each thread has different priority levels. Important threads can be set to high priority, while less important threads can have lower priority. After proper global planning, the real-time performance of the entire software can be guaranteed.4 Development Efficiency Since operating systems provide a unified abstract interface layer, they facilitate the accumulation of reusable components, thereby improving development efficiency.Operating systems are the result of the wisdom of many software experts. They encapsulate and abstract many common software functionalities from the perspective of application software and low-level driver development, such as: semaphores, event notifications, mailboxes, circular buffers, singly/doubly linked lists, etc. These functionalities are ready to use, making it very convenient for developers. Additionally, some operating systems, such as Linux and our domestic RT-Thread, have unified encapsulated a standard hardware operation interface for fragmented hardware, generally referred to as device driver frameworks. This allows our application software engineers to focus on application work without worrying about changing hardware and having to reinvent the wheel.What Are the Advantages of RTOS in Embedded Development?Common RTOS Comparisons ucos/freertos/RT-Thread, the reason for choosing these three OS is that they have been around for a long time, are well-known in the market, and have been used by many people, making them more persuasive. It is worth mentioning that FreeRTOS is available in the CubeMX tool, which supports very convenient:using STM32CubeMx tool to write FreeRTOS demo programs. If you are developing with STM32, FreeRTOS is basically the first choice for entry-level RTOS.

What Are the Advantages of RTOS in Embedded Development?

1 Basic Functions and Performance The differences among various RTOS are minimal, and comparability is not very significant.2 Usability/Readability In this regard, FreeRTOS is arguably the worst, with its peculiar Hungarian naming convention and heavy use of macros, making it very difficult to read. ucos has decent readability with comprehensive comments. RT-Thread excels in this area, featuring a Linux-like code style and object-oriented design patterns, with clean and understandable code. It maintains a small footprint (minimum ROM: 3K RAM: 1.5K) while also borrowing features from Linux such as device driver frameworks, virtual file systems, and shells, resulting in a more elegant design.3 Component Richness Compared to traditional UCOS and FreeRTOS, RT-Thread not only has more comprehensive basic functions but also boasts over 50 reusable software components, along with many IoT components, making it almost plug-and-play for IoT products. RT-Thread can also run scripts in high-level languages like Python, Java, and Lua, further reducing development difficulty.4 Development Resources In this area, ucos performs the best, with accompanying books available. FreeRTOS is a newcomer with a lot of related resources available online. RT-Thread was previously somewhat lacking in this regard, but now it is placing great emphasis on this area, as evidenced by the increasing number of application notes on its official website, along with accompanying instructional videos.5 Copyright ucos requires a fee for commercial use, while FreeRTOS and RT-Thread have more lenient licensing, especially RT-Thread, which has recently adopted the Apache license.6 Community Ecosystem The communities for these three RTOS are quite active. It can be felt that the number of users for ucos is gradually decreasing, while the number of users for RT-Thread and FreeRTOS is increasing. RT-Thread is also the most widely used domestic RTOS among developers and has the largest embedded open-source software community in the country.

Leave a Comment