From 7c584e80b0bcddab7b06f8695f38141a465e251a Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 8 Jan 2018 23:31:21 +0800 Subject: [PATCH] soc/rtc_clk: fix loss of precision in estimation of XTAL frequency RTC_FAST_CLK_FREQ_APPROX is defined as 8500000, so 0.5MHz part was lost when dividing by MHZ. Since cal_val is 64-bit the parens can be removed. With 40MHz XTAL for a nominal ESP32 chip, this fixes estimated XTAL frequency from 38 to 40MHz. --- components/soc/esp32/rtc_clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/soc/esp32/rtc_clk.c b/components/soc/esp32/rtc_clk.c index 7c8d9609a..54dea84c5 100644 --- a/components/soc/esp32/rtc_clk.c +++ b/components/soc/esp32/rtc_clk.c @@ -589,7 +589,7 @@ static rtc_xtal_freq_t rtc_clk_xtal_freq_estimate() * (shifted by RTC_CLK_CAL_FRACT bits). * Xtal frequency will be (cal_val * 8M / 256) / 2^19 */ - uint32_t freq_mhz = (cal_val * (RTC_FAST_CLK_FREQ_APPROX / MHZ) / 256 ) >> RTC_CLK_CAL_FRACT; + uint32_t freq_mhz = (cal_val * RTC_FAST_CLK_FREQ_APPROX / MHZ / 256 ) >> RTC_CLK_CAL_FRACT; /* Guess the XTAL type. For now, only 40 and 26MHz are supported. */ switch (freq_mhz) {