diff --git a/components/hal/esp32p4/include/hal/usb_wrap_ll.h b/components/hal/esp32p4/include/hal/usb_wrap_ll.h index 5e6b942366..113a56fe77 100644 --- a/components/hal/esp32p4/include/hal/usb_wrap_ll.h +++ b/components/hal/esp32p4/include/hal/usb_wrap_ll.h @@ -12,6 +12,7 @@ #include "soc/lp_system_struct.h" #include "soc/lp_clkrst_struct.h" #include "soc/hp_sys_clkrst_struct.h" +#include "soc/hp_system_struct.h" // For HP_SYSTEM domain #include "soc/usb_wrap_struct.h" #include "hal/usb_wrap_types.h" @@ -262,6 +263,14 @@ FORCE_INLINE_ATTR void usb_wrap_ll_reset_register(void) // P_AON_CLKRST.hp_usb_clkrst_ctrlx are shared registers, so this function must be used in an atomic way #define usb_wrap_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; usb_wrap_ll_reset_register(__VA_ARGS__) +/* ------------------------------- HP System ------------------------------- */ + +FORCE_INLINE_ATTR void usb_wrap_ll_enable_precise_detection(void) +{ + // Enable VBUS precise detection + HP_SYSTEM.sys_usbotg20_ctrl.sys_otg_suspendm = 1; +} + #ifdef __cplusplus } #endif diff --git a/components/usb/test_apps/hcd/main/test_hcd_port.c b/components/usb/test_apps/hcd/main/test_hcd_port.c index 67f502335b..7ddb4a2cb2 100644 --- a/components/usb/test_apps/hcd/main/test_hcd_port.c +++ b/components/usb/test_apps/hcd/main/test_hcd_port.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -18,6 +18,29 @@ #define URB_DATA_BUFF_SIZE (sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES) // 256 is worst case size for configuration descriptors #define POST_ENQUEUE_DELAY_US 10 +/* +Test a port for a disconnect event, when port is in ENABLED state + +Purpose: This test is essential on HS HCD ports, when device is detaching during the action. + When the HS port is ENABLED, the port operates in HS mode and device disconnection is detected by HS logic. + When the HS port is DISABLED (without issuing a reset), the port operates in FS mode and device disconnection differs for HS mode disconnection logic. + +Procedure: + - Setup the HCD and a port + - Trigger the port connection event + - Trigger the port disconnection event + - Teardown port and HCD +*/ +TEST_CASE("Test HCD port disconnect event, port enabled", "[port][low_speed][full_speed]") +{ + usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection + printf("Connected %s speed device \n", (char*[]) { + "Low", "Full", "High" + }[port_speed]); + vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS) + test_hcd_wait_for_disconn(port_hdl, true); +} + /* Test a port sudden disconnect and port recovery diff --git a/components/usb/usb_phy_p4.c b/components/usb/usb_phy_p4.c index cff6420e08..a541fafe4c 100644 --- a/components/usb/usb_phy_p4.c +++ b/components/usb/usb_phy_p4.c @@ -6,11 +6,27 @@ // This is only a dummy USB PHY file for successful linking of ESP32-P4 target // The internal HS PHY is enabled by default, therefore it needs no configuration + +// TODO: Refactor during the IDF-9198 +#include "sdkconfig.h" +#include "soc/usb_dwc_cfg.h" +#include "hal/usb_wrap_hal.h" // TODO: Remove this file when proper support of P4 PHYs is implemented IDF-7323 #include "esp_private/usb_phy.h" esp_err_t usb_new_phy(const usb_phy_config_t *config, usb_phy_handle_t *handle_ret) { +#if (OTG_HSPHY_INTERFACE != 0) +#if CONFIG_IDF_TARGET_ESP32P4 + /* + Additional setting to solve missing DCONN event on ESP32P4 (IDF-9953). + + Note: On ESP32P4, the HP_SYSTEM_OTG_SUSPENDM is not connected to 1 by hardware. + For correct detection of the device detaching, internal signal should be set to 1 by the software. + */ + usb_wrap_ll_enable_precise_detection(); +#endif // CONFIG_IDF_TARGET_ESP32P4 +#endif // (OTG_HSPHY_INTERFACE != 0) return ESP_OK; }