SoFunction
Updated on 2025-04-09

FreeRTOS real-time operating system structure example

FreeRTOS can be ported to many processors and compilers of different architectures. Each RTOS port comes with a configured sample program, which can facilitate and quickly start development. Even better, each show sample is accompanied by an explanation webpage, providing all information on how to locate the RTOS demonstration project source code, how to compile the show sample program, and how to configure the hardware platform.

The sample program description web page also provides basic RTOS porting details, including how to write FreeRTOS-compatible interrupt service routines. The interrupt handling of different architectures will be slightly different.

With the simple instructions below, RTOS can be run in minutes.

1. Find relevant document pages

FreeRTOS has detailed development instructions that can be viewed on its official website. First, open the official website, the current website address is:. In the navigation bar on the left side of the home page, expand the "Supported Devices & Demos" menu item, click the "OfficiallySupported Demos" link to view the list of microcontroller manufacturers supported by FreeRTOS. Click the microcontroller manufacturer name to enter the specific manufacturer documentation page list.

2. Obtain the RTOS source code

Go to the official FreeRTOS website to download the source code. The download package includes the RTOS kernel source code and the official porting demonstration project. Decompress and place it in the appropriate directory. (If you don't want to visit slow foreign websites, I made a mirror in CSDN, you can click here. This article has the latest download links for most of the FreeRTOS source code packages)

Each RTOS migration package comes with a pre-configured sample program. All necessary RTOS source files have been created and included the required RTOS header files. It is recommended to program your own FreeRTOS application based on the provided performance sample program.

Source code directory structure

The FreeRTOS download package contains the source code for each processor migration and performance sample program. Putting all ported packages into one download file greatly simplifies classification processing, but the number of files in the download package is also amazing! In any case, the directory structure is still very simple, and the FreeRTOS real-time kernel only has 3 files (and some additional files if needed, such as software timers, event groups, and coroutines).

The download package directory contains two subdirectories: FreeRTOS and FreeRTOS-Plus.

FreeRTOS-Plus         Contains FreeRTOS+ components and performance sample programs;
FreeRTOS                           Contains FreeRTOS real-time kernel source files and sample programs.

The FreeRTOS-Plus directory tree contains multiple readme files (Readme). Next, this article only describes the core source files and sample programs of the FreeRTOS kernel, which are divided into two main subdirectories, as shown below:

    FreeRTOS
|+-- Demo     Includes sample program projects;
|+-- Source   Contains real-time kernel source files.

The core of RTOS code is contained in three files: , , . These three files are located in the FreeRTOS/Source directory. This directory also contains three optional files: event_groups.c, which implements software timing, event grouping and coroutine functions respectively.

The FreeRTOS/Source directory structure is as follows:

    FreeRTOS
| +-- Source  FreeRTOS kernel code file
|   |+-- include             FreeRTOS kernel header file
|   |+-- Portable         Processor-specific code
|  |+--Compiler x     All ported packages that support compiler x
|  |+--Compiler y     All ported packages that support compiler y
|  |+--MemMang         Memory heap implementation example

Each supported processor architecture requires a small piece of RTOS code related to the processor architecture. This is the RTOS porting layer, which is located in the FreeRTOS/Source/Portable/[Relevant Compiler]/[Relevant CPU Architecture] subdirectory.

For FreeRTOS, stack design also belongs to the porting layer. The heap_x.c file in the FreeRTOS/Source/portable/MemMang directory provides a variety of stack solutions, and subsequent articles will introduce stack operations in detail.

Examples of the transplant layer directory:

If using TriCore1782 under the GCC compiler: TriCore specific file() is located in the FreeRTOS/Source/Portable/GCC/TriCore_1782 directory. All files in the FreeRTOS/Source/Portable subdirectory can be ignored or deleted except for the FreeRTOS/Source/Portable/MemMang directory.

If using Renesas RX600 under the IAR compiler: RX600 specific file() is located in the FreeRTOS/Source/Portable/IAR/RX600 directory. All files in the FreeRTOS/Source/Portable subdirectory can be ignored or deleted except for the FreeRTOS/Source/Portable/MemMang directory.

The FreeRTOS download package also contains sample programs for various processor architectures and compilers. Most of the sample program code is common to all ports and is located in the FreeRTOS/Demo/Common/Minimal directory. The FreeRTOS/Demo/Common/Full directory is historical code, which is only used for PC.

The FreeRTOS/Demo directory structure is as follows:

    FreeRTOS
      |+-- Demo
|  |+-- Common         Sample program file that can be used by all routines
|  |+-- Dir x             Sample project file for x platform
|  |+-- Dir y             Sample program project file for y platform

The remaining subdirectories under the FreeRTOS/Demo directory contain pre-configured projects that can be used to build personal performance examples. The naming of subdirectories is related to the porting platform and compiler. Each RTOS migration package has its own documentation.

Examples of the performance directory:

If you build TriCoreGCC program with Infineon TriBoard development board hardware: TriCore sample program project file is located in FreeRTOS/Demo/TriCore_TC1782_TriBoard_GCC directory. All subdirectories (except Common directories) under the directory FreeRTOS/Demo can be ignored or deleted.

If you build Renesas RX600 IAR performance example program with RX62N hardware: The IAR project file is located in the FreeRTOS/Demo/RX600_RX62N-RDK_IAR directory. All subdirectories (except Common directories) under the directory FreeRTOS/Demo can be ignored or deleted.

4. Compile project

Open and compile the demo project according to the location of the RTOS demonstration project described in the previous section, as described in the FreeRTOS source code directory structure.

5. Run the sample program

The description page that comes with the show sample program will explain how to configure the hardware, download the program, and execute the show sample program. The description page will also provide functional information for the show sample program, so you can determine whether the show sample program is executed correctly.

The above is the detailed content of the FreeRTOS real-time operating system structure example. For more information about FreeRTOS real-time operating system, please follow my other related articles!