2021-05-09 22:35:07 -04:00
|
|
|
/*
|
2021-12-22 09:18:43 -05:00
|
|
|
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
2021-05-09 22:35:07 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2019-08-08 01:27:22 -04:00
|
|
|
#include "sdkconfig.h"
|
2017-12-14 18:32:53 -05:00
|
|
|
#include "soc/soc.h"
|
|
|
|
#include "soc/rtc.h"
|
2021-12-22 09:18:43 -05:00
|
|
|
#include "hal/efuse_hal.h"
|
2019-12-26 02:25:24 -05:00
|
|
|
#include "soc/rtc_cntl_reg.h"
|
2021-07-12 22:45:06 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-11-26 03:56:13 -05:00
|
|
|
#include "soc/dport_reg.h"
|
2019-08-08 01:27:22 -04:00
|
|
|
#endif
|
2021-07-12 22:45:06 -04:00
|
|
|
#include "esp_rom_sys.h"
|
2020-07-13 09:33:23 -04:00
|
|
|
#include "esp_rom_uart.h"
|
2019-08-08 01:27:22 -04:00
|
|
|
|
2020-07-29 10:03:46 -04:00
|
|
|
__attribute__((weak)) void bootloader_clock_configure(void)
|
2017-12-14 18:32:53 -05:00
|
|
|
{
|
|
|
|
// 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.
|
2020-07-13 09:33:23 -04:00
|
|
|
esp_rom_uart_tx_wait_idle(0);
|
2017-12-14 18:32:53 -05:00
|
|
|
|
2020-02-12 07:56:59 -05:00
|
|
|
/* Set CPU to 80MHz. Keep other clocks unmodified. */
|
|
|
|
int cpu_freq_mhz = 80;
|
2020-07-29 10:03:46 -04:00
|
|
|
|
2020-02-12 07:56:59 -05:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2018-11-29 02:18:11 -05:00
|
|
|
/* On ESP32 rev 0, switching to 80/160 MHz if clock was previously set to
|
2017-12-14 18:32:53 -05:00
|
|
|
* 240 MHz may cause the chip to lock up (see section 3.5 of the errata
|
2018-11-29 02:18:11 -05:00
|
|
|
* document). For rev. 0, switch to 240 instead if it has been enabled
|
|
|
|
* previously.
|
2017-12-14 18:32:53 -05:00
|
|
|
*/
|
2021-12-22 09:18:43 -05:00
|
|
|
if (efuse_hal_get_chip_revision() == 0 &&
|
2019-02-26 04:07:59 -05:00
|
|
|
DPORT_REG_GET_FIELD(DPORT_CPU_PER_CONF_REG, DPORT_CPUPERIOD_SEL) == DPORT_CPUPERIOD_SEL_240) {
|
2018-07-29 03:51:02 -04:00
|
|
|
cpu_freq_mhz = 240;
|
2017-12-14 18:32:53 -05:00
|
|
|
}
|
2021-12-06 04:38:11 -05:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32H2
|
|
|
|
cpu_freq_mhz = 64;
|
2019-05-27 02:29:43 -04:00
|
|
|
#endif
|
2020-07-29 10:03:46 -04:00
|
|
|
|
2021-07-12 22:45:06 -04:00
|
|
|
if (rtc_clk_apb_freq_get() < APB_CLK_FREQ || esp_rom_get_reset_reason(0) != RESET_REASON_CPU0_SW) {
|
2020-04-30 10:50:41 -04:00
|
|
|
rtc_clk_config_t clk_cfg = RTC_CLK_CONFIG_DEFAULT();
|
2020-07-29 10:03:46 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-04-30 10:50:41 -04:00
|
|
|
clk_cfg.xtal_freq = CONFIG_ESP32_XTAL_FREQ;
|
2020-07-29 10:03:46 -04:00
|
|
|
#endif
|
2020-04-30 10:50:41 -04:00
|
|
|
/* ESP32-S2 doesn't have XTAL_FREQ choice, always 40MHz */
|
|
|
|
clk_cfg.cpu_freq_mhz = cpu_freq_mhz;
|
|
|
|
clk_cfg.slow_freq = rtc_clk_slow_freq_get();
|
|
|
|
clk_cfg.fast_freq = rtc_clk_fast_freq_get();
|
|
|
|
rtc_clk_init(clk_cfg);
|
|
|
|
}
|
2020-02-12 12:09:17 -05:00
|
|
|
|
2020-07-29 10:03:46 -04:00
|
|
|
/* 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.
|
|
|
|
*/
|
2020-07-14 08:39:30 -04:00
|
|
|
#if CONFIG_ESP_SYSTEM_RTC_EXT_XTAL
|
2017-12-14 18:32:53 -05:00
|
|
|
if (!rtc_clk_32k_enabled()) {
|
2020-07-14 08:39:30 -04:00
|
|
|
rtc_clk_32k_bootstrap(CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES);
|
2017-12-14 18:32:53 -05:00
|
|
|
}
|
2020-07-14 08:39:30 -04:00
|
|
|
#endif // CONFIG_ESP_SYSTEM_RTC_EXT_XTAL
|
2021-03-24 07:58:12 -04:00
|
|
|
|
|
|
|
REG_WRITE(RTC_CNTL_INT_ENA_REG, 0);
|
|
|
|
REG_WRITE(RTC_CNTL_INT_CLR_REG, UINT32_MAX);
|
2017-12-14 18:32:53 -05:00
|
|
|
}
|