mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-01 11:26:15 +00:00
RTC regulator & voltage calibration fixes
This commit is contained in:
@@ -22,6 +22,9 @@
|
||||
#include "soc/spi_mem_reg.h"
|
||||
#include "soc/extmem_reg.h"
|
||||
#include "i2c_rtc_clk.h"
|
||||
#include "soc_log.h"
|
||||
|
||||
static const char *TAG = "rtc_init";
|
||||
|
||||
void rtc_init(rtc_config_t cfg)
|
||||
{
|
||||
@@ -143,6 +146,56 @@ void rtc_init(rtc_config_t cfg)
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_UNHOLD);
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO);
|
||||
}
|
||||
if (cfg.cali_ocode)
|
||||
{
|
||||
/*
|
||||
Bangap output voltage is not precise when calibrate o-code by hardware sometimes, so need software o-code calibration(must close PLL).
|
||||
Method:
|
||||
1. read current cpu config, save in old_config;
|
||||
2. switch cpu to xtal because PLL will be closed when o-code calibration;
|
||||
3. begin o-code calibration;
|
||||
4. wait o-code calibration done flag(odone_flag & bg_odone_flag) or timeout;
|
||||
5. set cpu to old-config.
|
||||
*/
|
||||
rtc_slow_freq_t slow_clk_freq = rtc_clk_slow_freq_get();
|
||||
rtc_slow_freq_t rtc_slow_freq_x32k = RTC_SLOW_FREQ_32K_XTAL;
|
||||
rtc_slow_freq_t rtc_slow_freq_8MD256 = RTC_SLOW_FREQ_8MD256;
|
||||
rtc_cal_sel_t cal_clk = RTC_CAL_RTC_MUX;
|
||||
if (slow_clk_freq == (rtc_slow_freq_x32k)) {
|
||||
cal_clk = RTC_CAL_32K_XTAL;
|
||||
} else if (slow_clk_freq == rtc_slow_freq_8MD256) {
|
||||
cal_clk = RTC_CAL_8MD256;
|
||||
}
|
||||
|
||||
uint64_t max_delay_time_us = 10000;
|
||||
uint32_t slow_clk_period = rtc_clk_cal(cal_clk, 100);
|
||||
uint64_t max_delay_cycle = rtc_time_us_to_slowclk(max_delay_time_us, slow_clk_period);
|
||||
uint64_t cycle0 = rtc_time_get();
|
||||
uint64_t timeout_cycle = cycle0 + max_delay_cycle;
|
||||
uint64_t cycle1 = 0;
|
||||
|
||||
rtc_cpu_freq_config_t old_config;
|
||||
rtc_clk_cpu_freq_get_config(&old_config);
|
||||
rtc_clk_cpu_freq_set_xtal();
|
||||
|
||||
|
||||
I2C_WRITEREG_MASK_RTC(I2C_ULP, I2C_ULP_IR_RESETB, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_ULP, I2C_ULP_IR_RESETB, 1);
|
||||
bool odone_flag = 0;
|
||||
bool bg_odone_flag = 0;
|
||||
while(1) {
|
||||
odone_flag = I2C_READREG_MASK_RTC(I2C_ULP, I2C_ULP_O_DONE_FLAG);
|
||||
bg_odone_flag = I2C_READREG_MASK_RTC(I2C_ULP, I2C_ULP_BG_O_DONE_FLAG);
|
||||
cycle1 = rtc_time_get();
|
||||
if (odone_flag && bg_odone_flag)
|
||||
break;
|
||||
if (cycle1 >= timeout_cycle) {
|
||||
SOC_LOGW(TAG, "o_code calibration fail");
|
||||
break;
|
||||
}
|
||||
}
|
||||
rtc_clk_cpu_freq_set_config(&old_config);
|
||||
}
|
||||
}
|
||||
|
||||
rtc_vddsdio_config_t rtc_vddsdio_get_config(void)
|
||||
|
Reference in New Issue
Block a user