diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 26a0db78fba4..e0bf48656dee 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -12,6 +12,9 @@ CROSS_COMPILE = riscv32-esp-elf- else ifeq ($(IDF_TARGET),esp32c3) IDF_TARGET_ARCH = riscv CROSS_COMPILE = riscv32-esp-elf- +else ifeq ($(IDF_TARGET),esp32p4) +IDF_TARGET_ARCH = riscv +CROSS_COMPILE = riscv32-esp-elf- else ifeq ($(IDF_TARGET),esp32c6) IDF_TARGET_ARCH = riscv CROSS_COMPILE = riscv32-esp-elf- @@ -215,7 +218,13 @@ ifeq ($(IDF_TARGET_ARCH),xtensa) CFLAGS += -mlongcalls -isystem esp-idf/components/xtensa/deprecated_include/ -Wno-error=cpp else ifeq ($(IDF_TARGET_ARCH),riscv) + +ifeq ($(IDF_TARGET),esp32p4) +CFLAGS += -march=rv32imafc_zicsr_zifencei_xesppie -mabi=ilp32f +else CFLAGS += -march=rv32imac_zicsr_zifencei +endif + LDFLAGS += \ -Lesp-idf/components/riscv/ld \ -Trom.api.ld @@ -285,6 +294,16 @@ LDFLAGS += \ -Tesp32c6.rom.wdt.ld +CHIP_COMPONENTS = \ + esp_driver_tsens + +else ifeq ($(IDF_TARGET),esp32p4) +LDFLAGS += \ + -Tesp32p4.rom.newlib.ld \ + -Tesp32p4.rom.systimer.ld \ + -Tesp32p4.rom.wdt.ld + + CHIP_COMPONENTS = \ esp_driver_tsens @@ -338,6 +357,8 @@ else ifeq ($(IDF_TARGET),esp32c3) CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C3 else ifeq ($(IDF_TARGET),esp32c6) CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32C6 +else ifeq ($(IDF_TARGET),esp32p4) +CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32P4 else ifeq ($(IDF_TARGET),esp32h2) CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32H2 else ifeq ($(IDF_TARGET),esp32s2) @@ -578,7 +599,10 @@ update-board-sdkconfig: $(BUILD)/esp-idf/config/sdkconfig.h python tools/update_sdkconfig.py --board=$(BOARD) --debug=$(DEBUG) BINARY_WIFI_BLOBS = libcore.a libespnow.a libnet80211.a libpp.a libsmartconfig.a -BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a + +ifneq ($(IDF_TARGET),esp32p4) + BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a +endif ifneq ($(CIRCUITPY_WIFI),0) BINARY_BLOBS += esp-idf/components/esp_coex/lib/$(IDF_TARGET)/libcoexist.a $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS)) ifneq ($(IDF_TARGET),esp32c2) @@ -590,9 +614,9 @@ ifeq ($(IDF_TARGET),esp32) BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a endif -ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_gpio esp_driver_gptimer esp_driver_ledc esp_driver_spi esp_driver_uart efuse esp_adc esp_app_format esp_common esp_event esp_hw_support esp_mm esp_partition esp_phy esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log newlib nvs_flash pthread soc spi_flash vfs esp_vfs_console +ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_gpio esp_driver_gptimer esp_driver_ledc esp_driver_spi esp_driver_uart efuse esp_adc esp_app_format esp_common esp_event esp_hw_support esp_mm esp_partition esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log newlib nvs_flash pthread soc spi_flash vfs esp_vfs_console ifneq ($(CIRCUITPY_WIFI),0) - ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp-tls esp_wifi lwip mbedtls mdns wpa_supplicant + ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp-tls esp_wifi lwip mbedtls mdns wpa_supplicant esp_phy endif ifneq ($(CIRCUITPY_BLEIO),0) BLE_IMPL_esp32 := esp32 @@ -603,7 +627,7 @@ ifneq ($(CIRCUITPY_BLEIO),0) BLE_IMPL_esp32h2 := libble BLE_IMPL = $(BLE_IMPL_$(IDF_TARGET)) - ESP_IDF_COMPONENTS_LINK += bt + ESP_IDF_COMPONENTS_LINK += bt esp_phy ifeq ($(BLE_IMPL),esp32) # BLE will hang the ESP32 and trigger an interrupt watchdog without this undefined symbol at # link because a weak version of the interrupt that BLE uses will be linked incorrectly. @@ -665,6 +689,8 @@ else ifeq ($(IDF_TARGET),esp32c3) BOOTLOADER_OFFSET = 0x0 else ifeq ($(IDF_TARGET),esp32c6) BOOTLOADER_OFFSET = 0x0 +else ifeq ($(IDF_TARGET),esp32p4) +BOOTLOADER_OFFSET = 0x2000 else ifeq ($(IDF_TARGET),esp32s3) BOOTLOADER_OFFSET = 0x0 else ifeq ($(IDF_TARGET),esp32s2) diff --git a/ports/espressif/README.rst b/ports/espressif/README.rst index 93b793657724..63174fd16706 100644 --- a/ports/espressif/README.rst +++ b/ports/espressif/README.rst @@ -14,6 +14,7 @@ Support Status: ESP32-C2, "alpha" ESP32-C3, "beta" ESP32-C6, "alpha" + ESP32-P4, "alpha" ESP32-S2, "stable" ESP32-S3, "stable" diff --git a/ports/espressif/boards/espressif_esp32p4_function_ev/board.c b/ports/espressif/boards/espressif_esp32p4_function_ev/board.c new file mode 100644 index 000000000000..a3a9eec04714 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32p4_function_ev/board.c @@ -0,0 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.h b/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.h new file mode 100644 index 000000000000..37ade1fc539a --- /dev/null +++ b/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.h @@ -0,0 +1,20 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2019 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "ESP32-P4-Function-EV" +#define MICROPY_HW_MCU_NAME "ESP32P4" + +#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO38) +#define DEFAULT_UART_BUS_TX (&pin_GPIO37) + +#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX +#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX diff --git a/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.mk b/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.mk new file mode 100644 index 000000000000..43ab506659e3 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32p4_function_ev/mpconfigboard.mk @@ -0,0 +1,14 @@ +# USB_VID = 0x303A +# USB_PID = 0x7003 +# USB_PRODUCT = "ESP32-P4-Function-EV" +# USB_MANUFACTURER = "Espressif" + +IDF_TARGET = esp32p4 + +CIRCUITPY_ESP_FLASH_SIZE = 16MB +CIRCUITPY_ESP_FLASH_MODE = opi +CIRCUITPY_ESP_FLASH_FREQ = 80m + +CIRCUITPY_ESP_PSRAM_SIZE = 32MB +CIRCUITPY_ESP_PSRAM_MODE = opi +CIRCUITPY_ESP_PSRAM_FREQ = 80m diff --git a/ports/espressif/boards/espressif_esp32p4_function_ev/pins.c b/ports/espressif/boards/espressif_esp32p4_function_ev/pins.c new file mode 100644 index 000000000000..3bb64f434d02 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32p4_function_ev/pins.c @@ -0,0 +1,55 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_IO47), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO48) }, + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/espressif_esp32p4_function_ev/sdkconfig b/ports/espressif/boards/espressif_esp32p4_function_ev/sdkconfig new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/ports/espressif/common-hal/analogbufio/BufferedIn.c b/ports/espressif/common-hal/analogbufio/BufferedIn.c index 305bd10a37fe..aac7ad28daf2 100644 --- a/ports/espressif/common-hal/analogbufio/BufferedIn.c +++ b/ports/espressif/common-hal/analogbufio/BufferedIn.c @@ -33,7 +33,7 @@ #elif defined(CONFIG_IDF_TARGET_ESP32S2) #define ADC_RESULT_BYTE 2 #define ADC_CONV_LIMIT_EN 0 -#elif defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) +#elif defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) || defined(CONFIG_IDF_TARGET_ESP32P4) #define ADC_RESULT_BYTE 4 #define ADC_CONV_LIMIT_EN 0 #elif defined(CONFIG_IDF_TARGET_ESP32S3) diff --git a/ports/espressif/common-hal/analogio/AnalogIn.c b/ports/espressif/common-hal/analogio/AnalogIn.c index 9b1b14f07c3a..16340e91ac91 100644 --- a/ports/espressif/common-hal/analogio/AnalogIn.c +++ b/ports/espressif/common-hal/analogio/AnalogIn.c @@ -32,6 +32,8 @@ #define DATA_WIDTH ADC_BITWIDTH_12 #elif defined(CONFIG_IDF_TARGET_ESP32C6) #define DATA_WIDTH ADC_BITWIDTH_12 +#elif defined(CONFIG_IDF_TARGET_ESP32P4) +#define DATA_WIDTH ADC_BITWIDTH_12 #elif defined(CONFIG_IDF_TARGET_ESP32S2) #define DATA_WIDTH ADC_BITWIDTH_13 #elif defined(CONFIG_IDF_TARGET_ESP32S3) @@ -84,9 +86,10 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { adc_cali_scheme_ver_t supported_schemes; adc_cali_check_scheme(&supported_schemes); + #ifndef CONFIG_IDF_TARGET_ESP32P4 adc_cali_scheme_ver_t calibration_scheme = 0; adc_cali_handle_t calibration; - + #endif #if defined(ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED) && ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED adc_cali_curve_fitting_config_t config = { .unit_id = self->pin->adc_index, @@ -134,8 +137,11 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { // This corrects non-linear regions of the ADC range with a LUT, so it's a better reading than raw int voltage; + #ifdef CONFIG_IDF_TARGET_ESP32P4 + voltage = 0; + #else adc_cali_raw_to_voltage(calibration, adc_reading, &voltage); - + #endif #if defined(ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED) && ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED if (calibration_scheme == ADC_CALI_SCHEME_VER_CURVE_FITTING) { diff --git a/ports/espressif/common-hal/espidf/__init__.c b/ports/espressif/common-hal/espidf/__init__.c index 8af0318fed01..83e30657750d 100644 --- a/ports/espressif/common-hal/espidf/__init__.c +++ b/ports/espressif/common-hal/espidf/__init__.c @@ -27,7 +27,11 @@ static size_t psram_size_usable(void) { #ifdef CONFIG_SPIRAM /* PSRAM chip may be larger than the size we can map into address space */ + #ifdef CONFIG_IDF_TARGET_ESP32P4 + size_t s = esp_psram_get_size(); + #else size_t s = MIN(esp_psram_get_size(), SOC_EXTRAM_DATA_SIZE); + #endif return s - esp_himem_reserved_area_size(); #else return 0; diff --git a/ports/espressif/common-hal/microcontroller/Pin.c b/ports/espressif/common-hal/microcontroller/Pin.c index 056ce54b781f..70912afb545b 100644 --- a/ports/espressif/common-hal/microcontroller/Pin.c +++ b/ports/espressif/common-hal/microcontroller/Pin.c @@ -171,6 +171,26 @@ static const uint64_t pin_mask_reset_forbidden = #endif #endif // ESP32H2 + #if defined(CONFIG_IDF_TARGET_ESP32P4) + // Never ever reset pins used to communicate with the SPI flash. + GPIO_SEL_28 | + GPIO_SEL_29 | + GPIO_SEL_30 | + GPIO_SEL_32 | + GPIO_SEL_33 | + GPIO_SEL_34 | + #if CIRCUITPY_ESP_USB_SERIAL_JTAG + // Never ever reset serial/JTAG communication pins. + GPIO_SEL_50 | // USB D- + GPIO_SEL_51 | // USB D+ + #endif + #if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) && CONFIG_ESP_CONSOLE_UART_DEFAULT && CONFIG_ESP_CONSOLE_UART_NUM == 0 + // Never reset debug UART/console pins. + GPIO_SEL_37 | + GPIO_SEL_38 | + #endif + #endif // ESP32P4 + #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) #if CIRCUITPY_USB_DEVICE // Never ever reset USB pins. diff --git a/ports/espressif/common-hal/microcontroller/Processor.c b/ports/espressif/common-hal/microcontroller/Processor.c index 97b41a97c3ae..8a6a14c0236f 100644 --- a/ports/espressif/common-hal/microcontroller/Processor.c +++ b/ports/espressif/common-hal/microcontroller/Processor.c @@ -107,11 +107,14 @@ void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t } #endif +#ifndef CONFIG_IDF_TARGET_ESP32P4 static uint8_t swap_nibbles(uint8_t v) { return ((v << 4) | (v >> 4)) & 0xff; } +#endif void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { + #ifndef CONFIG_IDF_TARGET_ESP32P4 memset(raw_id, 0, COMMON_HAL_MCU_PROCESSOR_UID_LENGTH); uint8_t *ptr = &raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH - 1]; @@ -149,6 +152,10 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { *ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8; *ptr-- = swap_nibbles(mac_address_part & 0xff); + #else + // TODO: Get UID for ESP32-P4. + return; + #endif } mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { diff --git a/ports/espressif/common-hal/microcontroller/__init__.c b/ports/espressif/common-hal/microcontroller/__init__.c index 4375f942f550..b3ef638b964d 100644 --- a/ports/espressif/common-hal/microcontroller/__init__.c +++ b/ports/espressif/common-hal/microcontroller/__init__.c @@ -36,6 +36,8 @@ #elif defined(CONFIG_IDF_TARGET_ESP32C6) #include "soc/lp_aon_reg.h" #include "esp32c6/rom/rtc.h" +#elif defined(CONFIG_IDF_TARGET_ESP32P4) +#include "esp32p4/rom/rtc.h" #elif defined(CONFIG_IDF_TARGET_ESP32S2) #include "soc/rtc_cntl_reg.h" #include "esp32s2/rom/rtc.h" @@ -93,18 +95,22 @@ void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) REG_WRITE(RTC_RESET_CAUSE_REG, 0); // reset uf2 #endif - #ifdef SOC_LP_AON_SUPPORTED + #if defined(CONFIG_IDF_TARGET_ESP32P4) + REG_WRITE(LP_SYSTEM_REG_LP_STORE15_REG, 0); + #elif defined(SOC_LP_AON_SUPPORTED) REG_WRITE(LP_AON_STORE0_REG, 0); // reset safe mode #else REG_WRITE(RTC_CNTL_STORE0_REG, 0); // reset safe mode #endif - #if !defined(CONFIG_IDF_TARGET_ESP32) - #ifdef SOC_LP_AON_SUPPORTED + #if defined(CONFIG_IDF_TARGET_ESP32) + // No UF2 bootloader. + #elif defined(CONFIG_IDF_TARGET_ESP32P4) + REG_WRITE(LP_SYSTEM_REG_SYS_CTRL_REG, 0); + #elif defined(SOC_LP_AON_SUPPORTED) REG_WRITE(LP_AON_SYS_CFG_REG, 0); // reset bootloader #else REG_WRITE(RTC_CNTL_OPTION1_REG, 0); // reset bootloader #endif - #endif break; case RUNMODE_SAFE_MODE: // enter safe mode on next boot @@ -118,7 +124,10 @@ void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) chip_usb_set_persist_flags(USBDC_BOOT_DFU); #endif - #ifdef SOC_LP_AON_SUPPORTED + + #if defined(CONFIG_IDF_TARGET_ESP32P4) + REG_WRITE(LP_SYSTEM_REG_SYS_CTRL_REG, LP_SYSTEM_REG_FORCE_DOWNLOAD_BOOT); + #elif defined(SOC_LP_AON_SUPPORTED) REG_WRITE(LP_AON_SYS_CFG_REG, LP_AON_FORCE_DOWNLOAD_BOOT); #else REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); diff --git a/ports/espressif/esp-idf-config/sdkconfig-esp32p4.defaults b/ports/espressif/esp-idf-config/sdkconfig-esp32p4.defaults new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/ports/espressif/esp-idf-config/sdkconfig-psram-32MB.defaults b/ports/espressif/esp-idf-config/sdkconfig-psram-32MB.defaults new file mode 100644 index 000000000000..9494e7dece8c --- /dev/null +++ b/ports/espressif/esp-idf-config/sdkconfig-psram-32MB.defaults @@ -0,0 +1,4 @@ +# CONFIG_SPIRAM_TYPE_AUTO is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +CONFIG_SPIRAM_TYPE_AUTO=y diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index e1bbea5c12ee..a185c69ad469 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -23,6 +23,8 @@ CIRCUITPY_SSL_MBEDTLS = 1 # Wifi Power Save CIRCUITPY_WIFI_RADIO_SETTABLE_LISTEN_INTERVAL = 1 +# Never use our copy of MBEDTLS +CIRCUITPY_HASHLIB_MBEDTLS_ONLY = 0 # These modules are implemented in ports//common-hal: CIRCUITPY_ALARM ?= 1 @@ -155,7 +157,7 @@ CIRCUITPY_PARALLELDISPLAYBUS = 0 CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 -CIRCUITPY_HASHLIB_MBEDTLS_ONLY = 0 + # Features CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 @@ -163,6 +165,36 @@ CIRCUITPY_WIFI = 0 CIRCUITPY_MAX3421E = 0 +else ifeq ($(IDF_TARGET),esp32p4) + +# No wifi +# TODO: Support ESP32-C6 coprocessor on some boards. +CIRCUITPY_BLEIO = 0 +CIRCUITPY_WIFI = 0 +CIRCUITPY_SSL = 0 + +CIRCUITPY_TOUCHIO = 1 +CIRCUITPY_TOUCHIO_USE_NATIVE = 0 + +# TinyUSB doesn't have it upstreamed +# https://github.com/hathach/tinyusb/issues/2791 +CIRCUITPY_USB_DEVICE = 0 + +# Update this for the 40mhz processor. +CIRCUITPY_ESPULP = 0 + +# Update this for multiple TWAI? +CIRCUITPY_CANIO = 0 + +# Protomatter needs an update +CIRCUITPY_RGBMATRIX = 0 + +# No I80 support from the IDF +CIRCUITPY_PARALLELDISPLAYBUS = 0 + +# Library doesn't support P4 yet it seems +CIRCUITPY_ESPCAMERA = 0 + else ifeq ($(IDF_TARGET),esp32s2) # Modules CIRCUITPY_ALARM_TOUCH = 1 diff --git a/ports/espressif/mphalport.c b/ports/espressif/mphalport.c index 7c7ec5481c08..87b16ac3e4ca 100644 --- a/ports/espressif/mphalport.c +++ b/ports/espressif/mphalport.c @@ -12,6 +12,8 @@ #include "components/esp_rom/include/esp32/rom/ets_sys.h" #elif defined(CONFIG_IDF_TARGET_ESP32C2) #include "components/esp_rom/include/esp32c2/rom/ets_sys.h" +#elif defined(CONFIG_IDF_TARGET_ESP32P4) +#include "components/esp_rom/include/esp32p4/rom/ets_sys.h" #elif defined(CONFIG_IDF_TARGET_ESP32C3) #include "components/esp_rom/include/esp32c3/rom/ets_sys.h" #elif defined(CONFIG_IDF_TARGET_ESP32C6) diff --git a/ports/espressif/peripherals/esp32p4/pins.c b/ports/espressif/peripherals/esp32p4/pins.c new file mode 100644 index 000000000000..0f67f5acda93 --- /dev/null +++ b/ports/espressif/peripherals/esp32p4/pins.c @@ -0,0 +1,53 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 microDev +// +// SPDX-License-Identifier: MIT + +#include "peripherals/pins.h" + +const mcu_pin_obj_t pin_GPIO0 = PIN(0, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO1 = PIN(1, ADC_UNIT_1, ADC_CHANNEL_0, TOUCH_PAD_NUM1); +const mcu_pin_obj_t pin_GPIO2 = PIN(2, ADC_UNIT_1, ADC_CHANNEL_1, TOUCH_PAD_NUM2); +const mcu_pin_obj_t pin_GPIO3 = PIN(3, ADC_UNIT_1, ADC_CHANNEL_2, TOUCH_PAD_NUM3); +const mcu_pin_obj_t pin_GPIO4 = PIN(4, ADC_UNIT_1, ADC_CHANNEL_3, TOUCH_PAD_NUM4); +const mcu_pin_obj_t pin_GPIO5 = PIN(5, ADC_UNIT_1, ADC_CHANNEL_4, TOUCH_PAD_NUM5); +const mcu_pin_obj_t pin_GPIO6 = PIN(6, ADC_UNIT_1, ADC_CHANNEL_5, TOUCH_PAD_NUM6); +const mcu_pin_obj_t pin_GPIO7 = PIN(7, ADC_UNIT_1, ADC_CHANNEL_6, TOUCH_PAD_NUM7); +const mcu_pin_obj_t pin_GPIO8 = PIN(8, ADC_UNIT_1, ADC_CHANNEL_7, TOUCH_PAD_NUM8); +const mcu_pin_obj_t pin_GPIO9 = PIN(9, ADC_UNIT_1, ADC_CHANNEL_8, TOUCH_PAD_NUM9); +const mcu_pin_obj_t pin_GPIO10 = PIN(10, ADC_UNIT_1, ADC_CHANNEL_9, TOUCH_PAD_NUM10); +const mcu_pin_obj_t pin_GPIO11 = PIN(11, ADC_UNIT_2, ADC_CHANNEL_0, TOUCH_PAD_NUM11); +const mcu_pin_obj_t pin_GPIO12 = PIN(12, ADC_UNIT_2, ADC_CHANNEL_1, TOUCH_PAD_NUM12); +const mcu_pin_obj_t pin_GPIO13 = PIN(13, ADC_UNIT_2, ADC_CHANNEL_2, TOUCH_PAD_NUM13); +const mcu_pin_obj_t pin_GPIO14 = PIN(14, ADC_UNIT_2, ADC_CHANNEL_3, TOUCH_PAD_NUM14); +const mcu_pin_obj_t pin_GPIO15 = PIN(15, ADC_UNIT_2, ADC_CHANNEL_4, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO16 = PIN(16, ADC_UNIT_2, ADC_CHANNEL_5, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO17 = PIN(17, ADC_UNIT_2, ADC_CHANNEL_6, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO18 = PIN(18, ADC_UNIT_2, ADC_CHANNEL_7, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO19 = PIN(19, ADC_UNIT_2, ADC_CHANNEL_8, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO20 = PIN(20, ADC_UNIT_2, ADC_CHANNEL_9, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO21 = PIN(21, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO26 = PIN(26, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO27 = PIN(27, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO28 = PIN(28, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO29 = PIN(29, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO30 = PIN(30, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO31 = PIN(31, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO32 = PIN(32, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO33 = PIN(33, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO34 = PIN(34, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO35 = PIN(35, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO36 = PIN(36, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO37 = PIN(37, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO38 = PIN(38, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO39 = PIN(39, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO40 = PIN(40, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO41 = PIN(41, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO42 = PIN(42, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO43 = PIN(43, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO44 = PIN(44, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO45 = PIN(45, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO46 = PIN(46, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO47 = PIN(47, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); +const mcu_pin_obj_t pin_GPIO48 = PIN(48, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL); \ No newline at end of file diff --git a/ports/espressif/peripherals/esp32p4/pins.h b/ports/espressif/peripherals/esp32p4/pins.h new file mode 100644 index 000000000000..19e2d5fba61a --- /dev/null +++ b/ports/espressif/peripherals/esp32p4/pins.h @@ -0,0 +1,102 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 microDev +// +// SPDX-License-Identifier: MIT + +// DO NOT include this file directly. +// Use shared-bindings/microcontroller/Pin.h instead. +// This ensures that all necessary includes are already included. + +#pragma once + +#define GPIO0_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO0; +#define GPIO1_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO1; +#define GPIO2_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO2; +#define GPIO3_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO3; +#define GPIO4_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO4; +#define GPIO5_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO5; +#define GPIO6_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO6; +#define GPIO7_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO7; +#define GPIO8_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO8; +#define GPIO9_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO9; +#define GPIO10_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO10; +#define GPIO11_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO11; +#define GPIO12_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO12; +#define GPIO13_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO13; +#define GPIO14_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO14; +#define GPIO15_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO15; +#define GPIO16_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO16; +#define GPIO17_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO17; +#define GPIO18_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO18; +#define GPIO19_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO19; +#define GPIO20_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO20; +#define GPIO21_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO21; +#define GPIO26_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO26; +#define GPIO27_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO27; +#define GPIO28_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO28; +#define GPIO29_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO29; +#define GPIO30_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO30; +#define GPIO31_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO31; +#define GPIO32_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO32; +#define GPIO33_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO33; +#define GPIO34_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO34; +#define GPIO35_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO35; +#define GPIO36_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO36; +#define GPIO37_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO37; +#define GPIO38_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO38; +#define GPIO39_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO39; +#define GPIO40_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO40; +#define GPIO41_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO41; +#define GPIO42_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO42; +#define GPIO43_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO43; +#define GPIO44_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO44; +#define GPIO45_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO45; +#define GPIO46_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO46; +#define GPIO47_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO47; +#define GPIO48_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO48; diff --git a/ports/espressif/peripherals/pins.h b/ports/espressif/peripherals/pins.h index 30bb21cdec70..f89855e308f5 100644 --- a/ports/espressif/peripherals/pins.h +++ b/ports/espressif/peripherals/pins.h @@ -52,6 +52,8 @@ extern const mp_obj_type_t mcu_pin_type; #include "esp32c3/pins.h" #elif defined(CONFIG_IDF_TARGET_ESP32C6) #include "esp32c6/pins.h" +#elif defined(CONFIG_IDF_TARGET_ESP32P4) +#include "esp32p4/pins.h" #elif defined(CONFIG_IDF_TARGET_ESP32H2) #include "esp32h2/pins.h" #elif defined(CONFIG_IDF_TARGET_ESP32S2) diff --git a/ports/espressif/supervisor/port.c b/ports/espressif/supervisor/port.c index 3288ec5c724a..a662e279ce8e 100644 --- a/ports/espressif/supervisor/port.c +++ b/ports/espressif/supervisor/port.c @@ -57,9 +57,18 @@ #include "soc/lp_aon_reg.h" #define CP_SAVED_WORD_REGISTER LP_AON_STORE0_REG #else +#ifdef CONFIG_IDF_TARGET_ESP32P4 +#include "soc/lp_system_reg.h" +#define CP_SAVED_WORD_REGISTER LP_SYSTEM_REG_LP_STORE15_REG + +#else +// To-do idf v5.0: remove following include #include "soc/rtc_cntl_reg.h" #define CP_SAVED_WORD_REGISTER RTC_CNTL_STORE0_REG #endif + +#endif + #include "soc/spi_pins.h" #include "bootloader_flash_config.h" @@ -238,20 +247,6 @@ safe_mode_t port_init(void) { common_hal_never_reset_pin(&pin_GPIOn_EXPAND(CONFIG_CONSOLE_UART_RX_GPIO)); #endif - #if DEBUG - // debug UART - #if defined(CONFIG_IDF_TARGET_ESP32C3) - common_hal_never_reset_pin(&pin_GPIO20); - common_hal_never_reset_pin(&pin_GPIO21); - #elif defined(CONFIG_IDF_TARGET_ESP32C6) - common_hal_never_reset_pin(&pin_GPIO16); - common_hal_never_reset_pin(&pin_GPIO17); - #elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) - common_hal_never_reset_pin(&pin_GPIO43); - common_hal_never_reset_pin(&pin_GPIO44); - #endif - #endif - #ifndef ENABLE_JTAG #define ENABLE_JTAG (0) #endif @@ -269,6 +264,11 @@ safe_mode_t port_init(void) { common_hal_never_reset_pin(&pin_GPIO40); common_hal_never_reset_pin(&pin_GPIO41); common_hal_never_reset_pin(&pin_GPIO42); + #elif defined(CONFIG_IDF_TARGET_ESP32P4) + common_hal_never_reset_pin(&pin_GPIO3); + common_hal_never_reset_pin(&pin_GPIO4); + common_hal_never_reset_pin(&pin_GPIO5); + common_hal_never_reset_pin(&pin_GPIO6); #endif #endif diff --git a/ports/espressif/tools/build_memory_info.py b/ports/espressif/tools/build_memory_info.py index fa97bb9ed611..ba4b6db4cbce 100644 --- a/ports/espressif/tools/build_memory_info.py +++ b/ports/espressif/tools/build_memory_info.py @@ -38,6 +38,14 @@ ("Internal SRAM 1", (0x3FC8_0000, 0x4037_8000), 416 * 1024), ("Internal SRAM 2", (0x3FCF_0000,), 64 * 1024), ], + "esp32p4": [ + # Name, Start, Length + ("RTC Fast Memory", (0x600F_E000,), 8 * 1024), + ("RTC Slow Memory", (0x5000_0000,), 8 * 1024), + ("Internal SRAM 0", (0x4037_0000,), 32 * 1024), + ("Internal SRAM 1", (0x3FC8_0000, 0x4037_8000), 416 * 1024), + ("Internal SRAM 2", (0x3FCF_0000,), 64 * 1024), + ], "esp32c2": [ # Name, Start, Length ("Internal SRAM 0", (0x4037_C000,), 16 * 1024),