[Jihai APM32F407 Tiny Board] Porting FreeRTOS system
[Copy link]
This post was last edited by TL-LED on 2023-5-26 11:49
In this article, we will learn how to port the freeRTOS system to the development board.
1. Source code download
Source code download address: https://www.freertos.org/zh-cn-cmn-s/a00104.html
Download the latest source code
2. Add files
Add freeRTOS related files to the project created in the previous article
2.1. Copy the freeRTOS source code to the project folder
2.2. Add freeRTOS source code to the project
Add source C file to the project
Add hardware interface files to the project
Add memory management files to the project
3. Modification and Configuration Files
3.1. After adding the files in the above steps, specify the header file location
3.2 Compile Project
After the modification is completed, execute the compilation and the following error is reported. This is the configuration file, which is the file of the copy example board and needs to be modified according to the hardware of the development board.
3.3. Errors during the migration process
Error content:
Modification method:
Comment out the following function in the interrupt function
The SVC and PendSV interrupt functions have been defined in the freeRTOS system and need to be commented out in the interrupt function.
Shield the definition in the freeRTOS configuration file and use the systick interrupt function in the SDK interrupt.
Modify the following file
Compile the project again
No error is reported. The above is the process of porting freeRTOS.
4. Create a task
4.1、main.c
#include "main.h"
#include "usart.h"
#include "FreeRTOS.h"
#include "task.h"
#define TASK1_PRIO 2
#define TASK1_STK_SIZE 128
static TaskHandle_t Task1Task_Handler = NULL;
#define TASK2_PRIO 3
#define TASK2_STK_SIZE 128
static TaskHandle_t Task2Task_Handler = NULL;
void start_task(void *pvParameters);
void task1(void *pvParameters);
void task2(void *pvParameters);
int main(void)
{
SysTick_Init();
init_usart(115200);
printf("apm32f407-freeRTOS-test\r\n");
init_led();
led2_off();
led3_on();
//task1
xTaskCreate((TaskFunction_t )task1,
(const char* )"task1",
(uint16_t )TASK1_STK_SIZE,
(void* )NULL,
(UBaseType_t )TASK1_PRIO,
(TaskHandle_t* )&Task1Task_Handler);
//task2
xTaskCreate((TaskFunction_t )task2,
(const char* )"task2",
(uint16_t )TASK2_STK_SIZE,
(void* )NULL,
(UBaseType_t )TASK2_PRIO,
(TaskHandle_t* )&Task2Task_Handler);
vTaskStartScheduler();
while(1);
}
//task1
void task1(void *pvParameters)
{
while (1)
{
printf("task1 run ...\r\n");
led2_tog();
vTaskDelay(500);
}
}
//task2
void task2(void *pvParameters)
{
while (1)
{
led3_tog();
printf("task2 run ...\r\n");
vTaskDelay(100);
}
}
5. Hardware Connection
The serial port on the link strip on the board cannot be used. Use a serial port module to connect to J3 and J5.
6. Program running
6.1、Serial port output content
6.2. Run Video
320
7. Program source code
|