diff options
Diffstat (limited to 'ports/esp32/main.c')
-rw-r--r-- | ports/esp32/main.c | 67 |
1 files changed, 14 insertions, 53 deletions
diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 3e7c9ee162..b8ba03e513 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -35,16 +35,9 @@ #include "esp_system.h" #include "nvs_flash.h" #include "esp_task.h" -#include "soc/cpu.h" +#include "esp_event.h" #include "esp_log.h" - -#if CONFIG_IDF_TARGET_ESP32 -#include "esp32/spiram.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/spiram.h" -#elif CONFIG_IDF_TARGET_ESP32S3 -#include "esp32s3/spiram.h" -#endif +#include "esp_psram.h" #include "py/stackctrl.h" #include "py/nlr.h" @@ -88,11 +81,11 @@ int vprintf_null(const char *format, va_list ap) { } void mp_task(void *pvParameter) { - volatile uint32_t sp = (uint32_t)get_sp(); + volatile uint32_t sp = (uint32_t)esp_cpu_get_sp(); #if MICROPY_PY_THREAD mp_thread_init(pxTaskGetStackStart(NULL), MP_TASK_STACK_SIZE / sizeof(uintptr_t)); #endif - #if CONFIG_USB_ENABLED + #if CONFIG_USB_OTG_SUPPORTED usb_init(); #elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG usb_serial_jtag_init(); @@ -102,50 +95,18 @@ void mp_task(void *pvParameter) { #endif machine_init(); - size_t mp_task_heap_size; - void *mp_task_heap = NULL; - - #if CONFIG_SPIRAM_USE_MALLOC - // SPIRAM is issued using MALLOC, fallback to normal allocation rules - mp_task_heap = NULL; - #elif CONFIG_ESP32_SPIRAM_SUPPORT - // Try to use the entire external SPIRAM directly for the heap - mp_task_heap = (void *)SOC_EXTRAM_DATA_LOW; - 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 = NULL; - break; - } - #elif CONFIG_ESP32S2_SPIRAM_SUPPORT || CONFIG_ESP32S3_SPIRAM_SUPPORT - // Try to use the entire external SPIRAM directly for the heap - size_t esp_spiram_size = esp_spiram_get_size(); - if (esp_spiram_size > 0) { - mp_task_heap = (void *)SOC_EXTRAM_DATA_HIGH - esp_spiram_size; - mp_task_heap_size = esp_spiram_size; + esp_err_t err = esp_event_loop_create_default(); + if (err != ESP_OK) { + ESP_LOGE("esp_init", "can't create event loop: 0x%x\n", err); } - #endif - if (mp_task_heap == NULL) { - // Allocate the uPy heap using malloc and get the largest available region, - // limiting to 1/2 total available memory to leave memory for the OS. - #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0) - size_t heap_total = heap_caps_get_total_size(MALLOC_CAP_8BIT); - #else - multi_heap_info_t info; - heap_caps_get_info(&info, MALLOC_CAP_8BIT); - size_t heap_total = info.total_free_bytes + info.total_allocated_bytes; - #endif - mp_task_heap_size = MIN(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT), heap_total / 2); - mp_task_heap = malloc(mp_task_heap_size); - } + // Allocate the uPy heap using malloc and get the largest available region, + // limiting to 1/2 total available memory to leave memory for the OS. + // When SPIRAM is enabled, this will allocate from SPIRAM. + uint32_t caps = MALLOC_CAP_8BIT; + size_t heap_total = heap_caps_get_total_size(caps); + size_t mp_task_heap_size = MIN(heap_caps_get_largest_free_block(caps), heap_total / 2); + void *mp_task_heap = heap_caps_malloc(mp_task_heap_size, caps); soft_reset: // initialise the stack pointer for the main thread |