Error with lv_bindings/lvgl/src/lv_misc/lv_printf.c

Hello everyone,

I am working with Micropython LittlevGL binding. My board is STM32F4 Discovery

Because this board is still not supported, I do as @amirgon instructed in this post:

However, I meet this error stemming from the file lv_printf.c:
2019-12-10 2019-12-10.png

So how can i fix this error? I am finding solution online but still haven’t found anything yet.

Thank you very much, Nguyen Duc Huy

Looks like lvgl bug.
Please try to #define LV_SPRINTF_CUSTOM 1 in lv_conf.h, I don’t think you need a lvgl printf implementation

You could also add -Wno-double-promotion to the compiler flags.

Hi @amirgon

As I searched in the lv_conf.h, #define LV_SPRINTF_CUSTOM (1) was already written in the file.

If the lvgl printf is not neccesary, how can i disable that?

Thank you, Huy

Hi embeddeddt,

could you please be more specific about this solution? How can i add -Wno-double-promotion to the compiler flags?

Thank you, Huy

That is strange - the way to disable lvgl printf is to define LV_SPRINTF_CUSTOM as 1.
Please check lv_conf.h again, on github it’s 0 (maybe should be 1 by default)

You need to find whatever Makefile is responsible for setting the compiler flags. For STM32 it seems to be done here.

Hi @amirgon,

As i check in this link on Github the file lib/lv_bindings/lv_conf.h

The LV_SPRINTF_CUSTOM was already defined 1:

Screen Shot 2019-12-11 at 9.53.52 AM

so yeah it is 1 by default

Hi @embeddedt

SO if i want to add -Wno-double-promotion to the compiler flags, i need to insert:
CFLAG += -Wno-double-promotion
at the place you pointed out?

I changed it yesterday to 1. Does it work for you now?

Hi @amirgon

I successfully “make BOARD=STM32F4DISC” in lv_binding/ports/stm32.

However, after i flashed the F4 board and then access the REPL ( by inserting “screen /dev/ttyACM0”), i could not “import lvgl as lv”. It replied "ImportError: no module named ‘lvgl’ ".

What might be the cause of this error?

Did you integrate stm32: add lvgl binding by cidermole · Pull Request #16 · lvgl/lv_micropython · GitHub to your code?

Did you update mpconfigport.h on the STM32 port to use lvgl as a builtin module?
Please have a look at mpconfigport.h on ESP32. See how MICROPY_PORT_LVGL_DEF is defined and used.

Hi @amirgon

My apologies for replying so late, my team is busy for writing documents for our university.

I have some time researching on the links you gave me on the last comment:

  • About the Github link pull/16 you gave
    In this link, I suppose you refered to the first comment and the link under it by @cidermore. In this link, I did the same thing as him except there is a line " MP_ROM_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl }" is under #define STM_BUILTIN_MODULE. I also accessed his repo and checked mpconfigport.h in stm32. The line " MP_ROM_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl }" is under #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS ( As i did initially).

I guess you are mentioning having “MICROPY_PORT_LVGL_DEF” under MICROPY_PORT_BUILTIN_MODULES.

  • About the reference you gave about mpconfigport.h on ESP32
    In this link, "{ MP_OBJ_NEW_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl }, "
    is under MICROPY_PORT_LVGL_DEF, which is different from the link of @cidermore. I am a bit confused about this.

  • About the MICROPY_PORT_LVGL_DEF, I tried to did the same thing as MICROPY_PORT_LVGL_DEF was used in esp32. And I received this error:
    2019-12-12 2019-12-12.png

What version of mpconfigport.h should I refer to?

Once again, sorry for replying late.

I also see some lines of code about ESPIDF, LODEPNG, and RTCH. Do i need to add that into my code?

The ESP32 is officially supported (while stm32 not yet), so you’d better look at the mpconfigport.h from the ESP32 port.
The important parts are:

#define MICROPY_PY_LVGL                     (1)
...
extern const struct _mp_obj_module_t mp_module_lvgl;
...
#if MICROPY_PY_LVGL
#define MICROPY_PORT_LVGL_DEF \
    { MP_OBJ_NEW_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl }, 
#else
#define MICROPY_PORT_LVGL_DEF
#endif

#define MICROPY_PORT_BUILTIN_MODULES \
    ... \
    MICROPY_PORT_LVGL_DEF \

#if MICROPY_PY_LVGL
#include "lib/lv_bindings/lvgl/src/lv_misc/lv_gc.h"
#else
#define LV_ROOTS
#endif

#define MICROPY_PORT_ROOT_POINTERS \
    LV_ROOTS \
    ...

It’s a bit strange that your stm32 libraries don’t include strncpy, don’t you think?
You can implement it yourself if it’s missing. Here is what I found from a quick search on the internet: https://github.com/bjornfor/stm32-test/blob/master/baselibc/src/strncpy.c

These are additional (optional) ESP32-specific C libraries. ESPIDF provides API to ESP32 hardware and peripherals, RTCH is a resistive touch driver.
I guess you don’t need them.
LODEPNG decodes png files, it is not ESP32 specific, you can use it if you want.

Hi @amirgon

I followed the ESP32 version and had important parts like you mentioned.

Also, as I deleted { MP_OBJ_NEW_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl } under STM_BUILTIN_MODULE, the error of strncpy has gone.

However, I still have an issue of “ImportError: no module named ‘lvgl’”. I don’t know what i miss.

Do i need a real display module to be able to “import lvgl as lv”?

Also, how can i post a link to Github here, “Sorry you cannot post a link to that host.” constantly appears. I want to post a link of Github to my mpconfigport.h file.
Thank you.

The reason you can’t import lvgl is that you deleted { MP_OBJ_NEW_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl } under STM_BUILTIN_MODULE.
This is not the right way to solve the strncpy problem.

Please put it back and provide an implementation for strncpy as I suggested above.

No. You can use lvgl without a display (although it’s a bit pointless as you will not be able to see anything)

@kisvegabor, @embeddedt any idea why @Huy_Nguyen_Duc_Huy is getting these errors? There’s probably a problem with the forum’s settings.

Odd. It let me post a link to GitHub without any problems (maybe because I’m a moderator). I’ll have a look in the settings.

I’ve added GitHub to the list of whitelisted spam domains. @Huy_Nguyen_Duc_Huy can you try it and see if it works now?

1 Like

Hi @amirgon,

you are right! I add the definition of function “strncpy” in the lib/lv_bindings/lvgl/src/lv_objx/lv_chart.h. And it works well.

Here is my file mpconfigport.h: lv_micropython/ports/stm32/mpconfigport.h at huy_stm32f4 · huynguyennguyen/lv_micropython · GitHub

Thank you very much@amirgon. I guess the procedure is similar on STM32L4R9DISC.