Questions about freertos task creation [Full demo]
Posted: Tue Jan 30, 2024 4:03 am
刚入手ESP的小白一个,最近在学习freertos,遇到了如下问题,我不知道为什么,请帮帮我。
创建了7个任务,2个指定核心0,2个指定核心1,还有3个未指定
但程序运行起来只跑前5个任务,任务6和7像是未创建的一样,且任务5只运行在核心0上,这使我很困扰
A little white who just started ESP, recently in learning freertos, encountered the following problems, I don't know why, please help me.
7 tasks were created, 2 designated core 0,2 designated core 1, and 3 unspecified
But it bothers me that the program only runs the first 5 tasks, tasks 6 and 7 are not created, and task 5 only runs on core 0
设备信息打印 Device information printing:
完整程序代码 Complete program code:
控制台打印信息 Console print message:
创建了7个任务,2个指定核心0,2个指定核心1,还有3个未指定
但程序运行起来只跑前5个任务,任务6和7像是未创建的一样,且任务5只运行在核心0上,这使我很困扰
A little white who just started ESP, recently in learning freertos, encountered the following problems, I don't know why, please help me.
7 tasks were created, 2 designated core 0,2 designated core 1, and 3 unspecified
But it bothers me that the program only runs the first 5 tasks, tasks 6 and 7 are not created, and task 5 only runs on core 0
设备信息打印 Device information printing:
- ESP-ROM:esp32s3-20210327
- Build:Mar 27 2021
- rst:0x15 (USB_UART_CHIP_RESET),boot:0x8 (SPI_FAST_FLASH_BOOT)
- Saved PC:0x4037879a
- 0x4037879a: esp_cpu_wait_for_intr at X:/ESP-IDF/components/esp_hw_support/cpu.c:121
- SPIWP:0xee
- mode:DIO, clock div:1
- load:0x3fce3818,len:0x1758
- load:0x403c9700,len:0x4
- load:0x403c9704,len:0xc00
- load:0x403cc700,len:0x2e04
- entry 0x403c9908
- I (26) boot: ESP-IDF v5.1.2-dirty 2nd stage bootloader
- I (27) boot: compile time Jan 30 2024 10:25:01
- I (27) boot: Multicore bootloader
- I (30) boot: chip revision: v0.2
- I (34) boot.esp32s3: Boot SPI Speed : 80MHz
- I (39) boot.esp32s3: SPI Mode : DIO
- I (44) boot.esp32s3: SPI Flash Size : 8MB
- I (48) boot: Enabling RNG early entropy source...
- I (54) boot: Partition Table:
- I (57) boot: ## Label Usage Type ST Offset Length
- I (65) boot: 0 nvs WiFi data 01 02 00009000 00006000
- I (72) boot: 1 phy_init RF data 01 01 0000f000 00001000
- I (79) boot: 2 factory factory app 00 00 00010000 00100000
- I (87) boot: End of partition table
- I (91) esp_image: segment 0: paddr=00010020 vaddr=3c050020 size=1c780h (116608) map
- I (120) esp_image: segment 1: paddr=0002c7a8 vaddr=3fc91f00 size=02ce0h ( 11488) load
- I (123) esp_image: segment 2: paddr=0002f490 vaddr=40374000 size=00b88h ( 2952) load
- I (127) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=49334h (299828) map
- I (189) esp_image: segment 4: paddr=0007935c vaddr=40374b88 size=0d2c4h ( 53956) load
- I (207) boot: Loaded app from partition at offset 0x10000
- I (207) boot: Disabling RNG early entropy source...
- I (218) cpu_start: Multicore app
- I (219) octal_psram: vendor id : 0x0d (AP)
- I (219) octal_psram: dev id : 0x02 (generation 3)
- I (222) octal_psram: density : 0x03 (64 Mbit)
- I (227) octal_psram: good-die : 0x01 (Pass)
- I (233) octal_psram: Latency : 0x01 (Fixed)
- I (238) octal_psram: VCC : 0x01 (3V)
- I (243) octal_psram: SRF : 0x01 (Fast Refresh)
- I (249) octal_psram: BurstType : 0x01 (Hybrid Wrap)
- I (255) octal_psram: BurstLen : 0x01 (32 Byte)
- I (260) octal_psram: Readlatency : 0x02 (10 cycles@Fixed)
- I (266) octal_psram: DriveStrength: 0x00 (1/1)
- I (271) esp_psram: Found 8MB PSRAM device
- I (276) esp_psram: Speed: 40MHz
- I (280) cpu_start: Pro cpu up.
- I (284) cpu_start: Starting app cpu, entry point is 0x40375440
- 0x40375440: call_start_cpu1 at X:/ESP-IDF/components/esp_system/port/cpu_start.c:157
- I (0) cpu_start: App cpu up.
- I (1021) esp_psram: SPI SRAM memory test OK
- I (1030) cpu_start: Pro cpu start user code
- I (1030) cpu_start: cpu freq: 160000000 Hz
- I (1031) cpu_start: Application information:
- I (1034) cpu_start: Project name: freertostest
- I (1039) cpu_start: App version: 1
- I (1044) cpu_start: Compile time: Jan 30 2024 10:24:48
- I (1050) cpu_start: ELF file SHA256: a1d20ca8c63203d2...
- I (1056) cpu_start: ESP-IDF: v5.1.2-dirty
- I (1061) cpu_start: Min chip rev: v0.0
- I (1066) cpu_start: Max chip rev: v0.99
- I (1071) cpu_start: Chip rev: v0.2
- I (1076) heap_init: Initializing. RAM available for dynamic allocation:
- I (1083) heap_init: At 3FC96B18 len 00052BF8 (330 KiB): DRAM
- I (1089) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
- I (1096) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
- I (1103) heap_init: At 600FE010 len 00001FD8 (7 KiB): RTCRAM
- I (1109) esp_psram: Adding pool of 8192K of PSRAM memory to heap allocator
- I (1117) spi_flash: detected chip: gd
- I (1121) spi_flash: flash io: dio
- I (1127) sleep: Configure to isolate all GPIO pins in sleep state
- I (1132) sleep: Enable automatic switching of GPIO sleep configuration
- I (1139) app_start: Starting scheduler on CPU0
- I (1144) app_start: Starting scheduler on CPU1
- I (1144) main_task: Started on CPU0
- I (1154) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
- I (1164) main_task: Calling app_main()
- #include <iostream>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- static TaskHandle_t task1Handle;
- static TaskHandle_t task2Handle;
- static TaskHandle_t task3Handle;
- static TaskHandle_t task4Handle;
- static TaskHandle_t task5Handle;
- static TaskHandle_t task6Handle;
- static TaskHandle_t task7Handle;
- static void Task1(void *pvParameters) {
- while(1) {
- printf("core:%d | task1 run\n", xPortGetCoreID());
- vTaskDelay(pdMS_TO_TICKS(20));
- }
- }
- static void Task2(void *pvParameters) {
- while(1) {
- printf("core:%d | task2 run\n", xPortGetCoreID());
- vTaskDelay(pdMS_TO_TICKS(20));
- }
- }
- static void Task3(void *pvParameters) {
- while(1) {
- printf("core:%d | task3 run\n", xPortGetCoreID());
- vTaskDelay(pdMS_TO_TICKS(20));
- }
- }
- static void Task4(void *pvParameters) {
- while(1) {
- printf("core:%d | task4 run\n", xPortGetCoreID());
- vTaskDelay(pdMS_TO_TICKS(20));
- }
- }
- static void Task5(void *pvParameters) {
- while(1) {
- printf("core:%d | task5 run\n", xPortGetCoreID());
- vTaskDelay(pdMS_TO_TICKS(20));
- }
- }
- static void Task6(void *pvParameters) {
- while(1) {
- printf("core:%d | task6 run\n", xPortGetCoreID());
- vTaskDelay(pdMS_TO_TICKS(50));
- }
- }
- static void Task7(void *pvParameters) {
- while(1) {
- printf("core:%d | task7 run\n", xPortGetCoreID());
- vTaskDelay(pdMS_TO_TICKS(50));
- }
- }
- extern "C" void app_main(void)
- {
- xTaskCreatePinnedToCore(Task1, "Task1", 1024*50, NULL, configMAX_PRIORITIES-3, &task1Handle, 0);
- xTaskCreatePinnedToCore(Task2, "Task2", 1024*50, NULL, configMAX_PRIORITIES-3, &task2Handle, 0);
- xTaskCreatePinnedToCore(Task3, "Task3", 1024*50, NULL, configMAX_PRIORITIES-3, &task3Handle, 1);
- xTaskCreatePinnedToCore(Task4, "Task4", 1024*50, NULL, configMAX_PRIORITIES-3, &task4Handle, 1);
- xTaskCreate(Task5, "Task5", 1024*50, NULL, configMAX_PRIORITIES-3, &task5Handle);
- xTaskCreate(Task6, "Task6", 1024*50, NULL, configMAX_PRIORITIES-2, &task6Handle);
- xTaskCreate(Task7, "Task7", 1024*50, NULL, configMAX_PRIORITIES-1, &task7Handle);
- while(1) {
- printf(">>>>>- main -<<<<<\n");
- // lv_timer_handler();
- vTaskDelay(pdMS_TO_TICKS(10));
- }
- }
- core:0 | task1 run
- core:0 | task2 run
- core:1 | task3 run
- core:0 | task5 run
- core:1 | task4 run
- >>>>- main -<<<<
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run
- >>>>- main -<<<<
- core:0 | task2 run
- core:0 | task5 run
- >>>>- main -<<<<
- core:1 | task3 run
- core:1 | task4 run
- core:0 | task1 run