Featured image of post HAL_Freertos的使用记录2

HAL_Freertos的使用记录2

HAL_Freertos的使用记录2

关于主任务函数

之前写到在主函数里面处理的事件也不知道有没有问题 之所以这么写是因为我觉得如果全用cubemax配置好的话下次如果换主控可能会比较麻烦 所以今天再细看一下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
void AppTaskCreate(void)
{
    taskENTER_CRITICAL();        // 进入临界区
    BaseType_t xReturn = pdPASS; /* 定义一个创建信息返回值,默认为pdPASS */
    uint32_t count = 0;
    /* 创建Test_Task任务 */
    xReturn = xTaskCreate((TaskFunction_t)color_led_task_fun, /* 任务入口函数 */
                          (const char *)"COLOR_LED_TASK",     /* 任务名字 */
                          (uint16_t)256,                      /* 任务栈大小 */
                          (void *)NULL,                       /* 任务入口函数参数 */
                          (UBaseType_t)osPriorityNormal,      /* 任务的优先级 */
                          (TaskHandle_t *)&COLOR_LED_Handle); /* 任务控制块指针 */
    if (pdPASS != xReturn)
    {
        goto error;
    }
    UART1_Printf("COLOR_LED_TASK[info]:Runing, Priority:%d\n", osPriorityNormal);

    /* 运行占用  */
    memset(pcWriteBuffer, 0, 400);
    vTaskList(pcWriteBuffer); // 获取内存信息
    UART1_Printf("\r\n");
    UART1_Printf("%s\n\r", pcWriteBuffer);

    memset(pcWriteBuffer, 0, 400);
    vTaskGetRunTimeStats(pcWriteBuffer); // 获取CPU占用率信息
    UART1_Printf("\r\n");
    UART1_Printf("%s\n\r", pcWriteBuffer);

    return;
error:
    UART1_Printf("App_Task_Create[error]:Task Create fail,system exception\n");
    while (1)
    {
        UART1_Printf("error count:%d\n", (int)count++);
        app_main_delay_ms(1000);
    }
    taskEXIT_CRITICAL(); // 退出临界区
}

又添加了一些功能

  • 串口就会打印出这样的内容

当然在这之前还是要在cubemax里面打开一些东西

参考链接 全部打开变成Enable

每次配置任务就可以这样进行 修改如下

当然应用函数还是得要你自己写的 这样好处我感觉就是到时候你要是迁移芯片修改的应该不是很大

最后更新于 Mar 20, 2025 15:00 +0800
世界是你们
使用 Hugo 构建
主题 StackJimmy 设计