From 178e5b25e6b6a254e40cca6b0663c398ab732ca5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 29 Nov 2018 15:18:11 +0800 Subject: [PATCH] bootloader: check previously used clock frequency at run time In the situation when bootloader was compiled for 240MHz, and app was compiled for 160MHz, and the chip is a revision 0 chip, the bootloader will assume that the application has also been running at 240MHz. This will cause the chip to lock up later. Modify this to use a run time check of DPORT_CPUPERIOD_SEL, which indicates which of the PLL frequencies was used. Closes https://github.com/espressif/esp-idf/issues/2731. --- components/bootloader_support/src/bootloader_clock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/bootloader_support/src/bootloader_clock.c b/components/bootloader_support/src/bootloader_clock.c index d5a1e52aba..50c84cfb01 100644 --- a/components/bootloader_support/src/bootloader_clock.c +++ b/components/bootloader_support/src/bootloader_clock.c @@ -31,14 +31,14 @@ void bootloader_clock_configure() /* Set CPU to 80MHz. Keep other clocks unmodified. */ 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 - * document). For rev. 0, switch to 240 instead if it was chosen in - * menuconfig. + * document). For rev. 0, switch to 240 instead if it has been enabled + * previously. */ uint32_t chip_ver_reg = REG_READ(EFUSE_BLK0_RDATA3_REG); 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) == 2) { cpu_freq_mhz = 240; }