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.
This commit is contained in:
Damien George 2019-01-29 22:22:47 +11:00
parent 98f790b03a
commit 6a95e74387
2 changed files with 23 additions and 0 deletions

View File

@ -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

View File

@ -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