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

Tobi82m
Posts: 23
Joined: Wed Feb 16, 2022 9:10 am

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

Postby Tobi82m » Wed Jul 20, 2022 9:15 am

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.

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Wed Jul 20, 2022 9:19 am

Given you enabled psram in menuconfig, heap_caps_malloc() with the proper arguments or a plain malloc() should work.

Tobi82m
Posts: 23
Joined: Wed Feb 16, 2022 9:10 am

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

Postby Tobi82m » Wed Jul 20, 2022 9:30 am

Have i to enable "Support for external, SPI-connected RAM"? Its on my ESP32-S3 board

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Wed Jul 20, 2022 10:22 am

Yes. 'External' here means 'not on the CPU die'.

Tobi82m
Posts: 23
Joined: Wed Feb 16, 2022 9:10 am

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

Postby Tobi82m » Wed Jul 20, 2022 1:04 pm

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?

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Thu Jul 21, 2022 2:14 am

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.

Tobi82m
Posts: 23
Joined: Wed Feb 16, 2022 9:10 am

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

Postby Tobi82m » Fri Jul 22, 2022 6:24 am

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.

Tobi82m
Posts: 23
Joined: Wed Feb 16, 2022 9:10 am

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

Postby Tobi82m » Fri Jul 22, 2022 6:51 am

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

Tobi82m
Posts: 23
Joined: Wed Feb 16, 2022 9:10 am

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

Postby Tobi82m » Fri Jul 22, 2022 7:26 am

It works...there was wrong settings in menuconfig

Who is online

Users browsing this forum: No registered users and 345 guests