Skip to content

Commit e1fc85c

Browse files
committed
fix usb issue with latest idf
1 parent b7ed18d commit e1fc85c

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

ports/esp32s2/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ menuconfig: $(BUILD)/esp-idf/config
271271
$(HEADER_BUILD)/qstr.i.last: | $(BUILD)/esp-idf/config/sdkconfig.h
272272

273273
# Order here matters
274-
ESP_IDF_COMPONENTS_LINK = freertos log esp_system esp32s2 bootloader_support pthread esp_timer vfs spi_flash app_update esp_common esp32s2 heap newlib driver xtensa soc esp_ringbuf esp_wifi esp_event wpa_supplicant mbedtls efuse nvs_flash esp_netif lwip esp_rom esp-tls
274+
ESP_IDF_COMPONENTS_LINK = freertos log hal esp_system esp32s2 bootloader_support pthread esp_timer vfs spi_flash app_update esp_common esp32s2 heap newlib driver xtensa soc esp_ringbuf esp_wifi esp_event wpa_supplicant mbedtls efuse nvs_flash esp_netif lwip esp_rom esp-tls
275275

276276
ESP_IDF_COMPONENTS_INCLUDE = driver freertos log soc
277277

@@ -283,11 +283,11 @@ ESP_IDF_WIFI_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_WIFI_COMPONENT
283283
MBEDTLS_COMPONENTS_LINK = crypto tls x509
284284
MBEDTLS_COMPONENTS_LINK_EXPANDED = $(foreach component, $(MBEDTLS_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/mbedtls/mbedtls/library/libmbed$(component).a)
285285

286-
BINARY_BLOBS = esp-idf/components/xtensa/esp32s2/libhal.a
286+
BINARY_BLOBS = esp-idf/components/xtensa/esp32s2/libxt_hal.a
287287
BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a librtc.a libsmartconfig.a libphy.a
288288
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/esp32s2/, $(BINARY_WIFI_BLOBS))
289289

290-
ESP_IDF_COMPONENTS_EXPANDED += $(BUILD)/esp-idf/esp-idf/soc/soc/esp32s2/libsoc_esp32s2.a esp-idf/components/xtensa/esp32s2/libhal.a
290+
ESP_IDF_COMPONENTS_EXPANDED += $(BUILD)/esp-idf/esp-idf/soc/soc/esp32s2/libsoc_esp32s2.a esp-idf/components/xtensa/esp32s2/libxt_hal.a
291291
ESP_AUTOGEN_LD = $(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld $(BUILD)/esp-idf/esp-idf/esp32s2/ld/esp32s2.project.ld
292292

293293
FLASH_FLAGS = --flash_mode $(CIRCUITPY_ESP_FLASH_MODE) --flash_freq $(CIRCUITPY_ESP_FLASH_FREQ) --flash_size $(CIRCUITPY_ESP_FLASH_SIZE)

ports/esp32s2/supervisor/usb.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "components/driver/include/driver/periph_ctrl.h"
3434
#include "components/driver/include/driver/gpio.h"
3535
#include "components/esp_rom/include/esp32s2/rom/gpio.h"
36+
#include "components/esp_rom/include/esp_rom_gpio.h"
37+
#include "components/hal/esp32s2/include/hal/gpio_ll.h"
3638

3739
#include "freertos/FreeRTOS.h"
3840
#include "freertos/task.h"
@@ -68,17 +70,41 @@ void usb_device_task(void* param)
6870
}
6971
}
7072

73+
static void configure_pins (usb_hal_context_t *usb)
74+
{
75+
/* usb_periph_iopins currently configures USB_OTG as USB Device.
76+
* Introduce additional parameters in usb_hal_context_t when adding support
77+
* for USB Host.
78+
*/
79+
for ( const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin ) {
80+
if ( (usb->use_external_phy) || (iopin->ext_phy_only == 0) ) {
81+
esp_rom_gpio_pad_select_gpio(iopin->pin);
82+
if ( iopin->is_output ) {
83+
esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false);
84+
}
85+
else {
86+
esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false);
87+
if ( (iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH) ) {
88+
gpio_ll_input_enable(&GPIO, iopin->pin);
89+
}
90+
}
91+
esp_rom_gpio_pad_unhold(iopin->pin);
92+
}
93+
}
94+
if ( !usb->use_external_phy ) {
95+
gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
96+
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
97+
}
98+
}
99+
71100
void init_usb_hardware(void) {
72101
periph_module_reset(PERIPH_USB_MODULE);
73102
periph_module_enable(PERIPH_USB_MODULE);
74103
usb_hal_context_t hal = {
75104
.use_external_phy = false // use built-in PHY
76105
};
77106
usb_hal_init(&hal);
78-
79-
// Initialize the pin drive strength.
80-
gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
81-
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
107+
configure_pins(&hal);
82108

83109
(void) xTaskCreateStatic(usb_device_task,
84110
"usbd",

0 commit comments

Comments
 (0)