Page 1 of 1

how to allocate more heap for 16mb version?

Posted: Sun Nov 28, 2021 3:42 am
by societyofrobots
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.

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

Posted: Sun Nov 28, 2021 4:57 am
by WiFive
To get more heap you need psram not a bigger flash.

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

Posted: Sun Nov 28, 2021 7:27 pm
by username
You can set the heap in menuconfig

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

Posted: Mon Nov 29, 2021 2:59 am
by societyofrobots
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.