CMake (STACK_MAIN) (COMPILE_FLAGS)

I am modifying the landing module, to make a throw launch module.

While looking at the CMake file there where two lines that caught my attention differing from the example shown in Writing your First Application · PX4 Developer Guide

MODULE modules__throw_launch
MAIN throw_launch
STACK_MAIN 1200 # dont understand
COMPILE_FLAGS # dont understand
SRCS
	throw_launch_main.cpp
	ThrowLaunch.cpp
	MulticopterThrowLaunch.cpp
DEPENDS
	platforms__common # dont understand
)

What does the number after STACK_MAIN do, i have seen it at 2000, and now at 1200?
What does COMPILE_FLAGS do?

Hi
STACK_MAIN defines the stack size in bytes for your main task. Only if you see low stack warnings on the debug console or in the log, you will need to increase it. Use the top command to see the stack usage of all running applications.
COMPILE_FLAGS are additional flags passed to the compiler. You typically don’t need them.

1 Like

Although I increased the value of STACK_MAIN because ‘low on stack!’ message happens, the stack size is not changed when I see it by the ‘top’ command.

And also I changed all the stack values such as CONFIG_USERMAIN_STACKSIZE in deconfig file, but the stack size of a user made application module does not change.

Finally, the stack size changed after I increased the size in px4_task_spawn_cmd().

So my problem was resolved.

1 Like

This was my experience as well. Does anyone know relation to the stack_size argument in px4_task_spawn_cmd() and STACK_MAIN in the CMakeLists?

Thanks for your feedbacks, I’ve got the same issue. Change STACK_MAIN and STACK_MAX in CMakeLists.txt doesn’t take any effect.

I think because my custom controller (based on mc_att_control) is running on a workqueue (_task_id = task_id_is_work_queue in task_spawn() method). So according to the PX4 documentation (Background Tasks) if I want to run independently from the calling (parent) task, I need to use this px4_task_spawn_cmd() and don’t derive my class from px4::WorkItem class. See navigator_main.cpp as an example.

Please create a new post, PX4 has changed drastically since 2019.