Five Embedded Operating Systems You Must Know for Learning STM32

Five Embedded Operating Systems You Must Know for Learning STM32

Good news: New Year sale! The 2017 collection of “Microcontroller and Embedded System Applications” electronic journals is only 29.9! Welcome to the Embedded Fan Mall to purchase~

There are five operating systems based on the STM platform that meet real-time control requirements available for porting: μClinux, μC/OS-II, eCos, FreeRTOS, and RT-Thread. Below, we will introduce the characteristics and shortcomings of these five embedded operating systems, allowing readers to choose the appropriate platform based on their application needs.

TOP1: μClinux

μClinux is an excellent embedded version of Linux, formally known as micro-control Linux, which literally means micro-control Linux. Compared to standard Linux, μClinux has a very small kernel, but it still inherits the main features of the Linux operating system, including good stability and portability, powerful networking capabilities, excellent file system support, a rich standard API, and TCP/IP network protocols. Because it lacks an MMU (Memory Management Unit), its multitasking implementation requires certain techniques.

Structurally, μClinux inherits the multitasking implementation of standard Linux, dividing processes into real-time processes and ordinary processes, using first-come-first-served and time-slice rotation scheduling, respectively, and is improved specifically for the characteristics of mid-range embedded CPUs, without supporting kernel preemption, resulting in average real-time performance.

In memory management, since μClinux is designed for processors without an MMU, it cannot use the processor’s virtual memory management technology and can only adopt physical memory management strategies. The system uses paged memory allocation, paging the actual memory at startup. Memory access is direct, with no protection of memory space by the operating system, allowing multiple processes to share a running space, so even a non-privileged process calling an invalid pointer can trigger an address error, potentially leading to program crashes or even system crashes.

μClinux’s interrupt management divides interrupt handling into two parts: top-half processing and bottom-half processing. In top-half processing, interrupts must be disabled, and only necessary, minimal, fast processing is performed, while other processing is delegated to bottom-half processing; bottom-half processing executes complex, time-consuming tasks and accepts interrupts. The existence of many bottom-half processing tasks can lead to delays in system interrupt handling.

μClinux has good file system support; it inherits Linux’s excellent file system performance, supporting ROMFS, NFS, ext2, MS-DOS, JFFS, etc. However, it generally uses the ROMFS file system, which occupies less space than typical file systems (like ext2). However, the ROMFS file system does not support dynamic erase and save, so dynamically saved data must use virtual RAM disk/JFFS methods.

In terms of hardware support, μClinux inherits most of Linux’s capabilities, requiring at least 512KB of RAM space and 1MB of ROM/Flash space.

Regarding the porting of μClinux, it is a modification of Linux for embedded systems, and its structure is relatively complex. To port μClinux, the target processor needs to modify processor-related code and have sufficient external ROM and RAM capacity.

Review: The main feature of μClinux is its design for processors without MMUs, which is suitable for the STM32F103 that lacks MMU functionality. However, porting this system requires at least 512KB of RAM space and 1MB of ROM/FLASH space, while the STM32F103 has 256K of FLASH, necessitating external memory, increasing hardware design costs. μClinux has a complex structure, making it relatively difficult to port, and its kernel is larger, with average real-time performance. If the developed embedded product emphasizes file systems and network applications, μClinux is a good choice.

TOP2: μC/OS-II

μC/OS-II is developed based on μC/OS and is a small, preemptive multitasking real-time kernel written in C. μC/OS-II can manage 64 tasks and provides task scheduling and management, memory management, inter-task synchronization and communication, time management, and interrupt service functions, featuring high execution efficiency, small footprint, excellent real-time performance, and strong scalability.

To meet real-time requirements, μC/OS-II’s kernel is designed specifically for real-time systems, supporting only fixed-priority preemptive scheduling; the scheduling method is simple and can meet high real-time requirements.

