Skip to content

Commit e600810

Browse files
committed
esp32/main: Allocate the uPy heap via malloc instead of on the bss.
This allows to get slightly more memory for the heap (currently around 110k vs previous 92k) because the ESP IDF frees up some RAM after booting up.
1 parent c49a73a commit e600810

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

ports/esp32/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@
5353
#define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1)
5454
#define MP_TASK_STACK_SIZE (16 * 1024)
5555
#define MP_TASK_STACK_LEN (MP_TASK_STACK_SIZE / sizeof(StackType_t))
56-
#define MP_TASK_HEAP_SIZE (92 * 1024)
5756

5857
STATIC StaticTask_t mp_task_tcb;
5958
STATIC StackType_t mp_task_stack[MP_TASK_STACK_LEN] __attribute__((aligned (8)));
60-
STATIC uint8_t mp_task_heap[MP_TASK_HEAP_SIZE];
6159

6260
void mp_task(void *pvParameter) {
6361
volatile uint32_t sp = (uint32_t)get_sp();
@@ -66,11 +64,15 @@ void mp_task(void *pvParameter) {
6664
#endif
6765
uart_init();
6866

67+
// Allocate the uPy heap using malloc and get the largest available region
68+
size_t mp_task_heap_size = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
69+
void *mp_task_heap = malloc(mp_task_heap_size);
70+
6971
soft_reset:
7072
// initialise the stack pointer for the main thread
7173
mp_stack_set_top((void *)sp);
7274
mp_stack_set_limit(MP_TASK_STACK_SIZE - 1024);
73-
gc_init(mp_task_heap, mp_task_heap + sizeof(mp_task_heap));
75+
gc_init(mp_task_heap, mp_task_heap + mp_task_heap_size);
7476
mp_init();
7577
mp_obj_list_init(mp_sys_path, 0);
7678
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_));

0 commit comments

Comments
 (0)