system_ciu32f003(2).c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /************************************************************************************************/
  2. /**
  3. * @file system_ciu32f003.c
  4. * @author MCU Ecosystem Development Team
  5. * @brief CMSIS Device System Source File for CIU32F003.
  6. *
  7. *
  8. **************************************************************************************************
  9. * @attention
  10. * Copyright (c) CEC Huada Electronic Design Co.,Ltd. All rights reserved.
  11. *
  12. **************************************************************************************************
  13. */
  14. /************************************************************************************************/
  15. /**
  16. * @addtogroup CMSIS
  17. * @{
  18. *
  19. * @addtogroup Device_System Device System
  20. * @{
  21. *
  22. */
  23. /************************************************************************************************/
  24. /*------------------------------------------includes--------------------------------------------*/
  25. #include "ciu32f003.h"
  26. /*--------------------------------------------define--------------------------------------------*/
  27. /************************************************************************************************/
  28. /**
  29. * @defgroup Device_System_Constants Device System Constants
  30. * @{
  31. */
  32. /************************************************************************************************/
  33. #if !defined (EXTCLK_VALUE)
  34. #define EXTCLK_VALUE (8000000UL) /**< EXT clock frequency(Hz) */
  35. #endif
  36. #if !defined (RCH_VALUE)
  37. #define RCH_VALUE (48000000UL) /**< RCH clock frequency(Hz) */
  38. #endif
  39. #if !defined (RCL_VALUE)
  40. #define RCL_VALUE (32000UL) /**< RCL clock frequency(Hz) */
  41. #endif
  42. /**
  43. * @}
  44. */
  45. /*--------------------------------------------variables-----------------------------------------*/
  46. /* The SystemCoreClock variable is the system core clock(HCLK) frequency.*/
  47. uint32_t SystemCoreClock = RCH_VALUE/6;
  48. const uint32_t g_ahb_divider_table[8] = {1UL, 2UL, 4UL, 8UL, 16UL, 32UL, 64UL, 128UL};
  49. const uint32_t g_apb_divider_table[8] = {1UL, 1UL, 1UL, 1UL, 2UL, 4UL, 8UL, 16UL};
  50. #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
  51. extern uint32_t __vector_table;
  52. #endif
  53. /*-------------------------------------------functions------------------------------------------*/
  54. /************************************************************************************************/
  55. /**
  56. * @addtogroup Device_System_External_Functions
  57. * @{
  58. *
  59. */
  60. /************************************************************************************************/
  61. /**
  62. * @brief MCU system initialization function
  63. * @retval None
  64. */
  65. void SystemInit(void)
  66. {
  67. /* Configure the vector table location add offset address */
  68. #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
  69. SCB->VTOR = (uint32_t) &__vector_table;
  70. #endif
  71. SystemCoreClock = RCH_VALUE/6;
  72. }
  73. /**
  74. * @brief System core clock(HCLK) update function
  75. *
  76. * @note This function is used to update the variable SystemCoreClock
  77. * and must be called whenever HCLK is changed
  78. * @retval None
  79. */
  80. void SystemCoreClockUpdate(void)
  81. {
  82. uint32_t tmp,tmp_clock;
  83. /* Get SYSCLK source */
  84. switch (RCC->CFG & RCC_CFG_SYSWS_MASK)
  85. {
  86. case RCC_CFG_SYSWS_RCHDIV3: /* RCHDIV3 used as system clock */
  87. {
  88. tmp_clock = RCH_VALUE/3;
  89. }break;
  90. case RCC_CFG_SYSWS_RCH: /* RCH used as system clock */
  91. {
  92. tmp_clock = RCH_VALUE;
  93. }break;
  94. case RCC_CFG_SYSWS_RCL: /* RCL used as system clock */
  95. {
  96. tmp_clock = RCL_VALUE;
  97. }break;
  98. case RCC_CFG_SYSWS_EXTCLK: /* EXTCLK used as system clock */
  99. {
  100. tmp_clock = EXTCLK_VALUE;
  101. }break;
  102. case RCC_CFG_SYSWS_RCHDIV6: /* RCHDIV6 used as system clock */
  103. default: /* RCH used as system clock */
  104. {
  105. tmp_clock = RCH_VALUE/6;
  106. }break;
  107. }
  108. /* Compute HCLK clock frequency */
  109. tmp = g_ahb_divider_table[((RCC->CFG & RCC_CFG_HPRE_MASK) >> RCC_CFG_HPRE_POS)];
  110. SystemCoreClock = tmp_clock/tmp;
  111. }
  112. /**
  113. * @}
  114. */
  115. /**
  116. * @}
  117. */
  118. /**
  119. * @}
  120. */