From 93cdad7a3b504f7390bee32c6112aa89936b7fc3 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Wed, 19 Feb 2025 10:10:57 +0800 Subject: [PATCH] feat(esp_hw_support): support esp32h21 retention link software trigger --- components/esp_hw_support/CMakeLists.txt | 23 ++--- .../esp_hw_support/lowpower/CMakeLists.txt | 2 +- components/esp_hw_support/sleep_retention.c | 8 +- .../test_apps/.build-test-rules.yml | 4 +- components/soc/CMakeLists.txt | 2 +- .../esp32h21/include/soc/Kconfig.soc_caps.in | 8 ++ .../include/soc/retention_periph_defs.h | 89 +++++++++++++++++++ .../soc/esp32h21/include/soc/soc_caps.h | 3 +- components/soc/include/soc/ledc_periph.h | 2 +- 9 files changed, 124 insertions(+), 17 deletions(-) create mode 100644 components/soc/esp32h21/include/soc/retention_periph_defs.h diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index 4235e184e2..262f235d3e 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -28,12 +28,6 @@ if(NOT non_os_build) "periph_ctrl.c" "revision.c" "rtc_module.c" - "sleep_modem.c" - "sleep_modes.c" - "sleep_console.c" - "sleep_usb.c" - "sleep_gpio.c" - "sleep_event.c" "regi2c_ctrl.c" "esp_gpio_reserve.c" "sar_periph_ctrl_common.c" @@ -49,14 +43,23 @@ if(NOT non_os_build) if(CONFIG_SOC_ADC_SUPPORTED) list(APPEND srcs "adc_share_hw_ctrl.c") endif() - if(CONFIG_SOC_ISP_SHARE_CSI_BRG) list(APPEND srcs "mipi_csi_share_hw_ctrl.c") endif() if(CONFIG_SOC_PAU_SUPPORTED) - list(APPEND srcs "sleep_retention.c" - "sleep_system_peripheral.c" - ) + list(APPEND srcs "sleep_retention.c") + endif() + if(CONFIG_SOC_LIGHT_SLEEP_SUPPORTED) + list(APPEND srcs "sleep_modem.c" + "sleep_modes.c" + "sleep_console.c" + "sleep_usb.c" + "sleep_gpio.c" + "sleep_event.c" + ) + if(CONFIG_SOC_PAU_SUPPORTED) + list(APPEND srcs "sleep_system_peripheral.c") + endif() endif() # [refactor-todo] diff --git a/components/esp_hw_support/lowpower/CMakeLists.txt b/components/esp_hw_support/lowpower/CMakeLists.txt index 2d4124bb61..bb470ef3b8 100644 --- a/components/esp_hw_support/lowpower/CMakeLists.txt +++ b/components/esp_hw_support/lowpower/CMakeLists.txt @@ -1,6 +1,6 @@ idf_build_get_property(non_os_build NON_OS_BUILD) -if(non_os_build) +if(non_os_build OR NOT CONFIG_SOC_LIGHT_SLEEP_SUPPORTED) return() endif() diff --git a/components/esp_hw_support/sleep_retention.c b/components/esp_hw_support/sleep_retention.c index d7b63cb63f..7df1d700cd 100644 --- a/components/esp_hw_support/sleep_retention.c +++ b/components/esp_hw_support/sleep_retention.c @@ -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 */ @@ -514,7 +514,9 @@ static void sleep_retention_entries_destroy(sleep_retention_module_t module) } if (created_modules == 0) { sleep_retention_entries_check_and_distroy_final_default(); +#if SOC_LIGHT_SLEEP_SUPPORTED pmu_sleep_disable_regdma_backup(); +#endif memset((void *)s_retention.lists, 0, sizeof(s_retention.lists)); s_retention.highpri = (uint8_t)-1; } @@ -641,8 +643,12 @@ esp_err_t sleep_retention_entries_create(const sleep_retention_entries_config_t if (err) goto error; err = sleep_retention_entries_create_wrapper(retent, num, priority, module); if (err) goto error; +#if SOC_LIGHT_SLEEP_SUPPORTED pmu_sleep_enable_regdma_backup(); +#endif +#if SOC_LIGHT_SLEEP_SUPPORTED && SOC_DEEP_SLEEP_SUPPORTED ESP_ERROR_CHECK(esp_deep_sleep_register_hook(&pmu_sleep_disable_regdma_backup)); +#endif error: return err; diff --git a/components/esp_hw_support/test_apps/.build-test-rules.yml b/components/esp_hw_support/test_apps/.build-test-rules.yml index 90b80e7967..43d2838e14 100644 --- a/components/esp_hw_support/test_apps/.build-test-rules.yml +++ b/components/esp_hw_support/test_apps/.build-test-rules.yml @@ -44,8 +44,8 @@ components/esp_hw_support/test_apps/rtc_power_modes: components/esp_hw_support/test_apps/sleep_retention: enable: - - if: SOC_PAU_SUPPORTED == 1 and CONFIG_NAME != "xip_psram" - - if: SOC_PAU_SUPPORTED == 1 and (SOC_SPIRAM_XIP_SUPPORTED == 1 and CONFIG_NAME == "xip_psram") + - if: SOC_PAU_SUPPORTED == 1 and SOC_LIGHT_SLEEP_SUPPORTED == 1 and CONFIG_NAME != "xip_psram" + - if: SOC_PAU_SUPPORTED == 1 and SOC_LIGHT_SLEEP_SUPPORTED == 1 and (SOC_SPIRAM_XIP_SUPPORTED == 1 and CONFIG_NAME == "xip_psram") components/esp_hw_support/test_apps/vad_wakeup: disable: diff --git a/components/soc/CMakeLists.txt b/components/soc/CMakeLists.txt index 8bdbe3c63d..e446e96994 100644 --- a/components/soc/CMakeLists.txt +++ b/components/soc/CMakeLists.txt @@ -165,7 +165,7 @@ if(CONFIG_SOC_SDIO_SLAVE_SUPPORTED) list(APPEND srcs "${target_folder}/sdio_slave_periph.c") endif() -if(CONFIG_SOC_PAU_SUPPORTED) +if(CONFIG_SOC_PAU_SUPPORTED AND CONFIG_SOC_LIGHT_SLEEP_SUPPORTED) list(APPEND srcs "${target_folder}/system_retention_periph.c") endif() diff --git a/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in index 92a2b39f61..2d7188f64b 100644 --- a/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in @@ -43,6 +43,10 @@ config SOC_SPI_FLASH_SUPPORTED bool default y +config SOC_PAU_SUPPORTED + bool + default y + config SOC_XTAL_SUPPORT_32M bool default y @@ -671,6 +675,10 @@ config SOC_PM_PAU_LINK_NUM int default 5 +config SOC_PM_RETENTION_MODULE_NUM + int + default 32 + config SOC_PM_PAU_REGDMA_LINK_CONFIGURABLE bool default y diff --git a/components/soc/esp32h21/include/soc/retention_periph_defs.h b/components/soc/esp32h21/include/soc/retention_periph_defs.h new file mode 100644 index 0000000000..44a487382f --- /dev/null +++ b/components/soc/esp32h21/include/soc/retention_periph_defs.h @@ -0,0 +1,89 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include "soc_caps.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum periph_retention_module { + SLEEP_RETENTION_MODULE_MIN = 0, + SLEEP_RETENTION_MODULE_NULL = SLEEP_RETENTION_MODULE_MIN, /* This module is for all peripherals that can't survive from PD_TOP to call init only. Shouldn't have any dependency. */ + /* clock module, which includes system and modem */ + SLEEP_RETENTION_MODULE_CLOCK_SYSTEM = 1, + SLEEP_RETENTION_MODULE_CLOCK_MODEM = 2, + /* digital peripheral module, which includes Interrupt Matrix, HP_SYSTEM, + * TEE, APM, UART, IOMUX, SPIMEM, SysTimer, etc.. */ + SLEEP_RETENTION_MODULE_SYS_PERIPH = 3, + /* Timer Group by target*/ + SLEEP_RETENTION_MODULE_TG0_WDT = 4, + SLEEP_RETENTION_MODULE_TG1_WDT = 5, + SLEEP_RETENTION_MODULE_TG0_TIMER0 = 6, + SLEEP_RETENTION_MODULE_TG1_TIMER0 = 7, + /* GDMA by channel */ + SLEEP_RETENTION_MODULE_GDMA_CH0 = 8, + SLEEP_RETENTION_MODULE_GDMA_CH1 = 9, + SLEEP_RETENTION_MODULE_GDMA_CH2 = 10, + /* MISC Peripherals */ + SLEEP_RETENTION_MODULE_ADC = 11, + SLEEP_RETENTION_MODULE_I2C0 = 12, + SLEEP_RETENTION_MODULE_I2C1 = 13, + SLEEP_RETENTION_MODULE_RMT0 = 14, + SLEEP_RETENTION_MODULE_UART0 = 15, + SLEEP_RETENTION_MODULE_UART1 = 16, + SLEEP_RETENTION_MODULE_I2S0 = 17, + SLEEP_RETENTION_MODULE_ETM0 = 18, + SLEEP_RETENTION_MODULE_TEMP_SENSOR = 19, + SLEEP_RETENTION_MODULE_TWAI0 = 20, + SLEEP_RETENTION_MODULE_PARLIO0 = 21, + SLEEP_RETENTION_MODULE_GPSPI2 = 22, + SLEEP_RETENTION_MODULE_LEDC = 23, + SLEEP_RETENTION_MODULE_PCNT0 = 24, + SLEEP_RETENTION_MODULE_MCPWM0 = 25, + + /* Modem module, which includes BLE and 802.15.4 */ + SLEEP_RETENTION_MODULE_BLE_MAC = 28, + SLEEP_RETENTION_MODULE_BT_BB = 29, + SLEEP_RETENTION_MODULE_802154_MAC = 30, + + SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 +} periph_retention_module_t; + +#define is_top_domain_module(m) \ + ( ((m) == SLEEP_RETENTION_MODULE_NULL) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_SYS_PERIPH) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH2) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_ADC) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_I2C0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_I2C1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_RMT0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_I2S0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_ETM0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TEMP_SENSOR) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TWAI0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_PARLIO0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GPSPI2) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_LEDC) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_PCNT0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_MCPWM0) ? true \ + : false) + +#ifdef __cplusplus +} +#endif diff --git a/components/soc/esp32h21/include/soc/soc_caps.h b/components/soc/esp32h21/include/soc/soc_caps.h index 1a6c4bb68a..a85199d7c0 100644 --- a/components/soc/esp32h21/include/soc/soc_caps.h +++ b/components/soc/esp32h21/include/soc/soc_caps.h @@ -74,7 +74,7 @@ // #define SOC_RMT_SUPPORTED 1 //TODO: [ESP32H21] IDF-11622 // #define SOC_AES_SUPPORTED 1 //TODO: [ESP32H21] IDF-11504 // #define SOC_SDIO_SLAVE_SUPPORTED 1 -// #define SOC_PAU_SUPPORTED 1 +#define SOC_PAU_SUPPORTED 1 // #define SOC_LIGHT_SLEEP_SUPPORTED 1 //TODO: [ESP32H21] IDF-11517, IDF-11520 // #define SOC_DEEP_SLEEP_SUPPORTED 1 //TODO: [ESP32H21] IDF-11515 // #define SOC_MODEM_CLOCK_SUPPORTED 1 @@ -529,6 +529,7 @@ #define SOC_PM_SUPPORT_VDDSDIO_PD (1) #define SOC_PM_SUPPORT_TOP_PD (1) #define SOC_PM_PAU_LINK_NUM (5) +#define SOC_PM_RETENTION_MODULE_NUM (32) #define SOC_PM_PAU_REGDMA_LINK_CONFIGURABLE (1) #define SOC_PM_CPU_RETENTION_BY_SW (1) #define SOC_PM_MODEM_RETENTION_BY_REGDMA (1) diff --git a/components/soc/include/soc/ledc_periph.h b/components/soc/include/soc/ledc_periph.h index 8ed332010b..066dc5ca7c 100644 --- a/components/soc/include/soc/ledc_periph.h +++ b/components/soc/include/soc/ledc_periph.h @@ -31,7 +31,7 @@ extern const ledc_signal_conn_t ledc_periph_signal[2]; extern const ledc_signal_conn_t ledc_periph_signal[1]; #endif -#if SOC_PAU_SUPPORTED +#if SOC_PAU_SUPPORTED && SOC_LEDC_SUPPORT_SLEEP_RETENTION #if SOC_LIGHT_SLEEP_SUPPORTED #if SOC_PHY_SUPPORTED