Adequate stack size in FreeRTOS

What is the minimum or recommended stack size for a FreeRTOS task that handles LVGL only? I use LVGL on ESP32.

I haven’t used FreeRTOS for a while with LVGL so I’d be very curious too. :slightly_smiling_face:

Do you remember an approximate value that you used for other MCUs as well? Currently I use a value of 32000, by default for ESP32 tasks a value of 10000 or so is used.

Depends on how complex your task is, how many functions it calls and how much deeper those function goes. That is nesting. Your task calls one function and then that function calls another and another. And how many local variables those function allocates.

You can start with a stack size of say 128x5 words (not bytes, stack size is always specified in words) and then use a FreeRTOS aware debugger to find out the actual stack utilization. If it is too close to the size of stack then you can expand the stack.

1 Like

Excuse me, I have another problem: I also use FreeRTOS to process lvgl tasks on esp32, but by dynamically creating a tab view and deleting the tab view to achieve page switching between the main page and the tab view, switching pages repeatedly , the memory occupied by this lvgl FreeRTOS task is getting bigger and bigger, and eventually the screen is stuck, I don’t know how to solve it

Dynamic memory is allocated on heap and not stack. Their is memory leak in your system.

1 Like

So how do I need to solve such a memory leak problem?

Thanks for your reply, I found the possible cause of memory overflow: Styles.
Styles are stored in variables. Style variables should be , global or dynamically allocated.
When I use lv_obj_del() to delete the tab view, the style variable is not recycled, which leads to a memory leak. However, if the memory leaks too many times, it will lead to memory overflow. But I am not sure if my analysis is correct, please correct me. thank you all.
My solution: Before initializing the style, add lv_style_reset(&style) to reset the style, so that all its data can be released, and then the screen stuck situation does not appear again for the time being.

For example, for the “music player” demo in the “demos” folder attached to lvgl how much is the appropriate value for the stack? I just need an approximate value, it doesn’t have to be an accurate value!

Problem solved, just use
log_i("lvgl %d", uxTaskGetStackHighWaterMark(LVGLtask));
to see the remaining free stack, if it is too high just reduce the assigned stack.

What have you found e.g. for the music player or the widgets demo?
The result is in bytes or words?

Unfortunately, I haven’t tried it with the demo.
The result I think is in word, since FreeRTOS asks for the stack size in word in the task declaration.