at32f403a_407_clock.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. **************************************************************************
  3. * @file at32f403a_407_clock.c
  4. * @brief system clock config program
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. /* includes ------------------------------------------------------------------*/
  25. #include "at32f403a_407_clock.h"
  26. /** @addtogroup AT32F403A_periph_template
  27. * @{
  28. */
  29. /** @addtogroup 403A_System_clock_configuration System_clock_configuration
  30. * @{
  31. */
  32. /**
  33. * @brief system clock config program
  34. * @note the system clock is configured as follow:
  35. * system clock (sclk) = hext / 2 * pll_mult
  36. * system clock source = pll (hext)
  37. * - hext = HEXT_VALUE
  38. * - sclk = 240000000
  39. * - ahbdiv = 1
  40. * - ahbclk = 240000000
  41. * - apb2div = 2
  42. * - apb2clk = 120000000
  43. * - apb1div = 2
  44. * - apb1clk = 120000000
  45. * - pll_mult = 60
  46. * - pll_range = GT72MHZ (greater than 72 mhz)
  47. * @param none
  48. * @retval none
  49. */
  50. void system_clock_config(void)
  51. {
  52. /* reset crm */
  53. crm_reset();
  54. crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE);
  55. /* wait till hext is ready */
  56. while(crm_hext_stable_wait() == ERROR)
  57. {
  58. }
  59. /* config pll clock resource */
  60. crm_pll_config(CRM_PLL_SOURCE_HEXT_DIV, CRM_PLL_MULT_60, CRM_PLL_OUTPUT_RANGE_GT72MHZ);
  61. /* config hext division */
  62. crm_hext_clock_div_set(CRM_HEXT_DIV_2);
  63. /* enable pll */
  64. crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
  65. /* wait till pll is ready */
  66. while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET)
  67. {
  68. }
  69. /* config ahbclk */
  70. crm_ahb_div_set(CRM_AHB_DIV_1);
  71. /* config apb2clk, the maximum frequency of APB1/APB2 clock is 120 MHz */
  72. crm_apb2_div_set(CRM_APB2_DIV_2);
  73. /* config apb1clk, the maximum frequency of APB1/APB2 clock is 120 MHz */
  74. crm_apb1_div_set(CRM_APB1_DIV_2);
  75. /* enable auto step mode */
  76. crm_auto_step_mode_enable(TRUE);
  77. /* select pll as system clock source */
  78. crm_sysclk_switch(CRM_SCLK_PLL);
  79. /* wait till pll is used as system clock source */
  80. while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL)
  81. {
  82. }
  83. /* disable auto step mode */
  84. crm_auto_step_mode_enable(FALSE);
  85. /* update system_core_clock global variable */
  86. system_core_clock_update();
  87. }
  88. /**
  89. * @}
  90. */
  91. /**
  92. * @}
  93. */