From 25ad46d911fbc15f13c42c4073d7b393e47bd922 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 21 Mar 2024 13:40:54 -0700 Subject: [PATCH] Update to IDF 5.2.1 --- lib/tinyusb | 2 +- ports/espressif/Makefile | 12 ++++++-- ports/espressif/common-hal/busio/UART.c | 6 ++-- ports/espressif/esp-idf | 2 +- ports/espressif/mpconfigport.mk | 28 ++++++++++------- ports/espressif/supervisor/usb.c | 40 +++++++------------------ 6 files changed, 43 insertions(+), 47 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 15775727e7e2..60764de56461 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 15775727e7e29cf6b4d748f01d9457479f8f6899 +Subproject commit 60764de56461edbf1e8bafe4e73fdc97ec3d2e6e diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 7eff93736b21..8490cbd8fa40 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -97,6 +97,7 @@ INC += \ -isystem esp-idf/components/esp_adc/include \ -isystem esp-idf/components/esp_adc/$(IDF_TARGET)/include \ -isystem esp-idf/components/esp_app_format/include \ + -isystem esp-idf/components/esp_bootloader_format/include \ -isystem esp-idf/components/esp_common/include \ -isystem esp-idf/components/esp_event/include \ -isystem esp-idf/components/esp_hw_support/include \ @@ -110,12 +111,15 @@ INC += \ -isystem esp-idf/components/esp_system/include \ -isystem esp-idf/components/esp_timer/include \ -isystem esp-idf/components/esp_wifi/include \ + -isystem esp-idf/components/freertos/config/include \ + -isystem esp-idf/components/freertos/config/include/freertos \ + -isystem esp-idf/components/freertos/config/$(IDF_TARGET_ARCH)/include \ -isystem esp-idf/components/freertos/esp_additions/include \ -isystem esp-idf/components/freertos/esp_additions/include/freertos \ - -isystem esp-idf/components/freertos/esp_additions/arch/$(IDF_TARGET_ARCH)/include \ -isystem esp-idf/components/freertos/FreeRTOS-Kernel/include \ -isystem esp-idf/components/freertos/FreeRTOS-Kernel/include/freertos \ -isystem esp-idf/components/freertos/FreeRTOS-Kernel/portable/$(IDF_TARGET_ARCH)/include \ + -isystem esp-idf/components/freertos/FreeRTOS-Kernel/portable/$(IDF_TARGET_ARCH)/include/freertos \ -isystem esp-idf/components/hal/include \ -isystem esp-idf/components/hal/$(IDF_TARGET)/include \ -isystem esp-idf/components/hal/platform_port/include \ @@ -134,6 +138,7 @@ INC += \ -isystem esp-idf/components/soc/include \ -isystem esp-idf/components/soc/$(IDF_TARGET)/include \ -isystem esp-idf/components/spi_flash/include \ + -isystem esp-idf/components/usb/include \ -isystem esp-idf/components/ulp/ulp_fsm/include \ -isystem esp-idf/components/ulp/ulp_riscv/include \ -isystem esp-idf/components/ulp/ulp_common/include \ @@ -498,6 +503,9 @@ endif ifneq ($(CIRCUITPY_PARALLELDISPLAYBUS),0) ESP_IDF_COMPONENTS_LINK += esp_lcd endif +ifneq ($(CIRCUITPY_USB),0) + ESP_IDF_COMPONENTS_LINK += usb +endif ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a) @@ -579,7 +587,7 @@ esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h $(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp $(IDF_CMAKE_TARGETS) $(STEPECHO) "LINK $@" - $(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--print-memory-usage -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) $(LIBS) -Wl,--end-group -u newlib_include_pthread_impl -u ld_include_highint_hdl -u __cxx_fatal_exception + $(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--print-memory-usage -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) $(LIBS) -Wl,--end-group -u newlib_include_pthread_impl -u ld_include_highint_hdl -u __cxx_fatal_exception -u esp_app_desc $(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf | tools/build_memory_info.py $(STEPECHO) "Create $@" diff --git a/ports/espressif/common-hal/busio/UART.c b/ports/espressif/common-hal/busio/UART.c index 1770f88bd1ff..41f30b23f7f4 100644 --- a/ports/espressif/common-hal/busio/UART.c +++ b/ports/espressif/common-hal/busio/UART.c @@ -151,11 +151,11 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, uart_config.flow_ctrl = UART_HW_FLOWCTRL_CTS; } - if (receiver_buffer_size <= UART_FIFO_LEN) { - receiver_buffer_size = UART_FIFO_LEN + 8; + if (receiver_buffer_size <= UART_HW_FIFO_LEN(self->uart_num)) { + receiver_buffer_size = UART_HW_FIFO_LEN(self->uart_num) + 8; } - uart_config.rx_flow_ctrl_thresh = UART_FIFO_LEN - 8; + uart_config.rx_flow_ctrl_thresh = UART_HW_FIFO_LEN(self->uart_num) - 8; // Install the driver before we change the settings. if (uart_driver_install(self->uart_num, receiver_buffer_size, 0, 20, &self->event_queue, 0) != ESP_OK || uart_set_mode(self->uart_num, mode) != ESP_OK) { diff --git a/ports/espressif/esp-idf b/ports/espressif/esp-idf index c3e368f96933..722fba96a17f 160000 --- a/ports/espressif/esp-idf +++ b/ports/espressif/esp-idf @@ -1 +1 @@ -Subproject commit c3e368f96933e10d0d70f497c9127dee3034c2ab +Subproject commit 722fba96a17fba2809434e01d65b6ce88ec4ca2e diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index bfc22b74f883..cf689d97d5ca 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -56,15 +56,19 @@ CIRCUITPY_USB = 0 else ifeq ($(IDF_TARGET),esp32c3) # Modules CIRCUITPY_ALARM = 0 -CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_BLEIO ?= 0 -CIRCUITPY_COUNTIO = 0 CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_ESPULP = 0 -CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_MEMORYMAP = 0 + +# No I80 support from the IDF CIRCUITPY_PARALLELDISPLAYBUS = 0 + +# No PCNT peripheral +CIRCUITPY_FREQUENCYIO = 0 +CIRCUITPY_COUNTIO = 0 CIRCUITPY_ROTARYIO = 0 + CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # Features @@ -74,13 +78,18 @@ CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 else ifeq ($(IDF_TARGET),esp32c6) # Modules CIRCUITPY_ALARM = 0 -CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_BLEIO ?= 0 CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_ESPULP = 0 CIRCUITPY_MEMORYMAP = 0 -CIRCUITPY_PARALLELDISPLAYBUS = 0 CIRCUITPY_RGBMATRIX = 0 + +# No space for this +CIRCUITPY_AUDIOBUSIO = 0 + +# No I80 support from the IDF +CIRCUITPY_PARALLELDISPLAYBUS = 0 + CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # Features @@ -90,16 +99,15 @@ CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 else ifeq ($(IDF_TARGET),esp32h2) # Modules CIRCUITPY_ALARM = 0 -# Turn off analogio because calibration is currently supported. -# https://github.com/espressif/esp-idf/issues/11038 -CIRCUITPY_ANALOGIO = 0 -CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_BLEIO ?= 1 CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_ESPULP = 0 CIRCUITPY_MEMORYMAP = 0 -CIRCUITPY_PARALLELDISPLAYBUS = 0 CIRCUITPY_RGBMATRIX = 0 + +# No I80 support from the IDF +CIRCUITPY_PARALLELDISPLAYBUS = 0 + CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 CIRCUITPY_HASHLIB_MBEDTLS_ONLY = 0 diff --git a/ports/espressif/supervisor/usb.c b/ports/espressif/supervisor/usb.c index ad4c95033389..0f4f7579424a 100644 --- a/ports/espressif/supervisor/usb.c +++ b/ports/espressif/supervisor/usb.c @@ -32,7 +32,9 @@ #include "shared/readline/readline.h" #include "hal/gpio_ll.h" -#include "hal/usb_hal.h" + +#include "esp_err.h" +#include "esp_private/usb_phy.h" #include "soc/usb_periph.h" #include "driver/gpio.h" @@ -60,6 +62,8 @@ StackType_t usb_device_stack[USBD_STACK_SIZE]; StaticTask_t usb_device_taskdef; +static usb_phy_handle_t phy_hdl; + // USB Device Driver task // This top level thread process all usb events and invoke callbacks STATIC void usb_device_task(void *param) { @@ -76,37 +80,13 @@ STATIC void usb_device_task(void *param) { } } -static void configure_pins(usb_hal_context_t *usb) { - /* usb_periph_iopins currently configures USB_OTG as USB Device. - * Introduce additional parameters in usb_hal_context_t when adding support - * for USB Host. - */ - for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) { - if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) { - gpio_pad_select_gpio(iopin->pin); - if (iopin->is_output) { - gpio_matrix_out(iopin->pin, iopin->func, false, false); - } else { - gpio_matrix_in(iopin->pin, iopin->func, false); - gpio_pad_input_enable(iopin->pin); - } - gpio_pad_unhold(iopin->pin); - } - } - if (!usb->use_external_phy) { - gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3); - gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3); - } -} - void init_usb_hardware(void) { - periph_module_reset(PERIPH_USB_MODULE); - periph_module_enable(PERIPH_USB_MODULE); - usb_hal_context_t hal = { - .use_external_phy = false // use built-in PHY + // Configure USB PHY + usb_phy_config_t phy_conf = { + .controller = USB_PHY_CTRL_OTG, + .otg_mode = USB_OTG_MODE_DEVICE, }; - usb_hal_init(&hal); - configure_pins(&hal); + usb_new_phy(&phy_conf, &phy_hdl); // Pin the USB task to the same core as CircuitPython. This way we leave // the other core for networking.