Description
I want to allocate memory from LV_STDLIB_BUILTIN to use PSRAM with ps_malloc
on ESP32. Is this possible, and how can it be done?
Thank you.
What MCU/Processor/Board and compiler are you using?
ESP32, ESP32S3
What LVGL version are you using?
v9.2.2
What do you want to achieve?
use PSRAM with ps_malloc
for widgets
in your sdkconfig file you need to set
CONFIG_SPIRAM_USE_MALLOC=y
optionally you can use menuconfig to configure the project and you can locate that setting in Component config > ESP PSRAM > CONFIG_SPIRAM > SPI RAM config
also I an not sure what ps_malloc
is because it is not in the SDK for the ESP32. The memory allocation function for the ESP32 begin with heap_caps_
.
Thank you for your response.
Currently, I am using the Arduino platform, and PSRAM has been successfully set up using ESP-IDF as you suggested earlier.
Now, I want to use ps_malloc(…) to replace the default LV_STDLIB_MALLOC, which is currently set to LV_STDLIB_BUILDIN. I intend to change it to LV_STDLIB_CUSTOM in lv_conf.h.
However, I am unsure how to configure it when using LV_STDLIB_CUSTOM. Specifically, how should I set ps_malloc(…) to be called as a custom allocation function?
In earlier versions of LVGL, it was possible to replace malloc with an external function like ps_malloc(…). However, in LVGL 9.x, I don’t understand how to configure this for using external malloc ( ps_malloc(…) .
If you open up src/stdlib/builtin/lv_mem_core_builtin.c
in lvgl you will see all of the different memory functions. You need to create your own version of all of those functions. Then set LV_USE_STDLIB_MALLOC
to LV_STDLIB_CUSTOM
make sure in the C course file that contain your versions of the functions that you include src/stdlib/lv_mem.h
as that is where the function prototypes are
This doesn’t seem reasonable; do I need to implement every function in lv_mem.h?
Hi, did you ever manage to resolve this ? I have an ESP32S3 now and can’t succeed using PSRAM in any way. Thanks.
for the ESP32 it’s a setting you need to set in the ESP-IDF menuconfig to get the memory to be used.
Why not just setup the conf LV_ATTRIBUTE_LARGE_RAM_ARRAY
to EXT_RAM_BSS_ATTR
in lv_conf.h
In my projects (using esp-idf and cmake) I add this to CMakeLists.txt
add_compile_definitions(CONFIG_LV_ATTRIBUTE_LARGE_RAM_ARRAY=EXT_RAM_BSS_ATTR)
Since the option doesn’t show in menuconfig
, it uses LVGL internal memory manager with a static buffer (set size with LV_MEM_SIZE
), but the buffer is allocated in the external SPIRAM.
Obviously SPIRAM must be enabled in the project configuration…