fpga_overrides.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. static const char *TAG = "fpga";
  26. #ifdef CONFIG_IDF_TARGET_ESP32
  27. #include "esp32/rom/rtc.h"
  28. #endif
  29. #ifdef CONFIG_IDF_TARGET_ESP32S2
  30. #include "esp32s2/rom/rtc.h"
  31. #endif
  32. extern void ets_update_cpu_frequency(uint32_t ticks_per_us);
  33. static void s_warn(void)
  34. {
  35. ESP_EARLY_LOGW(TAG, "Project configuration is for internal FPGA use, not all functions will work");
  36. }
  37. void bootloader_clock_configure(void)
  38. {
  39. s_warn();
  40. esp_rom_uart_tx_wait_idle(0);
  41. uint32_t xtal_freq_mhz = 40;
  42. #ifdef CONFIG_IDF_TARGET_ESP32S2
  43. uint32_t apb_freq_hz = 20000000;
  44. #elif CONFIG_IDF_TARGET_ESP32S2H2
  45. uint32_t apb_freq_hz = 32000000;
  46. #else
  47. uint32_t apb_freq_hz = 40000000;
  48. #endif // CONFIG_IDF_TARGET_ESP32S2
  49. ets_update_cpu_frequency(apb_freq_hz / 1000000);
  50. #ifdef RTC_APB_FREQ_REG
  51. REG_WRITE(RTC_APB_FREQ_REG, (apb_freq_hz >> 12) | ((apb_freq_hz >> 12) << 16));
  52. #endif
  53. REG_WRITE(RTC_CNTL_STORE4_REG, (xtal_freq_mhz) | ((xtal_freq_mhz) << 16));
  54. }
  55. /* Placed in IRAM since test_apps expects it to be */
  56. void IRAM_ATTR bootloader_fill_random(void *buffer, size_t length)
  57. {
  58. uint8_t *buffer_bytes = (uint8_t *)buffer;
  59. for (int i = 0; i < length; i++) {
  60. buffer_bytes[i] = 0x5A;
  61. }
  62. }
  63. void esp_clk_init(void)
  64. {
  65. s_warn();
  66. }
  67. void esp_perip_clk_init(void)
  68. {
  69. }
  70. /**
  71. * @brief No-op function, used to force linking this file
  72. *
  73. */
  74. void esp_common_include_fpga_overrides(void)
  75. {
  76. }