Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable USB on ESP32-P4 #9841

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 410 files
1 change: 1 addition & 0 deletions ports/broadcom/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SRC_C += bindings/videocore/__init__.c \
lib/sdmmc/sdmmc_mmc.c \
lib/sdmmc/sdmmc_sd.c \
lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c \
lib/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c \
peripherals/broadcom/caches.c \
peripherals/broadcom/gen/interrupt_handlers.c \
peripherals/broadcom/gen/pins.c \
Expand Down
6 changes: 5 additions & 1 deletion ports/espressif/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ INC += \
-isystem esp-idf/components/esp_hw_support/dma/include \
-isystem esp-idf/components/esp_hw_support/include \
-isystem esp-idf/components/esp_hw_support/include/soc \
-isystem esp-idf/components/esp_mm/include \
-isystem esp-idf/components/esp_netif/include \
-isystem esp-idf/components/esp_partition/include \
-isystem esp-idf/components/esp_pm/include \
Expand Down Expand Up @@ -412,7 +413,9 @@ SRC_C += peripherals/touch.c
endif

ifneq ($(CIRCUITPY_USB_DEVICE),0)
SRC_C += lib/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c
SRC_C += \
lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c \
lib/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c
endif

ifneq ($(CIRCUITPY_AUDIOBUSIO),0)
Expand Down Expand Up @@ -766,6 +769,7 @@ endif

UF2_FAMILY_ID_esp32s2 = 0xbfdd4eee
UF2_FAMILY_ID_esp32s3 = 0xc47e5767
UF2_FAMILY_ID_esp32p4 = 0x540ddf62

$(BUILD)/firmware.uf2: $(BUILD)/circuitpython-firmware.bin
$(STEPECHO) "Create $@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@

#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
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# USB_VID = 0x303A
# USB_PID = 0x7003
# USB_PRODUCT = "ESP32-P4-Function-EV"
# USB_MANUFACTURER = "Espressif"
USB_VID = 0x303A
USB_PID = 0x7013
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_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m

CIRCUITPY_ESP_PSRAM_SIZE = 32MB
CIRCUITPY_ESP_PSRAM_MODE = opi
CIRCUITPY_ESP_PSRAM_FREQ = 80m
CIRCUITPY_ESP_PSRAM_MODE = hpi
CIRCUITPY_ESP_PSRAM_FREQ = 200m
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# USB_VID = 0x303A
# USB_PID = 0x7003
# USB_PRODUCT = "ESP32-P4 Stamp XL"
# USB_MANUFACTURER = "Solder Party"
USB_VID = 0x1209
USB_PID = 0x0001
USB_PRODUCT = "ESP32-P4 Stamp XL"
USB_MANUFACTURER = "Solder Party"

IDF_TARGET = esp32p4

CIRCUITPY_ESP_FLASH_SIZE = 16MB
CIRCUITPY_ESP_FLASH_MODE = opi
CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m

CIRCUITPY_ESP_PSRAM_SIZE = 32MB
CIRCUITPY_ESP_PSRAM_MODE = opi
CIRCUITPY_ESP_PSRAM_FREQ = 80m
CIRCUITPY_ESP_PSRAM_MODE = hpi
CIRCUITPY_ESP_PSRAM_FREQ = 200m
21 changes: 21 additions & 0 deletions ports/espressif/esp-idf-config/sdkconfig-esp32p4.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Espressif IoT Development Framework Configuration
#
#
# Component config
#
#
# Bluetooth
#
# CONFIG_BT_ENABLED is not set
# end of Bluetooth

#
# mbedTLS
#
# CONFIG_MBEDTLS_CMAC_C is not set
# end of mbedTLS

# end of Component config

