Merge branch 'fix/fix_usb_hs_phy_leakage_on_deepsleep_v5.5' into 'release/v5.5'

fix(esp_hw_support): Fix deepsleep leakage after initializing USB HS phy (v5.5)

See merge request espressif/esp-idf!39167
This commit is contained in:
Jiang Jiang Jian
2025-05-20 14:01:02 +08:00
6 changed files with 49 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -13,7 +13,8 @@
extern "C" {
#endif
#if SOC_USB_OTG_SUPPORTED && SOC_PM_SUPPORT_CNNT_PD
#if SOC_USB_OTG_SUPPORTED
#if SOC_PM_SUPPORT_CNNT_PD
/**
* @brief Backup usb OTG phy bus_clock / stoppclk configuration and
* before light sleep to avoid current leakage
@ -26,6 +27,16 @@ void sleep_usb_otg_phy_backup_and_disable(void);
void sleep_usb_otg_phy_restore(void);
#endif
#if SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO
/**
* @brief The DP/DM part of the UTMI PHY circuit of esp32p4 that converts logic level to digital
* has no power off isolation, which will cause leakage when entering deepsleep.
* This problem can be workarounded by enabling USB-OTG's HNP (Host negotiation protocol)
* to enable DM pull-down to suppress leakage.
*/
void sleep_usb_suppress_deepsleep_leakage(void);
#endif
#endif
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -9,10 +9,13 @@
#include "esp_private/sleep_usb.h"
#include "esp_attr.h"
#if SOC_USB_OTG_SUPPORTED && SOC_PM_SUPPORT_CNNT_PD
#if SOC_USB_OTG_SUPPORTED && (SOC_PM_SUPPORT_CNNT_PD || SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO)
#include "hal/usb_utmi_ll.h"
#include "hal/usb_dwc_ll.h"
#endif
#if SOC_USB_OTG_SUPPORTED
#if SOC_PM_SUPPORT_CNNT_PD
static bool s_usb_utmi_bus_clock_state, s_usb_utmi_stoppclk_state;
void sleep_usb_otg_phy_backup_and_disable(void)
@ -34,3 +37,13 @@ void sleep_usb_otg_phy_restore(void)
}
}
#endif
#if SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO
void sleep_usb_suppress_deepsleep_leakage(void)
{
if (_usb_utmi_ll_bus_clock_is_enabled()) {
usb_dwc_ll_gusbcfg_en_hnp_cap(&USB_DWC_HS);
}
}
#endif
#endif

View File

@ -204,6 +204,11 @@ static inline void usb_dwc_ll_gusbcfg_force_host_mode(usb_dwc_dev_t *hw)
hw->gusbcfg_reg.forcehstmode = 1;
}
static inline void usb_dwc_ll_gusbcfg_en_hnp_cap(usb_dwc_dev_t *hw)
{
hw->gusbcfg_reg.hnpcap = 1;
}
static inline void usb_dwc_ll_gusbcfg_dis_hnp_cap(usb_dwc_dev_t *hw)
{
hw->gusbcfg_reg.hnpcap = 0;

View File

@ -1339,6 +1339,10 @@ config SOC_USB_UTMI_PHY_NUM
int
default 1
config SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO
bool
default y
config SOC_PARLIO_GROUPS
int
default 1

View File

@ -478,6 +478,7 @@
// USB PHY Caps
#define SOC_USB_UTMI_PHY_NUM (1U)
#define SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO 1
/*-------------------------- PARLIO CAPS --------------------------------------*/
#define SOC_PARLIO_GROUPS 1U /*!< Number of parallel IO peripherals */

View File

@ -20,6 +20,11 @@
#include "driver/gpio.h"
#include "soc/soc_caps.h"
#if SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO
#include "esp_private/sleep_usb.h"
#include "esp_sleep.h"
#endif
#if !SOC_RCC_IS_INDEPENDENT
#define USB_PHY_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
#else
@ -294,6 +299,12 @@ esp_err_t usb_new_phy(const usb_phy_config_t *config, usb_phy_handle_t *handle_r
}
#endif
#if SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO
if (phy_target == USB_PHY_TARGET_UTMI) {
esp_deep_sleep_register_hook(&sleep_usb_suppress_deepsleep_leakage);
}
#endif
ESP_RETURN_ON_FALSE(config, ESP_ERR_INVALID_ARG, USBPHY_TAG, "config argument is invalid");
ESP_RETURN_ON_FALSE(phy_target < USB_PHY_TARGET_MAX, ESP_ERR_INVALID_ARG, USBPHY_TAG, "specified PHY argument is invalid");
ESP_RETURN_ON_FALSE(config->controller < USB_PHY_CTRL_MAX, ESP_ERR_INVALID_ARG, USBPHY_TAG, "specified source argument is invalid");