Skip to content

allocating frame buffers in SPIRAM fails on ESP32-S3 w/ rgb_display #192

@h-milz

Description

@h-milz

Hi,

I am trying to get my build to run with the CrowPanel 5.0"-HMI ESP32 Display sporting a ESP32-S3-WROOM-1-N4R8 module. The build was made with

python3 make.py esp32 BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT --flash-size=4 PORT=/dev/ttyUSB0 INDEV=gt911 DISPLAY=rgb_display clean

with CONFIG_LCD_ENABLE_DEBUG_LOG set in sdkconfig.board.

It seems that when initializing the display driver, allocating frame buffer memory in SPIRAM fails. The display resolution is 800*480, hence the 768000 bytes below at 16bpp.

At the moment I am trying to replicate the ST7796 example with the display_bus changed to lcd_bus. When I run the routine as in the example:

display_bus = lcd_bus.RGBBus(
    hsync = _HSYNC,
    vsync = _VSYNC,
    de = _DE,
    pclk = _PCLK,
    data0 = _DATA0,
    ...
    pclk_idle_high = False,
)

# we are going to let the display driver sort out the best freame buffer size and where to allocate it to.
#fb1 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)
#fb2 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)

import rgb_display
import lvgl as lv

display = rgb_display.RGBDisplay(
    data_bus=display_bus,
    display_width=_WIDTH,
    display_height=_HEIGHT,
    # frame_buffer1 = fb1,
    # frame_buffer2 = fb2,
    backlight_pin=_BACKLIGHT,
    color_space=lv.COLOR_FORMAT.RGB565,
    color_byte_order=rgb_display.BYTE_ORDER_RGB,
    # rgb565_byte_swap=True,
)

then I get the message

rgb_allocate_framebuffer(self, size=768000, caps=2056)
rgb_allocate_framebuffer(self, size=768000, caps=1032)
rgb_allocate_framebuffer(self, size=768000, caps=2048)
rgb_allocate_framebuffer(self, size=768000, caps=1024)
Traceback (most recent call last):
File "boot.py", line 103, in
File "rgb_display.py", line 38, in init
File "rgb_display_framework.py", line 42, in init
File "display_driver_framework.py", line 205, in init
MemoryError: Unable to allocate memory for frame buffer (768000)

The 4 allocate_framebuffer calls come from class DisplayDriver in ./api_drivers/lvgl_api_drivers/frozen/display/display_driver_framework.py, where if frame_buffer1 is None, the code attempts to allocate memory in the following sequence beginning in line 189, until one calls succeds:

                for flags in (
                    lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA,
                    lcd_bus.MEMORY_SPIRAM | lcd_bus.MEMORY_DMA,
                    lcd_bus.MEMORY_INTERNAL,
                    lcd_bus.MEMORY_SPIRAM
                ):

It appears that none succeeds. Sure, there is not enough internal memory, but MEMORY_SPIRAM should succeed because the heap is just shy of 8 MB after system start, as determined using gc.mem_free().

If I allocate small buffers manually using MEMORY_INTERNAL, the heap_caps_calloc() call succeeds but needless to say that the buffers are just too small. In this case, the display driver code tries to allocate a larger buffer but fails as well:

rgb_allocate_framebuffer(self, size=1024, caps=2056)
rgb_allocate_framebuffer(self, size=1024, caps=2056)
Traceback (most recent call last):
File "boot.py", line 103, in
File "rgb_display.py", line 38, in init
File "rgb_display_framework.py", line 42, in init
File "display_driver_framework.py", line 101, in init
MemoryError: memory allocation failed, allocating 1107657580 bytes

Heaven knows where this large number comes from. FWIW, the error message is produced in ./lib/micropython/py/runtime.c.

When I try to preallocate the framebuffers using MEMORY_SPIRAM, the following happens:

rgb_allocate_framebuffer(self, size=1024, caps=1032)
Traceback (most recent call last):
File "boot.py", line 87, in
MemoryError: Not enough memory available (1024)

And this is with a tiny 1KB buffer. Line 87 is

fb1 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_SPIRAM | lcd_bus.MEMORY_DMA)

Does anyone have an idea what goes wrong here?

TIA!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions