Page 1 of 1

ESP32 Main Task Size

Posted: Thu Aug 17, 2017 5:14 am
by llewellyn
In my main function if I start 4 tasks of 2048 heap size each. Does my main task size need to be 4 * 2048?

Re: ESP32 Main Task Size

Posted: Thu Aug 17, 2017 1:34 pm
by kolban
Howdy ... no sir.

Each task you create has its own stack size that YOU explicitly specify when you create a task. If you look at the API you are using to create a task, you will find that the stack size for THAT task that you are are creating is a parameter on the API. Since there are some tasks within ESP-IDF that are created outside of your control (i.e. the main task that gets the story running in the first place), it is the stack size for those ESP-IDF tasks that are specified in the make menuconfig.

Re: ESP32 Main Task Size

Posted: Thu Aug 17, 2017 5:49 pm
by permal
Edit: As per ESP_igrr's post below, the FreeRTOS documentation doesn't correspond the the IDF-version of FreeRTOS. Please refer to ESP_igrr's post for correct info.

Also worth noting is that the number you specify isn't the size in the traditional sense. It is, as is clearly documented here (see usStackDepth), the depth of the stack.
The number of words (not bytes!) to allocate for use as the task's stack. For example, if the stack is 16-bits wide and usStackDepth is 100, then 200 bytes will be allocated for use as the task's stack. As another example, if the stack is 32-bits wide and usStackDepth is 400 then 1600 bytes will be allocated for use as the task's stack.
The stack depth multiplied by the stack width must not exceed the maximum value that can be contained in a variable of type size_t.


In the case if the ESP32, the word size is four (32 bits, 4 bytes)

Re: ESP32 Main Task Size

Posted: Thu Aug 17, 2017 6:30 pm
by ESP_igrr
Actually, stack size is given in units StackType_t (even though FreeRTOS documentation says that it is given in words).
In the original xtensa port StackType_t was defined as uint8_t. This was preserved in ESP-IDF version of FreeRTOS as well:
https://github.com/espressif/esp-idf/bl ... .h#L50-L52
https://github.com/espressif/esp-idf/bl ... #L104-L108

Re: ESP32 Main Task Size

Posted: Thu Aug 17, 2017 6:42 pm
by permal
Oh, wow. That's a factor of four from what the manual says!

What other IDF-specific quirks are there that are not corresponding to the official documentation? Is there a list of such things? These kind of differences are rather valuable/important to know.

Re: ESP32 Main Task Size

Posted: Sat Aug 19, 2017 9:20 am
by llewellyn
Thanx A lot everyone. This helps !!

Re: ESP32 Main Task Size

Posted: Thu Dec 27, 2018 1:08 pm
by burkulesomesh43
kolban wrote:
Thu Aug 17, 2017 1:34 pm
Howdy ... no sir.

Each task you create has its own stack size that YOU explicitly specify when you create a task. If you look at the API you are using to create a task, you will find that the stack size for THAT task that you are are creating is a parameter on the API. Since there are some tasks within ESP-IDF that are created outside of your control (i.e. the main task that gets the story running in the first place), it is the stack size for those ESP-IDF tasks that are specified in the make menuconfig.
How can we determine the main task stack size?
it is 3584 default.