In memory management, μC/OS-II manages large contiguous memory blocks by partitioning, with each partition containing an integer number of equally sized memory blocks, while the sizes of different partitions can vary. When users dynamically allocate memory, they only need to choose an appropriate partition and allocate memory by block, returning the block to its original partition upon release, eliminating fragmentation issues caused by multiple dynamic memory allocations and releases.

μC/OS-II’s interrupt handling is relatively simple. An interrupt vector can only have one interrupt service routine (ISR) attached, and user code must be completed in the ISR. The more tasks an ISR needs to perform, the longer the interrupt delay, with the maximum nesting depth supported by the kernel being 255.

In terms of file system support, μC/OS-II is aimed at small to medium-sized embedded systems, and even with full functionality, the compiled kernel is less than 10 KB, so the system itself does not provide file system support. However, μC/OS-II has good extensibility, allowing users to add file system content as needed.

μC/OS-II can support most of the currently popular CPUs, with a small kernel size, and the minimum trimmed code can be as small as 2KB, requiring a minimum data RAM space of 4KB. Porting μC/OS-II is relatively simple, requiring only modifications to processor-related code.

Review: μC/OS-II is a simple structure, fully functional, and highly real-time embedded operating system kernel, very suitable for CPUs without MMUs. It requires minimal kernel code space and data storage space, possesses excellent real-time performance and scalability, is open-source, and has abundant online resources and examples, making it ideal for porting to the STM32F103 CPU.

TOP3: eCos

eCos (embedded Configurable operating system) is an open-source, configurable, portable real-time operating system aimed at deeply embedded applications. Its main feature is flexible configuration, utilizing a modular design, with core components including the kernel, C library, and low-level runtime packages. Each component offers numerous configuration options (the real-time kernel can also be a selectable configuration), allowing for easy configuration using eCos’s configuration tools, thus meeting different embedded application requirements.

Regarding real-time performance, eCos provides rich scheduling methods, offering two priority-based schedulers (bitmap scheduler and multi-level queue scheduler), allowing users to select one during configuration, providing good adaptability. Therefore, it performs well in real-time aspects.

In memory management, eCos does not segment or page memory allocation but uses a dynamic memory allocation mechanism based on memory pools. Two types of memory pools implement two memory management methods: one is a variable-length memory pool; the other is a fixed-length memory pool, similar to VxWorks’ management scheme.

For interrupt management, eCos employs a layered interrupt handling mechanism, dividing interrupt handling into traditional ISR (interrupt service routine) and deferred service routine (DSR). Similar to μClinux’s handling mechanism, this mechanism allows DSR to run when interrupts are enabled, permitting high-priority interrupts and handling while processing lower-priority interrupts. To significantly reduce interrupt delays, ISRs should run quickly. If the service amount caused by an interrupt is small, the ISR can handle the interrupt individually; if the interrupt service is complex, the ISR only masks the interrupt source and hands it over to the DSR for processing.

The configurability of the eCos operating system is very powerful, allowing users to add the required file systems. eCos also supports most of the currently popular embedded CPUs and can be ported across different architectures such as 16-bit, 32-bit, and 64-bit. Due to its small kernel size, the minimum trimmed code can be as small as 10 KB, requiring a minimum data RAM space of 10 KB.

In terms of system porting, eCos has good portability, easier than μC/OS-II and μClinux.

Review: The main feature of eCos is its flexible configuration, supporting porting to CPUs without MMUs, being open-source and highly portable, making it suitable for porting to STM32 platform CPUs. However, eCos’s applications are not very widespread compared to μC/OS-II, and there is less documentation available than for μC/OS-II. eCos is suitable for some commercially or industrially sensitive embedded systems, such as applications in the consumer electronics field.

TOP4: FreeRTOS

Since RTOS requires certain system resources (especially RAM), only a few real-time operating systems like μC/OS-II, embOS, salvo, and FreeRTOS can run on small RAM microcontrollers. Compared to commercial operating systems like μC/OS-II and embOS, FreeRTOS is a completely free operating system, featuring open-source code, portability, scalability, and flexible scheduling strategies, making it easy to port to various microcontrollers, with its latest version being 6.0.

