Ⅰ
Introduction
To satisfy everyone’s curiosity, this article will describe several steps to get the FreeRTOS system running directly on the chip. Many details in the source code will be presented in the next article. A demo project that can be run directly will also be provided for everyone to modify and test conveniently.
Why not discuss the source code first?
Many friends probably start learning by looking at others’ well-written, ready-to-use source code. Based on correct code projects, we can conduct many tests to understand why it can run this way.
The content within the entire FreeRTOS project source code involves many aspects, and it only takes a few simple steps to get the code running and see the results. If I were to explain the source code line by line, I would probably lose everyone after just a few lines, and you wouldn’t know why things are done this way.
Therefore, showing you the well-written source code project, allowing you to test and analyze it yourself is the best approach.
Ⅱ
Steps to Port
The content in the source code has very little variation; this article will not detail it but will describe the few steps to port it, ultimately allowing the code project to run on the board. Only a few simple steps are needed:
1. Extract the source code and add it to the project
The previous article discussed the meaning of various directories and files in the FreeRTOS source code and briefly explained the need to extract the source code.
Mainly extract: Source directory + FreeRTOSConfig.h
(Some content inside is unused; I deleted it to avoid overwhelming everyone with too many files or clutter.)
Add this source code to your project (the STM32 project that was previously discussed and established). For specific extracted source code and the effect of adding it to the project, please download the code to check.
2. Add paths
When we add source code to the project, some header files need to be included, so we need to add the corresponding paths.
Methods for adding .c source code paths can be found in the articles:
1. MDK-ARM_New Software Project Detailed Process
2. EWARM_New Software Project Detailed Process
Here, I mainly want to remind you: in the IAR project, there is an assembly file portasm.s that includes <FreeRTOSConfig.h>, and we need to add the path where <FreeRTOSConfig.h> is located.
Note: This is done in EWARM’s Project -> Options -> Assembler -> Preprocessor.
3. Create your tasks and add corresponding code
We create four tasks, using the classic LED task.
void AppTaskCreate(void)
{
xTaskCreate(vAppTask1, “Task1”, TASK1_STACK_SIZE, NULL, TASK1_PRIORITY, NULL);
xTaskCreate(vAppTask2, “Task2”, TASK2_STACK_SIZE, NULL, TASK2_PRIORITY, NULL);
xTaskCreate(vAppTask3, “Task3”, TASK3_STACK_SIZE, NULL, TASK3_PRIORITY, NULL);
xTaskCreate(vAppTask4, “Task4”, TASK4_STACK_SIZE, NULL, TASK4_PRIORITY, NULL);
}
void vAppTask1(void *pvParameters)
{
for(;;)
{
LED1_TOGGLE;
vTaskDelay(50);
}
}
I created app_task.c and app_task.h files to add the source code for the tasks.
4. Modify the FreeRTOSConfig.h configuration file
This file must be configured, depending on the actual situation. Our system’s trimming is also related to this file, similar to the os_cfg.h file in UCOS.
For example: main frequency, system tick, system stack size, etc.
#define configCPU_CLOCK_HZ ((unsigned long)72000000)
#define configTICK_RATE_HZ ((TickType_t)100)
#define configTOTAL_HEAP_SIZE ((size_t)(4 * 1024))
This article will not discuss specific content. A detailed analysis of each parameter in FreeRTOSConfig.h will be provided later.
At this point, the basic steps are considered complete.
Ⅲ
Code Download
Currently, only demo projects for STM32F0, F1, and F4 are provided, with updates to come later.
【Note: WeChat public accounts do not support external links】
FreeRTOS_STM32F0_Demo download link:
http://pan.baidu.com/s/1qYbmfy0
FreeRTOS_STM32F1_Demo download link:
http://pan.baidu.com/s/1jHDHRPc
FreeRTOS_STM32F4_Demo download link:
http://pan.baidu.com/s/1bplLZ7x
Ⅳ
Conclusion
Search for “EmbeddDeveloper” on WeChat or scan the QR code below to follow and see more exciting content in my bottom menu!
Long press to recognize the QR code in the picture to follow
A like is also a support!