Typically, microcontrollers are developed in a bare-metal mode, where a single while loop runs indefinitely. However, when there are multiple tasks to manage that need to switch back and forth rather than executing in a serial mode, an operating system must be assigned to the microcontroller. Common operating systems used for microcontrollers include UCOS, RTX, RT-Thread, and FreeRTOS. This article introduces FreeRTOS, which translates to “Free Real-Time Operating System” in English. It is quite compact, much smaller than UCOS, and is free, having been successfully ported to various microcontrollers.
The operating system allows multiple tasks to run simultaneously. For single-core processors, a task scheduler completes the polling execution of tasks, and due to the fast switching speed, it creates the illusion that multiple tasks are executing at the same time.
Ways to learn FreeRTOS include visiting the official website www.freertos.org to learn from the guides, downloading the source code, and using it.
As for the advantages of FreeRTOS, let’s let the official explanation do the talking:
Supported processors and development environments
The core FreeRTOS kernel source files and demo projects are contained in two subdirectories:
FreeRTOS
|
+-Demo Contains demo examples.
|
+-Source Kernel source code.
The core RTOS code is contained in three files, named task.c, queue.c, and list.c. These three files are located in the FreeRTOS/Source directory. The same directory contains two optional files named timers.c and croutine.c, which implement software timers and coroutine functionality, respectively. Each supported processor architecture requires a small amount of architecture-specific RTOS code. This is the RTOS portable layer, located in the FreeRTOS/Source/Portable/[compiler]/[architecture] subdirectory, where [compiler] and [architecture] are the compiler used for creating the port and the architecture used for running the port.
FreeRTOS is designed to be simple and easy to use: it only requires three source files that are applicable to all RTOS ports and one microcontroller-specific source file, making its API design straightforward and intuitive.
FreeRTOS uses the FreeRTOSConfig.h configuration file for customization. Each FreeRTOS application must include the FreeRTOSConfig.h header file in its preprocessor include path. FreeRTOSConfig.h customizes the RTOS kernel for the application being built. Therefore, it is application-specific and not RTOS-specific, and should be located in the application directory, not in the RTOS kernel source code directory. Each demo application in the RTOS source code download has its own FreeRTOSConfig.h file.
To create a new project, see here
https://www.freertos.org/zh-cn-cmn-s/Creating-a-new-FreeRTOS-project.html
For configuration parameters, see here
https://www.freertos.org/zh-cn-cmn-s/a00110.html#kernel_priority
The screenshot below shows some parameters
For testing a demo, I used Keil to develop for STM32F103RCT6, so I will use the demo below
However, the demo uses Keil2, while I use Keil5, which is no big deal; switching development environments works just the same.
When porting to a new device, you can refer to the portable folder under source to find the corresponding device.
When creating a project, you need to copy port.c from RVDS and heap_4.c from MemMang into the project directory and add them to the project.
There were errors during compilation because some files provided by the official library conflict with the ST standard library; I will post the fixes later.
