]> granicus.if.org Git - esp-idf/commitdiff
soc/rtc_clk: fix loss of precision in estimation of XTAL frequency
authorIvan Grokhotkov <ivan@espressif.com>
Mon, 8 Jan 2018 15:31:21 +0000 (23:31 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Mon, 8 Jan 2018 15:31:21 +0000 (23:31 +0800)
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

index 7c8d9609a4da34f7dd36a5fae85d2e599604b2dc..54dea84c51d4ed3a9764c9571192cd01dab55ae3 100644 (file)
@@ -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) {