From 80966c61565001e0259c643055d10e1856b589b3 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Wed, 29 Apr 2026 17:51:09 +0800 Subject: [PATCH] fix(rtc_io): fixed invalid clock access on C5 (cherry picked from commit 2bcbe0e3650df4596f38b65444707bee09725b67) --- .../esp32c5/include/hal/rtc_io_ll.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/components/esp_hal_gpio/esp32c5/include/hal/rtc_io_ll.h b/components/esp_hal_gpio/esp32c5/include/hal/rtc_io_ll.h index f29b0c36779..0248e415bd4 100644 --- a/components/esp_hal_gpio/esp32c5/include/hal/rtc_io_ll.h +++ b/components/esp_hal_gpio/esp32c5/include/hal/rtc_io_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -61,10 +61,19 @@ static inline void rtcio_ll_iomux_func_sel(int rtcio_num, int func) */ static inline void _rtcio_ll_enable_io_clock(bool enable) { - LPPERI.clk_en.lp_io_ck_en = enable; - LP_GPIO.clock_gate.clk_en = enable; - while ((LPPERI.clk_en.lp_io_ck_en != enable) || (LP_GPIO.clock_gate.clk_en != enable)) { - ; + // LPPERI clock controls LP_GPIO so needs to be enabled first/disabled last + if (enable) { + LPPERI.clk_en.lp_io_ck_en = enable; + LP_GPIO.clock_gate.clk_en = enable; + } else { + LP_GPIO.clock_gate.clk_en = enable; + LPPERI.clk_en.lp_io_ck_en = enable; + } + + if (enable) { + while ((LPPERI.clk_en.lp_io_ck_en != enable) || (LP_GPIO.clock_gate.clk_en != enable)) { + ; + } } }