kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/bootloader_freq_check_runtime' into 'master'
bootloader: check previously used clock frequency at run time See merge request idf/esp-idf!3827pull/3110/head
commit
80f02cd0ea
|
@ -31,14 +31,14 @@ void bootloader_clock_configure()
|
||||||
/* Set CPU to 80MHz. Keep other clocks unmodified. */
|
/* Set CPU to 80MHz. Keep other clocks unmodified. */
|
||||||
int cpu_freq_mhz = 80;
|
int cpu_freq_mhz = 80;
|
||||||
|
|
||||||
/* On ESP32 rev 0, switching to 80MHz if clock was previously set to
|
/* On ESP32 rev 0, switching to 80/160 MHz if clock was previously set to
|
||||||
* 240 MHz may cause the chip to lock up (see section 3.5 of the errata
|
* 240 MHz may cause the chip to lock up (see section 3.5 of the errata
|
||||||
* document). For rev. 0, switch to 240 instead if it was chosen in
|
* document). For rev. 0, switch to 240 instead if it has been enabled
|
||||||
* menuconfig.
|
* previously.
|
||||||
*/
|
*/
|
||||||
uint32_t chip_ver_reg = REG_READ(EFUSE_BLK0_RDATA3_REG);
|
uint32_t chip_ver_reg = REG_READ(EFUSE_BLK0_RDATA3_REG);
|
||||||
if ((chip_ver_reg & EFUSE_RD_CHIP_VER_REV1_M) == 0 &&
|
if ((chip_ver_reg & EFUSE_RD_CHIP_VER_REV1_M) == 0 &&
|
||||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ == 240) {
|
DPORT_REG_GET_FIELD(DPORT_CPU_PER_CONF_REG, DPORT_CPUPERIOD_SEL) == DPORT_CPUPERIOD_SEL_240) {
|
||||||
cpu_freq_mhz = 240;
|
cpu_freq_mhz = 240;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,9 @@
|
||||||
#define DPORT_CPUPERIOD_SEL_M ((DPORT_CPUPERIOD_SEL_V)<<(DPORT_CPUPERIOD_SEL_S))
|
#define DPORT_CPUPERIOD_SEL_M ((DPORT_CPUPERIOD_SEL_V)<<(DPORT_CPUPERIOD_SEL_S))
|
||||||
#define DPORT_CPUPERIOD_SEL_V 0x3
|
#define DPORT_CPUPERIOD_SEL_V 0x3
|
||||||
#define DPORT_CPUPERIOD_SEL_S 0
|
#define DPORT_CPUPERIOD_SEL_S 0
|
||||||
|
#define DPORT_CPUPERIOD_SEL_80 0
|
||||||
|
#define DPORT_CPUPERIOD_SEL_160 1
|
||||||
|
#define DPORT_CPUPERIOD_SEL_240 2
|
||||||
|
|
||||||
#define DPORT_PRO_CACHE_CTRL_REG (DR_REG_DPORT_BASE + 0x040)
|
#define DPORT_PRO_CACHE_CTRL_REG (DR_REG_DPORT_BASE + 0x040)
|
||||||
/* DPORT_PRO_DRAM_HL : R/W ;bitpos:[16] ;default: 1'b0 ; */
|
/* DPORT_PRO_DRAM_HL : R/W ;bitpos:[16] ;default: 1'b0 ; */
|
||||||
|
|
|
@ -398,7 +398,6 @@ void rtc_clk_cpu_freq_to_xtal(int freq, int div)
|
||||||
REG_WRITE(APB_CTRL_XTAL_TICK_CONF_REG, freq * MHZ / REF_CLK_FREQ - 1);
|
REG_WRITE(APB_CTRL_XTAL_TICK_CONF_REG, freq * MHZ / REF_CLK_FREQ - 1);
|
||||||
/* switch clock source */
|
/* switch clock source */
|
||||||
REG_SET_FIELD(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, RTC_CNTL_SOC_CLK_SEL_XTL);
|
REG_SET_FIELD(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, RTC_CNTL_SOC_CLK_SEL_XTL);
|
||||||
DPORT_REG_WRITE(DPORT_CPU_PER_CONF_REG, 0); /* clear DPORT_CPUPERIOD_SEL */
|
|
||||||
rtc_clk_apb_freq_update(freq * MHZ);
|
rtc_clk_apb_freq_update(freq * MHZ);
|
||||||
/* lower the voltage */
|
/* lower the voltage */
|
||||||
if (freq <= 2) {
|
if (freq <= 2) {
|
||||||
|
@ -414,7 +413,6 @@ static void rtc_clk_cpu_freq_to_8m()
|
||||||
REG_SET_FIELD(RTC_CNTL_REG, RTC_CNTL_DIG_DBIAS_WAK, DIG_DBIAS_XTAL);
|
REG_SET_FIELD(RTC_CNTL_REG, RTC_CNTL_DIG_DBIAS_WAK, DIG_DBIAS_XTAL);
|
||||||
REG_SET_FIELD(APB_CTRL_SYSCLK_CONF_REG, APB_CTRL_PRE_DIV_CNT, 0);
|
REG_SET_FIELD(APB_CTRL_SYSCLK_CONF_REG, APB_CTRL_PRE_DIV_CNT, 0);
|
||||||
REG_SET_FIELD(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, RTC_CNTL_SOC_CLK_SEL_8M);
|
REG_SET_FIELD(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, RTC_CNTL_SOC_CLK_SEL_8M);
|
||||||
DPORT_REG_WRITE(DPORT_CPU_PER_CONF_REG, 0); // clear DPORT_CPUPERIOD_SEL
|
|
||||||
rtc_clk_apb_freq_update(RTC_FAST_CLK_FREQ_8M);
|
rtc_clk_apb_freq_update(RTC_FAST_CLK_FREQ_8M);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,14 +453,14 @@ static void rtc_clk_bbpll_enable()
|
||||||
static void rtc_clk_cpu_freq_to_pll_mhz(int cpu_freq_mhz)
|
static void rtc_clk_cpu_freq_to_pll_mhz(int cpu_freq_mhz)
|
||||||
{
|
{
|
||||||
int dbias = DIG_DBIAS_80M_160M;
|
int dbias = DIG_DBIAS_80M_160M;
|
||||||
int per_conf = 0;
|
int per_conf = DPORT_CPUPERIOD_SEL_80;
|
||||||
if (cpu_freq_mhz == 80) {
|
if (cpu_freq_mhz == 80) {
|
||||||
/* nothing to do */
|
/* nothing to do */
|
||||||
} else if (cpu_freq_mhz == 160) {
|
} else if (cpu_freq_mhz == 160) {
|
||||||
per_conf = 1;
|
per_conf = DPORT_CPUPERIOD_SEL_160;
|
||||||
} else if (cpu_freq_mhz == 240) {
|
} else if (cpu_freq_mhz == 240) {
|
||||||
dbias = DIG_DBIAS_240M;
|
dbias = DIG_DBIAS_240M;
|
||||||
per_conf = 2;
|
per_conf = DPORT_CPUPERIOD_SEL_240;
|
||||||
} else {
|
} else {
|
||||||
SOC_LOGE(TAG, "invalid frequency");
|
SOC_LOGE(TAG, "invalid frequency");
|
||||||
abort();
|
abort();
|
||||||
|
@ -690,15 +688,15 @@ void rtc_clk_cpu_freq_get_config(rtc_cpu_freq_config_t* out_config)
|
||||||
case RTC_CNTL_SOC_CLK_SEL_PLL: {
|
case RTC_CNTL_SOC_CLK_SEL_PLL: {
|
||||||
source = RTC_CPU_FREQ_SRC_PLL;
|
source = RTC_CPU_FREQ_SRC_PLL;
|
||||||
uint32_t cpuperiod_sel = DPORT_REG_GET_FIELD(DPORT_CPU_PER_CONF_REG, DPORT_CPUPERIOD_SEL);
|
uint32_t cpuperiod_sel = DPORT_REG_GET_FIELD(DPORT_CPU_PER_CONF_REG, DPORT_CPUPERIOD_SEL);
|
||||||
if (cpuperiod_sel == 0) {
|
if (cpuperiod_sel == DPORT_CPUPERIOD_SEL_80) {
|
||||||
source_freq_mhz = RTC_PLL_FREQ_320M;
|
source_freq_mhz = RTC_PLL_FREQ_320M;
|
||||||
div = 4;
|
div = 4;
|
||||||
freq_mhz = 80;
|
freq_mhz = 80;
|
||||||
} else if (cpuperiod_sel == 1) {
|
} else if (cpuperiod_sel == DPORT_CPUPERIOD_SEL_160) {
|
||||||
source_freq_mhz = RTC_PLL_FREQ_320M;
|
source_freq_mhz = RTC_PLL_FREQ_320M;
|
||||||
div = 2;
|
div = 2;
|
||||||
freq_mhz = 160;
|
freq_mhz = 160;
|
||||||
} else if (cpuperiod_sel == 2) {
|
} else if (cpuperiod_sel == DPORT_CPUPERIOD_SEL_240) {
|
||||||
source_freq_mhz = RTC_PLL_FREQ_480M;
|
source_freq_mhz = RTC_PLL_FREQ_480M;
|
||||||
div = 2;
|
div = 2;
|
||||||
freq_mhz = 240;
|
freq_mhz = 240;
|
||||||
|
|
Ładowanie…
Reference in New Issue