Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDRAM, malloc and/or buffer defined in sketch, or in device tree? #26

Open
KurtE opened this issue Dec 27, 2024 · 1 comment
Open

SDRAM, malloc and/or buffer defined in sketch, or in device tree? #26

KurtE opened this issue Dec 27, 2024 · 1 comment

Comments

@KurtE
Copy link

KurtE commented Dec 27, 2024

Describe the bug
Short description: How should a sketch do memory allocations?

For example: Suppose I have an SPI display, currently using an ILI9341 which is 320 by 240 with RGB565. But might go to larger
display like ST7796 or ILI9488 which are 480 by 320. And I wish to allocate at least one full buffer for the display, maybe two.
For example, maybe I wish to have one image being read in from an SD drive and the other buffer being used to display an already
loaded buffer (and then swap)...

Currently trying stuff out on GIGA.

Note: my .conf file is already modified to allow some larger sketches to be loaded:
including:

CONFIG_SHELL_STACK_SIZE=32768
CONFIG_MAIN_STACK_SIZE=32768
CONFIG_LLEXT_HEAP_SIZE=128

Simply define it as part of the sketch:
Even with this, when I define the buffer in a sketch, like:
uint16_t frame_buffer[320 * 240] __attribute__((aligned(16)));
The sketch fails to run and the debug output:

uart:~$ sketch
[00:00:20.212,000] <err> llext: Failed to copy regions, ret -12

Malloc:
malloc of this size appears to work:

SDRAM.malloc()
Is not in implemented in the current stuff:
@mjs513 hacked up a version that appears to run:
ea_malloc.zip
Which includes ea_malloc library and a hacked up SDRAM library with hard coded address to start of SDRAM.

I was also trying to generate a version of SDRam, that was trying to use the kernel k_heap code like:

#define CONFIG_SDRAM_BUFFER_MAX 400000
extern "C" {
static struct k_heap sdram_pool;
__stm32_sdram1_section
__aligned(32) static uint8_t sdram_pool_buf[CONFIG_SDRAM_BUFFER_MAX];
}

int SDRAMClass::begin(uint32_t start_address) {
  UNUSED(start_address);
  k_heap_init(&sdram_pool, sdram_pool_buf, CONFIG_SDRAM_BUFFER_MAX);
  _begin_called = true;
  return 1;

}

void* SDRAMClass::malloc(size_t size) {
  if(!_begin_called) begin();

	return k_heap_alloc(&sdram_pool, size, K_NO_WAIT);
}

void SDRAMClass::free(void* ptr) {
	k_heap_free(&sdram_pool, ptr);
}

DRAMClass SDRAM;

But this code fails to load. Not sure about which segment ... to use. But this fails to load, again
with the failed to load region.

Device tree:
I noticed that you have a couple of branches in the Zephyr project where you have experimented with a few different devices, (GIGA Shield, and Camera) where it looks like you were allocating buffers in other areas by defining them into the device tree and overlays.
Is this the preferred way?

Would this then require us each time we change to a different display driver to update the device tree, do the build.sh, burn the bootloader and then load the sketch?

Thanks
Kurt

@mjs513
Copy link

mjs513 commented Dec 27, 2024

Just to be complete the overlay file we are using includes the changes in the open PR with the &fmc changes from the branches that @KurtE already mentioned:

arduino_giga_r1_m7.zip

in addition it includes the changes I made to llext_exports.c file

llext_exports.zip

Was tested with the following sketch. Was something that PJRC put together to test PSRAM but modified for Giga SDRAM.

GIGA_SDRAM_TEST-241227a.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants