|
27 | 27 | #include "freertos/semphr.h" |
28 | 28 |
|
29 | 29 | #include "hal/gpio_ll.h" |
30 | | -#include "hal/usb_hal.h" |
| 30 | + |
| 31 | +#include "esp_private/usb_phy.h" |
| 32 | +#include "soc/usb_pins.h" |
| 33 | + |
31 | 34 | #include "soc/usb_periph.h" |
32 | 35 | #include "esp_private/periph_ctrl.h" |
33 | 36 |
|
@@ -89,7 +92,6 @@ extern bool board_init_extension(); |
89 | 92 | #endif |
90 | 93 |
|
91 | 94 | extern int main(void); |
92 | | -static void configure_pins(usb_hal_context_t* usb); |
93 | 95 | static void internal_timer_cb(void* arg); |
94 | 96 |
|
95 | 97 | //--------------------------------------------------------------------+ |
@@ -257,16 +259,19 @@ void board_init(void) { |
257 | 259 | esp_timer_create(&periodic_timer_args, &timer_hdl); |
258 | 260 | } |
259 | 261 |
|
| 262 | +static usb_phy_handle_t phy_hdl; |
260 | 263 | void board_dfu_init(void) { |
261 | | - // USB Controller Hal init |
262 | | - periph_module_reset(PERIPH_USB_MODULE); |
263 | | - periph_module_enable(PERIPH_USB_MODULE); |
264 | | - |
265 | | - usb_hal_context_t hal = { |
266 | | - .use_external_phy = false // use built-in PHY |
| 264 | + // Configure USB PHY |
| 265 | + usb_phy_config_t phy_conf = { |
| 266 | + .controller = USB_PHY_CTRL_OTG, |
| 267 | + .target = USB_PHY_TARGET_INT, |
| 268 | + .otg_mode = USB_OTG_MODE_DEVICE, |
| 269 | + // https://github.com/hathach/tinyusb/issues/2943#issuecomment-2601888322 |
| 270 | + // Set speed to undefined (auto-detect) to avoid timinng/racing issue with S3 with host such as macOS |
| 271 | + .otg_speed = USB_PHY_SPEED_UNDEFINED, |
267 | 272 | }; |
268 | | - usb_hal_init(&hal); |
269 | | - configure_pins(&hal); |
| 273 | + |
| 274 | + usb_new_phy(&phy_conf, &phy_hdl); |
270 | 275 | } |
271 | 276 |
|
272 | 277 | void board_reset(void) { |
@@ -345,7 +350,6 @@ void board_timer_stop(void) { |
345 | 350 |
|
346 | 351 | #if CONFIG_IDF_TARGET_ESP32S3 |
347 | 352 | #include "hal/usb_serial_jtag_ll.h" |
348 | | -#include "hal/usb_fsls_phy_ll.h" |
349 | 353 |
|
350 | 354 | static void hw_cdc_reset_handler(void *arg) { |
351 | 355 | portBASE_TYPE xTaskWoken = 0; |
@@ -389,7 +393,7 @@ static void usb_switch_to_cdc_jtag(void) { |
389 | 393 | gpio_set_level((gpio_num_t)USBPHY_DP_NUM, 0); |
390 | 394 |
|
391 | 395 | // Initialize CDC+JTAG ISR to listen for BUS_RESET |
392 | | - usb_fsls_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG); |
| 396 | + usb_serial_jtag_ll_phy_enable_external(false); |
393 | 397 | usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); |
394 | 398 | usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK); |
395 | 399 | usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_BUS_RESET); |
@@ -579,32 +583,3 @@ void dotstar_write(uint8_t const rgb[]) { |
579 | 583 | } |
580 | 584 |
|
581 | 585 | #endif |
582 | | - |
583 | | -//--------------------------------------------------------------------+ |
584 | | -// Helper |
585 | | -//--------------------------------------------------------------------+ |
586 | | -static void configure_pins(usb_hal_context_t* usb) { |
587 | | - /* usb_periph_iopins currently configures USB_OTG as USB Device. |
588 | | - * Introduce additional parameters in usb_hal_context_t when adding support |
589 | | - * for USB Host. |
590 | | - */ |
591 | | - for (const usb_iopin_dsc_t* iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) { |
592 | | - if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) { |
593 | | - esp_rom_gpio_pad_select_gpio(iopin->pin); |
594 | | - if (iopin->is_output) { |
595 | | - esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false); |
596 | | - } else { |
597 | | - esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false); |
598 | | - if ((iopin->pin != GPIO_MATRIX_CONST_ZERO_INPUT) && (iopin->pin != GPIO_MATRIX_CONST_ONE_INPUT)) { |
599 | | - gpio_ll_input_enable(&GPIO, iopin->pin); |
600 | | - } |
601 | | - } |
602 | | - esp_rom_gpio_pad_unhold(iopin->pin); |
603 | | - } |
604 | | - } |
605 | | - |
606 | | - if (!usb->use_external_phy) { |
607 | | - gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3); |
608 | | - gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3); |
609 | | - } |
610 | | -} |
0 commit comments