fpga_overrides.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "sdkconfig.h"
  7. #include "soc/soc.h"
  8. #ifndef CONFIG_IDF_TARGET_ESP32
  9. #include "soc/system_reg.h"
  10. #endif // not CONFIG_IDF_TARGET_ESP32
  11. #include "soc/rtc.h"
  12. #include "soc/rtc_cntl_reg.h"
  13. #include "esp_log.h"
  14. #include "esp_rom_sys.h"
  15. #include "esp_rom_uart.h"
  16. #include "esp_attr.h"
  17. static const char *TAG = "fpga";
  18. #ifdef CONFIG_IDF_TARGET_ESP32
  19. #include "esp32/rom/rtc.h"
  20. #endif
  21. #ifdef CONFIG_IDF_TARGET_ESP32S2
  22. #include "esp32s2/rom/rtc.h"
  23. #endif
  24. extern void ets_update_cpu_frequency(uint32_t ticks_per_us);
  25. static void s_warn(void)
  26. {
  27. ESP_EARLY_LOGW(TAG, "Project configuration is for internal FPGA use, not all functions will work");
  28. }
  29. void bootloader_clock_configure(void)
  30. {
  31. s_warn();
  32. esp_rom_uart_tx_wait_idle(0);
  33. uint32_t xtal_freq_mhz = 40;
  34. #ifdef CONFIG_IDF_TARGET_ESP32S2
  35. uint32_t apb_freq_hz = 20000000;
  36. #elif CONFIG_IDF_TARGET_ESP32H2
  37. uint32_t apb_freq_hz = 32000000;
  38. #else
  39. uint32_t apb_freq_hz = 40000000;
  40. #endif // CONFIG_IDF_TARGET_ESP32S2
  41. ets_update_cpu_frequency(apb_freq_hz / 1000000);
  42. #ifdef RTC_APB_FREQ_REG
  43. REG_WRITE(RTC_APB_FREQ_REG, (apb_freq_hz >> 12) | ((apb_freq_hz >> 12) << 16));
  44. #endif
  45. REG_WRITE(RTC_CNTL_STORE4_REG, (xtal_freq_mhz) | ((xtal_freq_mhz) << 16));
  46. }
  47. /* Placed in IRAM since test_apps expects it to be */
  48. void IRAM_ATTR bootloader_fill_random(void *buffer, size_t length)
  49. {
  50. uint8_t *buffer_bytes = (uint8_t *)buffer;
  51. for (int i = 0; i < length; i++) {
  52. buffer_bytes[i] = 0x5A;
  53. }
  54. }
  55. void esp_clk_init(void)
  56. {
  57. s_warn();
  58. }
  59. void esp_perip_clk_init(void)
  60. {
  61. }
  62. /**
  63. * @brief No-op function, used to force linking this file
  64. *
  65. */
  66. void esp_common_include_fpga_overrides(void)
  67. {
  68. }