Technology often updates very quickly, and it always makes us feel that learning is difficult and somewhat confusing. However, it’s okay; we enthusiasts focus on learning with joy. To learn about STM32, we first need to understand the five major embedded operating systems: μClinux, μC/OS-II, eCos, FreeRTOS, and RT-thread.
μClinux
μClinux is an excellent version of embedded Linux, literally meaning microcontroller Linux. Compared to standard Linux, μClinux has a very small kernel, but it still inherits the main characteristics of the Linux operating system, including good stability and portability, powerful networking capabilities, excellent file system support, a rich set of standard APIs, and TCP/IP network protocols.
The interrupt management of the μClinux operating system divides interrupt handling into two parts: top half processing and bottom half processing. In top half processing, interrupts must be disabled, and only necessary, very few, and fast processing is done; other processing is handed over to the bottom half processing; the bottom half processing executes those complex and time-consuming processes and can accept interrupts. Because there are many bottom half processes in the system, it can cause delays in interrupt handling.
μClinux has good support for file systems, as it inherits the excellent file system performance of Linux, supporting ROMFS, NFS, ext2, MS-DOS, JFFS, and other file systems.
The biggest feature of μClinux is its design for processors without MMU, which is suitable for the STM32F103 that lacks MMU functionality, but porting this system requires at least 512KB of RAM and 1MB of ROM/FLASH space. The STM32F103 has 256K of FLASH and requires external memory, which increases the cost of hardware design.
μClinux has a complex structure, is relatively difficult to port, has a larger kernel, and its real-time performance is not as good. If the embedded product being developed focuses on file systems and network applications, μClinux is a good choice.
μC/OS-II
μC/OS-II is developed based on μC/OS and is a compact, 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.
Regarding real-time performance, since the μC/OS-II kernel is designed to meet the requirements of real-time systems, it only supports fixed-priority preemptive scheduling; the scheduling method is simple and can meet high real-time performance requirements.
The interrupt handling in μC/OS-II is relatively simple. An interrupt vector can only hang one interrupt service routine (ISR), and all user code must be completed in the ISR. The more tasks the ISR needs to perform, the longer the interrupt delay; the maximum nesting depth supported by the kernel is 255.
μC/OS-II is a simple-structured, fully functional, and highly real-time embedded operating system kernel, which is very suitable for CPUs without MMU functionality. It requires very little kernel code space and data storage space, has good real-time performance, good scalability, and is open-source, with many resources and examples available online, making it very suitable for porting to the STM32F103 CPU.
eCos
eCos, which stands for Embedded Configurable Operating System, is a source code open, configurable, portable real-time operating system aimed at deeply embedded applications. Its biggest feature is flexible configuration, using a modular design, where the core part consists of small components, including the kernel, C language library, and low-level runtime packages. Each component can provide a large number of configuration options (the real-time kernel can also be an optional configuration), and using the configuration tools provided by eCos, it can be easily configured to meet different embedded application requirements.
The configurability of the eCos operating system is very powerful, allowing users to add the required file systems. The eCos operating system also supports most currently popular embedded CPUs and can be ported between different architectures such as 16-bit, 32-bit, and 64-bit. Due to its small kernel size, the minimum code after trimming can be as small as 10 KB, and the minimum required data RAM space is 10 KB.
In terms of system portability, the eCos operating system is much better than μC/OS-II and μClinux.
The biggest feature of eCos is flexible configuration and support for porting to CPUs without MMU, is open-source, and has good portability, making it quite suitable for porting to CPUs on the STM32 platform. However, the application of eCos is not very widespread yet and is not as common as μC/OS-II, and there is not as much documentation available as for μC/OS-II. eCos is suitable for some commercially or industrially sensitive embedded systems, such as applications in the consumer electronics field.
FreeRTOS
Since RTOS requires certain system resources (especially RAM resources), 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, portability, configurability, 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 functions 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 priority scheduling algorithms, allowing each task to be assigned a priority based on its importance, with the CPU always running the highest priority task in the ready state first.FreeRT0S kernel also supports round-robin scheduling algorithms, allowing different tasks to share CPU time when there are no higher priority tasks ready.
Compared to the commonly used μC/OS-II operating system, FreeRTOS has both advantages and disadvantages. Its disadvantages are partly reflected in the system service functions, as FreeRTOS only implements message queues and semaphores and cannot send messages to the message queue in a last-in-first-out order.
On the other hand, FreeRTOS is just an operating system kernel and requires additional third-party GUI (Graphical User Interface), TCP/IP protocol 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.
RT-thread
RT-Thread is an open-source real-time operating system primarily developed by the Chinese open-source community (license GPLv2). The real-time thread operating system is not just a single real-time operating system kernel; it is also a complete application system that includes various components related to real-time and embedded systems: TCP/IP protocol stack, file system, libc interface, graphical user interface, etc.