Merge branch 'feat/support_usb_wakeup_v6.1' into 'release/v6.1'

feat: support usb as wakeup source from light sleep (v6.1)

See merge request espressif/esp-idf!49497
This commit is contained in:
Jiang Jiang Jian
2026-06-30 19:40:33 +08:00
21 changed files with 420 additions and 5 deletions
@@ -1,11 +1,12 @@
/*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
#include "soc/soc_caps.h"
@@ -164,6 +165,18 @@ esp_err_t usb_new_phy(const usb_phy_config_t *config, usb_phy_handle_t *handle_r
*/
esp_err_t usb_phy_otg_set_mode(usb_phy_handle_t handle, usb_otg_mode_t mode);
/**
* @brief Set the USB OTG suspend state for USB wakeup logic
*
* @param in_suspend True if the USB OTG bus is suspended
*/
void usb_phy_set_otg_suspend_state(bool in_suspend);
/**
* @brief Clear USB OTG wakeup status from the USB wakeup logic
*/
void usb_phy_clear_otg_wakeup_status(void);
/**
* @brief Delete a USB PHY
*
+17 -1
View File
@@ -137,6 +137,7 @@ typedef enum {
ESP_SLEEP_WAKEUP_BT, //!< Wakeup caused by BT (light sleep only)
ESP_SLEEP_WAKEUP_VAD, //!< Wakeup caused by VAD
ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT, //!< Wakeup caused by VDD_BAT under voltage.
ESP_SLEEP_WAKEUP_USB, //!< Wakeup caused by USB HS (light sleep only)
} esp_sleep_source_t;
/**
@@ -149,7 +150,6 @@ typedef enum {
/* Leave this type define for compatibility */
typedef esp_sleep_source_t esp_sleep_wakeup_cause_t;
enum {
ESP_ERR_SLEEP_REJECT = ESP_ERR_INVALID_STATE,
ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION = ESP_ERR_INVALID_ARG,
@@ -565,6 +565,22 @@ esp_err_t esp_sleep_enable_bt_wakeup(void);
*/
esp_err_t esp_sleep_disable_bt_wakeup(void);
/**
* @brief Enable wakeup by High-Speed USB-OTG
* @return
* - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if wakeup from USB is not supported
*/
esp_err_t esp_sleep_enable_usb_wakeup(void);
/**
* @brief Disable wakeup by High-Speed USB-OTG
* @return
* - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if wakeup from USB is not supported
*/
esp_err_t esp_sleep_disable_usb_wakeup(void);
/**
* @brief Enable wakeup by WiFi MAC
* @return
+29
View File
@@ -1826,6 +1826,10 @@ esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source)
#if SOC_VBAT_SUPPORTED
} else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT, RTC_VBAT_UNDER_VOLT_TRIG_EN)) {
s_config.wakeup_triggers &= ~RTC_VBAT_UNDER_VOLT_TRIG_EN;
#endif
#if SOC_PM_SUPPORT_USB_WAKEUP
} else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_USB, RTC_USB_TRIG_EN)) {
s_config.wakeup_triggers &= ~RTC_USB_TRIG_EN;
#endif
} else {
ESP_EARLY_LOGE(TAG, "Incorrect wakeup source (%d) to disable.", (int) source);
@@ -2452,6 +2456,26 @@ esp_err_t esp_sleep_disable_bt_wakeup(void)
#endif
}
esp_err_t esp_sleep_enable_usb_wakeup(void)
{
#if SOC_PM_SUPPORT_USB_WAKEUP
s_config.wakeup_triggers |= RTC_USB_TRIG_EN;
return ESP_OK;
#else
return ESP_ERR_NOT_SUPPORTED;
#endif
}
esp_err_t esp_sleep_disable_usb_wakeup(void)
{
#if SOC_PM_SUPPORT_USB_WAKEUP
s_config.wakeup_triggers &= (~RTC_USB_TRIG_EN);
return ESP_OK;
#else
return ESP_ERR_NOT_SUPPORTED;
#endif
}
esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void)
{
if (esp_rom_get_reset_reason(0) != RESET_REASON_CORE_DEEP_SLEEP && !s_light_sleep_wakeup) {
@@ -2636,6 +2660,11 @@ uint32_t esp_sleep_get_wakeup_causes(void)
if (wakeup_cause_raw & RTC_VBAT_UNDER_VOLT_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT);
}
#endif
#if SOC_PM_SUPPORT_USB_WAKEUP
if (wakeup_cause_raw & RTC_USB_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_USB);
}
#endif
if (wakeup_cause == 0) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UNDEFINED);
@@ -180,6 +180,22 @@ esp_err_t usb_phy_otg_set_mode(usb_phy_handle_t handle, usb_otg_mode_t mode)
return ESP_OK;
}
void usb_phy_set_otg_suspend_state(bool in_suspend)
{
#if SOC_USB_UTMI_PHY_NUM
usb_utmi_hal_set_suspend_state(in_suspend);
#else
(void)in_suspend;
#endif
}
void usb_phy_clear_otg_wakeup_status(void)
{
#if SOC_USB_UTMI_PHY_NUM
usb_utmi_hal_clear_wakeup_status();
#endif
}
static esp_err_t usb_phy_install(void)
{
PHY_ENTER_CRITICAL();