From 7ba5513f9a2f8010601e8b11877788aa2148d0c9 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 24 Nov 2021 00:00:00 +0530 Subject: [PATCH 1/4] update espressif port - update esp-idf to v4.4 - add esp32s3 support - add analogio on esp32c3 - disable rgbmatrix on all espressif soc Co-authored-by: Scott Shawcroft Co-authored-by: Seon Rozenblum --- .gitmodules | 2 +- ports/espressif/Makefile | 49 +++++++----- ports/espressif/cam.c | 5 ++ .../espressif/common-hal/alarm/pin/PinAlarm.c | 2 +- .../espressif/common-hal/analogio/AnalogIn.c | 6 ++ .../espressif/common-hal/analogio/AnalogOut.c | 10 +++ .../common-hal/frequencyio/FrequencyIn.c | 10 ++- .../common-hal/microcontroller/Processor.c | 4 + .../common-hal/microcontroller/__init__.c | 7 +- ports/espressif/esp-idf | 2 +- ports/espressif/mpconfigport.mk | 9 ++- ports/espressif/mphalport.c | 13 +-- ports/espressif/peripherals/esp32s3/pins.c | 73 +++++++++++++++++ ports/espressif/peripherals/esp32s3/pins.h | 80 +++++++++++++++++++ ports/espressif/peripherals/pcnt.h | 1 + ports/espressif/peripherals/pins.h | 4 +- ports/espressif/supervisor/port.c | 16 ++-- ports/espressif/supervisor/usb.c | 7 +- 18 files changed, 243 insertions(+), 57 deletions(-) create mode 100644 ports/espressif/peripherals/esp32s3/pins.c create mode 100644 ports/espressif/peripherals/esp32s3/pins.h diff --git a/.gitmodules b/.gitmodules index e26d3dd76b..afc3add5fc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -149,7 +149,7 @@ [submodule "ports/espressif/esp-idf"] path = ports/espressif/esp-idf url = https://github.com/espressif/esp-idf.git - branch = release/v4.3 + branch = release/v4.4 [submodule "ports/espressif/certificates/nina-fw"] path = ports/espressif/certificates/nina-fw url = https://github.com/adafruit/nina-fw.git diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 7a034c9d2a..b29c9f35cf 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -59,12 +59,12 @@ include $(TOP)/supervisor/supervisor.mk # Include make rules and variables common across CircuitPython builds. include $(TOP)/py/circuitpy_defns.mk -ifeq ($(IDF_TARGET),esp32s2) -IDF_TARGET_ARCH = xtensa -CROSS_COMPILE = xtensa-$(IDF_TARGET)-elf- -else ifeq ($(IDF_TARGET),esp32c3) +ifeq ($(IDF_TARGET),esp32c3) IDF_TARGET_ARCH = riscv CROSS_COMPILE = riscv32-esp-elf- +else +IDF_TARGET_ARCH = xtensa +CROSS_COMPILE = xtensa-$(IDF_TARGET)-elf- endif ####################################### @@ -92,6 +92,7 @@ INC += -I.\ -isystem esp-idf/components/esp_common/include \ -isystem esp-idf/components/esp_event/include \ -isystem esp-idf/components/esp_hw_support/include \ + -isystem esp-idf/components/esp_hw_support/include/soc \ -isystem esp-idf/components/esp_netif/include \ -isystem esp-idf/components/esp_pm/include \ -isystem esp-idf/components/esp_ringbuf/include \ @@ -101,6 +102,8 @@ INC += -I.\ -isystem esp-idf/components/esp_wifi/include \ -isystem esp-idf/components/freertos/include \ -isystem esp-idf/components/freertos/include/freertos \ + -isystem esp-idf/components/freertos/include/esp_additions \ + -isystem esp-idf/components/freertos/include/esp_additions/freertos \ -isystem esp-idf/components/freertos/port/$(IDF_TARGET_ARCH)/include \ -isystem esp-idf/components/hal/include \ -isystem esp-idf/components/hal/$(IDF_TARGET)/include \ @@ -158,12 +161,11 @@ endif LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref -Wl,--undefined=uxTopUsedPriority -LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/$(IDF_TARGET) \ - -L$(BUILD)/esp-idf/esp-idf/$(IDF_TARGET)/ld \ - -Lesp-idf/components/$(IDF_TARGET)/ld \ +LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp_system/ld \ -Lesp-idf/components/esp_rom/$(IDF_TARGET)/ld \ - -T$(IDF_TARGET)_out.ld \ - -T$(IDF_TARGET).project.ld \ + -Lesp-idf/components/soc/$(IDF_TARGET)/ld \ + -Tmemory.ld \ + -Tsections.ld \ -T$(IDF_TARGET).peripherals.ld \ -T$(IDF_TARGET).rom.ld \ -T$(IDF_TARGET).rom.api.ld \ @@ -174,10 +176,13 @@ ifeq ($(IDF_TARGET),esp32c3) LDFLAGS += -Tesp32c3.rom.newlib.ld \ -Tesp32c3.rom.version.ld \ -Tesp32c3.rom.eco3.ld -else +else ifeq ($(IDF_TARGET),esp32s2) LDFLAGS += -T$(IDF_TARGET).rom.newlib-data.ld \ -T$(IDF_TARGET).rom.newlib-funcs.ld \ -T$(IDF_TARGET).rom.spiflash.ld +else ifeq ($(IDF_TARGET),esp32s3) +LDFLAGS += -Tesp32s3.rom.newlib.ld \ + -Tesp32s3.rom.version.ld endif LDFLAGS += -Wl,-Bstatic \ @@ -224,10 +229,14 @@ SRC_C += \ peripherals/timer.c \ peripherals/$(IDF_TARGET)/pins.c -ifneq ($(IDF_TARGET),esp32c3) +ifeq ($(IDF_TARGET),esp32s2) SRC_C += \ cam.c \ - i2s_lcd_esp32s2_driver.c \ + i2s_lcd_esp32s2_driver.c +endif + +ifneq ($(IDF_TARGET),esp32c3) +SRC_C += \ peripherals/pcnt.c \ peripherals/touch.c endif @@ -315,20 +324,15 @@ menuconfig: $(BUILD)/esp-idf/config # qstr builds include headers so we need to make sure they are up to date $(HEADER_BUILD)/qstr.split: | $(BUILD)/esp-idf/config/sdkconfig.h -ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET) $(IDF_TARGET_ARCH) app_update bootloader_support driver efuse esp_adc_cal esp_common esp_event esp_hw_support esp_netif esp_pm esp_ringbuf esp_rom esp_system esp_timer esp-tls esp_wifi freertos hal heap log lwip mbedtls newlib nvs_flash pthread soc spi_flash vfs wpa_supplicant +BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libwapi.a +BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS)) +ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) app_update bootloader_support driver efuse esp_adc_cal esp_common esp_event esp_hw_support esp_ipc esp_netif esp_pm esp_phy esp_ringbuf esp_rom esp_system esp_timer esp-tls esp_wifi freertos hal heap log lwip mbedtls newlib nvs_flash pthread soc spi_flash vfs wpa_supplicant ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a) -ESP_IDF_WIFI_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_WIFI_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a) MBEDTLS_COMPONENTS_LINK = crypto tls x509 MBEDTLS_COMPONENTS_LINK_EXPANDED = $(foreach component, $(MBEDTLS_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/mbedtls/mbedtls/library/libmbed$(component).a) -BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libphy.a -ifneq ($(IDF_TARGET),esp32c3) -BINARY_WIFI_BLOBS += librtc.a -endif -BINARY_BLOBS = $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS)) - ifeq ($(IDF_TARGET_ARCH),xtensa) BINARY_BLOBS += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a ESP_IDF_COMPONENTS_EXPANDED += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a @@ -360,17 +364,18 @@ endif esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h $(Q)ninja -C $(BUILD)/esp-idf \ bootloader/bootloader.bin \ + esp-idf/esp_system/__ldgen_output_sections.ld \ esp-idf/app_update/libapp_update.a \ esp-idf/bootloader_support/libbootloader_support.a \ esp-idf/driver/libdriver.a \ esp-idf/efuse/libefuse.a \ - esp-idf/$(IDF_TARGET)/lib$(IDF_TARGET).a \ - esp-idf/$(IDF_TARGET)/ld/$(IDF_TARGET).project.ld \ esp-idf/esp_adc_cal/libesp_adc_cal.a \ esp-idf/esp_common/libesp_common.a \ esp-idf/esp_event/libesp_event.a \ esp-idf/esp_hw_support/libesp_hw_support.a \ + esp-idf/esp_ipc/libesp_ipc.a \ esp-idf/esp_netif/libesp_netif.a \ + esp-idf/esp_phy/libesp_phy.a \ esp-idf/esp_pm/libesp_pm.a \ esp-idf/esp_ringbuf/libesp_ringbuf.a \ esp-idf/esp_rom/libesp_rom.a \ diff --git a/ports/espressif/cam.c b/ports/espressif/cam.c index 146df43a41..ea50785cd9 100644 --- a/ports/espressif/cam.c +++ b/ports/espressif/cam.c @@ -21,8 +21,13 @@ #include "esp_log.h" #include "soc/i2s_struct.h" #include "soc/apb_ctrl_reg.h" +#ifdef CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/lldesc.h" #include "esp32s2/rom/cache.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "esp32s3/rom/lldesc.h" +#include "esp32s3/rom/cache.h" +#endif #include "soc/dport_access.h" #include "soc/dport_reg.h" #include "driver/ledc.h" diff --git a/ports/espressif/common-hal/alarm/pin/PinAlarm.c b/ports/espressif/common-hal/alarm/pin/PinAlarm.c index 754902f678..6318cc2cca 100644 --- a/ports/espressif/common-hal/alarm/pin/PinAlarm.c +++ b/ports/espressif/common-hal/alarm/pin/PinAlarm.c @@ -32,11 +32,11 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" +#include "esp_sleep.h" #include "hal/gpio_ll.h" #include "esp_debug_helpers.h" #include "components/driver/include/driver/rtc_io.h" -#include "components/esp_system/include/esp_sleep.h" #include "components/freertos/include/freertos/FreeRTOS.h" void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, const mcu_pin_obj_t *pin, bool value, bool edge, bool pull) { diff --git a/ports/espressif/common-hal/analogio/AnalogIn.c b/ports/espressif/common-hal/analogio/AnalogIn.c index df39b30c63..ba85d42735 100644 --- a/ports/espressif/common-hal/analogio/AnalogIn.c +++ b/ports/espressif/common-hal/analogio/AnalogIn.c @@ -40,7 +40,13 @@ #define DEFAULT_VREF 1100 #define NO_OF_SAMPLES 2 #define ATTENUATION ADC_ATTEN_DB_11 +#ifdef CONFIG_IDF_TARGET_ESP32C3 +#define DATA_WIDTH ADC_WIDTH_BIT_12 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #define DATA_WIDTH ADC_WIDTH_BIT_13 +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#define DATA_WIDTH ADC_WIDTH_BIT_12 +#endif void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) { diff --git a/ports/espressif/common-hal/analogio/AnalogOut.c b/ports/espressif/common-hal/analogio/AnalogOut.c index 589c477a78..2c79124759 100644 --- a/ports/espressif/common-hal/analogio/AnalogOut.c +++ b/ports/espressif/common-hal/analogio/AnalogOut.c @@ -41,6 +41,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) { + #ifdef CONFIG_IDF_TARGET_ESP32S2 if (pin == &pin_GPIO17) { self->channel = DAC_CHANNEL_1; } else if (pin == &pin_GPIO18) { @@ -49,6 +50,9 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, mp_raise_ValueError(translate("Invalid DAC pin supplied")); } dac_output_enable(self->channel); + #else + mp_raise_NotImplementedError(NULL); + #endif } bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) { @@ -56,18 +60,24 @@ bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) { } void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) { + #ifdef CONFIG_IDF_TARGET_ESP32S2 dac_output_disable(self->channel); self->channel = DAC_CHANNEL_MAX; + #endif } void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self, uint16_t value) { + #ifdef CONFIG_IDF_TARGET_ESP32S2 uint8_t dac_value = (value * 255) / 65535; dac_output_enable(self->channel); dac_output_voltage(self->channel, dac_value); + #endif } void analogout_reset(void) { + #ifdef CONFIG_IDF_TARGET_ESP32S2 dac_output_disable(DAC_CHANNEL_1); dac_output_disable(DAC_CHANNEL_2); + #endif } diff --git a/ports/espressif/common-hal/frequencyio/FrequencyIn.c b/ports/espressif/common-hal/frequencyio/FrequencyIn.c index cd13cddc66..e4d65c95bd 100644 --- a/ports/espressif/common-hal/frequencyio/FrequencyIn.c +++ b/ports/espressif/common-hal/frequencyio/FrequencyIn.c @@ -56,11 +56,15 @@ static void IRAM_ATTR timer_interrupt_handler(void *self_in) { // reset interrupt timg_dev_t *device = self->timer.group ? &(TIMERG1) : &(TIMERG0); if (self->timer.idx) { - device->int_clr.t1 = 1; + device->int_clr_timers.t1_int_clr = 1; } else { - device->int_clr.t0 = 1; + device->int_clr_timers.t0_int_clr = 1; } - device->hw_timer[self->timer.idx].config.alarm_en = 1; + #ifdef CONFIG_IDF_TARGET_ESP32S2 + device->hw_timer[self->timer.idx].config.tx_alarm_en = 1; + #elif defined(CONFIG_IDF_TARGET_ESP32S3) + device->hw_timer[self->timer.idx].config.tn_alarm_en = 1; + #endif } static void init_pcnt(frequencyio_frequencyin_obj_t *self) { diff --git a/ports/espressif/common-hal/microcontroller/Processor.c b/ports/espressif/common-hal/microcontroller/Processor.c index c50c6fbf7a..500d1f6d3e 100644 --- a/ports/espressif/common-hal/microcontroller/Processor.c +++ b/ports/espressif/common-hal/microcontroller/Processor.c @@ -43,11 +43,15 @@ float common_hal_mcu_processor_get_temperature(void) { float tsens_out; + #ifdef CONFIG_IDF_TARGET_ESP32S3 + mp_raise_NotImplementedError(NULL); + #else temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT(); // DEFAULT: range:-10℃ ~ 80℃, error < 1℃. temp_sensor_set_config(temp_sensor); temp_sensor_start(); temp_sensor_read_celsius(&tsens_out); temp_sensor_stop(); + #endif return tsens_out; } diff --git a/ports/espressif/common-hal/microcontroller/__init__.c b/ports/espressif/common-hal/microcontroller/__init__.c index 909ce19b00..3cf41ba7f0 100644 --- a/ports/espressif/common-hal/microcontroller/__init__.c +++ b/ports/espressif/common-hal/microcontroller/__init__.c @@ -47,13 +47,16 @@ #ifdef CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/rtc.h" -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #include "esp32s2/rom/rtc.h" #include "esp32s2/rom/usb/usb_persist.h" #include "esp32s2/rom/usb/chip_usb_dw_wrapper.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "esp32s3/rom/rtc.h" +#include "esp32s3/rom/usb/usb_persist.h" +#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h" #endif - void common_hal_mcu_delay_us(uint32_t delay) { mp_hal_delay_us(delay); } diff --git a/ports/espressif/esp-idf b/ports/espressif/esp-idf index e493a4c30e..ddc44956bf 160000 --- a/ports/espressif/esp-idf +++ b/ports/espressif/esp-idf @@ -1 +1 @@ -Subproject commit e493a4c30e1b2f7c54a376327388b9e12262cbbf +Subproject commit ddc44956bf718540d5451e17e1becf6c7dffe5b8 diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index a7b69e0933..21459e01f5 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -26,7 +26,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= 1 CIRCUITPY_FREQUENCYIO ?= 1 CIRCUITPY_IMAGECAPTURE ?= 1 CIRCUITPY_I2CPERIPHERAL ?= 1 -CIRCUITPY_RGBMATRIX ?= 1 +CIRCUITPY_RGBMATRIX ?= 0 CIRCUITPY_ROTARYIO ?= 1 CIRCUITPY_NVM ?= 1 CIRCUITPY_PS2IO ?= 1 @@ -43,17 +43,18 @@ CIRCUITPY_USB = 0 CIRCUITPY_ALARM = 0 CIRCUITPY_COUNTIO = 0 CIRCUITPY_ROTARYIO = 0 -CIRCUITPY_ANALOGIO = 0 -CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_IMAGECAPTURE = 0 CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 +else ifeq ($(IDF_TARGET),esp32s3) +CIRCUITPY_IMAGECAPTURE = 0 +CIRCUITPY_PARALLELDISPLAY = 0 endif -# From the ESP32-S2 datasheet: +# From ESP32-S2/S3 Technical Reference Manual: # # Endpoint number 0 always present (bi-directional, consisting of EP0 IN and EP0 OUT) # Six additional endpoints (endpoint numbers 1 to 6), configurable as IN or OUT diff --git a/ports/espressif/mphalport.c b/ports/espressif/mphalport.c index f22856f0a4..39b080fba3 100644 --- a/ports/espressif/mphalport.c +++ b/ports/espressif/mphalport.c @@ -25,22 +25,17 @@ * THE SOFTWARE. */ -#include - #include "py/mphal.h" -#include "py/mpstate.h" -#include "py/gc.h" - -#include "esp_debug_helpers.h" +#include "supervisor/cpu.h" #ifdef CONFIG_IDF_TARGET_ESP32C3 #include "components/esp_rom/include/esp32c3/rom/ets_sys.h" -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #include "components/esp_rom/include/esp32s2/rom/ets_sys.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "components/esp_rom/include/esp32s3/rom/ets_sys.h" #endif -#include "supervisor/cpu.h" - void mp_hal_delay_us(mp_uint_t delay) { ets_delay_us(delay); } diff --git a/ports/espressif/peripherals/esp32s3/pins.c b/ports/espressif/peripherals/esp32s3/pins.c new file mode 100644 index 0000000000..891cc398ae --- /dev/null +++ b/ports/espressif/peripherals/esp32s3/pins.c @@ -0,0 +1,73 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#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); diff --git a/ports/espressif/peripherals/esp32s3/pins.h b/ports/espressif/peripherals/esp32s3/pins.h new file mode 100644 index 0000000000..c2a932f572 --- /dev/null +++ b/ports/espressif/peripherals/esp32s3/pins.h @@ -0,0 +1,80 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// DO NOT include this file directly. +// Use shared-bindings/microcontroller/Pin.h instead. +// This ensures that all necessary includes are already included. + +#ifndef MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_ESP32S3_PINS_H +#define MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_ESP32S3_PINS_H + +extern const mcu_pin_obj_t pin_GPIO0; +extern const mcu_pin_obj_t pin_GPIO1; +extern const mcu_pin_obj_t pin_GPIO2; +extern const mcu_pin_obj_t pin_GPIO3; +extern const mcu_pin_obj_t pin_GPIO4; +extern const mcu_pin_obj_t pin_GPIO5; +extern const mcu_pin_obj_t pin_GPIO6; +extern const mcu_pin_obj_t pin_GPIO7; +extern const mcu_pin_obj_t pin_GPIO8; +extern const mcu_pin_obj_t pin_GPIO9; +extern const mcu_pin_obj_t pin_GPIO10; +extern const mcu_pin_obj_t pin_GPIO11; +extern const mcu_pin_obj_t pin_GPIO12; +extern const mcu_pin_obj_t pin_GPIO13; +extern const mcu_pin_obj_t pin_GPIO14; +extern const mcu_pin_obj_t pin_GPIO15; +extern const mcu_pin_obj_t pin_GPIO16; +extern const mcu_pin_obj_t pin_GPIO17; +extern const mcu_pin_obj_t pin_GPIO18; +extern const mcu_pin_obj_t pin_GPIO19; +extern const mcu_pin_obj_t pin_GPIO20; +extern const mcu_pin_obj_t pin_GPIO21; +extern const mcu_pin_obj_t pin_GPIO26; +extern const mcu_pin_obj_t pin_GPIO27; +extern const mcu_pin_obj_t pin_GPIO28; +extern const mcu_pin_obj_t pin_GPIO29; +extern const mcu_pin_obj_t pin_GPIO30; +extern const mcu_pin_obj_t pin_GPIO31; +extern const mcu_pin_obj_t pin_GPIO32; +extern const mcu_pin_obj_t pin_GPIO33; +extern const mcu_pin_obj_t pin_GPIO34; +extern const mcu_pin_obj_t pin_GPIO35; +extern const mcu_pin_obj_t pin_GPIO36; +extern const mcu_pin_obj_t pin_GPIO37; +extern const mcu_pin_obj_t pin_GPIO38; +extern const mcu_pin_obj_t pin_GPIO39; +extern const mcu_pin_obj_t pin_GPIO40; +extern const mcu_pin_obj_t pin_GPIO41; +extern const mcu_pin_obj_t pin_GPIO42; +extern const mcu_pin_obj_t pin_GPIO43; +extern const mcu_pin_obj_t pin_GPIO44; +extern const mcu_pin_obj_t pin_GPIO45; +extern const mcu_pin_obj_t pin_GPIO46; +extern const mcu_pin_obj_t pin_GPIO47; +extern const mcu_pin_obj_t pin_GPIO48; + +#endif // MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_ESP32S3_PINS_H diff --git a/ports/espressif/peripherals/pcnt.h b/ports/espressif/peripherals/pcnt.h index 86a90b4444..b2bae7b371 100644 --- a/ports/espressif/peripherals/pcnt.h +++ b/ports/espressif/peripherals/pcnt.h @@ -28,6 +28,7 @@ #define MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_PCNT_HANDLER_H #include "driver/pcnt.h" +#include "soc/pcnt_struct.h" extern int peripherals_pcnt_init(pcnt_config_t pcnt_config); extern void peripherals_pcnt_deinit(pcnt_unit_t *unit); diff --git a/ports/espressif/peripherals/pins.h b/ports/espressif/peripherals/pins.h index 3bd66d49ac..4958c46410 100644 --- a/ports/espressif/peripherals/pins.h +++ b/ports/espressif/peripherals/pins.h @@ -67,8 +67,10 @@ extern const mp_obj_type_t mcu_pin_type; // Choose based on chip #ifdef CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/pins.h" -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #include "esp32s2/pins.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "esp32s3/pins.h" #endif #endif // MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_PINS_H diff --git a/ports/espressif/supervisor/port.c b/ports/espressif/supervisor/port.c index 30106075e7..277777a332 100644 --- a/ports/espressif/supervisor/port.c +++ b/ports/espressif/supervisor/port.c @@ -58,6 +58,9 @@ #if CIRCUITPY_COUNTIO || CIRCUITPY_ROTARYIO || CIRCUITPY_FREQUENCYIO #include "peripherals/pcnt.h" +#endif + +#if CIRCUITPY_TOUCHIO_USE_NATIVE #include "peripherals/touch.h" #endif @@ -69,17 +72,10 @@ #include "cam.h" #endif -#include "esp_heap_caps.h" -#include "esp_debug_helpers.h" - #include "soc/cache_memory.h" #include "soc/rtc_cntl_reg.h" -#ifdef CONFIG_IDF_TARGET_ESP32C3 -#include "components/esp_rom/include/esp32c3/rom/ets_sys.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "components/esp_rom/include/esp32s2/rom/ets_sys.h" -#endif +#include "esp_debug_helpers.h" #define HEAP_SIZE (48 * 1024) @@ -136,7 +132,7 @@ safe_mode_t port_init(void) { #ifdef CONFIG_IDF_TARGET_ESP32C3 common_hal_never_reset_pin(&pin_GPIO20); common_hal_never_reset_pin(&pin_GPIO21); - #elif CONFIG_IDF_TARGET_ESP32S2 + #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 @@ -153,7 +149,7 @@ safe_mode_t port_init(void) { common_hal_never_reset_pin(&pin_GPIO5); common_hal_never_reset_pin(&pin_GPIO6); common_hal_never_reset_pin(&pin_GPIO7); - #elif CONFIG_IDF_TARGET_ESP32S2 + #elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) common_hal_never_reset_pin(&pin_GPIO39); common_hal_never_reset_pin(&pin_GPIO40); common_hal_never_reset_pin(&pin_GPIO41); diff --git a/ports/espressif/supervisor/usb.c b/ports/espressif/supervisor/usb.c index 2137a7b0a4..7be3e84536 100644 --- a/ports/espressif/supervisor/usb.c +++ b/ports/espressif/supervisor/usb.c @@ -33,6 +33,7 @@ #include "shared/readline/readline.h" #include "hal/gpio_ll.h" +#include "hal/usb_hal.h" #include "soc/usb_periph.h" #include "components/driver/include/driver/gpio.h" @@ -40,15 +41,15 @@ #ifdef CONFIG_IDF_TARGET_ESP32C3 #include "components/esp_rom/include/esp32c3/rom/gpio.h" -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif defined(CONFIG_IDF_TARGET_ESP32S2) #include "components/esp_rom/include/esp32s2/rom/gpio.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "components/esp_rom/include/esp32s3/rom/gpio.h" #endif #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "hal/usb_hal.h" - #include "tusb.h" #ifdef CFG_TUSB_DEBUG From e5c125d15342d1c581f72f5ae43fe067f2f17391 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 24 Nov 2021 10:00:01 +0530 Subject: [PATCH 2/4] update espressif makefile formatting --- ports/espressif/Makefile | 190 +++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index b29c9f35cf..fd8c2b251d 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -71,67 +71,69 @@ endif # CFLAGS ####################################### -INC += -I.\ - -I./boards \ - -I./boards/$(BOARD) \ - -I./peripherals \ - -I../.. \ - -I../../lib/mp-readline \ - -I../../lib/tinyusb/src \ - -I../../supervisor/shared/usb \ - -I$(BUILD) \ - -I$(BUILD)/genhdr \ - -I$(BUILD)/esp-idf/config \ - -isystem esp-idf \ - -isystem esp-idf/components/app_update/include \ - -isystem esp-idf/components/bootloader_support/include \ - -isystem esp-idf/components/driver/include \ - -isystem esp-idf/components/driver/$(IDF_TARGET)/include \ - -isystem esp-idf/components/$(IDF_TARGET)/include \ - -isystem esp-idf/components/esp_adc_cal/include \ - -isystem esp-idf/components/esp_common/include \ - -isystem esp-idf/components/esp_event/include \ - -isystem esp-idf/components/esp_hw_support/include \ - -isystem esp-idf/components/esp_hw_support/include/soc \ - -isystem esp-idf/components/esp_netif/include \ - -isystem esp-idf/components/esp_pm/include \ - -isystem esp-idf/components/esp_ringbuf/include \ - -isystem esp-idf/components/esp_rom/include \ - -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/include \ - -isystem esp-idf/components/freertos/include/freertos \ - -isystem esp-idf/components/freertos/include/esp_additions \ - -isystem esp-idf/components/freertos/include/esp_additions/freertos \ - -isystem esp-idf/components/freertos/port/$(IDF_TARGET_ARCH)/include \ - -isystem esp-idf/components/hal/include \ - -isystem esp-idf/components/hal/$(IDF_TARGET)/include \ - -isystem esp-idf/components/hal/platform_port/include \ - -isystem esp-idf/components/heap/include \ - -isystem esp-idf/components/log/include \ - -isystem esp-idf/components/lwip/include \ - -isystem esp-idf/components/lwip/lwip/src/include \ - -isystem esp-idf/components/lwip/port/esp32/include \ - -isystem esp-idf/components/mbedtls/esp_crt_bundle/include \ - -isystem esp-idf/components/mbedtls/mbedtls/include \ - -isystem esp-idf/components/mbedtls/port/include \ - -isystem esp-idf/components/newlib/platform_include \ - -isystem esp-idf/components/nvs_flash/include \ - -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/$(IDF_TARGET_ARCH)/include \ - -isystem esp-idf/components/$(IDF_TARGET_ARCH)/$(IDF_TARGET)/include +INC += \ + -I.\ + -I./boards \ + -I./boards/$(BOARD) \ + -I./peripherals \ + -I../.. \ + -I../../lib/mp-readline \ + -I../../lib/tinyusb/src \ + -I../../supervisor/shared/usb \ + -I$(BUILD) \ + -I$(BUILD)/genhdr \ + -I$(BUILD)/esp-idf/config \ + -isystem esp-idf \ + -isystem esp-idf/components/app_update/include \ + -isystem esp-idf/components/bootloader_support/include \ + -isystem esp-idf/components/driver/include \ + -isystem esp-idf/components/driver/$(IDF_TARGET)/include \ + -isystem esp-idf/components/$(IDF_TARGET)/include \ + -isystem esp-idf/components/esp_adc_cal/include \ + -isystem esp-idf/components/esp_common/include \ + -isystem esp-idf/components/esp_event/include \ + -isystem esp-idf/components/esp_hw_support/include \ + -isystem esp-idf/components/esp_hw_support/include/soc \ + -isystem esp-idf/components/esp_netif/include \ + -isystem esp-idf/components/esp_pm/include \ + -isystem esp-idf/components/esp_ringbuf/include \ + -isystem esp-idf/components/esp_rom/include \ + -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/include \ + -isystem esp-idf/components/freertos/include/freertos \ + -isystem esp-idf/components/freertos/include/esp_additions \ + -isystem esp-idf/components/freertos/include/esp_additions/freertos \ + -isystem esp-idf/components/freertos/port/$(IDF_TARGET_ARCH)/include \ + -isystem esp-idf/components/hal/include \ + -isystem esp-idf/components/hal/$(IDF_TARGET)/include \ + -isystem esp-idf/components/hal/platform_port/include \ + -isystem esp-idf/components/heap/include \ + -isystem esp-idf/components/log/include \ + -isystem esp-idf/components/lwip/include \ + -isystem esp-idf/components/lwip/lwip/src/include \ + -isystem esp-idf/components/lwip/port/esp32/include \ + -isystem esp-idf/components/mbedtls/esp_crt_bundle/include \ + -isystem esp-idf/components/mbedtls/mbedtls/include \ + -isystem esp-idf/components/mbedtls/port/include \ + -isystem esp-idf/components/newlib/platform_include \ + -isystem esp-idf/components/nvs_flash/include \ + -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/$(IDF_TARGET_ARCH)/include \ + -isystem esp-idf/components/$(IDF_TARGET_ARCH)/$(IDF_TARGET)/include # See https://github.com/espressif/esp-idf/issues/6906 ifeq ($(IDF_TARGET),esp32c3) CFLAGS += -include "esp32c3_fix.h" endif -CFLAGS += -DHAVE_CONFIG_H \ - -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" \ - -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX +CFLAGS += \ + -DHAVE_CONFIG_H \ + -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" \ + -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX # Make our canary value match FreeRTOS's # This define is in FreeRTOS as tskSTACK_FILL_BYTE 0xa5U which we expand out to a full word. @@ -161,35 +163,38 @@ endif LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref -Wl,--undefined=uxTopUsedPriority -LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp_system/ld \ - -Lesp-idf/components/esp_rom/$(IDF_TARGET)/ld \ - -Lesp-idf/components/soc/$(IDF_TARGET)/ld \ - -Tmemory.ld \ - -Tsections.ld \ - -T$(IDF_TARGET).peripherals.ld \ - -T$(IDF_TARGET).rom.ld \ - -T$(IDF_TARGET).rom.api.ld \ - -T$(IDF_TARGET).rom.libgcc.ld \ - -T$(IDF_TARGET).rom.newlib-nano.ld +LDFLAGS += \ + -L$(BUILD)/esp-idf/esp-idf/esp_system/ld \ + -Lesp-idf/components/esp_rom/$(IDF_TARGET)/ld \ + -Lesp-idf/components/soc/$(IDF_TARGET)/ld \ + -Tmemory.ld \ + -Tsections.ld \ + -T$(IDF_TARGET).peripherals.ld \ + -T$(IDF_TARGET).rom.ld \ + -T$(IDF_TARGET).rom.api.ld \ + -T$(IDF_TARGET).rom.libgcc.ld \ + -T$(IDF_TARGET).rom.newlib-nano.ld \ + -Wl,-Bstatic \ + -Wl,--no-warn-mismatch \ + -Wl,--build-id=none \ + -fno-rtti ifeq ($(IDF_TARGET),esp32c3) -LDFLAGS += -Tesp32c3.rom.newlib.ld \ - -Tesp32c3.rom.version.ld \ - -Tesp32c3.rom.eco3.ld +LDFLAGS += \ + -Tesp32c3.rom.newlib.ld \ + -Tesp32c3.rom.version.ld \ + -Tesp32c3.rom.eco3.ld else ifeq ($(IDF_TARGET),esp32s2) -LDFLAGS += -T$(IDF_TARGET).rom.newlib-data.ld \ - -T$(IDF_TARGET).rom.newlib-funcs.ld \ - -T$(IDF_TARGET).rom.spiflash.ld +LDFLAGS += \ + -T$(IDF_TARGET).rom.newlib-data.ld \ + -T$(IDF_TARGET).rom.newlib-funcs.ld \ + -T$(IDF_TARGET).rom.spiflash.ld else ifeq ($(IDF_TARGET),esp32s3) -LDFLAGS += -Tesp32s3.rom.newlib.ld \ - -Tesp32s3.rom.version.ld +LDFLAGS += \ + -Tesp32s3.rom.newlib.ld \ + -Tesp32s3.rom.version.ld endif -LDFLAGS += -Wl,-Bstatic \ - -Wl,--no-warn-mismatch \ - -Wl,--build-id=none \ - -fno-rtti - LIBS := -lgcc -lc -lstdc++ # Use toolchain libm if we're not using our own. @@ -229,16 +234,15 @@ SRC_C += \ peripherals/timer.c \ peripherals/$(IDF_TARGET)/pins.c +ifneq ($(IDF_TARGET),esp32c3) +SRC_C += \ + peripherals/pcnt.c \ + peripherals/touch.c ifeq ($(IDF_TARGET),esp32s2) SRC_C += \ cam.c \ i2s_lcd_esp32s2_driver.c endif - -ifneq ($(IDF_TARGET),esp32c3) -SRC_C += \ - peripherals/pcnt.c \ - peripherals/touch.c endif $(BUILD)/i2s_lcd_esp32s2_driver.o: CFLAGS += -Wno-sign-compare @@ -247,16 +251,15 @@ ifneq ($(CIRCUITPY_USB),0) SRC_C += lib/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c endif -SRC_S = - -SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ - $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ - $(addprefix common-hal/, $(SRC_COMMON_HAL)) - -SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ - $(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ - $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) +SRC_COMMON_HAL_EXPANDED = \ + $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ + $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ + $(addprefix common-hal/, $(SRC_COMMON_HAL)) +SRC_SHARED_MODULE_EXPANDED = \ + $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) ifneq ($(FROZEN_MPY_DIR),) FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py') @@ -270,7 +273,6 @@ ifeq ($(INTERNAL_LIBM),1) OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o)) endif OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o)) -OBJ += $(addprefix $(BUILD)/, $(SRC_S:.S=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) $(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os @@ -280,8 +282,6 @@ $(BUILD)/lib/protomatter/src/core.o: CFLAGS += -DESP32 # List of sources for qstr extraction SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) -# Sources that only hold QSTRs after pre-processing. -SRC_QSTR_PREPROCESSOR += # IDF build commands IDF_PATH = $(realpath ./esp-idf) From dddc282e34a318d15a3ecba00ea8e482fb82ad82 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Fri, 26 Nov 2021 22:44:22 +0530 Subject: [PATCH 3/4] update default sdkconfig and correct bootloader offset --- ports/espressif/Makefile | 11 ++++++----- ports/espressif/esp-idf-config/sdkconfig.defaults | 14 ++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index fd8c2b251d..c997dc6a0a 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -338,13 +338,14 @@ BINARY_BLOBS += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a ESP_IDF_COMPONENTS_EXPANDED += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a endif -ifeq ($(IDF_TARGET), esp32c3) -ESPTOOL_BAUDRATE = 230400 -BOOTLOADER_OFFSET = 0x0000 +ifeq ($(IDF_TARGET),esp32c3) +BOOTLOADER_OFFSET = 0x0 +else ifeq ($(IDF_TARGET),esp32s3) +BOOTLOADER_OFFSET = 0x0 else -ESPTOOL_BAUDRATE = 460800 BOOTLOADER_OFFSET = 0x1000 endif + PARTITION_TABLE_OFFSET = 0x8000 FIRMWARE_OFFSET = 0x10000 @@ -352,7 +353,7 @@ ESP_AUTOGEN_LD = $(BUILD)/esp-idf/esp-idf/$(IDF_TARGET)/$(IDF_TARGET)_out.ld $(B FLASH_FLAGS = --flash_mode $(CIRCUITPY_ESP_FLASH_MODE) --flash_freq $(CIRCUITPY_ESP_FLASH_FREQ) --flash_size $(CIRCUITPY_ESP_FLASH_SIZE) -ESPTOOL_FLAGS ?= -b $(ESPTOOL_BAUDRATE) --before=default_reset --after=no_reset +ESPTOOL_FLAGS ?= --before=default_reset --after=no_reset ifeq ($(IDF_TARGET),esp32c3) all: $(BUILD)/firmware.bin diff --git a/ports/espressif/esp-idf-config/sdkconfig.defaults b/ports/espressif/esp-idf-config/sdkconfig.defaults index 25e2f103d5..67e2594339 100644 --- a/ports/espressif/esp-idf-config/sdkconfig.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig.defaults @@ -1,9 +1,3 @@ -# -# Bootloader config -# -# CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V is not set -# end of Bootloader config - # # Serial flasher config # @@ -50,6 +44,14 @@ CONFIG_ESP32S2_DATA_CACHE_16KB=y # end of Cache config # end of ESP32S2-specific +# +# ESP32S3-specific +# +# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160 is not set +CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=240 +# end of ESP32S3-specific + # # Common ESP-related # From 9e286432d2546c658cb942ea516bad9603f7f192 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Fri, 3 Dec 2021 20:30:40 +0530 Subject: [PATCH 4/4] add esp32s3 documentation in readme --- README.rst | 4 +- ports/espressif/README.rst | 84 ++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index dafc8ee96e..801466cbad 100644 --- a/README.rst +++ b/README.rst @@ -213,7 +213,7 @@ Supported Support status ================ ============================================================ atmel-samd ``SAMD21`` stable | ``SAMD51`` stable cxd56 stable -espressif ``ESP32-C3`` beta | ``ESP32-S2`` stable +espressif ``ESP32-C3`` beta | ``ESP32-S2`` stable | ``ESP32-S3`` beta litex alpha mimxrt10xx alpha nrf stable @@ -229,7 +229,7 @@ unix alpha Boards ~~~~~~ -- Each ``port`` has a ``boards`` directory containing variations of boards +- Each ``port`` has a ``boards`` directory containing boards which belong to a specific microcontroller line. - A list of native modules supported by a particular board can be found `here `__. diff --git a/ports/espressif/README.rst b/ports/espressif/README.rst index 165f7a161e..7ef0fc5dc6 100644 --- a/ports/espressif/README.rst +++ b/ports/espressif/README.rst @@ -11,6 +11,7 @@ Support Status: ESP32-C3, "beta" ESP32-S2, "stable" + ESP32-S3, "beta" How this port is organized: --------------------------------------- @@ -31,9 +32,11 @@ Connecting to the ESP32-C3 **USB Connetion:** -On ESP32-C3 REV3 chips, a USB Serial/JTAG Controller is available. Note: The USB connection cannot be used for a ``CIRCUITPY`` drive. +On ESP32-C3 REV3 chips, a USB Serial/JTAG Controller is available. Note: This USB connection cannot be used for a ``CIRCUITPY`` drive. -Depending on the board you have the USB port may or may not be connected to native USB, if it isn't connected to native USB then following connections need to be made to get serial console, REPL interface, flashing CircuitPython and JTAG debugging. +Depending on the board you have, the USB port may or may not be connected to native USB. + +Following connections need to be made if native USB isn't available on USB port: .. csv-table:: :header: GPIO, USB @@ -47,7 +50,9 @@ Connect these pins using a `USB adapter ` **UART Connection:** -A `USB to UART convertor `_ can be used for connecting to ESP32-C3 to get serial console, REPL interface and flashing CircuitPython. Following connections need to be made in this case. +A `USB to UART convertor `_ can be used for connecting to ESP32-C3 to get serial console, REPL interface and flashing CircuitPython. + +Following connections need to be made in this case. .. csv-table:: :header: GPIO, UART @@ -66,7 +71,9 @@ Connecting to the ESP32-S2 **USB Connetion:** -Depending on the board you have the USB port may or may not be connected to native USB, if it isn't connected to native USB then following connections need to be made to get CircuitPython working. +Depending on the board you have, the USB port may or may not be connected to native USB. + +Following connections need to be made if native USB isn't available on USB port: .. csv-table:: :header: GPIO, USB @@ -78,16 +85,79 @@ Depending on the board you have the USB port may or may not be connected to nati Connect these pins using a `USB adapter `_ or `breakout cable `_ to access the CircuitPython drive. +**UART Connection:** + +A `USB to UART convertor `_ can be used for connecting to ESP32-S2 to get serial console and flashing CircuitPython. + +Following connections need to be made in this case: + +.. csv-table:: + :header: GPIO, UART + + 43, "RX" + 44, "TX" + GND, "GND" + 5V, "5V" + +**BLE Connection:** + +This feature isn't available on ESP32-S2. + +Connecting to the ESP32-S3 +--------------------------------------- + +**USB Connetion:** + +Depending on the board you have, the USB port may or may not be connected to native USB. + +Following connections need to be made if native USB isn't available on USB port: + +.. csv-table:: + :header: GPIO, USB + + 20, "D+ (green)" + 19, "D- (white)" + GND, "GND (black)" + 5V, "5V (red)" + +Connect these pins using a `USB adapter `_ or `breakout cable `_ to access the CircuitPython drive. + +**UART Connection:** + +A `USB to UART convertor `_ can be used for connecting to ESP32-S3 to get serial console and flashing CircuitPython. + +Following connections need to be made in this case: + +.. csv-table:: + :header: GPIO, UART + + 43, "RX" + 44, "TX" + GND, "GND" + 5V, "5V" + +**BLE Connection:** + +This feature is not yet available and currently under development. + Building and flashing --------------------------------------- -Before building or flashing the, you must `install the esp-idf `_. This must be re-done every time the esp-idf is updated, but not every time you build. Run ``cd ports/espressif`` from ``circuitpython/`` to move to the espressif port root, and run: +Before building or flashing the, you must `install the esp-idf `_. + +Note: This must be re-done every time the esp-idf is updated, but not every time you build. + +Run ``cd ports/espressif`` from ``circuitpython/`` to move to the espressif port root, and run: .. code-block:: ./esp-idf/install.sh -After this initial installation, you must add the esp-idf tools to your path. You must also do this **any time you open a new bash environment for building or flashing**: +After this initial installation, you must add the esp-idf tools to your path. + +Note: This must be re-done every time you open a new bash environment for building or flashing. + +Run ``cd ports/espressif`` from ``circuitpython/`` to move to the espressif port root, and run: .. code-block:: @@ -106,7 +176,7 @@ Building boards is typically done through ``make BOARD=board_id``. The default p Debugging --------------------------------------- -TODO: Add documentation for ESP32-C3 JTAG feature. +TODO: Add documentation for ESP32-C3/S3 JTAG feature. The ESP32-S2 supports JTAG debugging over OpenOCD using a JLink or other probe hardware. The official tutorials can be found on the Espressif website `here `_, but they are mostly for the ESP32-S2 Kaluga, which has built-in debugging.