Teach you to learn to build FreeRTOS project files

1. Preamble

First of all, we can go to FreeRTOS official download source package download link may be slow. We can also go to his code hosting website website link Here I downloaded the v9.00 version.
Here is a small tip : No matter what you download, the version should be neither the latest nor too old. The latest version is unstable and has less information, and the old version is outdated and may lack some functions compared to the new version.

2. Extract files

After the download is complete, we enter this folder. This is also the only folder we need.
insert image description here

2.1 Source folder

In the FreeRTOS/Source directory, there are include folders and some .c files, which contain FreeRTOS common header files and C files. Applies to various compilers and processors and is generic. What needs to be cropped and ported is the portblle folder.

2.2 portble folder

This folder is the file related to the compiler, and different support files are used in different editors. We use Keil to compile, and we found it when we opened the folder. There is only one .txt file. The file name says See-also-the-RVDS-directory
so the folder we need is RVDS, and we also need the folder MemMang. This folder is for memory management.
There are 5 heap files under MemMang, each with its own differences (we choose heap4.c here). The differences will be described later.
insert image description here

2.3 Demo folder

The contents of this directory are Deme routines. We can directly open the project files and complete demos of various development platforms. Developers can easily build their own projects or even use them directly. Of course, FreeRTOS has also written a lot of demos for ST, including F1, F4, F7 and other projects. This is very convenient for us to learn FreeRTOS. When you encounter something you don't understand, you can directly refer to the official demo.
insert image description here

3. Establish FreeRTOS project

This is one of my bare metal project directories.
insert image description here

3.1 Create a new FreeRTOS directory

This example is based on a bare metal project to build FreeRTOS. We first create a new folder under the root directory of the bare metal, named "FreeRTOS", and create two empty folders under the FreeRTOS folder. Name "src" and "port" respectively, the core source files in FreeRTOS are saved in the src folder, that is, the .c file, and the memory management and processor architecture-related codes are saved under the port. These codes have been officially provided by FreeRTOS to us, and you can use them directly. As I said earlier, FreeRTOS is software, and our development version is hardware. There must be a bridge to connect the software and hardware. These codes related to the processor architecture can be Called the RTOS hardware interface layer, they are located in the FreeRTOS/Source/Portable folder.
insert image description here

3.2 Migrating the src folder

We have created the src folder before, now open the FreeRTOS V9.0.0 source code, find
all the '.c files' in the "FreeRTOSv9.0.0\FreeRTOS\Source" directory, and copy them to our newly created src folder , copy as shown in the figure

insert image description here

3.3 Migrate the port folder

Open the FreeRTOS V9.0.0 source code, find the "MemMang" folder and "RVDS" folder in the "FreeRTOSv9.0.0\FreeRTOS\Source\portable" directory, and copy them to our newly created port folder, as shown in the figure
insert image description here

3.4 Add include folder

Open the FreeRTOS V9.0.0 source code, find the "include" folder in the "FreeRTOSv9.0.0\ FreeRTOS\Source" directory, it is some header files we need to use FreeRTOS, copy it directly to our newly created FreeRTOS folder as the picture shows:

insert image description here

3.5 Extract the FreeRTOSConfig.h file

3.5.1 Copy the FreeRTOSConfig.h file

Open the FreeRTOSv9.0.0 source code, find the "CORTEX_STM32F103_Keil" folder under the "FreeRTOSv9.0.0\FreeRTOS\Demo" folder
, double-click to open it, find the "FreeRTOSConfig.h" file in its root directory
, and copy it to our project user folder, we need to modify this file later. (The blogger here also provides a modified FreeRTOSConfig.h file, which can be downloaded for free in the blogger’s resources. )
You can refer to the blogger’s blog FreeRTOSConfig.h file explanation
insert image description here

4. Add the content of FreeRTOS to the project

4.1 Operation Guide

First click on this group.
insert image description here
After coming to this interface, you can add groups, as shown in the figure.
insert image description here

4.2 Add source files

Here we added FreeRTOS/src and FreeRTOS/port corresponding to the two folders in our project directory, and then added the corresponding .c file. Note: here we choose the heap_4.c under the MemMang file for FreeRTOS/port And the port.c under ARM_CM3 under the RVDS file (because I use the STM32F103 series chip).
![Insert picture description here](https://img-blog.csdnimg.cn/bb382053d9f7433b8cd0986d6fc6bdc8.png
Just add all the .c files under FreeRTOS/src.

insert image description here

4.3 Add FreeRTOSConfig.h header file

Add the FreeRTOSConfig.h file to the user directory (of course, you can apply your own project file, and each project structure may be different)
insert image description here

4.4 Specify header file path

The source code of FreeRTOS has been added under the group folder of the development environment. When compiling, you need to specify the path of the header file for these source files, otherwise the compilation will report an error. In the source code of FreeRTOS, there are only header files under the two folders of FreeRTOS\include and FreeRTOS\port\RVDS\ARM_CM3. You only need to specify the paths of these two header files in the development environment. At the same time, we also copied the header file FreeRTOSConfig.h to the user folder under the root directory of the project, so the user path should also be added to the development environment. The process is as follows

insert image description here
insert image description here

Five. Modify the stm32f10x_it.c file

Delete these two interrupt functions PendSV_Handler and SVC_Handler in stm32f10x_it.h . Because these two interrupt functions have been written in port.c. At the same time, add the following code in stm32f10x_it.c, and modify the SysTick_Handler interrupt service function. As shown below:

extern void xPortSysTickHandler(void);
void SysTick_Handler(void)
{
    
    
    
       #if (INCLUDE_xTaskGetSchedulerState  == 1 )
      if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
      {
    
    
    #endif  /* INCLUDE_xTaskGetSchedulerState */  
        xPortSysTickHandler();
    #if (INCLUDE_xTaskGetSchedulerState  == 1 )
      }
    #endif  /* INCLUDE_xTaskGetSchedulerState */
}

insert image description here

6. Conclusion

The whole project of building FreeRTOS is over here, and the whole structure is relatively clear. There is also a FreeRTOSConfig.h file that has not been explained yet. There will be a dedicated article in the future! Pay more attention! Thank you for your support!

Guess you like

Origin blog.csdn.net/qq_62553914/article/details/131280236