Page 1 of 1

Difference between ESP.getFreeHeap() and xPortGetFreeHeapSize() ?

Posted: Wed May 11, 2022 7:42 pm
by HankLloydRight
Hello,

I've been using xPortGetFreeHeapSize() in my project with a LOLIN32 V1.0.0 dev board and it's been working fine.

I tried upgrading my project to a LOLIN D32 PRO dev board with the exact same code (using Arduino framework on PIO), and now xPortGetFreeHeapSize() returns values around ~4,257,896 bytes instead of the ~100k range it was returning on the LOLIN32 board.

So I switched to ESP.getFreeHeap() instead, which seems to work, but on the LOLIN32 board, there's a constant 29,512 byte difference between the two function calls, with ESP.getFreeHeap() always being 29,512 bytes larger than xPortGetFreeHeapSize().

Any ideas why they would be different, and by this (seemingly fixed) amount?

Thank you.

Re: Difference between ESP.getFreeHeap() and xPortGetFreeHeapSize() ?

Posted: Thu May 12, 2022 2:54 am
by lbernstone
xPortGetFreeHeapSize() is a synonym for esp_get_free_heap_size():
https://github.com/espressif/esp-idf/bl ... #L113-L116
The ESP call is asking for a slightly different set of memory:
https://github.com/espressif/arduino-es ... #L123-L128
You can see the difference between INTERNAL and DEFAULT in the heap_caps definition:
https://github.com/espressif/esp-idf/bl ... .h#L20-L37

Re: Difference between ESP.getFreeHeap() and xPortGetFreeHeapSize() ?

Posted: Thu May 12, 2022 10:53 am
by HankLloydRight
lbernstone wrote:
Thu May 12, 2022 2:54 am
xPortGetFreeHeapSize() is a synonym for esp_get_free_heap_size():
https://github.com/espressif/esp-idf/bl ... #L113-L116
The ESP call is asking for a slightly different set of memory:
https://github.com/espressif/arduino-es ... #L123-L128
You can see the difference between INTERNAL and DEFAULT in the heap_caps definition:
https://github.com/espressif/esp-idf/bl ... .h#L20-L37
Wow, what a wealth of helpful information! Thank you so much.