Pixhawk: Stack size in CMakeLists.txt and in px4_task_create()

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.

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

1 Like

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.