espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.33k stars 7.2k forks source link

RAM assigned to Task is not displayed in the build output summary (IDFGH-11840) #12930

Closed eme-bennytang closed 8 months ago

eme-bennytang commented 8 months ago

Answers checklist.

General issue report

IDF version: v5.1.2

In my project, there are a lot of task created for different purpose. But when I create another one for a new feature, somehow the task just didnt execute at all! After some digging, I found that the task is created but never executes.

I have tried to change some options in the SDK config and find that "CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH" will make it work and the tasks will go back to normal.

But after reading the description of "CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH", it should just free 8KB IRAM, and this suggest my project is having a IRAM issue instead of a FREERTOS config issue. (proven by enabling the config, but have another task consume the 8KB freed from the config on the stack, and issue occur again)

I have purposefully create a task with 8KB stack, and rebuild to create the same task with 16KB stack. In the build summary, the used RAM is the same!

Is there anyway I can monitor the stack usage for each task and is the overall IRAM usage enough for everything?

sudeep-mohanty commented 8 months ago

Hi @eme-bennytang, I assume that you are creating tasks with dynamic allocation, i.e, you maybe using the xTaskCreate() (Or its ..PinnedToCore()alternatives) API to create tasks and not the xTaskCreateStatic() API. In such a case, the task stack is allocated from the heap memory by default. To see the affect of creating tasks with increasing stack sizes, I suggest to use the esp_get_free_heap_size() API.

To monitor statically allocated RAM for your app, I would suggest to use the IDF frontend idf.py size command (and its variations).

To monitor the stack usage of tasks, you may use the uxTaskGetStackHighWaterMark() API provided by FreeRTOS.

Some general guidelines for minimizing RAM usage can be found here.

Let us know if this information is helpful. Please feel free to reach out if you have more questions.

eme-bennytang commented 8 months ago

Hi @sudeep-mohanty I have tried "esp_get_free_heap_size()" and result is over 100k+ free heap

But according to my "trial and error" approach of the heap, it should be around 8K stack (which is 32K bytes I think). Anyway I will keep an eye on it, and keep monitor my stack on the tasks with water mark API.

Thanks for the help