Skip to content

Commit f6d6308

Browse files
committed
esp32: Add MICROPY_GC_INITIAL_HEAP_SIZE option and tune it.
This gets back the old heap-size behaviour on ESP32, before auto-split-heap was introduced: after the heap is grown one time the size is 111936 bytes, with about 40k left for the IDF. That's enough to start WiFi and do a HTTPS request. Signed-off-by: Damien George <[email protected]>
1 parent 97b1313 commit f6d6308

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

ports/esp32/main.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@
7979
#define MP_TASK_STACK_LIMIT_MARGIN (1024)
8080
#endif
8181

82-
// Initial Python heap size. This starts small but adds new heap areas on
83-
// demand due to settings MICROPY_GC_SPLIT_HEAP & MICROPY_GC_SPLIT_HEAP_AUTO
84-
#define MP_TASK_HEAP_SIZE (64 * 1024)
85-
8682
int vprintf_null(const char *format, va_list ap) {
8783
// do nothing: this is used as a log target during raw repl mode
8884
return 0;
@@ -120,13 +116,13 @@ void mp_task(void *pvParameter) {
120116
ESP_LOGE("esp_init", "can't create event loop: 0x%x\n", err);
121117
}
122118

123-
void *mp_task_heap = MP_PLAT_ALLOC_HEAP(MP_TASK_HEAP_SIZE);
119+
void *mp_task_heap = MP_PLAT_ALLOC_HEAP(MICROPY_GC_INITIAL_HEAP_SIZE);
124120

125121
soft_reset:
126122
// initialise the stack pointer for the main thread
127123
mp_stack_set_top((void *)sp);
128124
mp_stack_set_limit(MICROPY_TASK_STACK_SIZE - MP_TASK_STACK_LIMIT_MARGIN);
129-
gc_init(mp_task_heap, mp_task_heap + MP_TASK_HEAP_SIZE);
125+
gc_init(mp_task_heap, mp_task_heap + MICROPY_GC_INITIAL_HEAP_SIZE);
130126
mp_init();
131127
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
132128
readline_init0();

ports/esp32/mpconfigport.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
// memory allocation policies
2727
#define MICROPY_ALLOC_PATH_MAX (128)
2828

29+
// Initial Python heap size. This starts small but adds new heap areas on demand due to
30+
// the settings MICROPY_GC_SPLIT_HEAP and MICROPY_GC_SPLIT_HEAP_AUTO. The value is
31+
// different for different MCUs and is chosen so they can grow the heap once (double it)
32+
// and still have enough internal RAM to start WiFi and make a HTTPS request.
33+
#ifndef MICROPY_GC_INITIAL_HEAP_SIZE
34+
#if CONFIG_IDF_TARGET_ESP32
35+
#define MICROPY_GC_INITIAL_HEAP_SIZE (56 * 1024)
36+
#elif CONFIG_IDF_TARGET_ESP32S2 && !CONFIG_SPIRAM
37+
#define MICROPY_GC_INITIAL_HEAP_SIZE (36 * 1024)
38+
#else
39+
#define MICROPY_GC_INITIAL_HEAP_SIZE (64 * 1024)
40+
#endif
41+
#endif
42+
2943
// emitters
3044
#define MICROPY_PERSISTENT_CODE_LOAD (1)
3145
#if !CONFIG_IDF_TARGET_ESP32C3

0 commit comments

Comments
 (0)