Page 1 of 1

How to allocate a big array on ESP32-S3 (8MB Flash,8MB PSRAM)

Posted: Wed Jul 20, 2022 9:15 am
by Tobi82m
I have a int32 array with up to 4MB. How can i allocate Memory for this Array?
I tried with heap_caps_malloc but it dont work.

Re: How to allocate a big array on ESP32-S3 (8MB Flash,8MB PSRAM)

Posted: Wed Jul 20, 2022 9:19 am
by ESP_Sprite
Given you enabled psram in menuconfig, heap_caps_malloc() with the proper arguments or a plain malloc() should work.

Re: How to allocate a big array on ESP32-S3 (8MB Flash,8MB PSRAM)

Posted: Wed Jul 20, 2022 9:30 am
by Tobi82m
Have i to enable "Support for external, SPI-connected RAM"? Its on my ESP32-S3 board

Re: How to allocate a big array on ESP32-S3 (8MB Flash,8MB PSRAM)

Posted: Wed Jul 20, 2022 10:22 am
by ESP_Sprite
Yes. 'External' here means 'not on the CPU die'.

Re: How to allocate a big array on ESP32-S3 (8MB Flash,8MB PSRAM)

Posted: Wed Jul 20, 2022 1:04 pm
by Tobi82m
uint32_t *data = heap_caps_malloc(50000*(sizeof(uint32_t)),MALLOC_CAP_SPIRAM);

With this i get a "Store probihited" error. Is there a example to allocate the PSRAM?

Re: How to allocate a big array on ESP32-S3 (8MB Flash,8MB PSRAM)

Posted: Thu Jul 21, 2022 2:14 am
by ESP_Sprite
That's normally not something that can give you a store prohibited error... can you post your complete project? There's not really a psram example as it normally is not something people have issues with.

Re: How to allocate a big array on ESP32-S3 (8MB Flash,8MB PSRAM)

Posted: Fri Jul 22, 2022 6:24 am
by Tobi82m
I think the declaration is ok and i get no error. But if i write data on it it crashed.

With ESP_LOGI (TAG, "heap_caps_get_free_size: %d\n", heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
i get a size of 0. I dont know whats wrong.

Re: How to allocate a big array on ESP32-S3 (8MB Flash,8MB PSRAM)

Posted: Fri Jul 22, 2022 6:51 am
by Tobi82m

Code: Select all

    uint32_t *data = heap_caps_malloc(50000*(sizeof(uint32_t)),MALLOC_CAP_SPIRAM);
    
    heap_caps_print_heap_info(MALLOC_CAP_SPIRAM);
the answer:

Code: Select all

Heap summary for capabilities 0x00000400:
  Totals:
    free 0 allocated 0 min_free 0 largest_free_block 0

Re: How to allocate a big array on ESP32-S3 (8MB Flash,8MB PSRAM)

Posted: Fri Jul 22, 2022 7:26 am
by Tobi82m
It works...there was wrong settings in menuconfig