fix(usb_dwc_hal): Enabled precise detection of VBUS

This commit is contained in:
Roman Leonov 2024-07-10 12:05:28 +02:00
parent 2e59d3e0ad
commit 97d30e7c48
3 changed files with 49 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}