Five embedded operating systems for STM32
Based on the STM platform and meeting the real-time control requirements of the operating system, there are five options available for porting. They are μClinux, μC/OS-II, eCos, FreeRTOS and Dujiangyan operating system (djyos). The following describes the features and deficiencies of these five embedded operating systems.
μClinux is an excellent embedded Linux version, which is called micro-control Linux. It 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 network functions, excellent file system support, and a standard rich API. And TCP/IP network protocols, etc. Because there is no MMU memory management unit, its multitasking implementation requires some skill.
μClinux inherits the standard multi-tasking implementation of Linux, which is divided into real-time process and common process. It adopts first-come first-served service and time-slice rotation scheduling respectively. It only improves the characteristics of low-end embedded CPU, and does not support kernel preemption. , real-time general.
In memory management, since μClinux is designed for processors without MMU, the virtual memory management technology of the processor cannot be used, and only the real memory management strategy can be adopted. The system uses the paged memory allocation method to page the actual memory at startup. The system's access to memory is straightforward. The operating system has no protection for memory space. Multiple processes can share a single running space. Therefore, even an unprivileged process calling an invalid pointer triggers an address error and may cause a program. Crash or even crash the system.
The interrupt management of the μClinux operating system divides the interrupt processing into two parts: top half processing and bottom half processing. In the top half of the process, the interrupt must be shut down, and only the necessary, very few, and fast processing is performed, and the other processing is handed to the bottom half of the processing; the bottom half of the processing performs those complicated, time consuming processing, and accepts the interrupt. Because there are many bottom half processing of interrupts in the system, it will cause delays in system interrupt processing.
μClinux supports the file system well. Since μClinux inherits the perfect file system performance of Linux, it supports ROMFS, NFS, ext2, MS-DOS, JFFS and other file systems. However, the ROMFS file system is generally used. This file system takes up less space than a normal file system (such as ext2). However, the ROMFS file system does not support dynamic erasing and saving. For the system to dynamically save the data, it must be processed by the virtual RAM disk/JFFS method.
In terms of hardware support, since μClinux inherits most of the performance of Linux, it requires at least 512KB of RAM space and 1MB of ROM/Flash space.
In the porting of μClinux, μClinux is an improvement of Linux for embedded systems, and its structure is more complicated. To port μClinux, the target processor needs to have enough external ROM and RAM in addition to the processor-related code.
In summary, the biggest feature of μClinux is that it is designed for MMU-free processors. This is suitable for stm32f103 without MMU function, but porting this system requires at least 512KB of RAM space, 1MB of ROM/FLASH space, and stmf103 has 256K. FLASH requires external storage, which increases the cost of hardware design. μClinux is complex in structure, relatively difficult to port, and has a large kernel. Its real-time performance is also poor. If the embedded products developed are focused on file systems and network applications, μClinux is a good choice.
2, μC / OS-II
μC/OS-II is developed on the basis of μC/OS. It is a compact and preemptive multitasking real-time kernel written in C language. μC/OS-II can manage 64 tasks and provide functions such as task scheduling and management, memory management, task synchronization and communication, time management and interrupt service. It has high execution efficiency, small footprint, real-time performance and scalability. Strong and so on.
For real-time satisfaction, since the μC/OS-II core is designed and implemented for real-time system requirements, it only supports fixed-priority preemptive scheduling; the scheduling method is simple and can meet high real-time requirements.
In memory management, μC/OS-II manages continuous large blocks of memory by partition. Each partition contains an integer number of memory blocks of the same size, but the size of memory between different partitions can be different. When the user dynamically allocates memory, it is only necessary to select an appropriate partition, allocate memory by block, and put the block back to the previously owned partition when released, thus eliminating the fragmentation problem caused by multiple dynamic allocation and release of memory. .
The μC/OS-II interrupt processing is relatively simple. Only one interrupt service subroutine ISR can be attached to an interrupt vector, and the user code must be completed in the ISR (Interrupt Service Routine).
The more things ISR needs to do, the longer the interrupt latency will be.
The maximum nesting depth that the kernel can support is 255.
In terms of file system support, since μC/OS-II is for small and medium-sized embedded systems, even if it contains all the functions, the compiled kernel is less than 10 KB, so the system itself does not provide support for the file system. However, μC/OS-II has good scalability and can be added to the contents of the file system if necessary.
In terms of hardware support, μC/OS-II can support most of the currently popular CPUs. μC/OS-II is very small due to its own kernel. The minimum size of the clipped code can be 2KB, and the minimum required data RAM space. For 4 KB, the porting of μC/OS-II is relatively simple, and only the code associated with the processor needs to be modified.
In summary, μC/OS-II is an embedded operating system kernel with simple structure, complete functions and real-time performance. It is very suitable for CPUs without MMU function. It requires very little kernel code space and data storage space, has good real-time performance, good scalability, and is open source. There are a lot of data and examples on the Internet, so it is suitable for porting to stm32f103 CPU.
eCos (embedded Configurable operating system), which is an embedded configurable operating system. It is a configurable, portable, real-time operating system for deep embedded applications with open source code. The biggest feature is flexible configuration, modular design, the core part is composed of small components, including the kernel, C language library and the underlying running package. Each component provides a large number of configuration options (the real-time kernel is also available as an optional configuration), which can be easily configured using the configuration tools provided by eCos and enables eCos to meet different embedded application requirements through different configurations.
In real time, due to the rich eCos scheduling method, two priority-based schedulers (ie, bitmap scheduler and multi-level queue scheduler) are provided, which allows the user to select one of the schedulers when configuring, and the adaptability is good. Therefore, it performs well in terms of real-time performance.
In memory management, eCos allocates neither memory nor paging, but uses a dynamic memory allocation mechanism based on memory pool. Two memory management methods are implemented through two memory pools: one is a variable-length memory pool; the other is a fixed-length memory pool, similar to the VxWorks management scheme.
In interrupt management, eCos uses a layered interrupt handling mechanism to divide interrupt processing into traditional ISR (interrupt service routine) and lazy interrupt service routine DSR (deferred service program). Similar to μClinux's processing mechanism, this mechanism can run DSR when interrupts are enabled, thus allowing high priority interrupts and processing when dealing with lower priority interrupts. In order to greatly reduce the interrupt latency, the ISR should be able to run quickly. If the amount of service caused by the interrupt is small, the ISR can handle the interrupt separately; if the interrupt service is complex, the ISR only masks the interrupt source and then hands it over to the DSR (Deferred Service Program).
The eCos operating system is very configurable, and users can join the required file system by themselves. The eCos operating system also supports most popular embedded CPUs. The eCos operating system can be ported between 16-bit, 32-bit and 64-bit architectures. The eCos is small because of its own kernel. The clipped code can be as small as 10 KB and the minimum required data RAM is 10 KB.
In terms of system migration, the eCos operating system is very portable and easier than μC/OS-II and μClinux.
In summary, eCos is characterized by flexible configuration and support for MMU-free CPU migration, open source and good portability, and is more suitable for porting to the CPU of the stm32 platform. However, the application of eCOS is not too extensive, it is not as common as μC/OS-II, and the data is not as much as μC/OS-II. eCos are suitable for some commercial or industrial cost-sensitive embedded systems, such as some applications in the consumer electronics arena.
Since RTOS needs to occupy certain system resources (especially RAM resources), only a few real-time operating systems such as μC/OS-II, embOS, salvo, and FreeRTOS can run on small RAM microcontrollers. Compared with commercial operating systems such as C/OS-II and embOS, FreeRTOS operating system is a completely free operating system with open source, portable, scalable, and flexible scheduling strategy, which can be easily ported to various microcontrollers. The latest version is version 6.0.
As a lightweight operating system, FreeRTOS provides functions such as task management, time management, semaphores, message queues, memory management, and logging functions to meet the needs of smaller systems. The FreeRTOS kernel supports a priority scheduling algorithm. Each task can be given a certain priority according to the degree of importance. The CPU always runs the task with the highest priority in the ready state. The FreeRT0S kernel supports the rotation scheduling algorithm at the same time. The system allows different tasks to use the same priority. When no higher priority tasks are ready, the same priority tasks share the CPU usage time.
The FreeRTOS kernel can be set to a deprived kernel or an inelastic core depending on user needs. When FreeRTOS is set to a deprivable kernel, the high-priority task in the ready state can deprive the CPU of low-priority tasks, thus ensuring that the system meets real-time requirements; when FreeRTOS is set to an inelastic core The high-priority task in the ready state can only be run after the current running task actively releases the usage right of the CPU, which can improve the operating efficiency of the CPU.
Migration of FreeRTOS:
The FreeRTOS operating system can be easily ported to different processors and has been ported with ARM, MSP430, AVR, PIC, C8051F and many other processors. The migration of FrceRTOS on different processors is similar to μC/OS-II, so the migration of FreeRTOS is not detailed in this article. In addition, the TCP/IP protocol stack μIP has been ported to FreeRTOS. The specific code can be found on the FreeRTOS website.
Compared to the common μC/OS-II operating system, the FreeRTOS operating system has both advantages and disadvantages. The shortcomings, on the one hand, are reflected in the service functions of the system. For example, FreeRTOS only provides the implementation of message queues and semaphores, and cannot send messages to the message queue in the order of first in, first out; on the other hand, FreeRTOS is only an operating system. The kernel needs to extend the third-party GUI (graphical user interface), TCP/IP protocol stack, FS (file system), etc. to implement a more complex system, unlike μC/OS-II and μC/GUI, μC/. Seamless integration of FS, μC/TCP-IP, etc.
5, Dujiangyan operating system (djyos)
Dujiangyan operating system, referred to as djyos, is named after a great water conservancy project: Dujiangyan.
Unlike traditional operating systems, djyos is not a thread but an event-based scheduling core. This scheduling algorithm frees the programmer from the way of thinking about simulating the computer's execution process, but writing the application in the way of human cognitive world. As VC is introduced in embedded programming. Djyos' scheduling algorithm allows programmers to get rid of the constraints of threads and processes. DJyos has no API apis, and a programmer who doesn't know thread knowledge can write applications under djyos smoothly.
The djyos operating system is scheduled with events as the core. This scheduling strategy allows programmers to program according to the habits of human cognitive things rather than computer habits.
In a normal operating system, scheduling is thread-centric, and the event is treated as thread data, which is advertised as an "event-triggered" software model. It is also queued by the thread. When a specific event occurs, the thread resumes running and treats it as Enter the data for processing.
Event-centric scheduling, like the device and memory, treats the thread virtual machine as the resource needed to process the event. When an event needs to be processed, allocate or create a thread virtual machine to the event, and start the thread virtual. Machine processing events.
The djysiV0.4.2 release, added support for the stm32 version, can be ported to cortex-m3 (the chip is stm32f103). This system is suitable for industrial control. The system source code is open, but not always free.
From the above, for the stm32f103, it is suitable to transplant the μC/OS-II, eCos, FreeRTOS, and Dujiangyan operating systems.