Why Task execution interval become chaos

Description

I’m using v7.11 for my GUI and refresh my screen through LVGL Task. But I found that the task execution interval can’t meet its original setting through “lv_task_create”, e.g. the interval is 250ms, it should execute every 250ms, but now the task funciton been called 4 times every 250ms, what happened here?
I implemented more than one task, is it possible this test task been affected by others?

What MCU/Processor/Board and compiler are you using?

NXP i.MXRT1062;
IAR

What LVGL version are you using?

v7.11

What do you want to achieve?

Make the task execution stable

What have you tried so far?

I created a test Task which just print out the clock value (FreeRTOS clocks)

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

int main(void)
{
	xTaskCreate(vGUI_Task, "littlevgl", configMINIMAL_STACK_SIZE + 6000, NULL, tskIDLE_PRIORITY + 3, &xGUI_TaskHandle);

	vTaskStartScheduler();

    for (;;) /* should never get here */
    {
        configASSERT(0);
    } 
}
void vGUI_Task(void *param)
{
	lv_init();
    lv_port_disp_init();
    lv_port_indev_init();
    /* Notify that the LVGL has ready so enable the LVGL tick */
    g_lvgl_initialized = true;  
	
	SplashWinTimerCreate();
	
	for (;;)
    {
        lv_task_handler();
        vTaskDelay(5);
    }

    configASSERT(0);
    vTaskDelete( NULL );
}

static TickType_t xLastClkTimerTest;
static TickType_t xCurrClkTimerTest;
lv_task_t* SplashWinTimerCreate(void)
{
    lv_task_t* tsk = NULL;

    static uint32_t timerTest_id = 10;
    lv_task_t* tskTest = lv_task_create(testTask, 250, LV_TASK_PRIO_MID, &timerTest_id);
    
    PRINTMSG(LOG_PRIO_INFO, "Timer created!\r\n");

    xLastClkTimer = xTaskGetTickCount();   
    xLastClkTimerTest = xTaskGetTickCount();

    return tsk;
}
static void testTask(lv_task_t* tsk)
{
    xCurrClkTimerTest = xTaskGetTickCount();
    char str[128];
    sprintf(str, "SPLASHWIN Test Timer Interval: %d.\r\n", xCurrClkTimerTest - xLastClkTimerTest);
    PRINTMSG(LOG_PRIO_INFO, str);
    xLastClkTimerTest = xCurrClkTimerTest;
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Hi,

Please take a look at this: Operating system and interrupts — LVGL documentation

Sorry, I don’t get it.
My application has 3 FreeRTOS tasks, one of them is for LVGL GUI running, the LVGL tasks are created in LVGL GUI (RTOS task). Is there something wrong about it?

If you call LVGL code from multiple tasks, you should use a mutex to prevent the concurrent calling of LVGL functions.

I found the root cause for this problem: The lvgl task was accidently created more than once, so the printed log of timer interval is not correct, after update the code, the interval is all right to print out.

One more question: If I only call the LVGL functions in the LVGL timer/tasks (not RTOS task), then do I need to use mutex for protecting the access?

Glad to hear that you have found the reason!

Nope, if you use only LVGL’s tasks/timers/events/etc, they will be called from lv_timer_handler after each other in a sequential way. So need for a mutex.

sorry, “So need for a mutex”, is this a typo?

Yes, there’s no need for a mutex if you are only calling LVGL APIs from LVGL event handlers/timers.

Ok got it, thanks

Yes, typo sorry :sweat_smile: