What do you want to achieve?
I want to create custom functions for Lvgl memory allocator and that compilation and linking work.
What have you tried so far?
I downloaded Lvgl from “ESP Component Registry”.
In esp-idf menuconfig, inside Lvgl component config , i select the option “implement the function externally” in “Malloc functions source”.
I created the malloc families functions inside my components folder in my project folder.
C:\esp32-Proj\proj\components\lv_mem_custom_alloc\src\include\lv_mem_custom_alloc.h
C:\esp32-Proj\proj\components\lv_mem_custom_alloc\src\lv_mem_custom_alloc.c
C:\esp32-Proj\proj\components\lv_mem_custom_alloc\CMakeLists.txt
Lvgl folder stay located in managed_components folder inside my project folder.
C:\esp32-Proj\proj\managed_components\lvgl__lvgl
I tried using inline functions too in a .h file, but no luck.
When compiling project, at linker stage, the linker show undefined reference to.
Doubts
How do I get lvgl to recognize(link) my components folder (subfolder inside components folder) ?
C:\esp32-Proj\proj\components\lv_mem_custom_alloc
What are all the functions that need to be defined, which ones are mandatory, and how do I define / write mem_init() if needed ?
There’s a memory_init() function that I’m not sure it is necessary. I think only malloc(), realloc() and free() would be needed, but it seems I need to define other functions as well.
Is there any documentation on how to do this ?
Code to reproduce
lv_mem_custom_alloc.h file:
void* lv_malloc_core(size_t size);
void* lv_realloc_core(void* ptr, size_t size);
void lv_free_core(void* ptr);
lv_mem_custom_alloc.c file:
void* lv_malloc_core(size_t size)
{
return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT, MALLOC_CAP_SPIRAM);
}
void* lv_realloc_core(void* ptr, size_t size)
{
return heap_caps_realloc_prefer(ptr, size, 2, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT, MALLOC_CAP_SPIRAM);
}
void lv_free_core(void* ptr)
{
heap_caps_free(ptr);
}
Notes:
- The project is running (without custom memory allocator), but sometimes, i think, that “normal” allocator cannot allocate memory, and the system crash or the task running lvgl crash.
- Bot Challenge
Environment
ESP32-S3
ESP-IDF 5.5.3 with visual studio code
LVGL 9.4.0
Custom board.