ESP32 Demo FreeRTOS Task List
name | version |
---|---|
System | Ubuntu 20.04 |
CMake | 3.10 ≥ |
ESP-IDF | master--v5.1 |
ESP-IDF Programming GuideLogo | v5.1 |
Device | ESP32-S3-WROOM-1 |
创建空项目
- 激活环境
. ~/esp/esp-idf/export.sh
- 创建项目
idf.py create-project ${project_name}
vTaskList
void vTaskList( char *pcWriteBuffer );
示例代码
FreeRTOS_Task_List.c
#include <stdio.h>
#include <stdlib.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
void esp_task_list(void)
{
char *p_buffer = (char *)calloc(1, 2048);
printf("*****************heap:%lu******************\n", esp_get_free_heap_size());
vTaskList(p_buffer);
printf("Task State Prio Stack Num\n");
printf("-------------------------------------------\n");
printf("%s", p_buffer);
printf("*******************************************\n");
free(p_buffer);
}
void app_main(void)
{
while (1) {
esp_task_list();
vTaskDelay(3000 / portTICK_PERIOD_MS);
}
}
危险
使用 vTaskList() 前需使能:
make menuconfig
->Component config
->FreeRTOS
-> Enable FreeRTOS trace facilitymake menuconfig
->Component config
->FreeRTOS
-> Enable FreeRTOS trace facility -> Enable FreeRTOS stats formatting functions通过上面配置,等同于使能 FreeRTOSConfig.h 中如下两个宏: configUSE_TRACE_FACILITY 和 configUSE_STATS_FORMATTING_FUNCTIONS
- 可以直接在
CMakeLists.txt
中使用add_compile_definitions
使能这两个宏
CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
add_compile_definitions(configUSE_TRACE_FACILITY=1)
add_compile_definitions(configUSE_STATS_FORMATTING_FUNCTIONS=1)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(FreeRTOS_Task_List)
编译运行后执行结果,结果如下