mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
Merge branch 'feat/support_usb_wakeup_v6.0' into 'release/v6.0'
feat: support usb as wakeup source from light sleep (v6.0) See merge request espressif/esp-idf!49502
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -11,7 +11,9 @@
|
||||
#include "soc/lp_clkrst_struct.h"
|
||||
#include "soc/hp_sys_clkrst_struct.h"
|
||||
#include "soc/hp_system_struct.h"
|
||||
#include "soc/lp_system_struct.h"
|
||||
#include "soc/usb_utmi_struct.h"
|
||||
#include "hal/config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -81,6 +83,29 @@ FORCE_INLINE_ATTR void _usb_utmi_ll_reset_register(void)
|
||||
_usb_utmi_ll_reset_register(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Enable/disable 15k pulldown resistors on D+/D- lines
|
||||
*
|
||||
* In USB Host mode, 15k pulldown resistors must be connected on both D+ and D-.
|
||||
* In USB Device mode, pulldown resistors must be disconnected.
|
||||
*
|
||||
* @note On ESP32-P4 v3+, pulldowns are no longer controlled by USB-OTG peripheral
|
||||
* and must be controlled by software via LP_SYS registers.
|
||||
* On earlier revisions, pulldowns are controlled by the USB-OTG hardware.
|
||||
*
|
||||
* @param[in] enable true to connect pulldowns (Host mode), false to disconnect (Device mode)
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_utmi_ll_enable_data_pulldowns(bool enable)
|
||||
{
|
||||
#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
|
||||
LP_SYS.hp_usb_otghs_phy_ctrl.hp_utmiotg_dppulldown = enable;
|
||||
LP_SYS.hp_usb_otghs_phy_ctrl.hp_utmiotg_dmpulldown = enable;
|
||||
#else
|
||||
// On pre-v3 ESP32-P4, pulldowns are controlled by the USB-OTG peripheral
|
||||
(void)enable;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable precise detection of VBUS
|
||||
*
|
||||
@@ -92,6 +117,24 @@ FORCE_INLINE_ATTR void usb_utmi_ll_enable_precise_detection(bool enable)
|
||||
HP_SYSTEM.sys_usbotg20_ctrl.sys_otg_suspendm = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set USB OTG2.0 suspend state for PMU USB wakeup logic
|
||||
*
|
||||
* @param[in] in_suspend True if USB OTG2.0 is suspended
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_utmi_ll_set_suspend_state(bool in_suspend)
|
||||
{
|
||||
LP_SYS.usb_ctrl.usbotg20_in_suspend = in_suspend;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear USB OTG2.0 wakeup status sent to PMU
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_utmi_ll_clear_wakeup_status(void)
|
||||
{
|
||||
LP_SYS.usb_ctrl.usbotg20_wakeup_clr = 1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -57,6 +57,28 @@ void _usb_utmi_hal_disable(void);
|
||||
#define usb_utmi_hal_disable(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; _usb_utmi_hal_disable(__VA_ARGS__);} while(0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable/disable 15k pulldown resistors on D+/D- lines
|
||||
*
|
||||
* In USB Host mode, 15k pulldown resistors must be connected on both D+ and D-.
|
||||
* In USB Device mode, pulldown resistors must be disconnected.
|
||||
*
|
||||
* @param[in] enable true to connect pulldowns (Host mode), false to disconnect (Device mode)
|
||||
*/
|
||||
void usb_utmi_hal_enable_data_pulldowns(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Set USB OTG2.0 suspend state for PMU USB wakeup logic
|
||||
*
|
||||
* @param[in] in_suspend True if USB OTG2.0 is suspended
|
||||
*/
|
||||
void usb_utmi_hal_set_suspend_state(bool in_suspend);
|
||||
|
||||
/**
|
||||
* @brief Clear USB OTG2.0 wakeup status sent to PMU
|
||||
*/
|
||||
void usb_utmi_hal_clear_wakeup_status(void);
|
||||
|
||||
#endif // (SOC_USB_UTMI_PHY_NUM > 0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -23,6 +23,21 @@ void _usb_utmi_hal_init(usb_utmi_hal_context_t *hal)
|
||||
usb_utmi_ll_configure_ls(hal->dev, true);
|
||||
}
|
||||
|
||||
void usb_utmi_hal_enable_data_pulldowns(bool enable)
|
||||
{
|
||||
usb_utmi_ll_enable_data_pulldowns(enable);
|
||||
}
|
||||
|
||||
void usb_utmi_hal_set_suspend_state(bool in_suspend)
|
||||
{
|
||||
usb_utmi_ll_set_suspend_state(in_suspend);
|
||||
}
|
||||
|
||||
void usb_utmi_hal_clear_wakeup_status(void)
|
||||
{
|
||||
usb_utmi_ll_clear_wakeup_status();
|
||||
}
|
||||
|
||||
void _usb_utmi_hal_disable(void)
|
||||
{
|
||||
_usb_utmi_ll_enable_bus_clock(false);
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -121,6 +121,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;
|
||||
|
||||
/**
|
||||
@@ -133,7 +134,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,
|
||||
@@ -545,6 +545,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
|
||||
|
||||
@@ -1686,6 +1686,11 @@ esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source)
|
||||
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_LOGE(TAG, "Incorrect wakeup source (%d) to disable.", (int) source);
|
||||
@@ -2287,6 +2292,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) {
|
||||
@@ -2445,6 +2470,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);
|
||||
|
||||
@@ -190,6 +190,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();
|
||||
|
||||
@@ -1175,6 +1175,10 @@ config SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_PM_SUPPORT_USB_WAKEUP
|
||||
int
|
||||
default 1
|
||||
|
||||
config SOC_PARLIO_TX_UNIT_MAX_DATA_WIDTH
|
||||
int
|
||||
default 16
|
||||
|
||||
@@ -435,6 +435,7 @@
|
||||
// USB PHY Caps
|
||||
#define SOC_USB_UTMI_PHY_NUM (1U)
|
||||
#define SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO 1
|
||||
#define SOC_PM_SUPPORT_USB_WAKEUP (1U)
|
||||
|
||||
/*-------------------------- PARLIO CAPS --------------------------------------*/
|
||||
#define SOC_PARLIO_TX_UNIT_MAX_DATA_WIDTH 16 /*!< Number of data lines of the TX unit */
|
||||
|
||||
Reference in New Issue
Block a user