Questions about freertos(ESP32-s3)

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

Questions about freertos(ESP32-s3)

Postby juhua_yu » Mon Jan 29, 2024 1:57 pm

Just started to contact ESP32 also please everyone Pointers.
I tried to create 3 tasks. But no matter how hard you try, there's always a task that's not being performed.
For example, the following code, why not print "sweetHomeTask", which is very confusing to me.
The default freertos configuration is used (idf.py menuconfig)
  1. #include <iostream>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4.  
  5. #include "peripheral_init.h"
  6. #include "SweetHome.h"
  7. #include "mpu6050_driver.h"
  8.  
  9. #include <esp_system.h>
  10.  
  11. using namespace std;
  12.  
  13. static TaskHandle_t gyroTaskHandle;
  14. static TaskHandle_t lifeSupportHandle;
  15. static TaskHandle_t sweetHomeHandle;
  16.  
  17. // SemaphoreHandle_t lvglSemaphore = NULL;
  18.  
  19. static void gyroTask(void *pvParameters) {
  20.     mpu6050_driver_init();
  21.    
  22.     for(;;) {
  23.         mpu6050_driver_get_data();
  24.         vTaskDelay(pdMS_TO_TICKS(20));
  25.     }
  26. }
  27.  
  28. static void sweetHomeTask(void *pvParameters) {
  29.     printf("sweetHomeTask\n");
  30.     for(;;) {
  31.         vTaskDelay(pdMS_TO_TICKS(30));
  32.         printf(">>>>>>>>>>>>>>>>>>>%d\n", xPortGetCoreID());
  33.         // lv_timer_handler();
  34.     }
  35. }
  36.  
  37. static void lifeSupportTask(void *pvParameters) {
  38.     xTaskCreate(sweetHomeTask, "sweetHome", 1024*50, NULL, 10, &sweetHomeHandle);
  39.     for(;;) {
  40.         vTaskDelay(pdMS_TO_TICKS(1000));
  41.         // lv_timer_handler();
  42.         lv_tick_inc(5);
  43.         printf("================%d\n", xPortGetCoreID());
  44.     }
  45. }
  46.  
  47. extern "C" void app_main(void)
  48. {
  49.  
  50.     peripheral_lcd_init();
  51.  
  52.     xTaskCreatePinnedToCore(gyroTask, "gyro", 1024*50, NULL, 5, &gyroTaskHandle, 1);
  53.     xTaskCreatePinnedToCore(lifeSupportTask, "lifeSupport", 1024*50, NULL, 6, &lifeSupportHandle, 0);
  54.    
  55.    
  56.     printf("end free heap: %ld\n", esp_get_free_heap_size()); // 8439892
  57.  
  58. }
  59.  

ESP_Sprite
Posts: 9729
Joined: Thu Nov 26, 2015 4:08 am

Re: Questions about freertos(ESP32-s3)

Postby ESP_Sprite » Tue Jan 30, 2024 12:04 am

Isn't it simply that you're missing the first bit of startup chatter and as such aren't seeing that printf?

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

Re: Questions about freertos(ESP32-s3)

Postby juhua_yu » Tue Jan 30, 2024 2:35 am

It feels like the sweetHomeTask is not being created
While trying to create a task like this in the app_main function, task1 runs normally on core 0, but task2 and task3 always run the previous one on core 1
  1. xTaskCreatePinnedToCore(&Task1, "Task1", 1024*50, NULL, configMAX_PRIORITIES, &task1Handle, 0);
  2. xTaskCreate(&Task2, "Task2", 1024*50, NULL, configMAX_PRIORITIES, &task2Handle);
  3. xTaskCreatePinnedToCore(&Task3, "Task3", 1024*50, NULL, configMAX_PRIORITIES, &task3Handle, 1);

ESP_Sprite
Posts: 9729
Joined: Thu Nov 26, 2015 4:08 am

Re: Questions about freertos(ESP32-s3)

Postby ESP_Sprite » Tue Jan 30, 2024 4:00 am

Well, you can check that. xTaskCreate and friends give you a return code; you can check it to see if the task creation failed and why. You're simply throwing away those return codes in your code, though; I'd change that first.

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

Re: Questions about freertos(ESP32-s3)

Postby juhua_yu » Tue Jan 30, 2024 5:40 am

Thanks to you my friends, viewing the return value has been a great help. I have determined that the cause is a stack space allocation problem. But I have one more question.
The chip I use is ESP32-S3-WROOM-1U(N16R8), so how to check the size of DRAM and IRAM

MicroController
Posts: 1705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Questions about freertos(ESP32-s3)

Postby MicroController » Tue Jan 30, 2024 10:25 am

https://docs.espressif.com/projects/esp ... e8uint32_t

As a hint: Minimum permissible stack size for a task is about 1.5kb, default is about 3.5kb, which is enough for many tasks. 8-16kb is sufficient for almost all tasks if you don't use local variables/arrays excessively. Conversely, you may want to avoid using local variables/arrays of more than a few hundred bytes and consider using the heap for bigger things (buffers,...).

Who is online

Users browsing this forum: ESP_Sprite and 127 guests