# Pixhawk: Stack size in CMakeLists.txt and in px4\_task\_create()

**URL:** <https://discuss.px4.io/t/pixhawk-stack-size-in-cmakelists-txt-and-in-px4-task-create/1784>\
**Category:** Uncategorized\
**Created:** [November 23, 2016, 2:39pm UTC](https://discuss.px4.io/t/pixhawk-stack-size-in-cmakelists-txt-and-in-px4-task-create/1784 "2016-11-23T14:39:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![glennb](https://discuss.px4.io/user_avatar/discuss.px4.io/glennb/32/509_2.png) [@glennb](https://discuss.px4.io/u/glennb)\
**Post date:** [November 23, 2016, 2:39pm UTC](https://discuss.px4.io/t/pixhawk-stack-size-in-cmakelists-txt-and-in-px4-task-create/1784/1 "2016-11-23T14:39:51Z")

</div>

Hello.

In the CMakeLists.txt-file to create a module with the function `px4_add_module`, there are two fields: `STACK_MAIN` and `STACK_MAX`. Also, in the function to spawn a task `px4_task_spawn_cmd`, there is a field `stack_size`.

Does anyone know if these are independent? Why specify the stack multiple times?

In addition: Is the heap shared between tasks, or are there separate heaps for each task?

Thanks.

---

<div class="post-metadata">

**Author:** ![bkueng](https://discuss.px4.io/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@bkueng](https://discuss.px4.io/u/bkueng)\
**Post date:** [November 23, 2016, 4:01pm UTC](https://discuss.px4.io/t/pixhawk-stack-size-in-cmakelists-txt-and-in-px4-task-create/1784/2 "2016-11-23T16:01:10Z")

</div>

Hi @glennb

Stack sizes are a bit confusing. `STACK_MAIN` is used as the stack size for the module’s main function. `STACK_MAX` is used as a static check for the compiler (-Wframe-larger-than=).  
Typically the module’s main function then calls `px4_task_spawn_cmd`, which creates a new background task. This has yet another stack size (that’s the most important one) and this is the size you see with the `top` command.

Yes heaps are shared between tasks, there is only a single address space on NuttX, no virtual memory is used.

Hope that helps

---

<div class="post-metadata">

**Author:** ![Bravepaulo](https://discuss.px4.io/letter_avatar_proxy/v4/letter/b/65b543/32.png) [@Bravepaulo](https://discuss.px4.io/u/Bravepaulo)\
**Post date:** [February 10, 2021, 4:46pm UTC](https://discuss.px4.io/t/pixhawk-stack-size-in-cmakelists-txt-and-in-px4-task-create/1784/3 "2021-02-10T16:46:07Z")

</div>

Hello.  
It has been a long time since this post, but I have a question that is related to this topic.

Considering Nuttx, when a task is created and the stack is allocated using function px4\_task\_spawn\_cmd(…) such stack is located in stack memory or in heap memory?

The reason for my question is because in FreeRTOS, when a task is created, the stack is created inside the heap memory and I did not found any information related to Nuttx about that.
