system_gd32f30x.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. /*!
  2. \file system_gd32f30x.c
  3. \brief CMSIS Cortex-M4 Device Peripheral Access Layer Source File for
  4. GD32F30x Device Series
  5. */
  6. /* Copyright (c) 2012 ARM LIMITED
  7. All rights reserved.
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions are met:
  10. - Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. - Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. - Neither the name of ARM nor the names of its contributors may be used
  16. to endorse or promote products derived from this software without
  17. specific prior written permission.
  18. *
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  23. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. POSSIBILITY OF SUCH DAMAGE.
  30. ---------------------------------------------------------------------------*/
  31. /* This file refers the CMSIS standard, some adjustments are made according to GigaDevice chips */
  32. #include "gd32f30x.h"
  33. /* system frequency define */
  34. #define __IRC8M (IRC8M_VALUE) /* internal 8 MHz RC oscillator frequency */
  35. #define __HXTAL (HXTAL_VALUE) /* high speed crystal oscillator frequency */
  36. #define __SYS_OSC_CLK (__IRC8M) /* main oscillator frequency */
  37. /* select a system clock by uncommenting the following line */
  38. /* use IRC8M */
  39. //#define __SYSTEM_CLOCK_IRC8M (uint32_t)(__IRC8M)
  40. //#define __SYSTEM_CLOCK_48M_PLL_IRC8M (uint32_t)(48000000)
  41. //#define __SYSTEM_CLOCK_72M_PLL_IRC8M (uint32_t)(72000000)
  42. //#define __SYSTEM_CLOCK_108M_PLL_IRC8M (uint32_t)(108000000)
  43. //#define __SYSTEM_CLOCK_120M_PLL_IRC8M (uint32_t)(120000000)
  44. /* use HXTAL(XD series CK_HXTAL = 8M, CL series CK_HXTAL = 25M) */
  45. //#define __SYSTEM_CLOCK_HXTAL (uint32_t)(__HXTAL)
  46. //#define __SYSTEM_CLOCK_48M_PLL_HXTAL (uint32_t)(48000000)
  47. //#define __SYSTEM_CLOCK_72M_PLL_HXTAL (uint32_t)(72000000)
  48. //#define __SYSTEM_CLOCK_108M_PLL_HXTAL (uint32_t)(108000000)
  49. #define __SYSTEM_CLOCK_120M_PLL_HXTAL (uint32_t)(120000000)
  50. #define SEL_IRC8M 0x00U
  51. #define SEL_HXTAL 0x01U
  52. #define SEL_PLL 0x02U
  53. /* set the system clock frequency and declare the system clock configuration function */
  54. #ifdef __SYSTEM_CLOCK_IRC8M
  55. uint32_t SystemCoreClock = __SYSTEM_CLOCK_IRC8M;
  56. static void system_clock_8m_irc8m(void);
  57. #elif defined (__SYSTEM_CLOCK_48M_PLL_IRC8M)
  58. uint32_t SystemCoreClock = __SYSTEM_CLOCK_48M_PLL_IRC8M;
  59. static void system_clock_48m_irc8m(void);
  60. #elif defined (__SYSTEM_CLOCK_72M_PLL_IRC8M)
  61. uint32_t SystemCoreClock = __SYSTEM_CLOCK_72M_PLL_IRC8M;
  62. static void system_clock_72m_irc8m(void);
  63. #elif defined (__SYSTEM_CLOCK_108M_PLL_IRC8M)
  64. uint32_t SystemCoreClock = __SYSTEM_CLOCK_108M_PLL_IRC8M;
  65. static void system_clock_108m_irc8m(void);
  66. #elif defined (__SYSTEM_CLOCK_120M_PLL_IRC8M)
  67. uint32_t SystemCoreClock = __SYSTEM_CLOCK_120M_PLL_IRC8M;
  68. static void system_clock_120m_irc8m(void);
  69. #elif defined (__SYSTEM_CLOCK_HXTAL)
  70. uint32_t SystemCoreClock = __SYSTEM_CLOCK_HXTAL;
  71. static void system_clock_hxtal(void);
  72. #elif defined (__SYSTEM_CLOCK_48M_PLL_HXTAL)
  73. uint32_t SystemCoreClock = __SYSTEM_CLOCK_48M_PLL_HXTAL;
  74. static void system_clock_48m_hxtal(void);
  75. #elif defined (__SYSTEM_CLOCK_72M_PLL_HXTAL)
  76. uint32_t SystemCoreClock = __SYSTEM_CLOCK_72M_PLL_HXTAL;
  77. static void system_clock_72m_hxtal(void);
  78. #elif defined (__SYSTEM_CLOCK_108M_PLL_HXTAL)
  79. uint32_t SystemCoreClock = __SYSTEM_CLOCK_108M_PLL_HXTAL;
  80. static void system_clock_108m_hxtal(void);
  81. #elif defined (__SYSTEM_CLOCK_120M_PLL_HXTAL)
  82. uint32_t SystemCoreClock = __SYSTEM_CLOCK_120M_PLL_HXTAL;
  83. static void system_clock_120m_hxtal(void);
  84. #endif /* __SYSTEM_CLOCK_IRC8M */
  85. /* configure the system clock */
  86. static void system_clock_config(void);
  87. /*!
  88. \brief setup the microcontroller system, initialize the system
  89. \param[in] none
  90. \param[out] none
  91. \retval none
  92. */
  93. void SystemInit (void)
  94. {
  95. /* FPU settings */
  96. #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
  97. SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
  98. #endif
  99. /* reset the RCU clock configuration to the default reset state */
  100. /* Set IRC8MEN bit */
  101. RCU_CTL |= RCU_CTL_IRC8MEN;
  102. /* Reset CFG0 and CFG1 registers */
  103. RCU_CFG0 = 0x00000000U;
  104. RCU_CFG1 = 0x00000000U;
  105. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  106. /* reset HXTALEN, CKMEN and PLLEN bits */
  107. RCU_CTL &= ~(RCU_CTL_PLLEN | RCU_CTL_CKMEN | RCU_CTL_HXTALEN);
  108. /* disable all interrupts */
  109. RCU_INT = 0x009f0000U;
  110. #elif defined(GD32F30X_CL)
  111. /* Reset HXTALEN, CKMEN, PLLEN, PLL1EN and PLL2EN bits */
  112. RCU_CTL &= ~(RCU_CTL_PLLEN |RCU_CTL_PLL1EN | RCU_CTL_PLL2EN | RCU_CTL_CKMEN | RCU_CTL_HXTALEN);
  113. /* disable all interrupts */
  114. RCU_INT = 0x00ff0000U;
  115. #endif
  116. /* reset HXTALBPS bit */
  117. RCU_CTL &= ~(RCU_CTL_HXTALBPS);
  118. /* configure the system clock source, PLL Multiplier, AHB/APBx prescalers and Flash settings */
  119. system_clock_config();
  120. }
  121. /*!
  122. \brief configure the system clock
  123. \param[in] none
  124. \param[out] none
  125. \retval none
  126. */
  127. static void system_clock_config(void)
  128. {
  129. #ifdef __SYSTEM_CLOCK_IRC8M
  130. system_clock_8m_irc8m();
  131. #elif defined (__SYSTEM_CLOCK_48M_PLL_IRC8M)
  132. system_clock_48m_irc8m();
  133. #elif defined (__SYSTEM_CLOCK_72M_PLL_IRC8M)
  134. system_clock_72m_irc8m();
  135. #elif defined (__SYSTEM_CLOCK_108M_PLL_IRC8M)
  136. system_clock_108m_irc8m();
  137. #elif defined (__SYSTEM_CLOCK_120M_PLL_IRC8M)
  138. system_clock_120m_irc8m();
  139. #elif defined (__SYSTEM_CLOCK_HXTAL)
  140. system_clock_hxtal();
  141. #elif defined (__SYSTEM_CLOCK_48M_PLL_HXTAL)
  142. system_clock_48m_hxtal();
  143. #elif defined (__SYSTEM_CLOCK_72M_PLL_HXTAL)
  144. system_clock_72m_hxtal();
  145. #elif defined (__SYSTEM_CLOCK_108M_PLL_HXTAL)
  146. system_clock_108m_hxtal();
  147. #elif defined (__SYSTEM_CLOCK_120M_PLL_HXTAL)
  148. system_clock_120m_hxtal();
  149. #endif /* __SYSTEM_CLOCK_IRC8M */
  150. }
  151. #ifdef __SYSTEM_CLOCK_IRC8M
  152. /*!
  153. \brief configure the system clock to 8M by IRC8M
  154. \param[in] none
  155. \param[out] none
  156. \retval none
  157. */
  158. static void system_clock_8m_irc8m(void)
  159. {
  160. uint32_t timeout = 0U;
  161. uint32_t stab_flag = 0U;
  162. /* enable IRC8M */
  163. RCU_CTL |= RCU_CTL_IRC8MEN;
  164. /* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
  165. do{
  166. timeout++;
  167. stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
  168. }
  169. while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
  170. /* if fail */
  171. if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
  172. while(1){
  173. }
  174. }
  175. /* AHB = SYSCLK */
  176. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  177. /* APB2 = AHB/1 */
  178. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  179. /* APB1 = AHB/2 */
  180. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  181. /* select IRC8M as system clock */
  182. RCU_CFG0 &= ~RCU_CFG0_SCS;
  183. RCU_CFG0 |= RCU_CKSYSSRC_IRC8M;
  184. /* wait until IRC8M is selected as system clock */
  185. while(0U != (RCU_CFG0 & RCU_SCSS_IRC8M)){
  186. }
  187. }
  188. #elif defined (__SYSTEM_CLOCK_48M_PLL_IRC8M)
  189. /*!
  190. \brief configure the system clock to 48M by PLL which selects IRC8M as its clock source
  191. \param[in] none
  192. \param[out] none
  193. \retval none
  194. */
  195. static void system_clock_48m_irc8m(void)
  196. {
  197. uint32_t timeout = 0U;
  198. uint32_t stab_flag = 0U;
  199. /* enable IRC8M */
  200. RCU_CTL |= RCU_CTL_IRC8MEN;
  201. /* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
  202. do{
  203. timeout++;
  204. stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
  205. }
  206. while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
  207. /* if fail */
  208. if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
  209. while(1){
  210. }
  211. }
  212. /* LDO output voltage high mode */
  213. RCU_APB1EN |= RCU_APB1EN_PMUEN;
  214. PMU_CTL |= PMU_CTL_LDOVS;
  215. /* IRC8M is stable */
  216. /* AHB = SYSCLK */
  217. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  218. /* APB2 = AHB/1 */
  219. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  220. /* APB1 = AHB/2 */
  221. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  222. /* CK_PLL = (CK_IRC8M/2) * 12 = 48 MHz */
  223. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  224. RCU_CFG0 |= RCU_PLL_MUL12;
  225. /* enable PLL */
  226. RCU_CTL |= RCU_CTL_PLLEN;
  227. /* wait until PLL is stable */
  228. while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
  229. }
  230. /* enable the high-drive to extend the clock frequency to 120 MHz */
  231. PMU_CTL |= PMU_CTL_HDEN;
  232. while(0U == (PMU_CS & PMU_CS_HDRF)){
  233. }
  234. /* select the high-drive mode */
  235. PMU_CTL |= PMU_CTL_HDS;
  236. while(0U == (PMU_CS & PMU_CS_HDSRF)){
  237. }
  238. /* select PLL as system clock */
  239. RCU_CFG0 &= ~RCU_CFG0_SCS;
  240. RCU_CFG0 |= RCU_CKSYSSRC_PLL;
  241. /* wait until PLL is selected as system clock */
  242. while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
  243. }
  244. }
  245. #elif defined (__SYSTEM_CLOCK_72M_PLL_IRC8M)
  246. /*!
  247. \brief configure the system clock to 72M by PLL which selects IRC8M as its clock source
  248. \param[in] none
  249. \param[out] none
  250. \retval none
  251. */
  252. static void system_clock_72m_irc8m(void)
  253. {
  254. uint32_t timeout = 0U;
  255. uint32_t stab_flag = 0U;
  256. /* enable IRC8M */
  257. RCU_CTL |= RCU_CTL_IRC8MEN;
  258. /* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
  259. do{
  260. timeout++;
  261. stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
  262. }while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
  263. /* if fail */
  264. if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
  265. while(1){
  266. }
  267. }
  268. /* LDO output voltage high mode */
  269. RCU_APB1EN |= RCU_APB1EN_PMUEN;
  270. PMU_CTL |= PMU_CTL_LDOVS;
  271. /* IRC8M is stable */
  272. /* AHB = SYSCLK */
  273. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  274. /* APB2 = AHB/1 */
  275. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  276. /* APB1 = AHB/2 */
  277. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  278. /* CK_PLL = (CK_IRC8M/2) * 18 = 72 MHz */
  279. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  280. RCU_CFG0 |= RCU_PLL_MUL18;
  281. /* enable PLL */
  282. RCU_CTL |= RCU_CTL_PLLEN;
  283. /* wait until PLL is stable */
  284. while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
  285. }
  286. /* enable the high-drive to extend the clock frequency to 120 MHz */
  287. PMU_CTL |= PMU_CTL_HDEN;
  288. while(0U == (PMU_CS & PMU_CS_HDRF)){
  289. }
  290. /* select the high-drive mode */
  291. PMU_CTL |= PMU_CTL_HDS;
  292. while(0U == (PMU_CS & PMU_CS_HDSRF)){
  293. }
  294. /* select PLL as system clock */
  295. RCU_CFG0 &= ~RCU_CFG0_SCS;
  296. RCU_CFG0 |= RCU_CKSYSSRC_PLL;
  297. /* wait until PLL is selected as system clock */
  298. while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
  299. }
  300. }
  301. #elif defined (__SYSTEM_CLOCK_108M_PLL_IRC8M)
  302. /*!
  303. \brief configure the system clock to 108M by PLL which selects IRC8M as its clock source
  304. \param[in] none
  305. \param[out] none
  306. \retval none
  307. */
  308. static void system_clock_108m_irc8m(void)
  309. {
  310. uint32_t timeout = 0U;
  311. uint32_t stab_flag = 0U;
  312. /* enable IRC8M */
  313. RCU_CTL |= RCU_CTL_IRC8MEN;
  314. /* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
  315. do{
  316. timeout++;
  317. stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
  318. }while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
  319. /* if fail */
  320. if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
  321. while(1){
  322. }
  323. }
  324. /* LDO output voltage high mode */
  325. RCU_APB1EN |= RCU_APB1EN_PMUEN;
  326. PMU_CTL |= PMU_CTL_LDOVS;
  327. /* IRC8M is stable */
  328. /* AHB = SYSCLK */
  329. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  330. /* APB2 = AHB/1 */
  331. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  332. /* APB1 = AHB/2 */
  333. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  334. /* CK_PLL = (CK_IRC8M/2) * 27 = 108 MHz */
  335. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  336. RCU_CFG0 |= RCU_PLL_MUL27;
  337. /* enable PLL */
  338. RCU_CTL |= RCU_CTL_PLLEN;
  339. /* wait until PLL is stable */
  340. while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
  341. }
  342. /* enable the high-drive to extend the clock frequency to 120 MHz */
  343. PMU_CTL |= PMU_CTL_HDEN;
  344. while(0U == (PMU_CS & PMU_CS_HDRF)){
  345. }
  346. /* select the high-drive mode */
  347. PMU_CTL |= PMU_CTL_HDS;
  348. while(0U == (PMU_CS & PMU_CS_HDSRF)){
  349. }
  350. /* select PLL as system clock */
  351. RCU_CFG0 &= ~RCU_CFG0_SCS;
  352. RCU_CFG0 |= RCU_CKSYSSRC_PLL;
  353. /* wait until PLL is selected as system clock */
  354. while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
  355. }
  356. }
  357. #elif defined (__SYSTEM_CLOCK_120M_PLL_IRC8M)
  358. /*!
  359. \brief configure the system clock to 120M by PLL which selects IRC8M as its clock source
  360. \param[in] none
  361. \param[out] none
  362. \retval none
  363. */
  364. static void system_clock_120m_irc8m(void)
  365. {
  366. uint32_t timeout = 0U;
  367. uint32_t stab_flag = 0U;
  368. /* enable IRC8M */
  369. RCU_CTL |= RCU_CTL_IRC8MEN;
  370. /* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
  371. do{
  372. timeout++;
  373. stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
  374. }while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
  375. /* if fail */
  376. if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
  377. while(1){
  378. }
  379. }
  380. /* LDO output voltage high mode */
  381. RCU_APB1EN |= RCU_APB1EN_PMUEN;
  382. PMU_CTL |= PMU_CTL_LDOVS;
  383. /* IRC8M is stable */
  384. /* AHB = SYSCLK */
  385. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  386. /* APB2 = AHB/1 */
  387. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  388. /* APB1 = AHB/2 */
  389. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  390. /* CK_PLL = (CK_IRC8M/2) * 30 = 120 MHz */
  391. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  392. RCU_CFG0 |= RCU_PLL_MUL30;
  393. /* enable PLL */
  394. RCU_CTL |= RCU_CTL_PLLEN;
  395. /* wait until PLL is stable */
  396. while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
  397. }
  398. /* enable the high-drive to extend the clock frequency to 120 MHz */
  399. PMU_CTL |= PMU_CTL_HDEN;
  400. while(0U == (PMU_CS & PMU_CS_HDRF)){
  401. }
  402. /* select the high-drive mode */
  403. PMU_CTL |= PMU_CTL_HDS;
  404. while(0U == (PMU_CS & PMU_CS_HDSRF)){
  405. }
  406. /* select PLL as system clock */
  407. RCU_CFG0 &= ~RCU_CFG0_SCS;
  408. RCU_CFG0 |= RCU_CKSYSSRC_PLL;
  409. /* wait until PLL is selected as system clock */
  410. while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
  411. }
  412. }
  413. #elif defined (__SYSTEM_CLOCK_HXTAL)
  414. /*!
  415. \brief configure the system clock to HXTAL
  416. \param[in] none
  417. \param[out] none
  418. \retval none
  419. */
  420. static void system_clock_hxtal(void)
  421. {
  422. uint32_t timeout = 0U;
  423. uint32_t stab_flag = 0U;
  424. /* enable HXTAL */
  425. RCU_CTL |= RCU_CTL_HXTALEN;
  426. /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
  427. do{
  428. timeout++;
  429. stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
  430. }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
  431. /* if fail */
  432. if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
  433. while(1){
  434. }
  435. }
  436. /* AHB = SYSCLK */
  437. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  438. /* APB2 = AHB/1 */
  439. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  440. /* APB1 = AHB/2 */
  441. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  442. /* select HXTAL as system clock */
  443. RCU_CFG0 &= ~RCU_CFG0_SCS;
  444. RCU_CFG0 |= RCU_CKSYSSRC_HXTAL;
  445. /* wait until HXTAL is selected as system clock */
  446. while(0 == (RCU_CFG0 & RCU_SCSS_HXTAL)){
  447. }
  448. }
  449. #elif defined (__SYSTEM_CLOCK_48M_PLL_HXTAL)
  450. /*!
  451. \brief configure the system clock to 48M by PLL which selects HXTAL(8M) as its clock source
  452. \param[in] none
  453. \param[out] none
  454. \retval none
  455. */
  456. static void system_clock_48m_hxtal(void)
  457. {
  458. uint32_t timeout = 0U;
  459. uint32_t stab_flag = 0U;
  460. /* enable HXTAL */
  461. RCU_CTL |= RCU_CTL_HXTALEN;
  462. /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
  463. do{
  464. timeout++;
  465. stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
  466. }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
  467. /* if fail */
  468. if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
  469. while(1){
  470. }
  471. }
  472. RCU_APB1EN |= RCU_APB1EN_PMUEN;
  473. PMU_CTL |= PMU_CTL_LDOVS;
  474. /* HXTAL is stable */
  475. /* AHB = SYSCLK */
  476. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  477. /* APB2 = AHB/1 */
  478. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  479. /* APB1 = AHB/2 */
  480. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  481. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  482. /* select HXTAL/2 as clock source */
  483. RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0);
  484. RCU_CFG0 |= (RCU_PLLSRC_HXTAL_IRC48M | RCU_CFG0_PREDV0);
  485. /* CK_PLL = (CK_HXTAL/2) * 12 = 48 MHz */
  486. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  487. RCU_CFG0 |= RCU_PLL_MUL12;
  488. #elif defined(GD32F30X_CL)
  489. /* CK_PLL = (CK_PREDIV0) * 12 = 48 MHz */
  490. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  491. RCU_CFG0 |= (RCU_PLLSRC_HXTAL_IRC48M | RCU_PLL_MUL12);
  492. /* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
  493. RCU_CFG1 &= ~(RCU_CFG1_PLLPRESEL | RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
  494. RCU_CFG1 |= (RCU_PLLPRESRC_HXTAL | RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV10);
  495. /* enable PLL1 */
  496. RCU_CTL |= RCU_CTL_PLL1EN;
  497. /* wait till PLL1 is ready */
  498. while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
  499. }
  500. #endif /* GD32F30X_HD and GD32F30X_XD */
  501. /* enable PLL */
  502. RCU_CTL |= RCU_CTL_PLLEN;
  503. /* wait until PLL is stable */
  504. while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
  505. }
  506. /* enable the high-drive to extend the clock frequency to 120 MHz */
  507. PMU_CTL |= PMU_CTL_HDEN;
  508. while(0U == (PMU_CS & PMU_CS_HDRF)){
  509. }
  510. /* select the high-drive mode */
  511. PMU_CTL |= PMU_CTL_HDS;
  512. while(0U == (PMU_CS & PMU_CS_HDSRF)){
  513. }
  514. /* select PLL as system clock */
  515. RCU_CFG0 &= ~RCU_CFG0_SCS;
  516. RCU_CFG0 |= RCU_CKSYSSRC_PLL;
  517. /* wait until PLL is selected as system clock */
  518. while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
  519. }
  520. }
  521. #elif defined (__SYSTEM_CLOCK_72M_PLL_HXTAL)
  522. /*!
  523. \brief configure the system clock to 72M by PLL which selects HXTAL(8M) as its clock source
  524. \param[in] none
  525. \param[out] none
  526. \retval none
  527. */
  528. static void system_clock_72m_hxtal(void)
  529. {
  530. uint32_t timeout = 0U;
  531. uint32_t stab_flag = 0U;
  532. /* enable HXTAL */
  533. RCU_CTL |= RCU_CTL_HXTALEN;
  534. /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
  535. do{
  536. timeout++;
  537. stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
  538. }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
  539. /* if fail */
  540. if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
  541. while(1){
  542. }
  543. }
  544. RCU_APB1EN |= RCU_APB1EN_PMUEN;
  545. PMU_CTL |= PMU_CTL_LDOVS;
  546. /* HXTAL is stable */
  547. /* AHB = SYSCLK */
  548. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  549. /* APB2 = AHB/1 */
  550. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  551. /* APB1 = AHB/2 */
  552. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  553. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  554. /* select HXTAL/2 as clock source */
  555. RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0);
  556. RCU_CFG0 |= (RCU_PLLSRC_HXTAL_IRC48M | RCU_CFG0_PREDV0);
  557. /* CK_PLL = (CK_HXTAL/2) * 18 = 72 MHz */
  558. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  559. RCU_CFG0 |= RCU_PLL_MUL18;
  560. #elif defined(GD32F30X_CL)
  561. /* CK_PLL = (CK_PREDIV0) * 18 = 72 MHz */
  562. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  563. RCU_CFG0 |= (RCU_PLLSRC_HXTAL_IRC48M | RCU_PLL_MUL18);
  564. /* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
  565. RCU_CFG1 &= ~(RCU_CFG1_PLLPRESEL | RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
  566. RCU_CFG1 |= (RCU_PLLPRESRC_HXTAL | RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV10);
  567. /* enable PLL1 */
  568. RCU_CTL |= RCU_CTL_PLL1EN;
  569. /* wait till PLL1 is ready */
  570. while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
  571. }
  572. #endif /* GD32F30X_HD and GD32F30X_XD */
  573. /* enable PLL */
  574. RCU_CTL |= RCU_CTL_PLLEN;
  575. /* wait until PLL is stable */
  576. while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
  577. }
  578. /* enable the high-drive to extend the clock frequency to 120 MHz */
  579. PMU_CTL |= PMU_CTL_HDEN;
  580. while(0U == (PMU_CS & PMU_CS_HDRF)){
  581. }
  582. /* select the high-drive mode */
  583. PMU_CTL |= PMU_CTL_HDS;
  584. while(0U == (PMU_CS & PMU_CS_HDSRF)){
  585. }
  586. /* select PLL as system clock */
  587. RCU_CFG0 &= ~RCU_CFG0_SCS;
  588. RCU_CFG0 |= RCU_CKSYSSRC_PLL;
  589. /* wait until PLL is selected as system clock */
  590. while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
  591. }
  592. }
  593. #elif defined (__SYSTEM_CLOCK_108M_PLL_HXTAL)
  594. /*!
  595. \brief configure the system clock to 108M by PLL which selects HXTAL(8M) as its clock source
  596. \param[in] none
  597. \param[out] none
  598. \retval none
  599. */
  600. static void system_clock_108m_hxtal(void)
  601. {
  602. uint32_t timeout = 0U;
  603. uint32_t stab_flag = 0U;
  604. /* enable HXTAL */
  605. RCU_CTL |= RCU_CTL_HXTALEN;
  606. /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
  607. do{
  608. timeout++;
  609. stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
  610. }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
  611. /* if fail */
  612. if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
  613. while(1){
  614. }
  615. }
  616. RCU_APB1EN |= RCU_APB1EN_PMUEN;
  617. PMU_CTL |= PMU_CTL_LDOVS;
  618. /* HXTAL is stable */
  619. /* AHB = SYSCLK */
  620. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  621. /* APB2 = AHB/1 */
  622. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  623. /* APB1 = AHB/2 */
  624. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  625. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  626. /* select HXTAL/2 as clock source */
  627. RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0);
  628. RCU_CFG0 |= (RCU_PLLSRC_HXTAL_IRC48M | RCU_CFG0_PREDV0);
  629. /* CK_PLL = (CK_HXTAL/2) * 27 = 108 MHz */
  630. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  631. RCU_CFG0 |= RCU_PLL_MUL27;
  632. #elif defined(GD32F30X_CL)
  633. /* CK_PLL = (CK_PREDIV0) * 27 = 108 MHz */
  634. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  635. RCU_CFG0 |= (RCU_PLLSRC_HXTAL_IRC48M | RCU_PLL_MUL27);
  636. /* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
  637. RCU_CFG1 &= ~(RCU_CFG1_PLLPRESEL | RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
  638. RCU_CFG1 |= (RCU_PLLPRESRC_HXTAL | RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV10);
  639. /* enable PLL1 */
  640. RCU_CTL |= RCU_CTL_PLL1EN;
  641. /* wait till PLL1 is ready */
  642. while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
  643. }
  644. #endif /* GD32F30X_HD and GD32F30X_XD */
  645. /* enable PLL */
  646. RCU_CTL |= RCU_CTL_PLLEN;
  647. /* wait until PLL is stable */
  648. while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
  649. }
  650. /* enable the high-drive to extend the clock frequency to 120 MHz */
  651. PMU_CTL |= PMU_CTL_HDEN;
  652. while(0U == (PMU_CS & PMU_CS_HDRF)){
  653. }
  654. /* select the high-drive mode */
  655. PMU_CTL |= PMU_CTL_HDS;
  656. while(0U == (PMU_CS & PMU_CS_HDSRF)){
  657. }
  658. /* select PLL as system clock */
  659. RCU_CFG0 &= ~RCU_CFG0_SCS;
  660. RCU_CFG0 |= RCU_CKSYSSRC_PLL;
  661. /* wait until PLL is selected as system clock */
  662. while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
  663. }
  664. }
  665. #elif defined (__SYSTEM_CLOCK_120M_PLL_HXTAL)
  666. /*!
  667. \brief configure the system clock to 120M by PLL which selects HXTAL(8M) as its clock source
  668. \param[in] none
  669. \param[out] none
  670. \retval none
  671. */
  672. static void system_clock_120m_hxtal(void)
  673. {
  674. uint32_t timeout = 0U;
  675. uint32_t stab_flag = 0U;
  676. /* enable HXTAL */
  677. RCU_CTL |= RCU_CTL_HXTALEN;
  678. /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
  679. do{
  680. timeout++;
  681. stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
  682. }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
  683. /* if fail */
  684. if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
  685. while(1){
  686. }
  687. }
  688. RCU_APB1EN |= RCU_APB1EN_PMUEN;
  689. PMU_CTL |= PMU_CTL_LDOVS;
  690. /* HXTAL is stable */
  691. /* AHB = SYSCLK */
  692. RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
  693. /* APB2 = AHB/1 */
  694. RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
  695. /* APB1 = AHB/2 */
  696. RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
  697. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  698. /* select HXTAL/2 as clock source */
  699. RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0);
  700. RCU_CFG0 |= (RCU_PLLSRC_HXTAL_IRC48M | RCU_CFG0_PREDV0);
  701. /* CK_PLL = (CK_HXTAL/2) * 30 = 120 MHz */
  702. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  703. RCU_CFG0 |= RCU_PLL_MUL30;
  704. #elif defined(GD32F30X_CL)
  705. /* CK_PLL = (CK_PREDIV0) * 30 = 120 MHz */
  706. RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PLLMF_5);
  707. RCU_CFG0 |= (RCU_PLLSRC_HXTAL_IRC48M | RCU_PLL_MUL30);
  708. /* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
  709. RCU_CFG1 &= ~(RCU_CFG1_PLLPRESEL | RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
  710. RCU_CFG1 |= (RCU_PLLPRESRC_HXTAL | RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV10);
  711. /* enable PLL1 */
  712. RCU_CTL |= RCU_CTL_PLL1EN;
  713. /* wait till PLL1 is ready */
  714. while((RCU_CTL & RCU_CTL_PLL1STB) == 0U){
  715. }
  716. #endif /* GD32F30X_HD and GD32F30X_XD */
  717. /* enable PLL */
  718. RCU_CTL |= RCU_CTL_PLLEN;
  719. /* wait until PLL is stable */
  720. while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
  721. }
  722. /* enable the high-drive to extend the clock frequency to 120 MHz */
  723. PMU_CTL |= PMU_CTL_HDEN;
  724. while(0U == (PMU_CS & PMU_CS_HDRF)){
  725. }
  726. /* select the high-drive mode */
  727. PMU_CTL |= PMU_CTL_HDS;
  728. while(0U == (PMU_CS & PMU_CS_HDSRF)){
  729. }
  730. /* select PLL as system clock */
  731. RCU_CFG0 &= ~RCU_CFG0_SCS;
  732. RCU_CFG0 |= RCU_CKSYSSRC_PLL;
  733. /* wait until PLL is selected as system clock */
  734. while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
  735. }
  736. }
  737. #endif /* __SYSTEM_CLOCK_IRC8M */
  738. /*!
  739. \brief update the SystemCoreClock with current core clock retrieved from cpu registers
  740. \param[in] none
  741. \param[out] none
  742. \retval none
  743. */
  744. void SystemCoreClockUpdate (void)
  745. {
  746. uint32_t sws;
  747. uint32_t pllsel, pllpresel, predv0sel, pllmf,ck_src;
  748. #ifdef GD32F30X_CL
  749. uint32_t predv0, predv1, pll1mf;
  750. #endif /* GD32F30X_CL */
  751. sws = GET_BITS(RCU_CFG0, 2, 3);
  752. switch(sws){
  753. /* IRC8M is selected as CK_SYS */
  754. case SEL_IRC8M:
  755. SystemCoreClock = IRC8M_VALUE;
  756. break;
  757. /* HXTAL is selected as CK_SYS */
  758. case SEL_HXTAL:
  759. SystemCoreClock = HXTAL_VALUE;
  760. break;
  761. /* PLL is selected as CK_SYS */
  762. case SEL_PLL:
  763. /* PLL clock source selection, HXTAL, IRC48M or IRC8M/2 */
  764. pllsel = (RCU_CFG0 & RCU_CFG0_PLLSEL);
  765. if (RCU_PLLSRC_HXTAL_IRC48M == pllsel) {
  766. /* PLL clock source is HXTAL or IRC48M */
  767. pllpresel = (RCU_CFG1 & RCU_CFG1_PLLPRESEL);
  768. if(RCU_PLLPRESRC_HXTAL == pllpresel){
  769. /* PLL clock source is HXTAL */
  770. ck_src = HXTAL_VALUE;
  771. }else{
  772. /* PLL clock source is IRC48 */
  773. ck_src = IRC48M_VALUE;
  774. }
  775. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  776. predv0sel = (RCU_CFG0 & RCU_CFG0_PREDV0);
  777. /* PREDV0 input source clock divided by 2 */
  778. if(RCU_CFG0_PREDV0 == predv0sel){
  779. ck_src = HXTAL_VALUE/2U;
  780. }
  781. #elif defined(GD32F30X_CL)
  782. predv0sel = (RCU_CFG1 & RCU_CFG1_PREDV0SEL);
  783. /* source clock use PLL1 */
  784. if(RCU_PREDV0SRC_CKPLL1 == predv0sel){
  785. predv1 = ((RCU_CFG1 & RCU_CFG1_PREDV1) >> 4) + 1U;
  786. pll1mf = ((RCU_CFG1 & RCU_CFG1_PLL1MF) >> 8) + 2U;
  787. if(17U == pll1mf){
  788. pll1mf = 20U;
  789. }
  790. ck_src = (ck_src/predv1)*pll1mf;
  791. }
  792. predv0 = (RCU_CFG1 & RCU_CFG1_PREDV0) + 1U;
  793. ck_src /= predv0;
  794. #endif /* GD32F30X_HD and GD32F30X_XD */
  795. }else{
  796. /* PLL clock source is IRC8M/2 */
  797. ck_src = IRC8M_VALUE/2U;
  798. }
  799. /* PLL multiplication factor */
  800. pllmf = GET_BITS(RCU_CFG0, 18, 21);
  801. if((RCU_CFG0 & RCU_CFG0_PLLMF_4)){
  802. pllmf |= 0x10U;
  803. }
  804. if((RCU_CFG0 & RCU_CFG0_PLLMF_5)){
  805. pllmf |= 0x20U;
  806. }
  807. if( pllmf >= 15U){
  808. pllmf += 1U;
  809. }else{
  810. pllmf += 2U;
  811. }
  812. if(pllmf > 61U){
  813. pllmf = 63U;
  814. }
  815. SystemCoreClock = ck_src*pllmf;
  816. #ifdef GD32F30X_CL
  817. if(15U == pllmf){
  818. SystemCoreClock = ck_src*6U + ck_src/2U;
  819. }
  820. #endif /* GD32F30X_CL */
  821. break;
  822. /* IRC8M is selected as CK_SYS */
  823. default:
  824. SystemCoreClock = IRC8M_VALUE;
  825. break;
  826. }
  827. }