Questions about freertos task creation [Full demo]

juhua_yu
Posts: 5
Joined: Mon Jan 29, 2024 1:41 pm

Questions about freertos task creation [Full demo]

Postby juhua_yu » 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
  1. ESP-ROM:esp32s3-20210327
  2. Build:Mar 27 2021
  3. rst:0x15 (USB_UART_CHIP_RESET),boot:0x8 (SPI_FAST_FLASH_BOOT)
  4. Saved PC:0x4037879a
  5. 0x4037879a: esp_cpu_wait_for_intr at X:/ESP-IDF/components/esp_hw_support/cpu.c:121
  6.  
  7. SPIWP:0xee
  8. mode:DIO, clock div:1
  9. load:0x3fce3818,len:0x1758
  10. load:0x403c9700,len:0x4
  11. load:0x403c9704,len:0xc00
  12. load:0x403cc700,len:0x2e04
  13. entry 0x403c9908
  14. I (26) boot: ESP-IDF v5.1.2-dirty 2nd stage bootloader
  15. I (27) boot: compile time Jan 30 2024 10:25:01
  16. I (27) boot: Multicore bootloader
  17. I (30) boot: chip revision: v0.2
  18. I (34) boot.esp32s3: Boot SPI Speed : 80MHz
  19. I (39) boot.esp32s3: SPI Mode       : DIO
  20. I (44) boot.esp32s3: SPI Flash Size : 8MB
  21. I (48) boot: Enabling RNG early entropy source...
  22. I (54) boot: Partition Table:
  23. I (57) boot: ## Label            Usage          Type ST Offset   Length
  24. I (65) boot:  0 nvs              WiFi data        01 02 00009000 00006000
  25. I (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000
  26. I (79) boot:  2 factory          factory app      00 00 00010000 00100000
  27. I (87) boot: End of partition table
  28. I (91) esp_image: segment 0: paddr=00010020 vaddr=3c050020 size=1c780h (116608) map
  29. I (120) esp_image: segment 1: paddr=0002c7a8 vaddr=3fc91f00 size=02ce0h ( 11488) load
  30. I (123) esp_image: segment 2: paddr=0002f490 vaddr=40374000 size=00b88h (  2952) load
  31. I (127) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=49334h (299828) map
  32. I (189) esp_image: segment 4: paddr=0007935c vaddr=40374b88 size=0d2c4h ( 53956) load
  33. I (207) boot: Loaded app from partition at offset 0x10000
  34. I (207) boot: Disabling RNG early entropy source...
  35. I (218) cpu_start: Multicore app
  36. I (219) octal_psram: vendor id    : 0x0d (AP)
  37. I (219) octal_psram: dev id       : 0x02 (generation 3)
  38. I (222) octal_psram: density      : 0x03 (64 Mbit)
  39. I (227) octal_psram: good-die     : 0x01 (Pass)
  40. I (233) octal_psram: Latency      : 0x01 (Fixed)
  41. I (238) octal_psram: VCC          : 0x01 (3V)
  42. I (243) octal_psram: SRF          : 0x01 (Fast Refresh)
  43. I (249) octal_psram: BurstType    : 0x01 (Hybrid Wrap)
  44. I (255) octal_psram: BurstLen     : 0x01 (32 Byte)
  45. I (260) octal_psram: Readlatency  : 0x02 (10 cycles@Fixed)
  46. I (266) octal_psram: DriveStrength: 0x00 (1/1)
  47. I (271) esp_psram: Found 8MB PSRAM device
  48. I (276) esp_psram: Speed: 40MHz
  49. I (280) cpu_start: Pro cpu up.
  50. I (284) cpu_start: Starting app cpu, entry point is 0x40375440
  51. 0x40375440: call_start_cpu1 at X:/ESP-IDF/components/esp_system/port/cpu_start.c:157
  52.  
  53. I (0) cpu_start: App cpu up.
  54. I (1021) esp_psram: SPI SRAM memory test OK
  55. I (1030) cpu_start: Pro cpu start user code
  56. I (1030) cpu_start: cpu freq: 160000000 Hz
  57. I (1031) cpu_start: Application information:
  58. I (1034) cpu_start: Project name:     freertostest
  59. I (1039) cpu_start: App version:      1
  60. I (1044) cpu_start: Compile time:     Jan 30 2024 10:24:48
  61. I (1050) cpu_start: ELF file SHA256:  a1d20ca8c63203d2...
  62. I (1056) cpu_start: ESP-IDF:          v5.1.2-dirty
  63. I (1061) cpu_start: Min chip rev:     v0.0
  64. I (1066) cpu_start: Max chip rev:     v0.99
  65. I (1071) cpu_start: Chip rev:         v0.2
  66. I (1076) heap_init: Initializing. RAM available for dynamic allocation:
  67. I (1083) heap_init: At 3FC96B18 len 00052BF8 (330 KiB): DRAM
  68. I (1089) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
  69. I (1096) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
  70. I (1103) heap_init: At 600FE010 len 00001FD8 (7 KiB): RTCRAM
  71. I (1109) esp_psram: Adding pool of 8192K of PSRAM memory to heap allocator
  72. I (1117) spi_flash: detected chip: gd
  73. I (1121) spi_flash: flash io: dio
  74. I (1127) sleep: Configure to isolate all GPIO pins in sleep state
  75. I (1132) sleep: Enable automatic switching of GPIO sleep configuration
  76. I (1139) app_start: Starting scheduler on CPU0
  77. I (1144) app_start: Starting scheduler on CPU1
  78. I (1144) main_task: Started on CPU0
  79. I (1154) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
  80. I (1164) main_task: Calling app_main()
完整程序代码 Complete program code:
  1. #include <iostream>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4.  
  5. static TaskHandle_t task1Handle;
  6. static TaskHandle_t task2Handle;
  7. static TaskHandle_t task3Handle;
  8. static TaskHandle_t task4Handle;
  9. static TaskHandle_t task5Handle;
  10. static TaskHandle_t task6Handle;
  11. static TaskHandle_t task7Handle;
  12.  
  13. static void Task1(void *pvParameters) {    
  14.     while(1) {
  15.         printf("core:%d | task1 run\n", xPortGetCoreID());
  16.         vTaskDelay(pdMS_TO_TICKS(20));
  17.     }
  18. }
  19. static void Task2(void *pvParameters) {    
  20.     while(1) {
  21.         printf("core:%d | task2 run\n", xPortGetCoreID());
  22.         vTaskDelay(pdMS_TO_TICKS(20));
  23.     }
  24. }
  25. static void Task3(void *pvParameters) {    
  26.     while(1) {
  27.         printf("core:%d | task3 run\n", xPortGetCoreID());
  28.         vTaskDelay(pdMS_TO_TICKS(20));
  29.     }
  30. }
  31. static void Task4(void *pvParameters) {    
  32.     while(1) {
  33.         printf("core:%d | task4 run\n", xPortGetCoreID());
  34.         vTaskDelay(pdMS_TO_TICKS(20));
  35.     }
  36. }
  37. static void Task5(void *pvParameters) {    
  38.     while(1) {
  39.         printf("core:%d | task5 run\n", xPortGetCoreID());
  40.         vTaskDelay(pdMS_TO_TICKS(20));
  41.     }
  42. }
  43. static void Task6(void *pvParameters) {    
  44.     while(1) {
  45.         printf("core:%d | task6 run\n", xPortGetCoreID());
  46.         vTaskDelay(pdMS_TO_TICKS(50));
  47.     }
  48. }
  49. static void Task7(void *pvParameters) {    
  50.     while(1) {
  51.         printf("core:%d | task7 run\n", xPortGetCoreID());
  52.         vTaskDelay(pdMS_TO_TICKS(50));
  53.     }
  54. }
  55.  
  56. extern "C" void app_main(void)
  57. {
  58.     xTaskCreatePinnedToCore(Task1, "Task1", 1024*50, NULL, configMAX_PRIORITIES-3, &task1Handle, 0);
  59.     xTaskCreatePinnedToCore(Task2, "Task2", 1024*50, NULL, configMAX_PRIORITIES-3, &task2Handle, 0);
  60.     xTaskCreatePinnedToCore(Task3, "Task3", 1024*50, NULL, configMAX_PRIORITIES-3, &task3Handle, 1);
  61.     xTaskCreatePinnedToCore(Task4, "Task4", 1024*50, NULL, configMAX_PRIORITIES-3, &task4Handle, 1);
  62.     xTaskCreate(Task5, "Task5", 1024*50, NULL, configMAX_PRIORITIES-3, &task5Handle);
  63.     xTaskCreate(Task6, "Task6", 1024*50, NULL, configMAX_PRIORITIES-2, &task6Handle);
  64.     xTaskCreate(Task7, "Task7", 1024*50, NULL, configMAX_PRIORITIES-1, &task7Handle);
  65.  
  66.     while(1) {
  67.         printf(">>>>>- main -<<<<<\n");
  68.         // lv_timer_handler();
  69.         vTaskDelay(pdMS_TO_TICKS(10));
  70.     }
  71. }
控制台打印信息 Console print message:
  1. core:0 | task1 run
  2. core:0 | task2 run
  3. core:1 | task3 run
  4. core:0 | task5 run
  5. core:1 | task4 run
  6. >>>>- main -<<<<
  7. core:0 | task1 run
  8. >>>>- main -<<<<
  9. core:0 | task2 run
  10. core:0 | task5 run
  11. >>>>- main -<<<<
  12. core:1 | task3 run
  13. core:1 | task4 run
  14. core:0 | task1 run
  15. >>>>- main -<<<<
  16. core:0 | task2 run
  17. core:0 | task5 run
  18. >>>>- main -<<<<
  19. core:1 | task3 run
  20. core:1 | task4 run
  21. core:0 | task1 run
  22. >>>>- main -<<<<
  23. core:0 | task2 run
  24. core:0 | task5 run
  25. >>>>- main -<<<<
  26. core:1 | task3 run
  27. core:1 | task4 run
  28. core:0 | task1 run
  29. >>>>- main -<<<<
  30. core:0 | task2 run
  31. core:0 | task5 run
  32. >>>>- main -<<<<
  33. core:1 | task3 run
  34. core:1 | task4 run
  35. core:0 | task1 run
  36. >>>>- main -<<<<
  37. core:0 | task2 run
  38. core:0 | task5 run
  39. >>>>- main -<<<<
  40. core:1 | task3 run
  41. core:1 | task4 run
  42. core:0 | task1 run
  43. >>>>- main -<<<<
  44. core:0 | task2 run
  45. core:0 | task5 run
  46. >>>>- main -<<<<
  47. core:1 | task3 run
  48. core:1 | task4 run
  49. core:0 | task1 run
  50. >>>>- main -<<<<
  51. core:0 | task2 run
  52. core:0 | task5 run
  53. >>>>- main -<<<<
  54. core:1 | task3 run
  55. core:1 | task4 run
  56. core:0 | task1 run
  57. >>>>- main -<<<<
  58. core:0 | task2 run
  59. core:0 | task5 run
  60. >>>>- main -<<<<
  61. core:1 | task3 run
  62. core:1 | task4 run
  63. core:0 | task1 run
  64. >>>>- main -<<<<
  65. core:0 | task2 run
  66. core:0 | task5 run
  67. >>>>- main -<<<<
  68. core:1 | task3 run
  69. core:1 | task4 run
  70. core:0 | task1 run
  71. >>>>- main -<<<<
  72. core:0 | task2 run
  73. core:0 | task5 run
  74. >>>>- main -<<<<
  75. core:1 | task3 run
  76. core:1 | task4 run
  77. core:0 | task1 run
  78. >>>>- main -<<<<
  79. core:0 | task2 run
  80. core:0 | task5 run
  81. >>>>- main -<<<<
  82. core:1 | task3 run
  83. core:1 | task4 run
  84. core:0 | task1 run
  85. >>>>- main -<<<<
  86. core:0 | task2 run
  87. core:0 | task5 run
  88. >>>>- main -<<<<
  89. core:1 | task3 run
  90. core:1 | task4 run
  91. core:0 | task1 run
  92. >>>>- main -<<<<
  93. core:0 | task2 run
  94. core:0 | task5 run
  95. >>>>- main -<<<<
  96. core:1 | task3 run
  97. core:1 | task4 run
  98. core:0 | task1 run
  99. >>>>- main -<<<<
  100. core:0 | task2 run
  101. core:0 | task5 run
  102. >>>>- main -<<<<
  103. core:1 | task3 run
  104. core:1 | task4 run
  105. core:0 | task1 run
  106. >>>>- main -<<<<
  107. core:0 | task2 run
  108. core:0 | task5 run
  109. >>>>- main -<<<<
  110. core:1 | task3 run
  111. core:1 | task4 run
  112. core:0 | task1 run
  113. >>>>- main -<<<<
  114. core:0 | task2 run
  115. core:0 | task5 run
  116. >>>>- main -<<<<
  117. core:1 | task3 run
  118. core:1 | task4 run
  119. core:0 | task1 run
  120. >>>>- main -<<<<
  121. core:0 | task2 run
  122. core:0 | task5 run
  123. >>>>- main -<<<<
  124. core:1 | task3 run
  125. core:1 | task4 run
  126. core:0 | task1 run
  127. >>>>- main -<<<<
  128. core:0 | task2 run
  129. core:0 | task5 run
  130. >>>>- main -<<<<
  131. core:1 | task3 run
  132. core:1 | task4 run
  133. core:0 | task1 run
  134. >>>>- main -<<<<
  135. core:0 | task2 run
  136. core:0 | task5 run
  137. >>>>- main -<<<<
  138. core:1 | task3 run
  139. core:1 | task4 run
  140. core:0 | task1 run
  141. >>>>- main -<<<<
  142. core:0 | task2 run
  143. core:0 | task5 run
  144. >>>>- main -<<<<
  145. core:1 | task3 run
  146. core:1 | task4 run
  147. core:0 | task1 run
  148. >>>>- main -<<<<
  149. core:0 | task2 run
  150. core:0 | task5 run
  151. >>>>- main -<<<<
  152. core:1 | task3 run
  153. core:1 | task4 run
  154. core:0 | task1 run
  155. >>>>- main -<<<<
  156. core:0 | task2 run
  157. core:0 | task5 run
  158. >>>>- main -<<<<
  159. core:1 | task3 run
  160. core:1 | task4 run
  161. core:0 | task1 run
  162. >>>>- main -<<<<
  163. core:0 | task2 run
  164. core:0 | task5 run
  165. >>>>- main -<<<<
  166. core:1 | task3 run
  167. core:1 | task4 run
  168. core:0 | task1 run

juhua_yu
Posts: 5
Joined: Mon Jan 29, 2024 1:41 pm

Re: Questions about freertos task creation [Full demo]

Postby juhua_yu » Tue Jan 30, 2024 7:50 am

大哥们,是小弟愚蠢,栈分配不合理导致的,感谢社区
eldest, is me stupid, stack allocation is not reasonable cause, thank the community

Who is online

Users browsing this forum: No registered users and 115 guests