Flash footprint of lvgl is high ! How to reduce it?

Description

I interfaced lvgl library with my microcontroller. Everything works great, except one issue:
The flash memory footprint is high.
Here is what I found out after I integrated lvgl library into my project:

Case1: I disabled almost everything in lv_config.h:
lvgl RAM usage: 32,660 bytes
lvgl Flash usage: 170,012 bytes

Case 2: I enabled only button, and label in lv_config.h, everything else is disabled:
lvgl RAM usage: 32,664 bytes
lvgl Flash usage: 178,424 bytes

Case 3: I enabled the most common user interface objects, no animation or file system:
lvgl RAM usage: 32,984 bytes
lvgl Flash usage: 295,640 bytes

I had to add to my project 57 (.h) header files, and 74 (.c) source files from lvgl to get it to compile,
and link without errors even though I am not using most of them.
Yes, I used linker option: -gcc-sections. Adding these files is what consumes the flash…
Flash usage is the biggest problem. My micro has only 512K, so when almost 300K is used by lvgl I will have little left for my program.
The lvgl web page says: “64 kB flash and 8 kB RAM is enough for a simple user interface”
Has anyone been successful creating GUI with this footprint ?
If so, could you please share how did you do it ?

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

PIC32MX

What LVGL version are you using?

8.0.2

What do you want to achieve?

Want to reduce the memory footprint

What have you tried so far?

Used linker option: -gcc-sections

Code to reproduce

None

Screenshot and/or video

None

You need to pass -ffunction-sections -fdata-sections to the compiler in order for the --gc-sections linker option to be effective.

1 Like

Do you use cmake? Then lvgl is build as static Lib and I experience similar size problems. When I change to build an interface Lib, the size is about half of the static lib size. So it depends heavily on the optimization.

I just added it, and indeed it did make big drop in flash usage: over 100K.
So, now, if enabling minimal(button, label, one font) it is taking only 77K of flash.
I am ok with this.

Thanks a lot embeddedt.

1 Like

Good tip.

I have a couple of questions:

  1. Does this compiler optimization and size reduction has some penalties, such as speed reduction?
  2. How can I perform this in the STM32 CubeIDE? Is it here? (image below)

I’m not 100% sure, but I don’t think using this option would have significant impact on the speed of the code, and the benefit of dead code simply not being included in your binary would probably be worth a minor speed reduction anyways.

It looks like those are the linker flags; they appears to already be set up correctIy.

The -ffunction-sections and -fdata-sections options are under MCU GCC Compiler → Optimization, if I recall correctly. However, I wouldn’t be surprised to find they’re already enabled in a Cube project.

1 Like

Thanks.

This is the Optimization tab, it seems it can be selected (Os). If it makes the same effect as your offered flags do. In my case, “Os” selection caused 40K reduction in the used flash size.

That’s a separate option, but I would definitely advise choosing it anyways. The other two options are right underneath in your screenshot.

1 Like