1 // Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include "sdkconfig.h"
15 #include "soc/soc.h"
16 #ifndef CONFIG_IDF_TARGET_ESP32
17 #include "soc/system_reg.h"
18 #endif // not CONFIG_IDF_TARGET_ESP32
19 #include "soc/rtc.h"
20 #include "soc/rtc_cntl_reg.h"
21 #include "esp_log.h"
22 #include "esp_rom_sys.h"
23 #include "esp_rom_uart.h"
24 #include "esp_attr.h"
25
26 static const char *TAG = "fpga";
27
28 #ifdef CONFIG_IDF_TARGET_ESP32
29 #include "esp32/rom/rtc.h"
30 #endif
31 #ifdef CONFIG_IDF_TARGET_ESP32S2
32 #include "esp32s2/rom/rtc.h"
33 #endif
34
35 extern void ets_update_cpu_frequency(uint32_t ticks_per_us);
36
s_warn(void)37 static void s_warn(void)
38 {
39 ESP_EARLY_LOGW(TAG, "Project configuration is for internal FPGA use, not all functions will work");
40 }
41
bootloader_clock_configure(void)42 void bootloader_clock_configure(void)
43 {
44 s_warn();
45 esp_rom_uart_tx_wait_idle(0);
46
47 uint32_t xtal_freq_mhz = 40;
48 #ifdef CONFIG_IDF_TARGET_ESP32S2
49 uint32_t apb_freq_hz = 20000000;
50 #elif CONFIG_IDF_TARGET_ESP32S2H2
51 uint32_t apb_freq_hz = 32000000;
52 #else
53 uint32_t apb_freq_hz = 40000000;
54 #endif // CONFIG_IDF_TARGET_ESP32S2
55 ets_update_cpu_frequency(apb_freq_hz / 1000000);
56 #ifdef RTC_APB_FREQ_REG
57 REG_WRITE(RTC_APB_FREQ_REG, (apb_freq_hz >> 12) | ((apb_freq_hz >> 12) << 16));
58 #endif
59 REG_WRITE(RTC_CNTL_STORE4_REG, (xtal_freq_mhz) | ((xtal_freq_mhz) << 16));
60 }
61
62 /* Placed in IRAM since test_apps expects it to be */
bootloader_fill_random(void * buffer,size_t length)63 void IRAM_ATTR bootloader_fill_random(void *buffer, size_t length)
64 {
65 uint8_t *buffer_bytes = (uint8_t *)buffer;
66 for (int i = 0; i < length; i++) {
67 buffer_bytes[i] = 0x5A;
68 }
69 }
70
esp_clk_init(void)71 void esp_clk_init(void)
72 {
73 s_warn();
74 }
75
esp_perip_clk_init(void)76 void esp_perip_clk_init(void)
77 {
78
79 }
80
81 /**
82 * @brief No-op function, used to force linking this file
83 *
84 */
esp_common_include_fpga_overrides(void)85 void esp_common_include_fpga_overrides(void)
86 {
87 }
88