Using LVGL in FreeRTOS

Description

Using FreeRTOS simulator the thread starts but got stuck

What LVGL version are you using?

9.1

What do you want to achieve?

I want my_flush_cb to be called and copy the buffer in another buffer.

What have you tried so far?

I have created a display, set the buffer, create a sample object and call
lv_timer_handler in a thread;

Code to reproduce

#define 	hor_res 272

#define 	ver_res 480

lv_color16_t GUIThread::buf_1[hor_res*ver_res];

lv_color16_t GUIThread::buf_2[hor_res*ver_res];

void GUIThread::Run() {

	lv_init();

	display = lv_display_create(hor_res, ver_res);

	lv_display_set_buffers(display, buf_1, buf_2, sizeof(buf_1), LV_DISPLAY_RENDER_MODE_DIRECT); /*Set an initialized buffer*/

	lv_display_set_flush_cb(display,Graphics::my_flush_cb);


	lv_obj_t *label = lv_label_create(lv_screen_active());

	lv_label_set_text(label,"Hello World");

	lv_obj_align(label,LV_ALIGN_CENTER,0,0);
//
	CreateTimerGuiThread(); //just create a second thread which calls lv_tick_inc(10);

	while(1)
	{

		lv_timer_handler();

		osDelay(20);


	};
}

lv_color16_t Graphics::frameBuffer[272][480];

lv_color16_t (*Graphics::frameBufferPointer)[480] = Graphics::frameBuffer;

void Graphics::my_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * px_map)
{


	uint8_t *pbmp = (uint8_t *)(px_map);

	memcpy((uint32_t *)Graphics::frameBufferPointer,(uint32_t *)pbmp, 480*272 * 2);

	lv_display_flush_ready(disp);

}


Problem I have

I got stuck in this code

static void draw_buf_flush(lv_display_t * disp)
{
    /*Flush the rendered content to the display*/
    lv_layer_t * layer = disp->layer_head;

    while(layer->draw_task_head) {
        lv_draw_dispatch_wait_for_request();
        lv_draw_dispatch();
    }

    /* In double buffered mode wait until the other buffer is freed
     * and driver is ready to receive the new buffer.
     * If we need to wait here it means that the content of one buffer is being sent to display
     * and other buffer already contains the new rendered image. */
    if(lv_display_is_double_buffered(disp)) {
        wait_for_flushing(disp_refr);
    }

    disp->flushing = 1;

    if(disp->last_area && disp->last_part) disp->flushing_last = 1;
    else disp->flushing_last = 0;

    bool flushing_last = disp->flushing_last;

    if(disp->flush_cb) {
        call_flush_cb(disp, &disp->refreshed_area, layer->draw_buf->data);
    }
    /*If there are 2 buffers swap them. With direct mode swap only on the last area*/
    if(lv_display_is_double_buffered(disp) && (disp->render_mode != LV_DISPLAY_RENDER_MODE_DIRECT || flushing_last)) {
        if(disp->buf_act == disp->buf_1) {
            disp->buf_act = disp->buf_2;
        }
        else {
            disp->buf_act = disp->buf_1;
        }
    }
}

It never goes out of the first while

while(layer->draw_task_head) {
        lv_draw_dispatch_wait_for_request();
        lv_draw_dispatch();
    }

Need help

Am I missing some initialization?

Thanks very much for any help.

Bets Regards

Hello Glory-man,
Thanks for reply.
The function is included in the sdk in the file lv_refr.c and it is called by lv_timer_handler().
Best

Is lv_tick_inc() called in your app ?
EDIT: if it called in the thread
Call lv_tick_inc(x) periodically, where x is the elapsed milliseconds since the last call. lv_tick_inc should be called from a high priority interrupt.
Did you use LV_USE_OS ?

Yes, I use LV_USE_OS. There are only two threads. One increments lv_timer and the second calls the draw. But draw stucks in the while loop where it tests layer and never exit

Hi,
do you have any idea? Any suggestion?
Thanks very much

what about threads priority?

I do not think so but I should set a simple project for eclipse, it runs in win32. But i need time.

at first glance everything was done according to the instructions. i used lvgl up to 8.4 with FreeRTOS but LV_USE_OS = LV_OS_NONE. Have no experience with defined LV_USE_OS. Maybe developers can help - @kisvegabor or @embeddedt

I try with LV_OS_NONE. It does not change. Eventually I can upload the sample project.
Thanks

Hello Glory-man
thanks very much for help.
I installed 8.3 and it works. I mean it compiles, calls flush_cb and so far so on.
Now I have some problems with buffer and display size, I mean I write 480x272
but I got some overflow and crash if I transfer the full buffer.
Probably I will open a new how-to or similar.
Best Regards

You didnt mention your platform, is it pc simulator or esp or stm or other chips?

Hi.
Thanks for reply.
I started from freertos Win32-MingW demo.
I added lvgl.
Version 8.3.11 works perfectly.
Version 9 compile but stucks in the loop i told before.
But for my tests, 8.3.11 is enough.
Best

Hi,
We have this issue without OS. Setting LV_USE_DRAW_SW to 1 resolved this issue.

Thanks.
I used 8.3 and do not have this isuue.
I will try your solution.
Best