freetype for MCU
The "freeType" library tested in LVGL emulator is normal, can "LVGL + FreeType" add support for MCU?
It'a certainly possible to build FreeType on MCUs but it requires some adjustments on FreeTypes build system.
I moved this issue to the FreeType repo.
As I understand it, this library is not compatible with MCUs, but it is compatible with simulators, right?
FreeType can run on sufficiently powerful MCUs as well. I have used it on STM32 before, though not with LVGL.
FreeType can run on sufficiently powerful MCUs as well. I have used it on STM32 before, though not with LVGL.
Some MCUs do not support the C File API(fopen, etc).
EDIT: Does lv_lib_freetype supports ESP32?
I saw some implementations on ESP32, but it's unrelated to LVGL so I can't comment much on it.
I added freetype support to lvgl in Tasmota on Esp32. It runs fine but you need to be cautious about memory and stack size. The default 8kb stack is insufficient for freetype. I suppose similar MCUs will work with the same constraints.
I added freetype support to lvgl in Tasmota on Esp32.
That's great! Can share some details about how did you port FreeType to ESP32?
I agree with @kisvegabor. It would be great to support ESP32.
I added freetype support to lvgl in Tasmota on Esp32.
That's great! Can share some details about how did you port FreeType to ESP32?
Sure, and sorry for the late response.
First FreeType compiles out of the box on ESP32, so it does not require specific work here. The main problem is that calling get_glyph_dsc_cb() consumes more than 16KB of stack whereas the default ESP32 stack is 8KB. This yields to a crash.
Currently I run get_glyph_dsc_cb() in a separate FreeRTOS task with 24KB of stack allocated and pass parameters through a queue. I'm not satisfied with the solution and discovered in between that esp-idf has a function to pass a temporary stack bigger than the default one.
Here is the patched code: https://github.com/arendst/Tasmota/blob/development/lib/libesp32_lvgl/lv_lib_freetype/lv_freetype.c
That's great, thank you for the explanation!
I'm also looking into adding this functionality to my ESP32 project. Thanks @s-hadinger for sharing your solution!
I discovered in between that esp-idf has a function to pass a temporary stack bigger than the default one.
Are you refering too Call function with external stack?
Yes. That's the one. I will switch to this method which is simpler
I've also made a wrapper here for someone who needs it: https://github.com/huming2207/esp-ft2
Currently:
- It may cause crashing due to the stack overflow issue (stack is too small)
- May need this patch to allow LVGL to know my wrapper's existence: https://github.com/lvgl/lvgl/pull/3240
It may cause crashing due to the stack overflow issue (stack is too small)
Which stack do you mean?
Which stack do you mean?
As per @s-hadinger mentioned, the task that eventually does get_glyph_dsc_cb() needs to be big enough, otherwise it will crash due to stack overflow.
In my experience you need 24KB of CPU native stack to have Freetype run correctly. This gives 3 options:
- Resize your main stack's to 24KB
- Run
get_glyph_dsc_cb()in a separate RTOS stack with a stack sized at 24KB - Use esp-idf
esp_execute_shared_stack_function()to swap the stack with a 24KB memory chunk for this call
In my experience you need 24KB of CPU native stack to have Freetype run correctly. This gives 3 options:
Yep. For our scenario, we can just increase the main thread's stack to be 32KB as we also have a lot of other stuff that needs the stack memory anyway.
I think the right way of doing this is probably to spin up a FreeRTOS task with 24KB stack in the init function, that wait and deal with FT2, and pass the data over a FreeRTOS queue to the real get_glyph_dsc_cb() and pass the result back to LVGL. Otherwise I don't know how to pass the arguments when using esp_execute_shared_stack_function() - unless if we use global variables (which I'd prefer avoid doing that).
This is what I did the first time, because I couldn't increase the main stack. But it's a little more complicated to do.
Glad to use add this(LVGL+Freetype) into my ESP32 project. But my concern is the resource constraint because my project also use so much space and cpu. Can you share some info on resources usage of this Freetype?
Currently, we are using ESp32-WROOM but I can use ESP32-Wrover if it's suitable.
Thanks;
Everything is explained above. You need at least 24KB of stack when calling Freetype. It's really stretched if you don't have a PSRAM.