[活动专区] 【AT-START-F423测评】+移植freertos

[复制链接]
1588|0
 楼主| tlled 发表于 2023-10-26 17:36 | 显示全部楼层 |阅读模式
将freertos系统移植到STM32F423开发板。

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

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

在项目工程中添加源文件
201.png

添加头文件路径
202.png

修改FreeRTOSConfig.h文件
203.png

三、程序

main.c
  1. #include "at32f423_board.h"
  2. #include "at32f423_clock.h"
  3. #include "led/led.h"
  4. #include "key/key.h"
  5. #include "usart/usart.h"
  6. #include "delay/delay.h"
  7. #include "systick/systick.h"

  8. #include "FreeRTOS.h"
  9. #include "task.h"  

  10. #define START_TASK_PRIO      1                  
  11. #define START_STK_SIZE  128               
  12. static TaskHandle_t            StartTask_Handler = NULL;

  13. #define TASK1_PRIO      2                  
  14. #define TASK1_STK_SIZE  128                 
  15. static TaskHandle_t            Task1Task_Handler = NULL;  
  16.            
  17. #define TASK2_PRIO      3                  
  18. #define TASK2_STK_SIZE  128                 
  19. static TaskHandle_t            Task2Task_Handler = NULL;  

  20. void start_task(void *pvParameters);
  21. void task1(void *pvParameters);  
  22. void task2(void *pvParameters);

  23. int main(void)
  24. {
  25.         system_clock_config();
  26.         SysTick_Init();
  27.         init_led();
  28.         init_key();
  29.         init_usart(115200);
  30.         printf("at32f423 board test! \r\n");
  31.         
  32.         xTaskCreate((TaskFunction_t )start_task,                  
  33.                                                         (const char*    )"start_task",               
  34.                                                         (uint16_t       )START_STK_SIZE,         
  35.                                                         (void*          )NULL,                  
  36.                                                         (UBaseType_t    )START_TASK_PRIO,            
  37.                                                         (TaskHandle_t*  )&StartTask_Handler);            
  38.         vTaskStartScheduler();
  39.         return 0;
  40. }


  41. void start_task(void *pvParameters)
  42. {
  43.         taskENTER_CRITICAL();
  44.         xTaskCreate((TaskFunction_t )task1,                  
  45.                                                         (const char*    )"task1",               
  46.                                                         (uint16_t       )TASK1_STK_SIZE,         
  47.                                                         (void*          )NULL,                  
  48.                                                         (UBaseType_t    )TASK1_PRIO,            
  49.                                                         (TaskHandle_t*  )&Task1Task_Handler);
  50.         xTaskCreate((TaskFunction_t )task2,                  
  51.                                                         (const char*    )"task2",               
  52.                                                         (uint16_t       )TASK2_STK_SIZE,        
  53.                                                         (void*          )NULL,                  
  54.                                                         (UBaseType_t    )TASK2_PRIO,            
  55.                                                         (TaskHandle_t*  )&Task2Task_Handler);
  56.                                                         
  57.         vTaskDelete(StartTask_Handler);
  58.         taskEXIT_CRITICAL();
  59. }


  60. //task1
  61. void task1(void *pvParameters)
  62. {
  63.     while (1)
  64.     {
  65.         printf("task1 run ...\r\n");
  66.         led2_tog();
  67.         vTaskDelay(500);
  68.     }
  69. }

  70. //task2
  71. void task2(void *pvParameters)
  72. {
  73.     while (1)
  74.     {        
  75.                                 led3_tog();
  76.         printf("task2 run ...\r\n");
  77.         vTaskDelay(100);
  78.     }
  79. }


四、程序运行

开发板运行后,串口输出
204.png



您需要登录后才可以回帖 登录 | 注册

本版积分规则

132

主题

701

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部