I’m working on a project, where i use LVGL and freeRTOS. I’m having some issues related to my UI having some weird behaviour, but my main question is, should I use freeRTOS tasks for loading LVGL object? Also when using 1 object multiple times but changing the text by example, should i use semaphores? It’s a big project.
if you use separate threads to call lv_task_handler()
and to change any object property you need to use mutex to prevent lvgl objects sharing
I pin all the creations of lvgl objects and the lv_task_handler() to core 1 and all the other functionality like webservers and wifi to core 0,if that is what u are saying.
I also never run any lvgl creation task at the same time. These are handled by wifi handlers and other stuff. The reason i’m asking is because i call the loading screen, so i change the text of a label inside, on sta getting the IP i call the loading screen again but with a different text for the label. This sometimes messes with the layout of my UI.
These are called in the main, so the task is called in the main and the function is the task that is running.
xTaskCreatePinnedToCore(lv_tick_task, "lv_tick_task", 1024*10, NULL, 8, NULL, 1);
static void lv_tick_task(void * pvParameters)
{
while (1)
{
lv_task_handler();
vTaskDelay((20) / portTICK_PERIOD_MS);
}
}
Then by example these are 2 different calls for the loading screen, at 2 different places in the code.
xTaskCreatePinnedToCore(loading_screen_task, "loading_screen_task", 4096, (void*)"Connecting To Wifi...", 5, NULL, 1);
xTaskCreatePinnedToCore(loading_screen_task, "loading_screen_task", 4096, (void*)"http://192.168.4.1/index.html", 3, NULL, 1);
this is the loading screen task
void loading_screen_task(void * pvParameters) {
const char * text = (const char *) pvParameters;
ui_show_loading_screen(text);
vTaskDelete(NULL);
}
so you should use mutex when you call lv_task_handler()
xSemaphoreTake(xLvMutex, portMAX_DELAY);
lv_task_handler();
xSemaphoreGive(xLvMutex);
and when you need to lock mutex around every LVGL (lv_...
) related function call and code in the other threads. as far as I understand ui_show_loading_screen()
updates your ui elements so:
xSemaphoreTake(xLvMutex, portMAX_DELAY);
ui_show_loading_screen(text);
xSemaphoreGive(xLvMutex);
LVGL is not thread-safe .
it is recommended to handle lvgl in one thread to keep safe
Thanks! i’ll try it.