移植freertos系统到CW32L031CxTx StartKit评估板。
一、添加FreeRTOS系统
在之前创建的项目基础上,增加freertos系统。
1.1、添加系统源码
1.2、添加到工程文件
二、编译
添加源码后,编译项目,根据提示的错误,对文件进行修改,遇到的错误如下
2.1、文件重复定义
修改文件,屏蔽掉相关的函数
2.2、编译项目
编译完成,没有报错。
三、程序
编写测试程序
main.c
- #include "main.h"
- #include "led/led.h"
- #include "key/key.h"
- #include "usart/usart.h"
- #include "FreeRTOS.h"
- #include "task.h"
- typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
- #define START_TASK_PRIO 1
- #define START_STK_SIZE 64
- static TaskHandle_t StartTask_Handler = NULL;
- #define TASK1_PRIO 2
- #define TASK1_STK_SIZE 64
- static TaskHandle_t Task1Task_Handler = NULL;
-
- #define TASK2_PRIO 3
- #define TASK2_STK_SIZE 64
- static TaskHandle_t Task2Task_Handler = NULL;
-
- void start_task(void *pvParameters);
- void task1(void *pvParameters);
- void task2(void *pvParameters);
- void NVIC_Configuration(void);
- void RCC_Configuration(void);
- int main(void)
- {
- RCC_Configuration();
- NVIC_Configuration();
- init_uart(115200);
- init_led();
- init_key();
- printf("cw32l031 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("cw32l031 task1 run ...\r\n");
- led1_tog();
- vTaskDelay(500);
- }
- }
- //task2
- void task2(void *pvParameters)
- {
- while (1)
- {
- led2_tog();
- printf("cw32l031 task2 run ...\r\n");
- vTaskDelay(100);
- }
- }
四、程序运行
开发板运行后,串口输出
|