summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-02-21 14:22:33 +1100
committerDamien George <damien.p.george@gmail.com>2018-02-21 14:25:51 +1100
commite600810f39cf99ebab825fdd96b3c875dea4d6d5 (patch)
tree23141d51005346ca2a3eb8787e037667954defca
parentc49a73ab0e18035edaa732d31c882a13534caa7a (diff)
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.
-rw-r--r--ports/esp32/main.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ports/esp32/main.c b/ports/esp32/main.c
index 5b1be4cf7..eebf183cd 100644
--- a/ports/esp32/main.c
+++ b/ports/esp32/main.c
@@ -53,11 +53,9 @@
#define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1)
#define MP_TASK_STACK_SIZE (16 * 1024)
#define MP_TASK_STACK_LEN (MP_TASK_STACK_SIZE / sizeof(StackType_t))
-#define MP_TASK_HEAP_SIZE (92 * 1024)
STATIC StaticTask_t mp_task_tcb;
STATIC StackType_t mp_task_stack[MP_TASK_STACK_LEN] __attribute__((aligned (8)));
-STATIC uint8_t mp_task_heap[MP_TASK_HEAP_SIZE];
void mp_task(void *pvParameter) {
volatile uint32_t sp = (uint32_t)get_sp();
@@ -66,11 +64,15 @@ void mp_task(void *pvParameter) {
#endif
uart_init();
+ // Allocate the uPy heap using malloc and get the largest available region
+ size_t mp_task_heap_size = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
+ void *mp_task_heap = malloc(mp_task_heap_size);
+
soft_reset:
// initialise the stack pointer for the main thread
mp_stack_set_top((void *)sp);
mp_stack_set_limit(MP_TASK_STACK_SIZE - 1024);
- gc_init(mp_task_heap, mp_task_heap + sizeof(mp_task_heap));
+ gc_init(mp_task_heap, mp_task_heap + mp_task_heap_size);
mp_init();
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_));