Skip to content

Commit c84757d

Browse files
committed
fix(esp_hw_support): fix current leakage if ext32k slow clock source not exists
1 parent 6b4f08c commit c84757d

File tree

33 files changed

+216
-48
lines changed

33 files changed

+216
-48
lines changed

components/esp_hw_support/port/esp32/include/soc/rtc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -172,6 +172,11 @@ void rtc_clk_32k_enable(bool en);
172172
*/
173173
void rtc_clk_32k_enable_external(void);
174174

175+
/**
176+
* @brief Disable 32 kHz XTAL oscillator input.
177+
*/
178+
void rtc_clk_32k_disable_external(void);
179+
175180
/**
176181
* @brief Get the state of 32k XTAL oscillator
177182
* @return true if 32k XTAL oscillator has been enabled

components/esp_hw_support/port/esp32/rtc_clk.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -115,6 +115,11 @@ void rtc_clk_32k_enable_external(void)
115115
rtc_clk_32k_enable_common(CLK_LL_XTAL32K_ENABLE_MODE_EXTERNAL);
116116
}
117117

118+
void rtc_clk_32k_disable_external(void)
119+
{
120+
clk_ll_xtal32k_disable();
121+
}
122+
118123
/* Helping external 32kHz crystal to start up.
119124
* External crystal connected to outputs GPIO32 GPIO33.
120125
* Forms N pulses with a frequency of about 32KHz on the outputs of the crystal.

components/esp_hw_support/port/esp32c2/include/soc/rtc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -257,6 +257,11 @@ void rtc_clk_xtal_freq_update(soc_xtal_freq_t xtal_freq);
257257
*/
258258
void rtc_clk_32k_enable_external(void);
259259

260+
/**
261+
* @brief Disable 32KHz external oscillator
262+
*/
263+
void rtc_clk_32k_disable_external(void);
264+
260265
/**
261266
* @brief Enable or disable 8 MHz internal oscillator
262267
*

components/esp_hw_support/port/esp32c2/rtc_clk.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -37,6 +37,12 @@ void rtc_clk_32k_enable_external(void)
3737
REG_SET_BIT(RTC_CNTL_PAD_HOLD_REG, BIT(EXT_OSC_SLOW_GPIO_NUM));
3838
}
3939

40+
void rtc_clk_32k_disable_external(void)
41+
{
42+
PIN_INPUT_DISABLE(IO_MUX_GPIO0_REG);
43+
REG_CLR_BIT(RTC_CNTL_PAD_HOLD_REG, BIT(EXT_OSC_SLOW_GPIO_NUM));
44+
}
45+
4046
void rtc_clk_8m_enable(bool clk_8m_en, bool d256_en)
4147
{
4248
if (clk_8m_en) {

components/esp_hw_support/port/esp32c3/include/soc/rtc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -263,6 +263,11 @@ void rtc_clk_32k_enable(bool en);
263263
*/
264264
void rtc_clk_32k_enable_external(void);
265265

266+
/**
267+
* @brief Disable 32 kHz XTAL oscillator input.
268+
*/
269+
void rtc_clk_32k_disable_external(void);
270+
266271
/**
267272
* @brief Get the state of 32k XTAL oscillator
268273
* @return true if 32k XTAL oscillator has been enabled

components/esp_hw_support/port/esp32c3/rtc_clk.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -56,6 +56,13 @@ void rtc_clk_32k_enable_external(void)
5656
clk_ll_xtal32k_enable(CLK_LL_XTAL32K_ENABLE_MODE_EXTERNAL);
5757
}
5858

59+
void rtc_clk_32k_disable_external(void)
60+
{
61+
PIN_INPUT_DISABLE(IO_MUX_GPIO0_REG);
62+
CLEAR_PERI_REG_MASK(RTC_CNTL_PAD_HOLD_REG, RTC_CNTL_GPIO_PIN0_HOLD);
63+
clk_ll_xtal32k_disable();
64+
}
65+
5966
void rtc_clk_32k_bootstrap(uint32_t cycle)
6067
{
6168
/* No special bootstrapping needed for ESP32-C3, 'cycle' argument is to keep the signature

components/esp_hw_support/port/esp32c5/include/soc/rtc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -181,6 +181,11 @@ void rtc_clk_32k_enable(bool en);
181181
*/
182182
void rtc_clk_32k_enable_external(void);
183183

184+
/**
185+
* @brief Disable 32 kHz XTAL oscillator input.
186+
*/
187+
void rtc_clk_32k_disable_external(void);
188+
184189
/**
185190
* @brief Get the state of 32k XTAL oscillator
186191
* @return true if 32k XTAL oscillator has been enabled

components/esp_hw_support/port/esp32c5/rtc_clk.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -58,6 +58,13 @@ void rtc_clk_32k_enable_external(void)
5858
clk_ll_xtal32k_enable(CLK_LL_XTAL32K_ENABLE_MODE_EXTERNAL);
5959
}
6060

61+
void rtc_clk_32k_disable_external(void)
62+
{
63+
gpio_ll_input_disable(&GPIO, EXT_OSC_SLOW_GPIO_NUM);
64+
REG_CLR_BIT(LP_AON_GPIO_HOLD0_REG, BIT(EXT_OSC_SLOW_GPIO_NUM));
65+
clk_ll_xtal32k_disable();
66+
}
67+
6168
void rtc_clk_32k_bootstrap(uint32_t cycle)
6269
{
6370
/* No special bootstrapping needed for ESP32-C5, 'cycle' argument is to keep the signature

components/esp_hw_support/port/esp32c6/include/soc/rtc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -205,6 +205,11 @@ void rtc_clk_32k_enable(bool en);
205205
*/
206206
void rtc_clk_32k_enable_external(void);
207207

208+
/**
209+
* @brief Disable 32 kHz XTAL oscillator input.
210+
*/
211+
void rtc_clk_32k_disable_external(void);
212+
208213
/**
209214
* @brief Get the state of 32k XTAL oscillator
210215
* @return true if 32k XTAL oscillator has been enabled

components/esp_hw_support/port/esp32c6/rtc_clk.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -56,6 +56,13 @@ void rtc_clk_32k_enable_external(void)
5656
clk_ll_xtal32k_enable(CLK_LL_XTAL32K_ENABLE_MODE_EXTERNAL);
5757
}
5858

59+
void rtc_clk_32k_disable_external(void)
60+
{
61+
PIN_INPUT_DISABLE(IO_MUX_GPIO0_REG);
62+
REG_CLR_BIT(LP_AON_GPIO_HOLD0_REG, BIT(EXT_OSC_SLOW_GPIO_NUM));
63+
clk_ll_xtal32k_disable();
64+
}
65+
5966
void rtc_clk_32k_bootstrap(uint32_t cycle)
6067
{
6168
/* No special bootstrapping needed for ESP32-C6, 'cycle' argument is to keep the signature

0 commit comments

Comments
 (0)