Trouble Porting LvGL

Trouble Porting LvGL

I am currently trying to port LvGL to my project, but i’m having some issues.

I am using the EFM32GG11B420 MCU, no IDE i compile my code directly from vscode with arm-none-eabi.

I have successfully compiled and uploaded my code, but the mcu does not successfully initialize, meaning, the:


triggers a BUS FAULT, i’ve narrow down the cause to


the struct disp->act_scr contains the dafault 0xaaaaaaaa mapping to invalid memory space, this then is passed down to

void lv_obj_invalidate(const lv_obj_t * obj)
    if(lv_obj_get_hidden(obj)) return;

where the code tries to read it causing the fault

bool lv_obj_get_hidden(const lv_obj_t * obj)
    return obj->hidden == 0 ? false : true;

why is this happening? it doesn’t seem right.
i should mention the other elements of the struct seem to be initiated correctly pointing to valid memory

my initialization code




    static lv_disp_buf_t disp_buf_2;
    static lv_color_t buf2_1[LV_HOR_RES_MAX * 10];                        /*A buffer for 10 rows*/
    static lv_color_t buf2_2[LV_HOR_RES_MAX * 10];                        /*An other buffer for 10 rows*/
    lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 10);   /*Initialize the display buffer*/

    lv_disp_drv_t disp_drv;       /*Descriptor of a display driver*/
    lv_disp_drv_init(&disp_drv);    /*Basic initialization*/

    /*Set the resolution of the display*/
    disp_drv.hor_res = 480;
    disp_drv.ver_res = 320;

    /*Used to copy the buffer's content to the display*/
    disp_drv.flush_cb = disp_flush;

    /*Set a display buffer*/
    disp_drv.buffer = &disp_buf_2;

    /*Finally register the driver*/

if you need any more information i can provide.

Thank you.

Are you using global display driver and buffer variables?

Also, your code does not follow the template from documentation.

ups. didn’t post all the code, i copied this code directly from the porting template
the buffers are local, like they were in the template

This smells like memory corruption.

Can you step through here and find out why the return value is 0xaaaaaaaa? Are you using a custom heap which is broken?

Well, lvgl apparently initializes allocated memory as 0xaaaa… And simply nothing is written to that particular element after.

Other parts of the struct start as 0xaaa… And are then overwritten with valid objs.

Looking at the memory manager code, 0xaaa… Is written on allocation and 0xbbbb… On free, if I’m looking at it correctly

And nothing on that function looks like it’s trying to write to that particular element so I’m not quite making sense of what’s going on

You need to find why the pointer returned from lv_obj_create is 0xaaaaaaaa. Probably worth stepping through that function and checking the return value of lv_mem_alloc, not the contents of the pointer.

well, this is weird, and could explain this whole issue
this line does no exist in my code, i don’t know why, i haven’t edited it, at least not on purpose.
disp->act_scr = lv_obj_create(NULL, NULL); /*Create a default screen on the display*/
like i said i found it really weird that nothing attemped to initialize that element, ever, before trying to read something from, it didn’t make sense.

update, i guess this was the issue, it runs fine now, i haven’t tested any drawing yet, but right now i don’t have time.
At least the Bus Fault is no more!
I guess that line was missing all along, i have no idea how this happen.

Thank you for the help.

All allocated data is initialized to 0xaaaa... and all freed data is set to 0xbbbb... by default if LV_MEM_ADD_JUNK 1 in lv_mem.c.

I enabled it in the latest release because there were some issues with using the already freed memory and I wanted to get feedback in this regard. However these issues seems solved so LV_MEM_ADD_JUNK can be disabled.

That’s a bad sign. It means that what you downloaded must be corrupt (or you accidentally deleted the line). To avoid that problem in the future I recommend cloning the repository with git; that way you know if you changed something from the original.

i use git.
but i did change the “folder structure” in order to fit with my project/programming style, and somewhere along the way i somehow deleted that line.
i will verify the integrity of the files just to make sure

I would advise you to avoid changing the folder structure of the lvgl folder itself. That will make it harder to update easily (by just running git pull).