From 68bd919fda1be643e19c055a4fcf2fc12ea88755 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Wed, 6 May 2026 16:27:28 +0800 Subject: [PATCH] feat(esp_hw_support): support esp32s31 DFS --- components/esp_pm/pm_impl.c | 25 +------- components/soc/esp32c2/include/soc/soc.h | 1 - components/soc/esp32c3/include/soc/soc.h | 1 - components/soc/esp32c5/include/soc/soc.h | 1 - components/soc/esp32c6/include/soc/soc.h | 1 - components/soc/esp32c61/include/soc/soc.h | 1 - components/soc/esp32h2/include/soc/soc.h | 1 - components/soc/esp32h21/include/soc/soc.h | 1 - components/soc/esp32h4/include/soc/soc.h | 1 - components/soc/esp32p4/include/soc/soc.h | 1 - components/soc/esp32s3/include/soc/soc.h | 1 - .../esp32s31/include/soc/Kconfig.soc_caps.in | 4 ++ components/soc/esp32s31/include/soc/soc.h | 1 - .../soc/esp32s31/include/soc/soc_caps.h | 1 + .../main/Kconfig.esp32s31.supported_freq | 57 +++++++++++++++++++ 15 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 examples/lowpower/power_management/main/Kconfig.esp32s31.supported_freq diff --git a/components/esp_pm/pm_impl.c b/components/esp_pm/pm_impl.c index a3ac7442285..5a2f9e6b291 100644 --- a/components/esp_pm/pm_impl.c +++ b/components/esp_pm/pm_impl.c @@ -82,27 +82,6 @@ #elif CONFIG_IDF_TARGET_ESP32S2 /* Minimal divider at which REF_CLK_FREQ can be obtained */ #define REF_CLK_DIV_MIN 2 -#elif CONFIG_IDF_TARGET_ESP32S3 -/* Minimal divider at which REF_CLK_FREQ can be obtained */ -#define REF_CLK_DIV_MIN 2 // TODO: IDF-5660 -#elif CONFIG_IDF_TARGET_ESP32C3 -#define REF_CLK_DIV_MIN 2 -#elif CONFIG_IDF_TARGET_ESP32C2 -#define REF_CLK_DIV_MIN 2 -#elif CONFIG_IDF_TARGET_ESP32C6 -#define REF_CLK_DIV_MIN 2 -#elif CONFIG_IDF_TARGET_ESP32C61 -#define REF_CLK_DIV_MIN 2 -#elif CONFIG_IDF_TARGET_ESP32C5 -#define REF_CLK_DIV_MIN 2 -#elif CONFIG_IDF_TARGET_ESP32H2 -#define REF_CLK_DIV_MIN 2 -#elif CONFIG_IDF_TARGET_ESP32H21 -#define REF_CLK_DIV_MIN 2 -#elif CONFIG_IDF_TARGET_ESP32P4 -#define REF_CLK_DIV_MIN 2 -#elif CONFIG_IDF_TARGET_ESP32H4 -#define REF_CLK_DIV_MIN 2 #endif #ifdef CONFIG_PM_PROFILING @@ -451,11 +430,13 @@ esp_err_t esp_pm_configure(const void* vconfig) return ESP_ERR_INVALID_ARG; } +#ifdef REF_CLK_DIV_MIN int xtal_freq_mhz = esp_clk_xtal_freq() / MHZ; if (min_freq_mhz < xtal_freq_mhz && min_freq_mhz * MHZ / REF_CLK_FREQ < REF_CLK_DIV_MIN) { ESP_LOGW(TAG, "min_freq_mhz should be >= %d", REF_CLK_FREQ * REF_CLK_DIV_MIN / MHZ); return ESP_ERR_INVALID_ARG; } +#endif if (!rtc_clk_cpu_freq_mhz_to_config(max_freq_mhz, &freq_config)) { ESP_LOGW(TAG, "invalid max_freq_mhz value (%d)", max_freq_mhz); @@ -479,7 +460,7 @@ esp_err_t esp_pm_configure(const void* vconfig) /* Maximum SOC APB clock frequency is 40 MHz, maximum Modem (WiFi, * Bluetooth, etc..) APB clock frequency is 80 MHz */ int apb_clk_freq = esp_clk_apb_freq() / MHZ; -#if (CONFIG_ESP_WIFI_ENABLED || CONFIG_BT_ENABLED || CONFIG_IEEE802154_ENABLED) && SOC_PHY_SUPPORTED +#if (CONFIG_ESP_WIFI_ENABLED || CONFIG_BT_ENABLED || CONFIG_IEEE802154_ENABLED) && SOC_PHY_SUPPORTED && !SOC_MODEM_APB_CLOCK_IS_INDEPENDENT apb_clk_freq = MAX(apb_clk_freq, MODEM_REQUIRED_MIN_APB_CLK_FREQ / MHZ); #endif int apb_max_freq = MIN(max_freq_mhz, apb_clk_freq); /* CPU frequency in APB_MAX mode */ diff --git a/components/soc/esp32c2/include/soc/soc.h b/components/soc/esp32c2/include/soc/soc.h index a81dcfe1c27..ba17f66b864 100644 --- a/components/soc/esp32c2/include/soc/soc.h +++ b/components/soc/esp32c2/include/soc/soc.h @@ -142,7 +142,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ (SOC_XTAL_FREQ_MHZ * 1000000 ) #define MODEM_REQUIRED_MIN_APB_CLK_FREQ ( 80*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32c3/include/soc/soc.h b/components/soc/esp32c3/include/soc/soc.h index 19161ee2f1d..bbcd9680ee1 100644 --- a/components/soc/esp32c3/include/soc/soc.h +++ b/components/soc/esp32c3/include/soc/soc.h @@ -135,7 +135,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ ( 80*1000000 ) #define MODEM_REQUIRED_MIN_APB_CLK_FREQ ( 80*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32c5/include/soc/soc.h b/components/soc/esp32c5/include/soc/soc.h index 5aa0babd506..6383311de6c 100644 --- a/components/soc/esp32c5/include/soc/soc.h +++ b/components/soc/esp32c5/include/soc/soc.h @@ -133,7 +133,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ ( 40*1000000 ) #define MODEM_REQUIRED_MIN_APB_CLK_FREQ ( 80*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32c6/include/soc/soc.h b/components/soc/esp32c6/include/soc/soc.h index 2dc76dc8f5a..724a826034e 100644 --- a/components/soc/esp32c6/include/soc/soc.h +++ b/components/soc/esp32c6/include/soc/soc.h @@ -136,7 +136,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ ( 40*1000000 ) #define MODEM_REQUIRED_MIN_APB_CLK_FREQ ( 80*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32c61/include/soc/soc.h b/components/soc/esp32c61/include/soc/soc.h index 3c7bd81d5be..3cc4ad23ea2 100644 --- a/components/soc/esp32c61/include/soc/soc.h +++ b/components/soc/esp32c61/include/soc/soc.h @@ -133,7 +133,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ ( 40*1000000 ) #define MODEM_REQUIRED_MIN_APB_CLK_FREQ ( 80*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32h2/include/soc/soc.h b/components/soc/esp32h2/include/soc/soc.h index ab799e1b7d6..27f75641f99 100644 --- a/components/soc/esp32h2/include/soc/soc.h +++ b/components/soc/esp32h2/include/soc/soc.h @@ -135,7 +135,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ ( 32*1000000 ) #define MODEM_REQUIRED_MIN_APB_CLK_FREQ ( 32*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32h21/include/soc/soc.h b/components/soc/esp32h21/include/soc/soc.h index 38a25c7b937..24668ac5c5b 100644 --- a/components/soc/esp32h21/include/soc/soc.h +++ b/components/soc/esp32h21/include/soc/soc.h @@ -137,7 +137,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ ( 32*1000000 ) #define MODEM_REQUIRED_MIN_APB_CLK_FREQ ( 32*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32h4/include/soc/soc.h b/components/soc/esp32h4/include/soc/soc.h index 71275ced101..1daca7b6c6b 100644 --- a/components/soc/esp32h4/include/soc/soc.h +++ b/components/soc/esp32h4/include/soc/soc.h @@ -126,7 +126,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ ( 32*1000000 ) #define MODEM_REQUIRED_MIN_APB_CLK_FREQ ( 32*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32p4/include/soc/soc.h b/components/soc/esp32p4/include/soc/soc.h index a9046f83c05..d0f5d1ccc05 100644 --- a/components/soc/esp32p4/include/soc/soc.h +++ b/components/soc/esp32p4/include/soc/soc.h @@ -133,7 +133,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ ( 90*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32s3/include/soc/soc.h b/components/soc/esp32s3/include/soc/soc.h index d4c867a834f..8588770c3cf 100644 --- a/components/soc/esp32s3/include/soc/soc.h +++ b/components/soc/esp32s3/include/soc/soc.h @@ -150,7 +150,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ (80*1000000) #define MODEM_REQUIRED_MIN_APB_CLK_FREQ (80*1000000) -#define REF_CLK_FREQ (1000000) //}} /* Overall memory map */ diff --git a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in index 3394abd65c2..d876a82bcd8 100644 --- a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in @@ -975,6 +975,10 @@ config SOC_MODEM_CLOCK_IS_INDEPENDENT bool default y +config SOC_MODEM_APB_CLOCK_IS_INDEPENDENT + bool + default y + config SOC_MODEM_CLOCK_SOC_PLL_SOURCE_CG_SUPPORTED bool default y diff --git a/components/soc/esp32s31/include/soc/soc.h b/components/soc/esp32s31/include/soc/soc.h index 771d0ed6ec5..8c8da22ad16 100644 --- a/components/soc/esp32s31/include/soc/soc.h +++ b/components/soc/esp32s31/include/soc/soc.h @@ -128,7 +128,6 @@ //Periheral Clock {{ #define APB_CLK_FREQ ( 40*1000000 ) -#define REF_CLK_FREQ ( 1000000 ) //}} /* Overall memory map */ diff --git a/components/soc/esp32s31/include/soc/soc_caps.h b/components/soc/esp32s31/include/soc/soc_caps.h index 914c43ce69d..1b70b3d4327 100644 --- a/components/soc/esp32s31/include/soc/soc_caps.h +++ b/components/soc/esp32s31/include/soc/soc_caps.h @@ -402,6 +402,7 @@ // /*-------------------------- CLOCK SUBSYSTEM CAPS ----------------------------------------*/ #define SOC_MODEM_CLOCK_IS_INDEPENDENT (1) +#define SOC_MODEM_APB_CLOCK_IS_INDEPENDENT (1) #define SOC_MODEM_CLOCK_SOC_PLL_SOURCE_CG_SUPPORTED (1) #define SOC_MODEM_CLOCK_WIFI_BB_80X1_AS_APB (1) diff --git a/examples/lowpower/power_management/main/Kconfig.esp32s31.supported_freq b/examples/lowpower/power_management/main/Kconfig.esp32s31.supported_freq new file mode 100644 index 00000000000..770a65d671f --- /dev/null +++ b/examples/lowpower/power_management/main/Kconfig.esp32s31.supported_freq @@ -0,0 +1,57 @@ +choice EXAMPLE_PM_MAX_FREQ_MHZ + prompt "Max CPU frequency (MHz)" + default EXAMPLE_PM_MAX_FREQ_MHZ_320 + config EXAMPLE_PM_MAX_FREQ_MHZ_10 + bool "10" + config EXAMPLE_PM_MAX_FREQ_MHZ_20 + bool "20" + config EXAMPLE_PM_MAX_FREQ_MHZ_40 + bool "40" + config EXAMPLE_PM_MAX_FREQ_MHZ_80 + bool "80" + config EXAMPLE_PM_MAX_FREQ_MHZ_160 + bool "160" + config EXAMPLE_PM_MAX_FREQ_MHZ_240 + bool "240" + config EXAMPLE_PM_MAX_FREQ_MHZ_320 + bool "320" +endchoice + +config EXAMPLE_PM_MAX_FREQ + int + default 10 if EXAMPLE_PM_MAX_FREQ_MHZ_10 + default 20 if EXAMPLE_PM_MAX_FREQ_MHZ_20 + default 40 if EXAMPLE_PM_MAX_FREQ_MHZ_40 + default 80 if EXAMPLE_PM_MAX_FREQ_MHZ_80 + default 160 if EXAMPLE_PM_MAX_FREQ_MHZ_160 + default 240 if EXAMPLE_PM_MAX_FREQ_MHZ_240 + default 320 if EXAMPLE_PM_MAX_FREQ_MHZ_320 + +choice EXAMPLE_PM_MIN_FREQ_MHZ + prompt "Min CPU frequency (MHz)" + default EXAMPLE_PM_MIN_FREQ_MHZ_40 + config EXAMPLE_PM_MIN_FREQ_MHZ_10 + bool "10" + config EXAMPLE_PM_MIN_FREQ_MHZ_20 + bool "20" + config EXAMPLE_PM_MIN_FREQ_MHZ_40 + bool "40" + config EXAMPLE_PM_MIN_FREQ_MHZ_80 + bool "80" + config EXAMPLE_PM_MIN_FREQ_MHZ_160 + bool "160" + config EXAMPLE_PM_MIN_FREQ_MHZ_240 + bool "240" + config EXAMPLE_PM_MIN_FREQ_MHZ_320 + bool "320" +endchoice + +config EXAMPLE_PM_MIN_FREQ + int + default 10 if EXAMPLE_PM_MIN_FREQ_MHZ_10 + default 20 if EXAMPLE_PM_MIN_FREQ_MHZ_20 + default 40 if EXAMPLE_PM_MIN_FREQ_MHZ_40 + default 80 if EXAMPLE_PM_MIN_FREQ_MHZ_80 + default 160 if EXAMPLE_PM_MIN_FREQ_MHZ_160 + default 240 if EXAMPLE_PM_MIN_FREQ_MHZ_240 + default 320 if EXAMPLE_PM_MIN_FREQ_MHZ_320