ESP32 Main Task Size

llewellyn
Posts: 33
Joined: Fri May 05, 2017 8:22 am

ESP32 Main Task Size

Postby llewellyn » Thu Aug 17, 2017 5:14 am

In my main function if I start 4 tasks of 2048 heap size each. Does my main task size need to be 4 * 2048?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP32 Main Task Size

Postby kolban » 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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: ESP32 Main Task Size

Postby permal » Thu Aug 17, 2017 5:49 pm

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)
Last edited by permal on Thu Aug 17, 2017 6:46 pm, edited 1 time in total.

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP32 Main Task Size

Postby ESP_igrr » Thu Aug 17, 2017 6:30 pm

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

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: ESP32 Main Task Size

Postby permal » Thu Aug 17, 2017 6:42 pm

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.

llewellyn
Posts: 33
Joined: Fri May 05, 2017 8:22 am

Re: ESP32 Main Task Size

Postby llewellyn » Sat Aug 19, 2017 9:20 am

Thanx A lot everyone. This helps !!

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: ESP32 Main Task Size

Postby burkulesomesh43 » Thu Dec 27, 2018 1:08 pm

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.
--
Somesh Burkule

Who is online

Users browsing this forum: No registered users and 117 guests