mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
bugfix: fix rc_fast bad calibration value
This commit is contained in:
parent
6ad6fb9755
commit
8c714acfb5
@ -39,7 +39,25 @@ static const char *TAG = "rtc_time";
|
|||||||
#define TIMG_RTC_CALI_CLK_SEL_RC_FAST 1
|
#define TIMG_RTC_CALI_CLK_SEL_RC_FAST 1
|
||||||
#define TIMG_RTC_CALI_CLK_SEL_32K 2
|
#define TIMG_RTC_CALI_CLK_SEL_32K 2
|
||||||
|
|
||||||
uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
/**
|
||||||
|
* @brief Clock calibration function used by rtc_clk_cal
|
||||||
|
*
|
||||||
|
* Calibration of RTC_SLOW_CLK is performed using a special feature of TIMG0.
|
||||||
|
* This feature counts the number of XTAL clock cycles within a given number of
|
||||||
|
* RTC_SLOW_CLK cycles.
|
||||||
|
*
|
||||||
|
* Slow clock calibration feature has two modes of operation: one-off and cycling.
|
||||||
|
* In cycling mode (which is enabled by default on SoC reset), counting of XTAL
|
||||||
|
* cycles within RTC_SLOW_CLK cycle is done continuously. Cycling mode is enabled
|
||||||
|
* using TIMG_RTC_CALI_START_CYCLING bit. In one-off mode counting is performed
|
||||||
|
* once, and TIMG_RTC_CALI_RDY bit is set when counting is done. One-off mode is
|
||||||
|
* enabled using TIMG_RTC_CALI_START bit.
|
||||||
|
*
|
||||||
|
* @param cal_clk which clock to calibrate
|
||||||
|
* @param slowclk_cycles number of slow clock cycles to count
|
||||||
|
* @return number of XTAL clock cycles within the given number of slow clock cycles
|
||||||
|
*/
|
||||||
|
static uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
||||||
{
|
{
|
||||||
assert(slowclk_cycles < TIMG_RTC_CALI_MAX_V);
|
assert(slowclk_cycles < TIMG_RTC_CALI_MAX_V);
|
||||||
|
|
||||||
@ -103,15 +121,6 @@ uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
|||||||
&& !GET_PERI_REG_MASK(TIMG_RTCCALICFG2_REG(0), TIMG_RTC_CALI_TIMEOUT));
|
&& !GET_PERI_REG_MASK(TIMG_RTCCALICFG2_REG(0), TIMG_RTC_CALI_TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*The Fosc CLK of calibration circuit is divided by 32 for ECO1.
|
|
||||||
So we need to divide the calibrate cycles of the FOSC for ECO1 and above chips by 32 to
|
|
||||||
avoid excessive calibration time.*/
|
|
||||||
if (ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 1)) {
|
|
||||||
if (cal_clk == RTC_CAL_RC_FAST) {
|
|
||||||
slowclk_cycles = slowclk_cycles >> 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Prepare calibration */
|
/* Prepare calibration */
|
||||||
REG_SET_FIELD(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_CLK_SEL, cali_clk_sel);
|
REG_SET_FIELD(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_CLK_SEL, cali_clk_sel);
|
||||||
CLEAR_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_START_CYCLING);
|
CLEAR_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_START_CYCLING);
|
||||||
@ -200,6 +209,16 @@ static bool rtc_clk_cal_32k_valid(rtc_xtal_freq_t xtal_freq, uint32_t slowclk_cy
|
|||||||
uint32_t rtc_clk_cal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
uint32_t rtc_clk_cal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
||||||
{
|
{
|
||||||
rtc_xtal_freq_t xtal_freq = rtc_clk_xtal_freq_get();
|
rtc_xtal_freq_t xtal_freq = rtc_clk_xtal_freq_get();
|
||||||
|
|
||||||
|
/*The Fosc CLK of calibration circuit is divided by 32 for ECO1.
|
||||||
|
So we need to divide the calibrate cycles of the FOSC for ECO1 and above chips by 32 to
|
||||||
|
avoid excessive calibration time.*/
|
||||||
|
if (ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 1)) {
|
||||||
|
if (cal_clk == RTC_CAL_RC_FAST) {
|
||||||
|
slowclk_cycles = slowclk_cycles >> 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t xtal_cycles = rtc_clk_cal_internal(cal_clk, slowclk_cycles);
|
uint64_t xtal_cycles = rtc_clk_cal_internal(cal_clk, slowclk_cycles);
|
||||||
|
|
||||||
if (cal_clk == RTC_CAL_32K_XTAL && !rtc_clk_cal_32k_valid(xtal_freq, slowclk_cycles, xtal_cycles)) {
|
if (cal_clk == RTC_CAL_32K_XTAL && !rtc_clk_cal_32k_valid(xtal_freq, slowclk_cycles, xtal_cycles)) {
|
||||||
|
@ -39,7 +39,25 @@ static const char *TAG = "rtc_time";
|
|||||||
#define TIMG_RTC_CALI_CLK_SEL_RC_FAST 1
|
#define TIMG_RTC_CALI_CLK_SEL_RC_FAST 1
|
||||||
#define TIMG_RTC_CALI_CLK_SEL_32K 2
|
#define TIMG_RTC_CALI_CLK_SEL_32K 2
|
||||||
|
|
||||||
uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
/**
|
||||||
|
* @brief Clock calibration function used by rtc_clk_cal
|
||||||
|
*
|
||||||
|
* Calibration of RTC_SLOW_CLK is performed using a special feature of TIMG0.
|
||||||
|
* This feature counts the number of XTAL clock cycles within a given number of
|
||||||
|
* RTC_SLOW_CLK cycles.
|
||||||
|
*
|
||||||
|
* Slow clock calibration feature has two modes of operation: one-off and cycling.
|
||||||
|
* In cycling mode (which is enabled by default on SoC reset), counting of XTAL
|
||||||
|
* cycles within RTC_SLOW_CLK cycle is done continuously. Cycling mode is enabled
|
||||||
|
* using TIMG_RTC_CALI_START_CYCLING bit. In one-off mode counting is performed
|
||||||
|
* once, and TIMG_RTC_CALI_RDY bit is set when counting is done. One-off mode is
|
||||||
|
* enabled using TIMG_RTC_CALI_START bit.
|
||||||
|
*
|
||||||
|
* @param cal_clk which clock to calibrate
|
||||||
|
* @param slowclk_cycles number of slow clock cycles to count
|
||||||
|
* @return number of XTAL clock cycles within the given number of slow clock cycles
|
||||||
|
*/
|
||||||
|
static uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
||||||
{
|
{
|
||||||
assert(slowclk_cycles < TIMG_RTC_CALI_MAX_V);
|
assert(slowclk_cycles < TIMG_RTC_CALI_MAX_V);
|
||||||
|
|
||||||
@ -103,15 +121,6 @@ uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
|||||||
&& !GET_PERI_REG_MASK(TIMG_RTCCALICFG2_REG(0), TIMG_RTC_CALI_TIMEOUT));
|
&& !GET_PERI_REG_MASK(TIMG_RTCCALICFG2_REG(0), TIMG_RTC_CALI_TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*The Fosc CLK of calibration circuit is divided by 32 for ECO2.
|
|
||||||
So we need to divide the calibrate cycles of the FOSC for ECO1 and above chips by 32 to
|
|
||||||
avoid excessive calibration time.*/
|
|
||||||
if (ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 2)) {
|
|
||||||
if (cal_clk == RTC_CAL_RC_FAST) {
|
|
||||||
slowclk_cycles = slowclk_cycles >> 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Prepare calibration */
|
/* Prepare calibration */
|
||||||
REG_SET_FIELD(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_CLK_SEL, cali_clk_sel);
|
REG_SET_FIELD(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_CLK_SEL, cali_clk_sel);
|
||||||
CLEAR_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_START_CYCLING);
|
CLEAR_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_START_CYCLING);
|
||||||
@ -200,6 +209,16 @@ static bool rtc_clk_cal_32k_valid(rtc_xtal_freq_t xtal_freq, uint32_t slowclk_cy
|
|||||||
uint32_t rtc_clk_cal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
uint32_t rtc_clk_cal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
||||||
{
|
{
|
||||||
rtc_xtal_freq_t xtal_freq = rtc_clk_xtal_freq_get();
|
rtc_xtal_freq_t xtal_freq = rtc_clk_xtal_freq_get();
|
||||||
|
|
||||||
|
/*The Fosc CLK of calibration circuit is divided by 32 for ECO2.
|
||||||
|
So we need to divide the calibrate cycles of the FOSC for ECO1 and above chips by 32 to
|
||||||
|
avoid excessive calibration time.*/
|
||||||
|
if (ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 2)) {
|
||||||
|
if (cal_clk == RTC_CAL_RC_FAST) {
|
||||||
|
slowclk_cycles = slowclk_cycles >> 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t xtal_cycles = rtc_clk_cal_internal(cal_clk, slowclk_cycles);
|
uint64_t xtal_cycles = rtc_clk_cal_internal(cal_clk, slowclk_cycles);
|
||||||
|
|
||||||
if (cal_clk == RTC_CAL_32K_XTAL && !rtc_clk_cal_32k_valid(xtal_freq, slowclk_cycles, xtal_cycles)) {
|
if (cal_clk == RTC_CAL_32K_XTAL && !rtc_clk_cal_32k_valid(xtal_freq, slowclk_cycles, xtal_cycles)) {
|
||||||
|
@ -391,26 +391,6 @@ void rtc_clk_cpu_freq_to_pll_and_pll_lock_release(int cpu_freq_mhz);
|
|||||||
*/
|
*/
|
||||||
uint32_t rtc_clk_apb_freq_get(void);
|
uint32_t rtc_clk_apb_freq_get(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Clock calibration function used by rtc_clk_cal
|
|
||||||
*
|
|
||||||
* Calibration of RTC_SLOW_CLK is performed using a special feature of TIMG0.
|
|
||||||
* This feature counts the number of XTAL clock cycles within a given number of
|
|
||||||
* RTC_SLOW_CLK cycles.
|
|
||||||
*
|
|
||||||
* Slow clock calibration feature has two modes of operation: one-off and cycling.
|
|
||||||
* In cycling mode (which is enabled by default on SoC reset), counting of XTAL
|
|
||||||
* cycles within RTC_SLOW_CLK cycle is done continuously. Cycling mode is enabled
|
|
||||||
* using TIMG_RTC_CALI_START_CYCLING bit. In one-off mode counting is performed
|
|
||||||
* once, and TIMG_RTC_CALI_RDY bit is set when counting is done. One-off mode is
|
|
||||||
* enabled using TIMG_RTC_CALI_START bit.
|
|
||||||
*
|
|
||||||
* @param cal_clk which clock to calibrate
|
|
||||||
* @param slowclk_cycles number of slow clock cycles to count
|
|
||||||
* @return number of XTAL clock cycles within the given number of slow clock cycles
|
|
||||||
*/
|
|
||||||
uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Measure RTC slow clock's period, based on main XTAL frequency
|
* @brief Measure RTC slow clock's period, based on main XTAL frequency
|
||||||
*
|
*
|
||||||
|
@ -393,26 +393,6 @@ void rtc_clk_cpu_freq_set_xtal(void);
|
|||||||
*/
|
*/
|
||||||
uint32_t rtc_clk_apb_freq_get(void);
|
uint32_t rtc_clk_apb_freq_get(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Clock calibration function used by rtc_clk_cal
|
|
||||||
*
|
|
||||||
* Calibration of RTC_SLOW_CLK is performed using a special feature of TIMG0.
|
|
||||||
* This feature counts the number of XTAL clock cycles within a given number of
|
|
||||||
* RTC_SLOW_CLK cycles.
|
|
||||||
*
|
|
||||||
* Slow clock calibration feature has two modes of operation: one-off and cycling.
|
|
||||||
* In cycling mode (which is enabled by default on SoC reset), counting of XTAL
|
|
||||||
* cycles within RTC_SLOW_CLK cycle is done continuously. Cycling mode is enabled
|
|
||||||
* using TIMG_RTC_CALI_START_CYCLING bit. In one-off mode counting is performed
|
|
||||||
* once, and TIMG_RTC_CALI_RDY bit is set when counting is done. One-off mode is
|
|
||||||
* enabled using TIMG_RTC_CALI_START bit.
|
|
||||||
*
|
|
||||||
* @param cal_clk which clock to calibrate
|
|
||||||
* @param slowclk_cycles number of slow clock cycles to count
|
|
||||||
* @return number of XTAL clock cycles within the given number of slow clock cycles
|
|
||||||
*/
|
|
||||||
uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Measure RTC slow clock's period, based on main XTAL frequency
|
* @brief Measure RTC slow clock's period, based on main XTAL frequency
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user