tlled 发表于 2023-10-26 17:36

【AT-START-F423测评】+移植freertos

将freertos系统移植到STM32F423开发板。

一、下载源码
freertos源码下载地址:https://github.com/FreeRTOS/FreeRTOS

二、添加文件
将freertos源文件复制到项目文件夹


在项目工程中添加源文件


添加头文件路径


修改FreeRTOSConfig.h文件


三、程序

main.c
#include "at32f423_board.h"
#include "at32f423_clock.h"
#include "led/led.h"
#include "key/key.h"
#include "usart/usart.h"
#include "delay/delay.h"
#include "systick/systick.h"

#include "FreeRTOS.h"
#include "task.h"

#define START_TASK_PRIO      1                  
#define START_STK_SIZE128               
static TaskHandle_t            StartTask_Handler = NULL;

#define TASK1_PRIO      2                  
#define TASK1_STK_SIZE128               
static TaskHandle_t            Task1Task_Handler = NULL;
         
#define TASK2_PRIO      3                  
#define TASK2_STK_SIZE128               
static TaskHandle_t            Task2Task_Handler = NULL;

void start_task(void *pvParameters);
void task1(void *pvParameters);
void task2(void *pvParameters);

int main(void)
{
      system_clock_config();
      SysTick_Init();
      init_led();
      init_key();
      init_usart(115200);
      printf("at32f423 board test! \r\n");
      
      xTaskCreate((TaskFunction_t )start_task,                  
                                                      (const char*    )"start_task",               
                                                      (uint16_t       )START_STK_SIZE,         
                                                      (void*          )NULL,                  
                                                      (UBaseType_t    )START_TASK_PRIO,            
                                                      (TaskHandle_t*)&StartTask_Handler);            
      vTaskStartScheduler();
      return 0;
}


void start_task(void *pvParameters)
{
      taskENTER_CRITICAL();
      xTaskCreate((TaskFunction_t )task1,                  
                                                      (const char*    )"task1",               
                                                      (uint16_t       )TASK1_STK_SIZE,         
                                                      (void*          )NULL,                  
                                                      (UBaseType_t    )TASK1_PRIO,            
                                                      (TaskHandle_t*)&Task1Task_Handler);
      xTaskCreate((TaskFunction_t )task2,                  
                                                      (const char*    )"task2",               
                                                      (uint16_t       )TASK2_STK_SIZE,      
                                                      (void*          )NULL,                  
                                                      (UBaseType_t    )TASK2_PRIO,            
                                                      (TaskHandle_t*)&Task2Task_Handler);
                                                      
      vTaskDelete(StartTask_Handler);
      taskEXIT_CRITICAL();
}


//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);
    }
}

四、程序运行

开发板运行后,串口输出




页: [1]
查看完整版本: 【AT-START-F423测评】+移植freertos