# end of Espressif IoT Development Framework Configuration
4 changes: 4 additions & 0 deletions ports/espressif/esp-idf-config/sdkconfig-psram-200m.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# For ESP32-P4
CONFIG_SPIRAM_SPEED_200M=y
# CONFIG_SPIRAM_SPEED_20M is not set
CONFIG_SPIRAM_SPEED=200
3 changes: 3 additions & 0 deletions ports/espressif/esp-idf-config/sdkconfig-psram-hpi.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CONFIG_SPIRAM_MODE_QUAD is not set
# CONFIG_SPIRAM_MODE_OCT is not set
CONFIG_SPIRAM_MODE_HEX=y
2 changes: 2 additions & 0 deletions ports/espressif/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#define CIRCUITPY_DIGITALIO_HAVE_INPUT_ONLY (1)

#define CIRCUITPY_USB_DEVICE_INSTANCE 1

#include "py/circuitpy_mpconfig.h"

#define MICROPY_NLR_SETJMP (1)
Expand Down
11 changes: 8 additions & 3 deletions ports/espressif/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,14 @@ 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
# Second stage bootloader doesn't work when the factory partition is empty due to
# UF2 missing.
UF2_BOOTLOADER = 0
USB_HIGHSPEED = 1
CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_TUSB_MEM_ALIGN = 64

CIRCUITPY_MAX3421E = 0

# Update this for the 40mhz processor.
Expand Down
7 changes: 7 additions & 0 deletions ports/espressif/supervisor/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ void init_usb_hardware(void) {
// Configure USB PHY
usb_phy_config_t phy_conf = {
.controller = USB_PHY_CTRL_OTG,
.target = USB_PHY_TARGET_INT,

.otg_mode = USB_OTG_MODE_DEVICE,
#ifdef CONFIG_IDF_TARGET_ESP32P4
.otg_speed = USB_PHY_SPEED_HIGH,
#else
.otg_speed = USB_PHY_SPEED_FULL,
#endif
};
usb_new_phy(&phy_conf, &phy_hdl);

Expand Down
9 changes: 4 additions & 5 deletions ports/espressif/tools/build_memory_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@
],
"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),
("HP RAM", (0x3010_0000,), 8 * 1024),
("PSRAM", (0x4800_0000,), 64 * 1024 * 1024),
("L2MEM", (0x4FF0_0000,), 768 * 1024),
("LP RAM", (0x5010_8000,), 32 * 1024),
],
"esp32c2": [
# Name, Start, Length
Expand Down
4 changes: 3 additions & 1 deletion ports/stm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ ifneq ($(CIRCUITPY_AUDIOBUSIO_PDMIN),0)
endif

ifneq ($(CIRCUITPY_USB),0)
SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c
SRC_C += \
lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c \
lib/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c
endif

SRC_S = \
Expand Down
2 changes: 2 additions & 0 deletions ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ LD_COMMON = boards/common_default.ld
LD_FILE = boards/STM32F411_fs.ld

# Too big for the flash
CIRCUITPY_AESIO = 0
CIRCUITPY_AUDIOCORE = 0
CIRCUITPY_AUDIOPWMIO = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_BITMAPTOOLS = 0
CIRCUITPY_BLEIO_HCI = 0
CIRCUITPY_CODEOP = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_VECTORIO = 0
6 changes: 6 additions & 0 deletions supervisor/shared/usb/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ extern "C" {
#endif
#endif

// Use DMA with the USB peripheral.
#if defined(CONFIG_IDF_TARGET_ESP32P4) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
#define CFG_TUD_DWC2_DMA_ENABLE (1)
#define CFG_TUH_DWC2_DMA_ENABLE (1)
tannewt marked this conversation as resolved.
Show resolved Hide resolved
#endif

// Vendor name included in Inquiry response, max 8 bytes
#define CFG_TUD_MSC_VENDOR USB_MANUFACTURER_8

Expand Down
5 changes: 5 additions & 0 deletions supervisor/shared/usb/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "py/objstr.h"
#include "supervisor/background_callback.h"
#include "supervisor/linker.h"
#include "supervisor/shared/tick.h"
#include "supervisor/usb.h"
#include "shared/readline/readline.h"

Expand Down Expand Up @@ -152,6 +153,10 @@ void usb_background(void) {
}
}

uint32_t tusb_time_millis_api(void) {
return supervisor_ticks_ms32();
}

static background_callback_t usb_callback;
static void usb_background_do(void *unused) {
usb_background();
Expand Down