board.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-08-30 shelton first version
  9. */
  10. #include "board.h"
  11. void system_clock_config(void)
  12. {
  13. /* reset crm */
  14. crm_reset();
  15. /* config flash psr register */
  16. flash_psr_set(FLASH_WAIT_CYCLE_5);
  17. /* enable pwc periph clock */
  18. crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
  19. /* set power ldo output voltage to 1.3v */
  20. pwc_ldo_output_voltage_set(PWC_LDO_OUTPUT_1V3);
  21. crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE);
  22. /* wait till hext is ready */
  23. while(crm_hext_stable_wait() == ERROR)
  24. {
  25. }
  26. /* if pll parameter has changed, please use the AT32_New_Clock_Configuration tool for new configuration. */
  27. crm_pll_config(CRM_PLL_SOURCE_HEXT, 90, 1, CRM_PLL_FR_4);
  28. /* enable pll */
  29. crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
  30. /* wait till pll is ready */
  31. while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET)
  32. {
  33. }
  34. /* config ahbclk */
  35. crm_ahb_div_set(CRM_AHB_DIV_1);
  36. /* config apb3clk, the maximum frequency of APB3 clock is 90 MHz */
  37. crm_apb3_div_set(CRM_APB3_DIV_4);
  38. /* config apb2clk, the maximum frequency of APB2 clock is 180 MHz */
  39. crm_apb2_div_set(CRM_APB2_DIV_1);
  40. /* config apb1clk, the maximum frequency of APB1 clock is 180 MHz */
  41. crm_apb1_div_set(CRM_APB1_DIV_1);
  42. /* enable auto step mode */
  43. crm_auto_step_mode_enable(TRUE);
  44. /* select pll as system clock source */
  45. crm_sysclk_switch(CRM_SCLK_PLL);
  46. /* wait till pll is used as system clock source */
  47. while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL)
  48. {
  49. }
  50. /* disable auto step mode */
  51. crm_auto_step_mode_enable(FALSE);
  52. /* update system_core_clock global variable */
  53. system_core_clock_update();
  54. }