How to get LVGL to use PSRAM on ESP32 arduino

Hey guys,

As per title, I’ve been trying to figure out how to get LVGL to use the PSRAM on my esp32-wrover, but after hours of searching, I can’t seem to find any articles or advice on how to accomplish it!

Any help would be much appreciated!

Thanks,
Not-the-messiah

1 Like

Could you solve the problem?

what do u want to store in external psram? videobuffer? objects?

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/external-ram.html
check this link.
there is 2 solutions i think that would work

  1. setup memory mapping for entire esp32 (as described in espressif appnote)
  2. add some sort of HAL that will use ur custom alloc,malloc methods and will handle read write operations from/to external ram and force lvgl to use them by defining them in configuration file.
1 Like
import espidf as esp
import lvgl as lv

factor = 8
width = 320
height = 480

buf_size = (width * height * lv.color_t.__SIZE__) // factor
disp_buf = lv.disp_draw_buf_t()


buf1 = esp.heap_caps_malloc(buf_size, esp.MALLOC_CAP.SPIRAM)
buf2 = esp.heap_caps_malloc(buf_size, esp.MALLOC_CAP.SPIRAM)

disp_buf.init(buf1, buf2, buf_size // lv.color_t.__SIZE__)

in MicroPython code for the esp32 it would be the following which isn’t all that far off what it would be in C code

on latter version of the ESP32 like the ESP32-S3 the SPIRAM is also DMAable. so using the following you can direct what memory the frame buffers should use

DMA that is available anywhere: MALLOC_CAP.DMA
DMA in spi ram: MALLOC_CAP.DMA | MALLOC_CAP.SPIRAM
DMA in internal ram: MALLOC_CAP.DMA | MALLOC_CAP.INTERNAL

if not using DMA memory

anywhere: MALLOC_CAP.DEFAULT
spi ram: MALLOC_CAP.SPIRAM
internal ram: MALLOC_CAP.INTERNAL