m5stack / CoreS3-UserDemo

CoreS3 user demo for hardware evaluation.
14 stars 6 forks source link

Use PSRAM with DMA #1

Open chillymattster opened 4 months ago

chillymattster commented 4 months ago

Hi there,

I'm trying to understand this very helpful UserDemo to get prepared for my own project with a CoreS3.

Taking a deeper look at function m5gfx_lvgl_init, I wondered if there is a special reason to not use PSRAM in DMA mode for the lvgl buffers. Currently the buffers are created like this:

void m5gfx_lvgl_init(void) {
    static lv_color_t *buf1 = (lv_color_t *)heap_caps_malloc(
        LCD_WIDTH * 80 * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
    static lv_color_t *buf2 = (lv_color_t *)heap_caps_malloc(
        LCD_WIDTH * 80 * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);

I wonder if it wouldn't be beneficial to make use of the ESP32-S3 DMA capabilities, like this:

void m5gfx_lvgl_init(void) {
    static lv_color_t *buf1 = (lv_color_t *)heap_caps_malloc(
        LCD_WIDTH * 80 * sizeof(lv_color_t), MALLOC_CAP_DMA | MALLOC_CAP_SPIRAM);
    static lv_color_t *buf2 = (lv_color_t *)heap_caps_malloc(
        LCD_WIDTH * 80 * sizeof(lv_color_t), MALLOC_CAP_DMA | MALLOC_CAP_SPIRAM);

I'm not a pro developer, so unfortunately I cannot say if there would be more changes needed to use DMA but in general it seems to be a good idea for me to utilize the capabilities of the ESP32-S3 to reduce CPU load.

Any thoughts and hints or maybe even an updated version of this great demo are highly appreciated ☺️

Cheers

imliubo commented 4 months ago

Hi @chillymattster , Good question, there has some docs you can check:: dma-capable-memory external-ram restrictions

chillymattster commented 4 months ago

Hi @imliubo,

thanks for answering 😃 Unfortunately I'm not a professional embedded developer so I have serious doubts that I would be able to implement DMA capabilities in lvgl or this demo by myself. I don't even know if it is actually even possible for an experienced developer to do it or if there are limitations preventing the use of DMA for lvgl. As said, I was just wondering if it is possible and if yes, if you are considering to integrate it in the demo to have an example on how to do it for users that are on a less skilled development level. Of course only, if it is beneficial in any point, maybe there is just no advantage in using DMA for this case. 😃

imliubo commented 3 months ago

Hi @chillymattster , Answer at first, it is possible but not recommend. As we all know, the ESP32-S3 has internal SRAM, it around 500KB(not an exact number), however, most of the SRAM is needed for Wi-Fi and BLE, as well as for FreeRTOS.So if you want use lvgl with DMA, you will need allocate the draw buffer and the lvgl memory pool from the internal SRAM, which will consume a significant amount. If you don't have enough SRAM to use, you'll need external PSRAM, check these docs for some important restrictions to be aware of. It’s best to use octal PSRAM, although, unfortunately, cores3 does not support it.