From 99f5011d74e3d059a59f7c382974d57f03a0b6e9 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 8 Sep 2020 17:06:09 -0700 Subject: [PATCH] Fix heap without PSRAM. Never set heap_size. --- ports/esp32s2/supervisor/port.c | 15 +++++---------- supervisor/shared/safe_mode.c | 4 ++++ supervisor/shared/safe_mode.h | 1 + 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index 89ab166d51..e52b7f3762 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -59,8 +59,6 @@ void tick_timer_cb(void* arg) { supervisor_tick(); } -uint32_t* heap; - safe_mode_t port_init(void) { esp_timer_create_args_t args; args.callback = &tick_timer_cb; @@ -69,7 +67,7 @@ safe_mode_t port_init(void) { args.name = "CircuitPython Tick"; esp_timer_create(&args, &_tick_timer); - heap = malloc(HEAP_SIZE); + heap = NULL; never_reset_module_internal_pins(); #ifdef CONFIG_SPIRAM @@ -81,6 +79,10 @@ safe_mode_t port_init(void) { heap = malloc(HEAP_SIZE); heap_size = HEAP_SIZE / sizeof(uint32_t); } + if (heap == NULL) { + return NO_HEAP; + } + return NO_SAFE_MODE; } @@ -142,13 +144,6 @@ supervisor_allocation* port_fixed_stack(void) { return &_fixed_stack; } -supervisor_allocation _fixed_heap; -supervisor_allocation* port_fixed_heap(void) { - _fixed_heap.ptr = port_heap_get_bottom(); - _fixed_heap.length = (port_heap_get_top() - port_heap_get_bottom()) * sizeof(uint32_t); - return &_fixed_heap; -} - // Place the word to save just after our BSS section that gets blanked. void port_set_saved_word(uint32_t value) { } diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index 3275cc66f3..29a0a6a4ff 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -133,6 +133,10 @@ void print_safe_mode_message(safe_mode_t reason) { serial_write_compressed(translate("The CircuitPython heap was corrupted because the stack was too small.\nPlease increase the stack size if you know how, or if not:")); serial_write_compressed(FILE_AN_ISSUE); return; + case NO_HEAP: + serial_write_compressed(translate("CircuitPython was unable to allocate the heap.\n")); + serial_write_compressed(FILE_AN_ISSUE); + return; default: break; } diff --git a/supervisor/shared/safe_mode.h b/supervisor/shared/safe_mode.h index c160739aec..7d3cd63b58 100644 --- a/supervisor/shared/safe_mode.h +++ b/supervisor/shared/safe_mode.h @@ -42,6 +42,7 @@ typedef enum { FLASH_WRITE_FAIL, MEM_MANAGE, WATCHDOG_RESET, + NO_HEAP, } safe_mode_t; safe_mode_t wait_for_safe_mode_reset(void);