From 3b5ce456e2c59cb9a30a09e2b4645a8eaf100a78 Mon Sep 17 00:00:00 2001 From: Song Ruo Jing Date: Wed, 12 Oct 2022 12:33:47 +0800 Subject: [PATCH] rtc_clk: Fix rtc8m calibration failure after cpu/core reset Explicitly guarantee 8md256 clk is enabled before calibration --- components/soc/src/esp32/rtc_time.c | 4 ++++ components/soc/src/esp32s2/rtc_time.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/components/soc/src/esp32/rtc_time.c b/components/soc/src/esp32/rtc_time.c index a7dfdb2485..8d60253d83 100644 --- a/components/soc/src/esp32/rtc_time.c +++ b/components/soc/src/esp32/rtc_time.c @@ -49,7 +49,10 @@ static uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cyc REG_SET_FIELD(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_DIG_XTAL32K_EN, 1); } + bool clk8m_enabled = rtc_clk_8m_enabled(); + bool clk8md256_enabled = rtc_clk_8md256_enabled(); if (cal_clk == RTC_CAL_8MD256) { + rtc_clk_8m_enable(true, true); SET_PERI_REG_MASK(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_DIG_CLK8M_D256_EN); } /* Prepare calibration */ @@ -100,6 +103,7 @@ static uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cyc if (cal_clk == RTC_CAL_8MD256) { CLEAR_PERI_REG_MASK(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_DIG_CLK8M_D256_EN); + rtc_clk_8m_enable(clk8m_enabled, clk8md256_enabled); } if (timeout_us == 0) { /* timed out waiting for calibration */ diff --git a/components/soc/src/esp32s2/rtc_time.c b/components/soc/src/esp32s2/rtc_time.c index 064b984683..caab82194e 100644 --- a/components/soc/src/esp32s2/rtc_time.c +++ b/components/soc/src/esp32s2/rtc_time.c @@ -57,7 +57,10 @@ uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles) REG_SET_FIELD(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_DIG_XTAL32K_EN, 1); } + bool clk8m_enabled = rtc_clk_8m_enabled(); + bool clk8md256_enabled = rtc_clk_8md256_enabled(); if (cal_clk == RTC_CAL_8MD256) { + rtc_clk_8m_enable(true, true); SET_PERI_REG_MASK(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_DIG_CLK8M_D256_EN); } /* There may be another calibration process already running during we call this function, @@ -115,6 +118,7 @@ uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles) if (cal_clk == RTC_CAL_8MD256) { CLEAR_PERI_REG_MASK(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_DIG_CLK8M_D256_EN); + rtc_clk_8m_enable(clk8m_enabled, clk8md256_enabled); } return cal_val;