notro / gud-pico

Raspberry Pi Pico GUD USB Display
Other
22 stars 6 forks source link

Building for 240x240 resolution causes framebuffer size to exceed available RAM #5

Closed ryjelsum closed 3 months ago

ryjelsum commented 3 months ago

I attempted to build this project for my own ST7789 LCD, which is 240x240. With this resolution (and the other modification noted in the issues to make this project build on pico-sdk 1.5.1) the build fails:

[ 55%] Linking CXX executable pico_display.elf
/nix/store/rll3lcl70glldsfsrfpz87kn5qszvcks-gcc-arm-embedded-12.3.rel1/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld: pico_display.elf section `.bss' will not fit in region `RAM'
/nix/store/rll3lcl70glldsfsrfpz87kn5qszvcks-gcc-arm-embedded-12.3.rel1/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld: region RAM overflowed
/nix/store/rll3lcl70glldsfsrfpz87kn5qszvcks-gcc-arm-embedded-12.3.rel1/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld: region `RAM' overflowed by 90372 bytes
collect2: error: ld returned 1 exit status
make[2]: *** [examples/pico-display/CMakeFiles/pico_display.dir/build.make:1287: examples/pico-display/pico_display.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:1776: examples/pico-display/CMakeFiles/pico_display.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

With the default setting of WIDTH = 240 and HEIGHT = 135, the build succeeds. If you look at the memory map in build/examples/pico-display/pico-display.elf.map, after the failed build for 240x240 resolution, you will see that the increased size of the framebuffer from this modification makes memory allocation exceed the 0x20000000-0x20040000 range.

Memory Configuration

Name             Origin             Length             Attributes
FLASH            0x10000000         0x00200000         xr
RAM              0x20000000         0x00040000         xrw
SCRATCH_X        0x20040000         0x00001000         xrw
SCRATCH_Y        0x20041000         0x00001000         xrw
*default*        0x00000000         0xffffffff

[...]

 .bss.e15_last_sof
                0x20039a8c        0x4 CMakeFiles/pico_display.dir/nix/store/6j83icrxb2x68b7wa5as04prfdxviycl-pico-sdk-1.5.1/lib/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c.obj
                0x20039a8c                e15_last_sof
 .bss.filter    0x20039a90        0x4 CMakeFiles/pico_display.dir/nix/store/6j83icrxb2x68b7wa5as04prfdxviycl-pico-sdk-1.5.1/lib/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj
 .bss.framebuffer
                0x20039a94    0x1c200 CMakeFiles/pico_display.dir/pico-display.c.obj
 .bss.hw_endpoints
                0x20055c94      0x400 CMakeFiles/pico_display.dir/nix/store/6j83icrxb2x68b7wa5as04prfdxviycl-pico-sdk-1.5.1/lib/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c.obj

(My technical language here may be a little bit inexact, I hope this describes the issue sufficiently.)

This is more informational than anything else, for anyone else who may run into this issue trying to use this - I don't expect any action to be taken on this, since this project is not being actively developed.

Side note - thank you, notro, for your hard work in general - you make a lot of very useful projects and I've found myself using your work in the Linux kernel without knowing it many times :)

notro commented 3 months ago

It is possible have a look at the mi0283qt example. The downside is that the host driver have to split full framebuffer updates into two transfers. max_buffer_size specifies the maximum transfer (or receive buffer) size. See gud_flush_damage() in the host driver. You can also disable compression to avoid the decompression buffer, but that will most likely hurt your framerate (depending on use case I guess).

ryjelsum commented 3 months ago

Hey again, thanks for your guidance. Because of your advice to compare the two examples, I've managed to get it working with my 240x240 display, though not quite the way you said - I noticed there was a buffer_test allocated in pico_display.c but not the mi0283qt.c example that was only used by some code that didn't seem reachable without uncommenting some stuff in the pixel_formats array, and all of this code was completely missing in the mi0283qt example, so I commented out that buffer and all of the code that references it and it successfully compiled for 240x240 resolution. Didn't need to set the max_buffer_size. It looked like it just barely made it, though, I don't think this would work for anything higher. Further changes were also necessary to make it work with my particular LCD, but I've figured it out in the end.

For anybody interested I've made the changes available in a fork on my profile, in the st7789-240x240 branch. I've tried to explain my changes, hopefully it helps someone out, and I may take this a little bit further :)