esp32: Update port to support IDF v5.0.2.

This commit updates the esp32 port to work exclusively with ESP-IDF v5.
IDF v5 is needed for some of the newer ESP32 SoCs to work, and it also
cleans up a lot of the inconsistencies between existing SoCs (eg S2, S3,
and C3).

Support for IDF v4 is dropped because it's a lot of effort to maintain both
versions at the same time.

The following components have been verified to work on the various SoCs:

                ESP32     ESP32-S2  ESP32-S3  ESP32-C3
    build       pass      pass      pass      pass
    SPIRAM      pass      pass      pass      N/A
    REPL (UART) pass      pass      pass      pass
    REPL (USB)  N/A       pass      pass      N/A
    filesystem  pass      pass      pass      pass
    GPIO        pass      pass      pass      pass
    SPI         pass      pass      pass      pass
    I2C         pass      pass      pass      pass
    PWM         pass      pass      pass      pass
    ADC         pass      pass      pass      pass
    WiFi STA    pass      pass      pass      pass
    WiFi AP     pass      pass      pass      pass
    BLE         pass      N/A       pass      pass
    ETH         pass      --        --        --
    PPP         pass      pass      pass      --
    sockets     pass      pass      pass      pass
    SSL         pass      ENOMEM    pass      pass
    RMT         pass      pass      pass      pass
    NeoPixel    pass      pass      pass      pass
    I2S         pass      pass      pass      N/A
    ESPNow      pass      pass      pass      pass
    ULP-FSM     pass      pass      pass      N/A
    SDCard      pass      N/A       N/A       pass
    WDT         pass      pass      pass      pass

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Damien George
2023-05-09 09:52:54 +10:00
parent 2af229c3cc
commit e4650125b8
68 changed files with 491 additions and 681 deletions

View File

@@ -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;
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);
}
#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;
}
#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