2017-12-14 23:32:53 +00:00
|
|
|
// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2019-03-14 09:29:32 +00:00
|
|
|
#include "esp32/rom/uart.h"
|
|
|
|
#include "esp32/rom/rtc.h"
|
2017-12-14 23:32:53 +00:00
|
|
|
#include "soc/soc.h"
|
|
|
|
#include "soc/rtc.h"
|
|
|
|
#include "soc/dport_reg.h"
|
2019-05-13 10:02:45 +00:00
|
|
|
#include "soc/efuse_periph.h"
|
2017-12-14 23:32:53 +00:00
|
|
|
|
|
|
|
void bootloader_clock_configure()
|
|
|
|
{
|
|
|
|
// ROM bootloader may have put a lot of text into UART0 FIFO.
|
|
|
|
// Wait for it to be printed.
|
|
|
|
// This is not needed on power on reset, when ROM bootloader is running at
|
|
|
|
// 40 MHz. But in case of TG WDT reset, CPU may still be running at >80 MHZ,
|
|
|
|
// and will be done with the bootloader much earlier than UART FIFO is empty.
|
|
|
|
uart_tx_wait_idle(0);
|
|
|
|
|
|
|
|
/* Set CPU to 80MHz. Keep other clocks unmodified. */
|
2018-07-29 07:51:02 +00:00
|
|
|
int cpu_freq_mhz = 80;
|
2017-12-14 23:32:53 +00:00
|
|
|
|
2018-11-29 07:18:11 +00:00
|
|
|
/* On ESP32 rev 0, switching to 80/160 MHz if clock was previously set to
|
2017-12-14 23:32:53 +00:00
|
|
|
* 240 MHz may cause the chip to lock up (see section 3.5 of the errata
|
2018-11-29 07:18:11 +00:00
|
|
|
* document). For rev. 0, switch to 240 instead if it has been enabled
|
|
|
|
* previously.
|
2017-12-14 23:32:53 +00:00
|
|
|
*/
|
|
|
|
uint32_t chip_ver_reg = REG_READ(EFUSE_BLK0_RDATA3_REG);
|
|
|
|
if ((chip_ver_reg & EFUSE_RD_CHIP_VER_REV1_M) == 0 &&
|
2019-02-26 09:07:59 +00:00
|
|
|
DPORT_REG_GET_FIELD(DPORT_CPU_PER_CONF_REG, DPORT_CPUPERIOD_SEL) == DPORT_CPUPERIOD_SEL_240) {
|
2018-07-29 07:51:02 +00:00
|
|
|
cpu_freq_mhz = 240;
|
2017-12-14 23:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rtc_clk_config_t clk_cfg = RTC_CLK_CONFIG_DEFAULT();
|
|
|
|
clk_cfg.xtal_freq = CONFIG_ESP32_XTAL_FREQ;
|
2018-07-29 07:51:02 +00:00
|
|
|
clk_cfg.cpu_freq_mhz = cpu_freq_mhz;
|
2017-12-14 23:32:53 +00:00
|
|
|
clk_cfg.slow_freq = rtc_clk_slow_freq_get();
|
|
|
|
clk_cfg.fast_freq = rtc_clk_fast_freq_get();
|
|
|
|
rtc_clk_init(clk_cfg);
|
|
|
|
/* As a slight optimization, if 32k XTAL was enabled in sdkconfig, we enable
|
|
|
|
* it here. Usually it needs some time to start up, so we amortize at least
|
|
|
|
* part of the start up time by enabling 32k XTAL early.
|
|
|
|
* App startup code will wait until the oscillator has started up.
|
|
|
|
*/
|
2019-04-30 10:51:55 +00:00
|
|
|
#ifdef CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS
|
2017-12-14 23:32:53 +00:00
|
|
|
if (!rtc_clk_32k_enabled()) {
|
2018-03-19 08:05:32 +00:00
|
|
|
rtc_clk_32k_bootstrap(CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES);
|
2017-12-14 23:32:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|