As a lightweight operating system, FreeRTOS provides functionalities including task management, time management, semaphores, message queues, memory management, and logging, which can basically meet the needs of smaller systems. The FreeRTOS kernel supports a priority scheduling algorithm, allowing each task to be assigned a priority based on its importance, with the CPU always allowing the highest priority ready task to run first. FreeRTOS also supports round-robin scheduling, allowing different tasks to share CPU time when no higher priority tasks are ready.

The FreeRTOS kernel can be set as a preemptive or non-preemptive kernel based on user needs. When FreeRTOS is set as a preemptive kernel, ready high-priority tasks can preempt the CPU usage of low-priority tasks, ensuring that the system meets real-time requirements; when set as a non-preemptive kernel, ready high-priority tasks can only run after the currently running task voluntarily releases CPU usage, thus improving CPU operational efficiency.

Porting FreeRTOS: The FreeRTOS operating system can be easily ported to different processors, and ports for various processors like ARM, MSP430, AVR, PIC, C8051F, etc., have been provided. The porting of FreeRTOS on different processors is similar to that of μC/OS-II, so it will not be detailed here. Additionally, the TCP/IP stack μIP has been ported to FreeRTOS, with specific code available on the FreeRTOS website.

Review:: Compared to the common μC/OS-II operating system, FreeRTOS has both advantages and disadvantages. Its shortcomings are reflected in the system’s service functionalities; for example, FreeRTOS only provides message queue and semaphore implementations, lacking the ability to send messages to the message queue in a last-in-first-out order. On the other hand, FreeRTOS is just an operating system kernel, requiring external third-party GUI (Graphical User Interface), TCP/IP stack, FS (file system), etc., to implement a more complex system, unlike μC/OS-II, which can seamlessly integrate with μC/GUI, μC/FS, μC/TCP-IP, etc.

TOP5: RT-Thread

RT-Thread is an open-source real-time operating system primarily developed by the Chinese open-source community (GPLv2 license). The RT-Thread operating system is not just a single real-time operating system kernel; it is a complete application system that includes various components related to real-time and embedded systems: TCP/IP stack, file system, libc interface, graphical user interface, etc.

Developed by Chinese developers, the stable version is 1.2.1, with hopes of viewing the source code. It is streamlined, reliable, and comes with an onboard debugging tool called finsh, which is very practical. It has various threading cooperation functionalities such as semaphores, mutexes, mailboxes, events, etc.

It should be noted that the design philosophy of the RT-Thread 2.0 version is completely different from that of 1.2, which will incorporate Linux; that is, it is not embedding RT-Thread within Linux, but embedding Linux within RT-Thread!

Review: The documentation for RT-Thread is available on the official website, but it is really only for reference, clearly being a compilation of developers’ notes. Currently, it is still necessary to understand detailed usage methods by looking at the code, as it is difficult to reconstruct the truth from the fragments of documentation and forums. The advantage of RT-Thread is that its version is relatively small, allowing one to go through the source code even if documentation is lacking.

Five Embedded Operating Systems You Must Know for Learning STM32

1. The first issue of the 2018 “Microcontroller and Embedded System Applications” electronic journal is fresh out!

2. Eight development predictions for Linux in 2018, stating that Ubuntu will dominate the Internet of Things

3. The baud rate for serial communication of STM32 microcontrollers should be calculated this way~

4. How to choose the suitable MCU platform in embedded system development?

5. The top ten events in the Chinese semiconductor industry in 2017

6. The ten major development trends of open-source technology in 2018 | Linux China

Five Embedded Operating Systems You Must Know for Learning STM32

Disclaimer: This article is a network reprint, and the copyright belongs to the original author. If there are any copyright issues, please contact us, and we will confirm the copyright based on the copyright certificate you provide and pay remuneration or delete the content.

Leave a Comment

×