The module has 2 MB PSRAM and I enabled it in the config with these option (some other options were set but they didn't look relevant to this question):
Code: Select all
CONFIG_ESP32_SPIRAM_SUPPORT=y
CONFIG_SPIRAM_USE_CAPS_ALLOC=y
BEFORE adding PSRAM, I logged free heap like this:
Code: Select all
ESP_LOGI(TAG, "Free Heap: %u bytes", xPortGetFreeHeapSize());
AFTER adding PSRAM, this log message reported 2113379 bytes, so it looks like it's including the PSRAM. However, I want to report the free internal RAM, NOT PSRAM, so I can measure the effects of shifting various buffers to PSRAM.
I then tried logging a number of different "free size" measurements like this:
Code: Select all
ESP_LOGI(
TAG,
"Free Heap: %u bytes\n"
" MALLOC_CAP_8BIT %7zu bytes\n"
" MALLOC_CAP_DMA %7zu bytes\n"
" MALLOC_CAP_SPIRAM %7zu bytes\n"
" MALLOC_CAP_INTERNAL %7zu bytes\n"
" MALLOC_CAP_DEFAULT %7zu bytes\n"
" MALLOC_CAP_IRAM_8BIT %7zu bytes\n"
" MALLOC_CAP_RETENTION %7zu bytes\n",
xPortGetFreeHeapSize(),
heap_caps_get_free_size(MALLOC_CAP_8BIT),
heap_caps_get_free_size(MALLOC_CAP_DMA),
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_free_size(MALLOC_CAP_DEFAULT),
heap_caps_get_free_size(MALLOC_CAP_IRAM_8BIT),
heap_caps_get_free_size(MALLOC_CAP_RETENTION)
);
Code: Select all
I (2341) DEBG: Free Heap: 2109211 bytes
MALLOC_CAP_8BIT 2109211 bytes
MALLOC_CAP_DMA 14360 bytes
MALLOC_CAP_SPIRAM 2094851 bytes
MALLOC_CAP_INTERNAL 33980 bytes
MALLOC_CAP_DEFAULT 2109211 bytes
MALLOC_CAP_IRAM_8BIT 0 bytes
MALLOC_CAP_RETENTION 0 bytes
If I REMOVE the PSRAM options from the config, the free heap log shows this:
Code: Select all
I (1847) DEBG: Free Heap: 68804 bytes
MALLOC_CAP_8BIT 68804 bytes
MALLOC_CAP_DMA 68804 bytes
MALLOC_CAP_SPIRAM 0 bytes
MALLOC_CAP_INTERNAL 93452 bytes
MALLOC_CAP_DEFAULT 68804 bytes
MALLOC_CAP_IRAM_8BIT 0 bytes
MALLOC_CAP_RETENTION 0 bytes
So how do I interpret these numbers? Which is most comparable to the old measurement of "Free heap" I was logging before? Specifically, I want to see the effect of any code changes on the available free heap in internal RAM, I.e. can we increase available internal RAM by moving some buffers to PSRAM...