Skip to content
Snippets Groups Projects
Commit 6a95e743 authored by Damien George's avatar Damien George
Browse files

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.
parent 98f790b0
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment