Skip to content

Commit

Permalink
Merge branch 'fix/usb_host_hcd_dconn_hs' into 'master'
Browse files Browse the repository at this point in the history
fix(usb_dwc_hal): Enabled precise VBUS detection

Closes IDF-9953

See merge request espressif/esp-idf!32031
  • Loading branch information
roma-jam committed Jul 12, 2024
2 parents a9787fc + 97d30e7 commit d108ba1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
9 changes: 9 additions & 0 deletions components/hal/esp32p4/include/hal/usb_wrap_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
25 changes: 24 additions & 1 deletion components/usb/test_apps/hcd/main/test_hcd_port.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions components/usb/usb_phy_p4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d108ba1

Please sign in to comment.