summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-01-22 10:45:17 +1100
committerDamien George <damien@micropython.org>2022-01-22 10:46:31 +1100
commitbb9d688454336591803858b769ce3ea23ab2df91 (patch)
tree349c7c837558f5f2ab59bbd88f1eb858b5e3c16b
parentac39960aa13d1c4d4c93f002463b1b462be015e0 (diff)
esp32/main: Use heap_caps_get_info on IDF <4.1 to compute total heap.
heap_caps_get_total_size() is only available in IDF 4.1 and above. Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/esp32/main.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/ports/esp32/main.c b/ports/esp32/main.c
index d21dc9f75..e25e6fdd1 100644
--- a/ports/esp32/main.c
+++ b/ports/esp32/main.c
@@ -128,10 +128,14 @@ void mp_task(void *pvParameter) {
if (mp_task_heap == NULL) {
// Allocate the uPy heap using malloc and get the largest available region,
// limiting to 1/2 total available memory to leave memory for the OS.
- mp_task_heap_size = MIN(
- heap_caps_get_largest_free_block(MALLOC_CAP_8BIT),
- heap_caps_get_total_size(MALLOC_CAP_8BIT) / 2
- );
+ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
+ size_t heap_total = heap_caps_get_total_size(MALLOC_CAP_8BIT);
+ #else
+ multi_heap_info_t info;
+ heap_caps_get_info(&info, MALLOC_CAP_8BIT);
+ size_t heap_total = info.total_free_bytes + info.total_allocated_bytes;
+ #endif
+ mp_task_heap_size = MIN(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT), heap_total / 2);
mp_task_heap = malloc(mp_task_heap_size);
}