From d4b3d01b4db7c1037dd93acae406ef7b887dbd07 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Mon, 11 Aug 2025 16:00:09 +0800 Subject: [PATCH] feat(esp_hw_support): update cpu_pd support for esp32p4 v3.0 --- .../esp_hw_support/include/esp_private/sleep_cpu.h | 2 +- components/esp_hw_support/include/esp_sleep.h | 8 ++++++-- components/esp_hw_support/lowpower/CMakeLists.txt | 2 +- .../lowpower/port/esp32p4/rvsleep-frames.h | 3 +++ .../lowpower/port/esp32p4/sleep_cpu_asm.S | 11 ++++++++++- components/esp_hw_support/sleep_modes.c | 2 +- components/esp_pm/Kconfig | 6 +++--- components/esp_pm/linker.lf | 2 +- .../soc/esp32p4/register/hw_ver3/soc/cache_reg.h | 1 - .../api-guides/low-power-mode/low-power-mode-soc.rst | 3 +++ .../api-guides/low-power-mode/low-power-mode-soc.rst | 3 +++ 11 files changed, 32 insertions(+), 11 deletions(-) diff --git a/components/esp_hw_support/include/esp_private/sleep_cpu.h b/components/esp_hw_support/include/esp_private/sleep_cpu.h index cc2dd35980..c65d01a619 100644 --- a/components/esp_hw_support/include/esp_private/sleep_cpu.h +++ b/components/esp_hw_support/include/esp_private/sleep_cpu.h @@ -22,7 +22,7 @@ extern "C" { * This file contains declarations of cpu retention related functions in light sleep mode. */ -#if ESP_SLEEP_POWER_DOWN_CPU || SOC_PM_SUPPORT_CPU_PD +#if ESP_SLEEP_POWER_DOWN_CPU || (SOC_PM_SUPPORT_CPU_PD && !CONFIG_ESP32P4_SELECTS_REV_LESS_V3) /** * @brief Whether to allow the cpu power domain to be powered off. * diff --git a/components/esp_hw_support/include/esp_sleep.h b/components/esp_hw_support/include/esp_sleep.h index dee094ef7f..f6713adbb9 100644 --- a/components/esp_hw_support/include/esp_sleep.h +++ b/components/esp_hw_support/include/esp_sleep.h @@ -72,7 +72,7 @@ typedef enum { #if SOC_PM_SUPPORT_RC_FAST_PD ESP_PD_DOMAIN_RC_FAST, //!< Internal Fast oscillator #endif -#if SOC_PM_SUPPORT_CPU_PD +#if SOC_PM_SUPPORT_CPU_PD && !CONFIG_ESP32P4_SELECTS_REV_LESS_V3 ESP_PD_DOMAIN_CPU, //!< CPU core #endif #if SOC_PM_SUPPORT_VDDSDIO_PD @@ -139,7 +139,11 @@ enum { ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION = ESP_ERR_INVALID_ARG, }; -#define ESP_SLEEP_POWER_DOWN_CPU (CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP || (SOC_CPU_IN_TOP_DOMAIN && CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP)) +#if CONFIG_ESP32P4_SELECTS_REV_LESS_V3 +#define ESP_SLEEP_POWER_DOWN_CPU CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP +#else +#define ESP_SLEEP_POWER_DOWN_CPU CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP +#endif /** * @brief Disable wakeup source diff --git a/components/esp_hw_support/lowpower/CMakeLists.txt b/components/esp_hw_support/lowpower/CMakeLists.txt index 9525e68003..86c981daa8 100644 --- a/components/esp_hw_support/lowpower/CMakeLists.txt +++ b/components/esp_hw_support/lowpower/CMakeLists.txt @@ -5,7 +5,7 @@ endif() set(srcs) if(CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP OR - (CONFIG_SOC_CPU_IN_TOP_DOMAIN AND CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP)) + (CONFIG_ESP32P4_SELECTS_REV_LESS_V3 AND CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP)) list(APPEND srcs "port/${target}/sleep_cpu.c") if(CONFIG_SOC_PM_CPU_RETENTION_BY_SW) list(APPEND srcs "port/${target}/sleep_cpu_asm.S") diff --git a/components/esp_hw_support/lowpower/port/esp32p4/rvsleep-frames.h b/components/esp_hw_support/lowpower/port/esp32p4/rvsleep-frames.h index 76c88a8d0b..bcff56ea41 100644 --- a/components/esp_hw_support/lowpower/port/esp32p4/rvsleep-frames.h +++ b/components/esp_hw_support/lowpower/port/esp32p4/rvsleep-frames.h @@ -80,6 +80,9 @@ STRUCT_BEGIN STRUCT_FIELD (long, 4, RV_SLP_CTX_MSTATUS, mstatus) /* Machine Status */ STRUCT_FIELD (long, 4, RV_SLP_CTX_MTVEC, mtvec) /* Machine Trap-Vector Base Address */ STRUCT_FIELD (long, 4, RV_SLP_CTX_MTVT, mtvt) +#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3 + STRUCT_FIELD (long, 4, RV_SLP_CTX_MINTTHRESH, mintthresh) /* Machine intr threshold */ // TODO +#endif STRUCT_FIELD (long, 4, RV_SLP_CTX_MCAUSE, mcause) /* Machine Trap Cause */ STRUCT_FIELD (long, 4, RV_SLP_CTX_MTVAL, mtval) /* Machine Trap Value */ STRUCT_FIELD (long, 4, RV_SLP_CTX_MIE, mie) /* Machine intr enable */ diff --git a/components/esp_hw_support/lowpower/port/esp32p4/sleep_cpu_asm.S b/components/esp_hw_support/lowpower/port/esp32p4/sleep_cpu_asm.S index 1ae80231d6..9018ba9c25 100644 --- a/components/esp_hw_support/lowpower/port/esp32p4/sleep_cpu_asm.S +++ b/components/esp_hw_support/lowpower/port/esp32p4/sleep_cpu_asm.S @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,6 +12,7 @@ #include "soc/cache_reg.h" #define CACHE_MAP_L1_CACHE_MASK (BIT(0) | BIT(1) | BIT(4)) #define MTVT (0x307) +#define MINTTHRESH (0x347) .section .tcm.data,"aw" .global rv_core_critical_regs_frame @@ -93,6 +94,10 @@ rv_core_critical_regs_save: sw t3, RV_SLP_CTX_MCAUSE(t0) csrr t4, MTVT sw t4, RV_SLP_CTX_MTVT(t0) +#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3 + csrr t4, MINTTHRESH + sw t4, RV_SLP_CTX_MINTTHRESH(t0) +#endif csrr t1, mtval sw t1, RV_SLP_CTX_MTVAL(t0) csrr t2, mie @@ -177,6 +182,10 @@ rv_core_critical_regs_restore: csrw mstatus, t2 lw t4, RV_SLP_CTX_MTVT(t0) csrw MTVT, t4 +#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3 + lw t1, RV_SLP_CTX_MINTTHRESH(t0) + csrw MINTTHRESH, t1 +#endif lw t3, RV_SLP_CTX_MTVEC(t0) csrw mtvec, t3 lw t1, RV_SLP_CTX_MCAUSE(t0) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index c3a6afd22a..7aef55334f 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -2540,7 +2540,7 @@ static uint32_t get_power_down_flags(void) } #endif -#if SOC_PM_SUPPORT_CPU_PD && ESP_SLEEP_POWER_DOWN_CPU +#if SOC_PM_SUPPORT_CPU_PD && ESP_SLEEP_POWER_DOWN_CPU && !CONFIG_ESP32P4_SELECTS_REV_LESS_V3 if ((s_config.domain[ESP_PD_DOMAIN_CPU].pd_option != ESP_PD_OPTION_ON) && cpu_domain_pd_allowed()) { pd_flags |= RTC_SLEEP_PD_CPU; } diff --git a/components/esp_pm/Kconfig b/components/esp_pm/Kconfig index b4fbae2b2c..cfb80842ce 100644 --- a/components/esp_pm/Kconfig +++ b/components/esp_pm/Kconfig @@ -85,7 +85,7 @@ menu "Power Management" config PM_CHECK_SLEEP_RETENTION_FRAME bool depends on (PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP || \ - (SOC_CPU_IN_TOP_DOMAIN && PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP)) + (ESP32P4_SELECTS_REV_LESS_V3 && PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP)) default y if IDF_CI_BUILD default n help @@ -108,7 +108,7 @@ menu "Power Management" config PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP bool "Power down CPU in light sleep" - depends on SOC_PM_SUPPORT_CPU_PD + depends on SOC_PM_SUPPORT_CPU_PD && !ESP32P4_SELECTS_REV_LESS_V3 select PM_RESTORE_CACHE_TAGMEM_AFTER_LIGHT_SLEEP if ESP32S3_DATA_CACHE_16KB default y help @@ -143,7 +143,7 @@ menu "Power Management" config PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP bool "Power down Digital Peripheral in light sleep (EXPERIMENTAL)" depends on SOC_PM_SUPPORT_TOP_PD && SOC_PAU_SUPPORTED - select PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP if !SOC_CPU_IN_TOP_DOMAIN + select PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP if !ESP32P4_SELECTS_REV_LESS_V3 default n #TODO: enable by default if periph init/deinit management supported (WIFI-5252) help If enabled, digital peripherals will try to powered down in light sleep, then all related peripherals will diff --git a/components/esp_pm/linker.lf b/components/esp_pm/linker.lf index 050349e876..c03c1b3171 100644 --- a/components/esp_pm/linker.lf +++ b/components/esp_pm/linker.lf @@ -30,7 +30,7 @@ entries: sleep_gpio:gpio_sleep_mode_config_apply (noflash) if SOC_PM_CPU_RETENTION_BY_RTCCNTL = y && (PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP = y || SOC_PM_SUPPORT_TAGMEM_PD = y): sleep_cpu:sleep_enable_cpu_retention (noflash) - if PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP = y || (SOC_CPU_IN_TOP_DOMAIN = y && PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP = y): + if PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP = y || (ESP32P4_SELECTS_REV_LESS_V3 = y && PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP = y): sleep_cpu:cpu_domain_pd_allowed (noflash) if SOC_PM_SUPPORT_TOP_PD = y: sleep_clock:clock_domain_pd_allowed (noflash) diff --git a/components/soc/esp32p4/register/hw_ver3/soc/cache_reg.h b/components/soc/esp32p4/register/hw_ver3/soc/cache_reg.h index a99a74bbcb..ee63baf3a1 100644 --- a/components/soc/esp32p4/register/hw_ver3/soc/cache_reg.h +++ b/components/soc/esp32p4/register/hw_ver3/soc/cache_reg.h @@ -5,7 +5,6 @@ */ #pragma once -#include #include "soc/soc.h" #ifdef __cplusplus extern "C" { diff --git a/docs/en/api-guides/low-power-mode/low-power-mode-soc.rst b/docs/en/api-guides/low-power-mode/low-power-mode-soc.rst index 460a5c7bf5..2cc3315a8a 100644 --- a/docs/en/api-guides/low-power-mode/low-power-mode-soc.rst +++ b/docs/en/api-guides/low-power-mode/low-power-mode-soc.rst @@ -271,6 +271,9 @@ This section introduces the recommended configuration and configuration steps fo - Power down CPU (:ref:`CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP`) + .. only:: esp32p4 + + For ESP32P4, only revisions greater than 3.0 support the CPU power domain individual power-down. .. only:: SOC_PM_SUPPORT_TAGMEM_PD diff --git a/docs/zh_CN/api-guides/low-power-mode/low-power-mode-soc.rst b/docs/zh_CN/api-guides/low-power-mode/low-power-mode-soc.rst index 24c36f23d4..8bc7eebd7f 100644 --- a/docs/zh_CN/api-guides/low-power-mode/low-power-mode-soc.rst +++ b/docs/zh_CN/api-guides/low-power-mode/low-power-mode-soc.rst @@ -271,6 +271,9 @@ Light-sleep 模式配置 - 关闭 CPU (:ref:`CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP`) + .. only:: esp32p4 + + 对于 ESP32P4 芯片, 只有大于 3.0 的芯片版本才支持单独掉电 CPU 电源域。 .. only:: SOC_PM_SUPPORT_TAGMEM_PD