at32f403a_407_clock.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /**
  27. * @brief system clock config program
  28. * @note the system clock is configured as follow:
  29. * system clock (sclk) = hext / 2 * pll_mult
  30. * system clock source = pll (hext)
  31. * - hext = HEXT_VALUE
  32. * - sclk = 240000000
  33. * - ahbdiv = 1
  34. * - ahbclk = 240000000
  35. * - apb2div = 2
  36. * - apb2clk = 120000000
  37. * - apb1div = 2
  38. * - apb1clk = 120000000
  39. * - pll_mult = 60
  40. * - pll_range = GT72MHZ (greater than 72 mhz)
  41. * @param none
  42. * @retval none
  43. */
  44. void system_clock_config(void)
  45. {
  46. /* reset crm */
  47. crm_reset();
  48. crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE);
  49. /* wait till hext is ready */
  50. while(crm_hext_stable_wait() == ERROR)
  51. {
  52. }
  53. /* config pll clock resource */
  54. crm_pll_config(CRM_PLL_SOURCE_HEXT_DIV, CRM_PLL_MULT_48, CRM_PLL_OUTPUT_RANGE_GT72MHZ);
  55. /* config hext division */
  56. crm_hext_clock_div_set(CRM_HEXT_DIV_5);
  57. /* enable pll */
  58. crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
  59. /* wait till pll is ready */
  60. while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET)
  61. {
  62. }
  63. /* config ahbclk */
  64. crm_ahb_div_set(CRM_AHB_DIV_1);
  65. /* config apb2clk, the maximum frequency of APB1/APB2 clock is 120 MHz */
  66. crm_apb2_div_set(CRM_APB2_DIV_2);
  67. /* config apb1clk, the maximum frequency of APB1/APB2 clock is 120 MHz */
  68. crm_apb1_div_set(CRM_APB1_DIV_2);
  69. /* enable auto step mode */
  70. crm_auto_step_mode_enable(TRUE);
  71. /* select pll as system clock source */
  72. crm_sysclk_switch(CRM_SCLK_PLL);
  73. /* wait till pll is used as system clock source */
  74. while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL)
  75. {
  76. }
  77. /* disable auto step mode */
  78. crm_auto_step_mode_enable(FALSE);
  79. /* update system_core_clock global variable */
  80. system_core_clock_update();
  81. }