how to allocate more heap for 16mb version?

societyofrobots
Posts: 13
Joined: Fri Oct 02, 2020 9:32 pm

how to allocate more heap for 16mb version?

Postby societyofrobots » Sun Nov 28, 2021 3:42 am

I have the 16mb version and I'm trying to allocate more heap, but not sure how to do it.

ESP.getHeapSize() gives me 255kb

ESP.getMaxAllocHeap() gives me 65kb

I see this here, but is this true for just the 4mb version, or also the 16mb version as well?
Due to a technical limitation, the maximum statically allocated DRAM usage is 160KB. The remaining 160KB (for a total of 320KB of DRAM) can only be allocated at runtime as heap.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: how to allocate more heap for 16mb version?

Postby WiFive » Sun Nov 28, 2021 4:57 am

To get more heap you need psram not a bigger flash.

username
Posts: 477
Joined: Thu May 03, 2018 1:18 pm

Re: how to allocate more heap for 16mb version?

Postby username » Sun Nov 28, 2021 7:27 pm

You can set the heap in menuconfig

societyofrobots
Posts: 13
Joined: Fri Oct 02, 2020 9:32 pm

Re: how to allocate more heap for 16mb version?

Postby societyofrobots » Mon Nov 29, 2021 2:59 am

WiFive wrote:
Sun Nov 28, 2021 4:57 am
To get more heap you need psram not a bigger flash.
My PCB uses the WROOM formfactor, which doesn't have PSRAM:
https://www.digikey.com/en/products/det ... B/11613125

It has 536kB SRAM... how would I use this full amount for heap, as currently ESP.getHeapSize() says I only have 255kb?

edit: I just found this post which basically says I'm plain out of luck:
The ESP32 has 512K of RAM. Some of that is used as cache for code loaded from firmware. Some of that is used for writable variables in your application (.bss and .data). Some of it is used for internals workings of ESP-IDF (including FreeRTOS). What is left is available to you as heap. When you called:

heap_caps_get_free_size(MALLOC_CAP_8BIT)

You were told how much RAM remains on the heap for future allocation by your running applications.

The best source of knowledge of RAM layout and usage is the ESP32 Technical Reference manual. Also realize that the heap size shown at the very start of an application will diminish quickly as you start leveraging major subsystems like WiFi, TCP/IP and BLE as they will carve out what they need from the same heap.

Who is online

Users browsing this forum: Majestic-12 [Bot], zelenecul and 139 guests