diff --git a/components/driver/gpio/gpio.c b/components/driver/gpio/gpio.c index 48947dc9fa..8bacddd489 100644 --- a/components/driver/gpio/gpio.c +++ b/components/driver/gpio/gpio.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,6 +22,7 @@ #include "esp_check.h" #include "hal/gpio_hal.h" #include "esp_rom_gpio.h" +#include "esp_private/io_mux.h" static const char *GPIO_TAG = "gpio"; #define GPIO_CHECK(a, str, ret_val) ESP_RETURN_ON_FALSE(a, ret_val, GPIO_TAG, "%s", str) @@ -575,6 +576,11 @@ esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type) if ((intr_type == GPIO_INTR_LOW_LEVEL) || (intr_type == GPIO_INTR_HIGH_LEVEL)) { #if SOC_RTCIO_WAKE_SUPPORTED if (rtc_gpio_is_valid_gpio(gpio_num)) { +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + // LP_IO Wake-up function does not depend on LP_IO Matrix, but uses its clock to + // sample the wake-up signal, we need to enable the LP_IO clock here. + io_mux_enable_lp_io_clock(gpio_num, true); +#endif ret = rtc_gpio_wakeup_enable(gpio_num, intr_type); } #endif @@ -600,6 +606,9 @@ esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num) #if SOC_RTCIO_WAKE_SUPPORTED if (rtc_gpio_is_valid_gpio(gpio_num)) { ret = rtc_gpio_wakeup_disable(gpio_num); +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + io_mux_enable_lp_io_clock(gpio_num, false); +#endif } #endif portENTER_CRITICAL(&gpio_context.gpio_spinlock); @@ -926,6 +935,9 @@ esp_err_t gpio_deep_sleep_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t int return ESP_ERR_INVALID_ARG; } portENTER_CRITICAL(&gpio_context.gpio_spinlock); +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + io_mux_enable_lp_io_clock(gpio_num, true); +#endif gpio_hal_deepsleep_wakeup_enable(gpio_context.gpio_hal, gpio_num, intr_type); #if CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND || CONFIG_PM_SLP_DISABLE_GPIO gpio_hal_sleep_sel_dis(gpio_context.gpio_hal, gpio_num); @@ -944,6 +956,9 @@ esp_err_t gpio_deep_sleep_wakeup_disable(gpio_num_t gpio_num) gpio_hal_deepsleep_wakeup_disable(gpio_context.gpio_hal, gpio_num); #if CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND || CONFIG_PM_SLP_DISABLE_GPIO gpio_hal_sleep_sel_en(gpio_context.gpio_hal, gpio_num); +#endif +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + io_mux_enable_lp_io_clock(gpio_num, false); #endif portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; diff --git a/components/driver/gpio/rtc_io.c b/components/driver/gpio/rtc_io.c index 0920b0e729..4916f51e69 100644 --- a/components/driver/gpio/rtc_io.c +++ b/components/driver/gpio/rtc_io.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,8 @@ #include "esp_log.h" #include "esp_err.h" #include "esp_check.h" +#include "esp_private/periph_ctrl.h" +#include "esp_private/io_mux.h" #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "freertos/timers.h" @@ -30,6 +32,9 @@ esp_err_t rtc_gpio_init(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + io_mux_enable_lp_io_clock(gpio_num, true); +#endif rtcio_hal_function_select(rtc_io_number_get(gpio_num), RTCIO_FUNC_RTC); RTCIO_EXIT_CRITICAL(); @@ -42,6 +47,10 @@ esp_err_t rtc_gpio_deinit(gpio_num_t gpio_num) RTCIO_ENTER_CRITICAL(); // Select Gpio as Digital Gpio rtcio_hal_function_select(rtc_io_number_get(gpio_num), RTCIO_FUNC_DIGITAL); + +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + io_mux_enable_lp_io_clock(gpio_num, false); +#endif RTCIO_EXIT_CRITICAL(); return ESP_OK; diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 9025cd61e8..3b0aa0eb47 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -14,7 +14,9 @@ #include "esp_sleep.h" #include "esp_private/esp_sleep_internal.h" #include "esp_private/esp_timer_private.h" +#include "esp_private/rtc_clk.h" #include "esp_private/system_internal.h" +#include "esp_private/io_mux.h" #include "esp_log.h" #include "esp_newlib.h" #include "esp_timer.h" @@ -1152,6 +1154,9 @@ esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level) static void ext0_wakeup_prepare(void) { int rtc_gpio_num = s_config.ext0_rtc_gpio_num; +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + io_mux_enable_lp_io_clock(rtc_gpio_num, true); +#endif rtcio_hal_ext0_set_wakeup_pin(rtc_gpio_num, s_config.ext0_trigger_level); rtcio_hal_function_select(rtc_gpio_num, RTCIO_FUNC_RTC); rtcio_hal_input_enable(rtc_gpio_num); @@ -1189,6 +1194,9 @@ static void ext1_wakeup_prepare(void) if ((rtc_gpio_mask & BIT(rtc_pin)) == 0) { continue; } +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + io_mux_enable_lp_io_clock(rtc_pin, true); +#endif #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED // Route pad to RTC rtcio_hal_function_select(rtc_pin, RTCIO_FUNC_RTC);