diff options
author | Damien George <damien.p.george@gmail.com> | 2019-01-29 22:22:47 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-02-06 00:10:50 +1100 |
commit | 6a95e74387725e77ea368769ff53e03042ce7869 (patch) | |
tree | cf32a03a29b2f676e8b335f53e06e14aeef76f66 | |
parent | 98f790b03aeba3fca6b87716ecadd076bed0c506 (diff) |
esp32: Use SPIRAM in mem-map mode so all of it can be used for uPy heap.
Also enable CONFIG_SPIRAM_IGNORE_NOTFOUND to allow boards with faulty or
missing SPIRAM to still boot.
-rw-r--r-- | ports/esp32/boards/sdkconfig.spiram | 2 | ||||
-rw-r--r-- | ports/esp32/main.c | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/ports/esp32/boards/sdkconfig.spiram b/ports/esp32/boards/sdkconfig.spiram index 4154b5e42..f2ed44c5d 100644 --- a/ports/esp32/boards/sdkconfig.spiram +++ b/ports/esp32/boards/sdkconfig.spiram @@ -13,6 +13,8 @@ CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y # ESP32-specific CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y CONFIG_SPIRAM_SUPPORT=y +CONFIG_SPIRAM_IGNORE_NOTFOUND=y +CONFIG_SPIRAM_USE_MEMMAP=y CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=n CONFIG_ESP32_XTAL_FREQ_AUTO=y diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 01d22d3e7..a304dcbcc 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -37,6 +37,7 @@ #include "esp_task.h" #include "soc/cpu.h" #include "esp_log.h" +#include "esp_spiram.h" #include "py/stackctrl.h" #include "py/nlr.h" @@ -69,9 +70,29 @@ void mp_task(void *pvParameter) { #endif uart_init(); + #if CONFIG_SPIRAM_SUPPORT + // Try to use the entire external SPIRAM directly for the heap + size_t mp_task_heap_size; + void *mp_task_heap = (void*)0x3f800000; + switch (esp_spiram_get_chip_size()) { + case ESP_SPIRAM_SIZE_16MBITS: + mp_task_heap_size = 2 * 1024 * 1024; + break; + case ESP_SPIRAM_SIZE_32MBITS: + case ESP_SPIRAM_SIZE_64MBITS: + mp_task_heap_size = 4 * 1024 * 1024; + break; + default: + // No SPIRAM, fallback to normal allocation + mp_task_heap_size = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT); + mp_task_heap = malloc(mp_task_heap_size); + break; + } + #else // 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); + #endif soft_reset: // initialise the stack pointer for the main thread |