gd32f30x_rcu.h 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. /*!
  2. \file gd32f30x_rcu.h
  3. \brief definitions for the RCU
  4. \version 2017-02-10, V1.0.0, firmware for GD32F30x
  5. \version 2018-10-10, V1.1.0, firmware for GD32F30x
  6. \version 2018-12-25, V2.0.0, firmware for GD32F30x
  7. \version 2020-09-30, V2.1.0, firmware for GD32F30x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #ifndef GD32F30X_RCU_H
  33. #define GD32F30X_RCU_H
  34. #include "gd32f30x.h"
  35. /* RCU definitions */
  36. #define RCU RCU_BASE
  37. /* registers definitions */
  38. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  39. #define RCU_CTL REG32(RCU + 0x00U) /*!< control register */
  40. #define RCU_CFG0 REG32(RCU + 0x04U) /*!< clock configuration register 0 */
  41. #define RCU_INT REG32(RCU + 0x08U) /*!< clock interrupt register */
  42. #define RCU_APB2RST REG32(RCU + 0x0CU) /*!< APB2 reset register */
  43. #define RCU_APB1RST REG32(RCU + 0x10U) /*!< APB1 reset register */
  44. #define RCU_AHBEN REG32(RCU + 0x14U) /*!< AHB enable register */
  45. #define RCU_APB2EN REG32(RCU + 0x18U) /*!< APB2 enable register */
  46. #define RCU_APB1EN REG32(RCU + 0x1CU) /*!< APB1 enable register */
  47. #define RCU_BDCTL REG32(RCU + 0x20U) /*!< backup domain control register */
  48. #define RCU_RSTSCK REG32(RCU + 0x24U) /*!< reset source / clock register */
  49. #define RCU_CFG1 REG32(RCU + 0x2CU) /*!< clock configuration register 1 */
  50. #define RCU_DSV REG32(RCU + 0x34U) /*!< deep-sleep mode voltage register */
  51. #define RCU_ADDCTL REG32(RCU + 0xC0U) /*!< Additional clock control register */
  52. #define RCU_ADDINT REG32(RCU + 0xCCU) /*!< Additional clock interrupt register */
  53. #define RCU_ADDAPB1RST REG32(RCU + 0xE0U) /*!< APB1 additional reset register */
  54. #define RCU_ADDAPB1EN REG32(RCU + 0xE4U) /*!< APB1 additional enable register */
  55. #elif defined(GD32F30X_CL)
  56. #define RCU_CTL REG32(RCU + 0x00U) /*!< control register */
  57. #define RCU_CFG0 REG32(RCU + 0x04U) /*!< clock configuration register 0 */
  58. #define RCU_INT REG32(RCU + 0x08U) /*!< clock interrupt register */
  59. #define RCU_APB2RST REG32(RCU + 0x0CU) /*!< APB2 reset register */
  60. #define RCU_APB1RST REG32(RCU + 0x10U) /*!< APB1 reset register */
  61. #define RCU_AHBEN REG32(RCU + 0x14U) /*!< AHB1 enable register */
  62. #define RCU_APB2EN REG32(RCU + 0x18U) /*!< APB2 enable register */
  63. #define RCU_APB1EN REG32(RCU + 0x1CU) /*!< APB1 enable register */
  64. #define RCU_BDCTL REG32(RCU + 0x20U) /*!< backup domain control register */
  65. #define RCU_RSTSCK REG32(RCU + 0x24U) /*!< reset source / clock register */
  66. #define RCU_AHBRST REG32(RCU + 0x28U) /*!< AHB reset register */
  67. #define RCU_CFG1 REG32(RCU + 0x2CU) /*!< clock configuration register 1 */
  68. #define RCU_DSV REG32(RCU + 0x34U) /*!< deep-sleep mode voltage register */
  69. #define RCU_ADDCTL REG32(RCU + 0xC0U) /*!< Additional clock control register */
  70. #define RCU_ADDINT REG32(RCU + 0xCCU) /*!< Additional clock interrupt register */
  71. #define RCU_ADDAPB1RST REG32(RCU + 0xE0U) /*!< APB1 additional reset register */
  72. #define RCU_ADDAPB1EN REG32(RCU + 0xE4U) /*!< APB1 additional enable register */
  73. #endif /* GD32F30X_HD and GD32F30X_XD */
  74. /* bits definitions */
  75. /* RCU_CTL */
  76. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  77. #define RCU_CTL_IRC8MEN BIT(0) /*!< internal high speed oscillator enable */
  78. #define RCU_CTL_IRC8MSTB BIT(1) /*!< IRC8M high speed internal oscillator stabilization flag */
  79. #define RCU_CTL_IRC8MADJ BITS(3,7) /*!< high speed internal oscillator clock trim adjust value */
  80. #define RCU_CTL_IRC8MCALIB BITS(8,15) /*!< high speed internal oscillator calibration value register */
  81. #define RCU_CTL_HXTALEN BIT(16) /*!< external high speed oscillator enable */
  82. #define RCU_CTL_HXTALSTB BIT(17) /*!< external crystal oscillator clock stabilization flag */
  83. #define RCU_CTL_HXTALBPS BIT(18) /*!< external crystal oscillator clock bypass mode enable */
  84. #define RCU_CTL_CKMEN BIT(19) /*!< HXTAL clock monitor enable */
  85. #define RCU_CTL_PLLEN BIT(24) /*!< PLL enable */
  86. #define RCU_CTL_PLLSTB BIT(25) /*!< PLL clock stabilization flag */
  87. #elif defined(GD32F30X_CL)
  88. #define RCU_CTL_IRC8MEN BIT(0) /*!< internal high speed oscillator enable */
  89. #define RCU_CTL_IRC8MSTB BIT(1) /*!< IRC8M high speed internal oscillator stabilization flag */
  90. #define RCU_CTL_IRC8MADJ BITS(3,7) /*!< high speed internal oscillator clock trim adjust value */
  91. #define RCU_CTL_IRC8MCALIB BITS(8,15) /*!< high speed internal oscillator calibration value register */
  92. #define RCU_CTL_HXTALEN BIT(16) /*!< external high speed oscillator enable */
  93. #define RCU_CTL_HXTALSTB BIT(17) /*!< external crystal oscillator clock stabilization flag */
  94. #define RCU_CTL_HXTALBPS BIT(18) /*!< external crystal oscillator clock bypass mode enable */
  95. #define RCU_CTL_CKMEN BIT(19) /*!< HXTAL clock monitor enable */
  96. #define RCU_CTL_PLLEN BIT(24) /*!< PLL enable */
  97. #define RCU_CTL_PLLSTB BIT(25) /*!< PLL clock stabilization flag */
  98. #define RCU_CTL_PLL1EN BIT(26) /*!< PLL1 enable */
  99. #define RCU_CTL_PLL1STB BIT(27) /*!< PLL1 clock stabilization flag */
  100. #define RCU_CTL_PLL2EN BIT(28) /*!< PLL2 enable */
  101. #define RCU_CTL_PLL2STB BIT(29) /*!< PLL2 clock stabilization flag */
  102. #endif /* GD32F30X_HD and GD32F30X_XD */
  103. /* RCU_CFG0 */
  104. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  105. #define RCU_CFG0_SCS BITS(0,1) /*!< system clock switch */
  106. #define RCU_CFG0_SCSS BITS(2,3) /*!< system clock switch status */
  107. #define RCU_CFG0_AHBPSC BITS(4,7) /*!< AHB prescaler selection */
  108. #define RCU_CFG0_APB1PSC BITS(8,10) /*!< APB1 prescaler selection */
  109. #define RCU_CFG0_APB2PSC BITS(11,13) /*!< APB2 prescaler selection */
  110. #define RCU_CFG0_ADCPSC BITS(14,15) /*!< ADC prescaler selection */
  111. #define RCU_CFG0_PLLSEL BIT(16) /*!< PLL clock source selection */
  112. #define RCU_CFG0_PREDV0 BIT(17) /*!< PREDV0 division factor */
  113. #define RCU_CFG0_PLLMF BITS(18,21) /*!< PLL clock multiplication factor */
  114. #define RCU_CFG0_USBDPSC BITS(22,23) /*!< USBD clock prescaler selection */
  115. #define RCU_CFG0_CKOUT0SEL BITS(24,26) /*!< CKOUT0 clock source selection */
  116. #define RCU_CFG0_PLLMF_4 BIT(27) /*!< bit 4 of PLLMF */
  117. #define RCU_CFG0_ADCPSC_2 BIT(28) /*!< bit 2 of ADCPSC */
  118. #define RCU_CFG0_PLLMF_5 BIT(30) /*!< bit 5 of PLLMF */
  119. #define RCU_CFG0_USBDPSC_2 BIT(31) /*!< bit 2 of USBDPSC */
  120. #elif defined(GD32F30X_CL)
  121. #define RCU_CFG0_SCS BITS(0,1) /*!< system clock switch */
  122. #define RCU_CFG0_SCSS BITS(2,3) /*!< system clock switch status */
  123. #define RCU_CFG0_AHBPSC BITS(4,7) /*!< AHB prescaler selection */
  124. #define RCU_CFG0_APB1PSC BITS(8,10) /*!< APB1 prescaler selection */
  125. #define RCU_CFG0_APB2PSC BITS(11,13) /*!< APB2 prescaler selection */
  126. #define RCU_CFG0_ADCPSC BITS(14,15) /*!< ADC prescaler selection */
  127. #define RCU_CFG0_PLLSEL BIT(16) /*!< PLL clock source selection */
  128. #define RCU_CFG0_PREDV0_LSB BIT(17) /*!< the LSB of PREDV0 division factor */
  129. #define RCU_CFG0_PLLMF BITS(18,21) /*!< PLL clock multiplication factor */
  130. #define RCU_CFG0_USBFSPSC BITS(22,23) /*!< USBFS clock prescaler selection */
  131. #define RCU_CFG0_CKOUT0SEL BITS(24,27) /*!< CKOUT0 clock source selection */
  132. #define RCU_CFG0_ADCPSC_2 BIT(28) /*!< bit 2 of ADCPSC */
  133. #define RCU_CFG0_PLLMF_4 BIT(29) /*!< bit 4 of PLLMF */
  134. #define RCU_CFG0_PLLMF_5 BIT(30) /*!< bit 5 of PLLMF */
  135. #define RCU_CFG0_USBFSPSC_2 BIT(31) /*!< bit 2 of USBFSPSC */
  136. #endif /* GD32F30X_HD and GD32F30X_XD */
  137. /* RCU_INT */
  138. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  139. #define RCU_INT_IRC40KSTBIF BIT(0) /*!< IRC40K stabilization interrupt flag */
  140. #define RCU_INT_LXTALSTBIF BIT(1) /*!< LXTAL stabilization interrupt flag */
  141. #define RCU_INT_IRC8MSTBIF BIT(2) /*!< IRC8M stabilization interrupt flag */
  142. #define RCU_INT_HXTALSTBIF BIT(3) /*!< HXTAL stabilization interrupt flag */
  143. #define RCU_INT_PLLSTBIF BIT(4) /*!< PLL stabilization interrupt flag */
  144. #define RCU_INT_CKMIF BIT(7) /*!< HXTAL clock stuck interrupt flag */
  145. #define RCU_INT_IRC40KSTBIE BIT(8) /*!< IRC40K stabilization interrupt enable */
  146. #define RCU_INT_LXTALSTBIE BIT(9) /*!< LXTAL stabilization interrupt enable */
  147. #define RCU_INT_IRC8MSTBIE BIT(10) /*!< IRC8M stabilization interrupt enable */
  148. #define RCU_INT_HXTALSTBIE BIT(11) /*!< HXTAL stabilization interrupt enable */
  149. #define RCU_INT_PLLSTBIE BIT(12) /*!< PLL stabilization interrupt enable */
  150. #define RCU_INT_IRC40KSTBIC BIT(16) /*!< IRC40K Stabilization interrupt clear */
  151. #define RCU_INT_LXTALSTBIC BIT(17) /*!< LXTAL Stabilization interrupt clear */
  152. #define RCU_INT_IRC8MSTBIC BIT(18) /*!< IRC8M Stabilization interrupt clear */
  153. #define RCU_INT_HXTALSTBIC BIT(19) /*!< HXTAL Stabilization interrupt clear */
  154. #define RCU_INT_PLLSTBIC BIT(20) /*!< PLL stabilization interrupt clear */
  155. #define RCU_INT_CKMIC BIT(23) /*!< HXTAL clock stuck interrupt clear */
  156. #elif defined(GD32F30X_CL)
  157. #define RCU_INT_IRC40KSTBIF BIT(0) /*!< IRC40K stabilization interrupt flag */
  158. #define RCU_INT_LXTALSTBIF BIT(1) /*!< LXTAL stabilization interrupt flag */
  159. #define RCU_INT_IRC8MSTBIF BIT(2) /*!< IRC8M stabilization interrupt flag */
  160. #define RCU_INT_HXTALSTBIF BIT(3) /*!< HXTAL stabilization interrupt flag */
  161. #define RCU_INT_PLLSTBIF BIT(4) /*!< PLL stabilization interrupt flag */
  162. #define RCU_INT_PLL1STBIF BIT(5) /*!< PLL1 stabilization interrupt flag */
  163. #define RCU_INT_PLL2STBIF BIT(6) /*!< PLL2 stabilization interrupt flag */
  164. #define RCU_INT_CKMIF BIT(7) /*!< HXTAL clock stuck interrupt flag */
  165. #define RCU_INT_IRC40KSTBIE BIT(8) /*!< IRC40K stabilization interrupt enable */
  166. #define RCU_INT_LXTALSTBIE BIT(9) /*!< LXTAL stabilization interrupt enable */
  167. #define RCU_INT_IRC8MSTBIE BIT(10) /*!< IRC8M stabilization interrupt enable */
  168. #define RCU_INT_HXTALSTBIE BIT(11) /*!< HXTAL stabilization interrupt enable */
  169. #define RCU_INT_PLLSTBIE BIT(12) /*!< PLL stabilization interrupt enable */
  170. #define RCU_INT_PLL1STBIE BIT(13) /*!< PLL1 stabilization interrupt enable */
  171. #define RCU_INT_PLL2STBIE BIT(14) /*!< PLL2 stabilization interrupt enable */
  172. #define RCU_INT_IRC40KSTBIC BIT(16) /*!< IRC40K stabilization interrupt clear */
  173. #define RCU_INT_LXTALSTBIC BIT(17) /*!< LXTAL stabilization interrupt clear */
  174. #define RCU_INT_IRC8MSTBIC BIT(18) /*!< IRC8M stabilization interrupt clear */
  175. #define RCU_INT_HXTALSTBIC BIT(19) /*!< HXTAL stabilization interrupt clear */
  176. #define RCU_INT_PLLSTBIC BIT(20) /*!< PLL stabilization interrupt clear */
  177. #define RCU_INT_PLL1STBIC BIT(21) /*!< PLL1 stabilization interrupt clear */
  178. #define RCU_INT_PLL2STBIC BIT(22) /*!< PLL2 stabilization interrupt clear */
  179. #define RCU_INT_CKMIC BIT(23) /*!< HXTAL clock stuck interrupt clear */
  180. #endif /* GD32F30X_HD and GD32F30X_XD */
  181. /* RCU_APB2RST */
  182. #define RCU_APB2RST_AFRST BIT(0) /*!< alternate function I/O reset */
  183. #define RCU_APB2RST_PARST BIT(2) /*!< GPIO port A reset */
  184. #define RCU_APB2RST_PBRST BIT(3) /*!< GPIO port B reset */
  185. #define RCU_APB2RST_PCRST BIT(4) /*!< GPIO port C reset */
  186. #define RCU_APB2RST_PDRST BIT(5) /*!< GPIO port D reset */
  187. #define RCU_APB2RST_PERST BIT(6) /*!< GPIO port E reset */
  188. #define RCU_APB2RST_PFRST BIT(7) /*!< GPIO port F reset */
  189. #define RCU_APB2RST_PGRST BIT(8) /*!< GPIO port G reset */
  190. #define RCU_APB2RST_ADC0RST BIT(9) /*!< ADC0 reset */
  191. #define RCU_APB2RST_ADC1RST BIT(10) /*!< ADC1 reset */
  192. #define RCU_APB2RST_TIMER0RST BIT(11) /*!< TIMER0 reset */
  193. #define RCU_APB2RST_SPI0RST BIT(12) /*!< SPI0 reset */
  194. #define RCU_APB2RST_TIMER7RST BIT(13) /*!< TIMER7 reset */
  195. #define RCU_APB2RST_USART0RST BIT(14) /*!< USART0 reset */
  196. #ifndef GD32F30X_CL
  197. #define RCU_APB2RST_ADC2RST BIT(15) /*!< ADC2 reset */
  198. #endif /* GD32F30X_CL */
  199. #ifndef GD32F30X_HD
  200. #define RCU_APB2RST_TIMER8RST BIT(19) /*!< TIMER8 reset */
  201. #define RCU_APB2RST_TIMER9RST BIT(20) /*!< TIMER9 reset */
  202. #define RCU_APB2RST_TIMER10RST BIT(21) /*!< TIMER10 reset */
  203. #endif /* GD32F30X_HD */
  204. /* RCU_APB1RST */
  205. #define RCU_APB1RST_TIMER1RST BIT(0) /*!< TIMER1 reset */
  206. #define RCU_APB1RST_TIMER2RST BIT(1) /*!< TIMER2 reset */
  207. #define RCU_APB1RST_TIMER3RST BIT(2) /*!< TIMER3 reset */
  208. #define RCU_APB1RST_TIMER4RST BIT(3) /*!< TIMER4 reset */
  209. #define RCU_APB1RST_TIMER5RST BIT(4) /*!< TIMER5 reset */
  210. #define RCU_APB1RST_TIMER6RST BIT(5) /*!< TIMER6 reset */
  211. #ifndef GD32F30X_HD
  212. #define RCU_APB1RST_TIMER11RST BIT(6) /*!< TIMER11 reset */
  213. #define RCU_APB1RST_TIMER12RST BIT(7) /*!< TIMER12 reset */
  214. #define RCU_APB1RST_TIMER13RST BIT(8) /*!< TIMER13 reset */
  215. #endif /* GD32F30X_HD */
  216. #define RCU_APB1RST_WWDGTRST BIT(11) /*!< WWDGT reset */
  217. #define RCU_APB1RST_SPI1RST BIT(14) /*!< SPI1 reset */
  218. #define RCU_APB1RST_SPI2RST BIT(15) /*!< SPI2 reset */
  219. #define RCU_APB1RST_USART1RST BIT(17) /*!< USART1 reset */
  220. #define RCU_APB1RST_USART2RST BIT(18) /*!< USART2 reset */
  221. #define RCU_APB1RST_UART3RST BIT(19) /*!< UART3 reset */
  222. #define RCU_APB1RST_UART4RST BIT(20) /*!< UART4 reset */
  223. #define RCU_APB1RST_I2C0RST BIT(21) /*!< I2C0 reset */
  224. #define RCU_APB1RST_I2C1RST BIT(22) /*!< I2C1 reset */
  225. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  226. #define RCU_APB1RST_USBDRST BIT(23) /*!< USBD reset */
  227. #endif /* GD32F30X_HD and GD32F30X_XD */
  228. #define RCU_APB1RST_CAN0RST BIT(25) /*!< CAN0 reset */
  229. #ifdef GD32F30X_CL
  230. #define RCU_APB1RST_CAN1RST BIT(26) /*!< CAN1 reset */
  231. #endif /* GD32F30X_CL */
  232. #define RCU_APB1RST_BKPIRST BIT(27) /*!< backup interface reset */
  233. #define RCU_APB1RST_PMURST BIT(28) /*!< PMU reset */
  234. #define RCU_APB1RST_DACRST BIT(29) /*!< DAC reset */
  235. /* RCU_AHBEN */
  236. #define RCU_AHBEN_DMA0EN BIT(0) /*!< DMA0 clock enable */
  237. #define RCU_AHBEN_DMA1EN BIT(1) /*!< DMA1 clock enable */
  238. #define RCU_AHBEN_SRAMSPEN BIT(2) /*!< SRAM clock enable when sleep mode */
  239. #define RCU_AHBEN_FMCSPEN BIT(4) /*!< FMC clock enable when sleep mode */
  240. #define RCU_AHBEN_CRCEN BIT(6) /*!< CRC clock enable */
  241. #define RCU_AHBEN_EXMCEN BIT(8) /*!< EXMC clock enable */
  242. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  243. #define RCU_AHBEN_SDIOEN BIT(10) /*!< SDIO clock enable */
  244. #elif defined(GD32F30X_CL)
  245. #define RCU_AHBEN_USBFSEN BIT(12) /*!< USBFS clock enable */
  246. #define RCU_AHBEN_ENETEN BIT(14) /*!< ENET clock enable */
  247. #define RCU_AHBEN_ENETTXEN BIT(15) /*!< Ethernet TX clock enable */
  248. #define RCU_AHBEN_ENETRXEN BIT(16) /*!< Ethernet RX clock enable */
  249. #endif /* GD32F30X_HD and GD32F30X_XD */
  250. /* RCU_APB2EN */
  251. #define RCU_APB2EN_AFEN BIT(0) /*!< alternate function IO clock enable */
  252. #define RCU_APB2EN_PAEN BIT(2) /*!< GPIO port A clock enable */
  253. #define RCU_APB2EN_PBEN BIT(3) /*!< GPIO port B clock enable */
  254. #define RCU_APB2EN_PCEN BIT(4) /*!< GPIO port C clock enable */
  255. #define RCU_APB2EN_PDEN BIT(5) /*!< GPIO port D clock enable */
  256. #define RCU_APB2EN_PEEN BIT(6) /*!< GPIO port E clock enable */
  257. #define RCU_APB2EN_PFEN BIT(7) /*!< GPIO port F clock enable */
  258. #define RCU_APB2EN_PGEN BIT(8) /*!< GPIO port G clock enable */
  259. #define RCU_APB2EN_ADC0EN BIT(9) /*!< ADC0 clock enable */
  260. #define RCU_APB2EN_ADC1EN BIT(10) /*!< ADC1 clock enable */
  261. #define RCU_APB2EN_TIMER0EN BIT(11) /*!< TIMER0 clock enable */
  262. #define RCU_APB2EN_SPI0EN BIT(12) /*!< SPI0 clock enable */
  263. #define RCU_APB2EN_TIMER7EN BIT(13) /*!< TIMER7 clock enable */
  264. #define RCU_APB2EN_USART0EN BIT(14) /*!< USART0 clock enable */
  265. #ifndef GD32F30X_CL
  266. #define RCU_APB2EN_ADC2EN BIT(15) /*!< ADC2 clock enable */
  267. #endif /* GD32F30X_CL */
  268. #ifndef GD32F30X_HD
  269. #define RCU_APB2EN_TIMER8EN BIT(19) /*!< TIMER8 clock enable */
  270. #define RCU_APB2EN_TIMER9EN BIT(20) /*!< TIMER9 clock enable */
  271. #define RCU_APB2EN_TIMER10EN BIT(21) /*!< TIMER10 clock enable */
  272. #endif /* GD32F30X_HD */
  273. /* RCU_APB1EN */
  274. #define RCU_APB1EN_TIMER1EN BIT(0) /*!< TIMER1 clock enable */
  275. #define RCU_APB1EN_TIMER2EN BIT(1) /*!< TIMER2 clock enable */
  276. #define RCU_APB1EN_TIMER3EN BIT(2) /*!< TIMER3 clock enable */
  277. #define RCU_APB1EN_TIMER4EN BIT(3) /*!< TIMER4 clock enable */
  278. #define RCU_APB1EN_TIMER5EN BIT(4) /*!< TIMER5 clock enable */
  279. #define RCU_APB1EN_TIMER6EN BIT(5) /*!< TIMER6 clock enable */
  280. #ifndef GD32F30X_HD
  281. #define RCU_APB1EN_TIMER11EN BIT(6) /*!< TIMER11 clock enable */
  282. #define RCU_APB1EN_TIMER12EN BIT(7) /*!< TIMER12 clock enable */
  283. #define RCU_APB1EN_TIMER13EN BIT(8) /*!< TIMER13 clock enable */
  284. #endif /* GD32F30X_HD */
  285. #define RCU_APB1EN_WWDGTEN BIT(11) /*!< WWDGT clock enable */
  286. #define RCU_APB1EN_SPI1EN BIT(14) /*!< SPI1 clock enable */
  287. #define RCU_APB1EN_SPI2EN BIT(15) /*!< SPI2 clock enable */
  288. #define RCU_APB1EN_USART1EN BIT(17) /*!< USART1 clock enable */
  289. #define RCU_APB1EN_USART2EN BIT(18) /*!< USART2 clock enable */
  290. #define RCU_APB1EN_UART3EN BIT(19) /*!< UART3 clock enable */
  291. #define RCU_APB1EN_UART4EN BIT(20) /*!< UART4 clock enable */
  292. #define RCU_APB1EN_I2C0EN BIT(21) /*!< I2C0 clock enable */
  293. #define RCU_APB1EN_I2C1EN BIT(22) /*!< I2C1 clock enable */
  294. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  295. #define RCU_APB1EN_USBDEN BIT(23) /*!< USBD clock enable */
  296. #endif /* GD32F30X_HD and GD32F30X_XD */
  297. #define RCU_APB1EN_CAN0EN BIT(25) /*!< CAN0 clock enable */
  298. #ifdef GD32F30X_CL
  299. #define RCU_APB1EN_CAN1EN BIT(26) /*!< CAN1 clock enable */
  300. #endif /* GD32F30X_CL */
  301. #define RCU_APB1EN_BKPIEN BIT(27) /*!< backup interface clock enable */
  302. #define RCU_APB1EN_PMUEN BIT(28) /*!< PMU clock enable */
  303. #define RCU_APB1EN_DACEN BIT(29) /*!< DAC clock enable */
  304. /* RCU_BDCTL */
  305. #define RCU_BDCTL_LXTALEN BIT(0) /*!< LXTAL enable */
  306. #define RCU_BDCTL_LXTALSTB BIT(1) /*!< low speed crystal oscillator stabilization flag */
  307. #define RCU_BDCTL_LXTALBPS BIT(2) /*!< LXTAL bypass mode enable */
  308. #define RCU_BDCTL_LXTALDRI BITS(3,4) /*!< LXTAL drive capability */
  309. #define RCU_BDCTL_RTCSRC BITS(8,9) /*!< RTC clock entry selection */
  310. #define RCU_BDCTL_RTCEN BIT(15) /*!< RTC clock enable */
  311. #define RCU_BDCTL_BKPRST BIT(16) /*!< backup domain reset */
  312. /* RCU_RSTSCK */
  313. #define RCU_RSTSCK_IRC40KEN BIT(0) /*!< IRC40K enable */
  314. #define RCU_RSTSCK_IRC40KSTB BIT(1) /*!< IRC40K stabilization flag */
  315. #define RCU_RSTSCK_RSTFC BIT(24) /*!< reset flag clear */
  316. #define RCU_RSTSCK_EPRSTF BIT(26) /*!< external pin reset flag */
  317. #define RCU_RSTSCK_PORRSTF BIT(27) /*!< power reset flag */
  318. #define RCU_RSTSCK_SWRSTF BIT(28) /*!< software reset flag */
  319. #define RCU_RSTSCK_FWDGTRSTF BIT(29) /*!< free watchdog timer reset flag */
  320. #define RCU_RSTSCK_WWDGTRSTF BIT(30) /*!< window watchdog timer reset flag */
  321. #define RCU_RSTSCK_LPRSTF BIT(31) /*!< low-power reset flag */
  322. #ifdef GD32F30X_CL
  323. /* RCU_AHBRST */
  324. #define RCU_AHBRST_USBFSRST BIT(12) /*!< USBFS reset */
  325. #define RCU_AHBRST_ENETRST BIT(14) /*!< ENET reset */
  326. #endif /* GD32F30X_CL */
  327. /* RCU_CFG1 */
  328. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  329. #define RCU_CFG1_ADCPSC_3 BIT(29) /*!< bit 4 of ADCPSC */
  330. #define RCU_CFG1_PLLPRESEL BIT(30) /*!< PLL clock source selection */
  331. #elif defined(GD32F30X_CL)
  332. #define RCU_CFG1_PREDV0 BITS(0,3) /*!< PREDV0 division factor */
  333. #define RCU_CFG1_PREDV1 BITS(4,7) /*!< PREDV1 division factor */
  334. #define RCU_CFG1_PLL1MF BITS(8,11) /*!< PLL1 clock multiplication factor */
  335. #define RCU_CFG1_PLL2MF BITS(12,15) /*!< PLL2 clock multiplication factor */
  336. #define RCU_CFG1_PREDV0SEL BIT(16) /*!< PREDV0 input clock source selection */
  337. #define RCU_CFG1_I2S1SEL BIT(17) /*!< I2S1 clock source selection */
  338. #define RCU_CFG1_I2S2SEL BIT(18) /*!< I2S2 clock source selection */
  339. #define RCU_CFG1_ADCPSC_3 BIT(29) /*!< bit 4 of ADCPSC */
  340. #define RCU_CFG1_PLLPRESEL BIT(30) /*!< PLL clock source selection */
  341. #define RCU_CFG1_PLL2MF_4 BIT(31) /*!< bit 5 of PLL2MF */
  342. #endif /* GD32F30X_HD and GD32F30X_XD */
  343. /* RCU_DSV */
  344. #define RCU_DSV_DSLPVS BITS(0,2) /*!< deep-sleep mode voltage select */
  345. /* RCU_ADDCTL */
  346. #define RCU_ADDCTL_CK48MSEL BIT(0) /*!< 48MHz clock selection */
  347. #define RCU_ADDCTL_IRC48MEN BIT(16) /*!< internal 48MHz RC oscillator enable */
  348. #define RCU_ADDCTL_IRC48MSTB BIT(17) /*!< internal 48MHz RC oscillator clock stabilization flag */
  349. #define RCU_ADDCTL_IRC48MCAL BITS(24,31) /*!< internal 48MHz RC oscillator calibration value register */
  350. /* RCU_ADDINT */
  351. #define RCU_ADDINT_IRC48MSTBIF BIT(6) /*!< IRC48M stabilization interrupt flag */
  352. #define RCU_ADDINT_IRC48MSTBIE BIT(14) /*!< internal 48 MHz RC oscillator stabilization interrupt enable */
  353. #define RCU_ADDINT_IRC48MSTBIC BIT(22) /*!< internal 48 MHz RC oscillator stabilization interrupt clear */
  354. /* RCU_ADDAPB1RST */
  355. #define RCU_ADDAPB1RST_CTCRST BIT(27) /*!< CTC reset */
  356. /* RCU_ADDAPB1EN */
  357. #define RCU_ADDAPB1EN_CTCEN BIT(27) /*!< CTC clock enable */
  358. /* constants definitions */
  359. /* define the peripheral clock enable bit position and its register index offset */
  360. #define RCU_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
  361. #define RCU_REG_VAL(periph) (REG32(RCU + ((uint32_t)(periph) >> 6)))
  362. #define RCU_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
  363. /* register offset */
  364. /* peripherals enable */
  365. #define AHBEN_REG_OFFSET 0x14U /*!< AHB enable register offset */
  366. #define APB1EN_REG_OFFSET 0x1CU /*!< APB1 enable register offset */
  367. #define APB2EN_REG_OFFSET 0x18U /*!< APB2 enable register offset */
  368. #define ADD_APB1EN_REG_OFFSET 0xE4U /*!< APB1 additional enable register offset */
  369. /* peripherals reset */
  370. #define AHBRST_REG_OFFSET 0x28U /*!< AHB reset register offset */
  371. #define APB1RST_REG_OFFSET 0x10U /*!< APB1 reset register offset */
  372. #define APB2RST_REG_OFFSET 0x0CU /*!< APB2 reset register offset */
  373. #define ADD_APB1RST_REG_OFFSET 0xE0U /*!< APB1 additional reset register offset */
  374. #define RSTSCK_REG_OFFSET 0x24U /*!< reset source/clock register offset */
  375. /* clock control */
  376. #define CTL_REG_OFFSET 0x00U /*!< control register offset */
  377. #define BDCTL_REG_OFFSET 0x20U /*!< backup domain control register offset */
  378. #define ADDCTL_REG_OFFSET 0xC0U /*!< additional clock control register offset */
  379. /* clock stabilization and stuck interrupt */
  380. #define INT_REG_OFFSET 0x08U /*!< clock interrupt register offset */
  381. #define ADDINT_REG_OFFSET 0xCCU /*!< additional clock interrupt register offset */
  382. /* configuration register */
  383. #define CFG0_REG_OFFSET 0x04U /*!< clock configuration register 0 offset */
  384. #define CFG1_REG_OFFSET 0x2CU /*!< clock configuration register 1 offset */
  385. /* peripheral clock enable */
  386. typedef enum
  387. {
  388. /* AHB peripherals */
  389. RCU_DMA0 = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 0U), /*!< DMA0 clock */
  390. RCU_DMA1 = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 1U), /*!< DMA1 clock */
  391. RCU_CRC = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 6U), /*!< CRC clock */
  392. RCU_EXMC = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 8U), /*!< EXMC clock */
  393. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  394. RCU_SDIO = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 10U), /*!< SDIO clock */
  395. #elif defined(GD32F30X_CL)
  396. RCU_USBFS = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 12U), /*!< USBFS clock */
  397. RCU_ENET = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 14U), /*!< ENET clock */
  398. RCU_ENETTX = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 15U), /*!< ENETTX clock */
  399. RCU_ENETRX = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 16U), /*!< ENETRX clock */
  400. #endif /* GD32F30X_HD and GD32F30X_XD */
  401. /* APB1 peripherals */
  402. RCU_TIMER1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 0U), /*!< TIMER1 clock */
  403. RCU_TIMER2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 1U), /*!< TIMER2 clock */
  404. RCU_TIMER3 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 2U), /*!< TIMER3 clock */
  405. RCU_TIMER4 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 3U), /*!< TIMER4 clock */
  406. RCU_TIMER5 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 4U), /*!< TIMER5 clock */
  407. RCU_TIMER6 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 5U), /*!< TIMER6 clock */
  408. #ifndef GD32F30X_HD
  409. RCU_TIMER11 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 6U), /*!< TIMER11 clock */
  410. RCU_TIMER12 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 7U), /*!< TIMER12 clock */
  411. RCU_TIMER13 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 8U), /*!< TIMER13 clock */
  412. #endif /* GD32F30X_HD */
  413. RCU_WWDGT = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 11U), /*!< WWDGT clock */
  414. RCU_SPI1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 14U), /*!< SPI1 clock */
  415. RCU_SPI2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 15U), /*!< SPI2 clock */
  416. RCU_USART1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 17U), /*!< USART1 clock */
  417. RCU_USART2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 18U), /*!< USART2 clock */
  418. RCU_UART3 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 19U), /*!< UART3 clock */
  419. RCU_UART4 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 20U), /*!< UART4 clock */
  420. RCU_I2C0 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 21U), /*!< I2C0 clock */
  421. RCU_I2C1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 22U), /*!< I2C1 clock */
  422. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  423. RCU_USBD = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 23U), /*!< USBD clock */
  424. #endif /* GD32F30X_HD and GD32F30X_XD */
  425. RCU_CAN0 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 25U), /*!< CAN0 clock */
  426. #ifdef GD32F30X_CL
  427. RCU_CAN1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 26U), /*!< CAN1 clock */
  428. #endif /* GD32F30X_CL */
  429. RCU_BKPI = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 27U), /*!< BKPI clock */
  430. RCU_PMU = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 28U), /*!< PMU clock */
  431. RCU_DAC = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 29U), /*!< DAC clock */
  432. RCU_RTC = RCU_REGIDX_BIT(BDCTL_REG_OFFSET, 15U), /*!< RTC clock */
  433. RCU_CTC = RCU_REGIDX_BIT(ADD_APB1EN_REG_OFFSET, 27U), /*!< CTC clock */
  434. /* APB2 peripherals */
  435. RCU_AF = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 0U), /*!< alternate function clock */
  436. RCU_GPIOA = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 2U), /*!< GPIOA clock */
  437. RCU_GPIOB = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 3U), /*!< GPIOB clock */
  438. RCU_GPIOC = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 4U), /*!< GPIOC clock */
  439. RCU_GPIOD = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 5U), /*!< GPIOD clock */
  440. RCU_GPIOE = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 6U), /*!< GPIOE clock */
  441. RCU_GPIOF = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 7U), /*!< GPIOF clock */
  442. RCU_GPIOG = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 8U), /*!< GPIOG clock */
  443. RCU_ADC0 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 9U), /*!< ADC0 clock */
  444. RCU_ADC1 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 10U), /*!< ADC1 clock */
  445. RCU_TIMER0 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 11U), /*!< TIMER0 clock */
  446. RCU_SPI0 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 12U), /*!< SPI0 clock */
  447. RCU_TIMER7 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 13U), /*!< TIMER7 clock */
  448. RCU_USART0 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 14U), /*!< USART0 clock */
  449. #ifndef GD32F30X_CL
  450. RCU_ADC2 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 15U), /*!< ADC2 clock */
  451. #endif /* GD32F30X_CL */
  452. #ifndef GD32F30X_HD
  453. RCU_TIMER8 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 19U), /*!< TIMER8 clock */
  454. RCU_TIMER9 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 20U), /*!< TIMER9 clock */
  455. RCU_TIMER10 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 21U), /*!< TIMER10 clock */
  456. #endif /* GD32F30X_HD */
  457. }rcu_periph_enum;
  458. /* peripheral clock enable when sleep mode*/
  459. typedef enum
  460. {
  461. /* AHB peripherals */
  462. RCU_SRAM_SLP = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 2U), /*!< SRAM clock */
  463. RCU_FMC_SLP = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 4U), /*!< FMC clock */
  464. }rcu_periph_sleep_enum;
  465. /* peripherals reset */
  466. typedef enum
  467. {
  468. /* AHB peripherals */
  469. #ifdef GD32F30X_CL
  470. RCU_USBFSRST = RCU_REGIDX_BIT(AHBRST_REG_OFFSET, 12U), /*!< USBFS clock reset */
  471. RCU_ENETRST = RCU_REGIDX_BIT(AHBRST_REG_OFFSET, 14U), /*!< ENET clock reset */
  472. #endif /* GD32F30X_CL */
  473. /* APB1 peripherals */
  474. RCU_TIMER1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 0U), /*!< TIMER1 clock reset */
  475. RCU_TIMER2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 1U), /*!< TIMER2 clock reset */
  476. RCU_TIMER3RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 2U), /*!< TIMER3 clock reset */
  477. RCU_TIMER4RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 3U), /*!< TIMER4 clock reset */
  478. RCU_TIMER5RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 4U), /*!< TIMER5 clock reset */
  479. RCU_TIMER6RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 5U), /*!< TIMER6 clock reset */
  480. #ifndef GD32F30X_HD
  481. RCU_TIMER11RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 6U), /*!< TIMER11 clock reset */
  482. RCU_TIMER12RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 7U), /*!< TIMER12 clock reset */
  483. RCU_TIMER13RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 8U), /*!< TIMER13 clock reset */
  484. #endif /* GD32F30X_HD */
  485. RCU_WWDGTRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 11U), /*!< WWDGT clock reset */
  486. RCU_SPI1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 14U), /*!< SPI1 clock reset */
  487. RCU_SPI2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 15U), /*!< SPI2 clock reset */
  488. RCU_USART1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 17U), /*!< USART1 clock reset */
  489. RCU_USART2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 18U), /*!< USART2 clock reset */
  490. RCU_UART3RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 19U), /*!< UART3 clock reset */
  491. RCU_UART4RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 20U), /*!< UART4 clock reset */
  492. RCU_I2C0RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 21U), /*!< I2C0 clock reset */
  493. RCU_I2C1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 22U), /*!< I2C1 clock reset */
  494. #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
  495. RCU_USBDRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 23U), /*!< USBD clock reset */
  496. #endif /* GD32F30X_HD and GD32F30X_XD */
  497. RCU_CAN0RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 25U), /*!< CAN0 clock reset */
  498. #ifdef GD32F30X_CL
  499. RCU_CAN1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 26U), /*!< CAN1 clock reset */
  500. #endif /* GD32F30X_CL */
  501. RCU_BKPIRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 27U), /*!< BKPI clock reset */
  502. RCU_PMURST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 28U), /*!< PMU clock reset */
  503. RCU_DACRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 29U), /*!< DAC clock reset */
  504. RCU_CTCRST = RCU_REGIDX_BIT(ADD_APB1RST_REG_OFFSET, 27U), /*!< RTC clock reset */
  505. /* APB2 peripherals */
  506. RCU_AFRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 0U), /*!< alternate function clock reset */
  507. RCU_GPIOARST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 2U), /*!< GPIOA clock reset */
  508. RCU_GPIOBRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 3U), /*!< GPIOB clock reset */
  509. RCU_GPIOCRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 4U), /*!< GPIOC clock reset */
  510. RCU_GPIODRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 5U), /*!< GPIOD clock reset */
  511. RCU_GPIOERST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 6U), /*!< GPIOE clock reset */
  512. RCU_GPIOFRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 7U), /*!< GPIOF clock reset */
  513. RCU_GPIOGRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 8U), /*!< GPIOG clock reset */
  514. RCU_ADC0RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 9U), /*!< ADC0 clock reset */
  515. RCU_ADC1RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 10U), /*!< ADC1 clock reset */
  516. RCU_TIMER0RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 11U), /*!< TIMER0 clock reset */
  517. RCU_SPI0RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 12U), /*!< SPI0 clock reset */
  518. RCU_TIMER7RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 13U), /*!< TIMER7 clock reset */
  519. RCU_USART0RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 14U), /*!< USART0 clock reset */
  520. #ifndef GD32F30X_CL
  521. RCU_ADC2RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 15U), /*!< ADC2 clock reset */
  522. #endif /* GD32F30X_CL */
  523. #ifndef GD32F30X_HD
  524. RCU_TIMER8RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 19U), /*!< TIMER8 clock reset */
  525. RCU_TIMER9RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 20U), /*!< TIMER9 clock reset */
  526. RCU_TIMER10RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 21U), /*!< TIMER10 clock reset */
  527. #endif /* GD32F30X_HD */
  528. }rcu_periph_reset_enum;
  529. /* clock stabilization and peripheral reset flags */
  530. typedef enum
  531. {
  532. /* clock stabilization flags */
  533. RCU_FLAG_IRC8MSTB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 1U), /*!< IRC8M stabilization flags */
  534. RCU_FLAG_HXTALSTB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 17U), /*!< HXTAL stabilization flags */
  535. RCU_FLAG_PLLSTB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 25U), /*!< PLL stabilization flags */
  536. #ifdef GD32F30X_CL
  537. RCU_FLAG_PLL1STB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 27U), /*!< PLL1 stabilization flags */
  538. RCU_FLAG_PLL2STB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 29U), /*!< PLL2 stabilization flags */
  539. #endif /* GD32F30X_CL */
  540. RCU_FLAG_LXTALSTB = RCU_REGIDX_BIT(BDCTL_REG_OFFSET, 1U), /*!< LXTAL stabilization flags */
  541. RCU_FLAG_IRC40KSTB = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 1U), /*!< IRC40K stabilization flags */
  542. RCU_FLAG_IRC48MSTB = RCU_REGIDX_BIT(ADDCTL_REG_OFFSET, 17U), /*!< IRC48M stabilization flags */
  543. /* reset source flags */
  544. RCU_FLAG_EPRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 26U), /*!< external PIN reset flags */
  545. RCU_FLAG_PORRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 27U), /*!< power reset flags */
  546. RCU_FLAG_SWRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 28U), /*!< software reset flags */
  547. RCU_FLAG_FWDGTRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 29U), /*!< FWDGT reset flags */
  548. RCU_FLAG_WWDGTRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 30U), /*!< WWDGT reset flags */
  549. RCU_FLAG_LPRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 31U), /*!< low-power reset flags */
  550. }rcu_flag_enum;
  551. /* clock stabilization and ckm interrupt flags */
  552. typedef enum
  553. {
  554. RCU_INT_FLAG_IRC40KSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 0U), /*!< IRC40K stabilization interrupt flag */
  555. RCU_INT_FLAG_LXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 1U), /*!< LXTAL stabilization interrupt flag */
  556. RCU_INT_FLAG_IRC8MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 2U), /*!< IRC8M stabilization interrupt flag */
  557. RCU_INT_FLAG_HXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 3U), /*!< HXTAL stabilization interrupt flag */
  558. RCU_INT_FLAG_PLLSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 4U), /*!< PLL stabilization interrupt flag */
  559. #ifdef GD32F30X_CL
  560. RCU_INT_FLAG_PLL1STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 5U), /*!< PLL1 stabilization interrupt flag */
  561. RCU_INT_FLAG_PLL2STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 6U), /*!< PLL2 stabilization interrupt flag */
  562. #endif /* GD32F30X_CL */
  563. RCU_INT_FLAG_CKM = RCU_REGIDX_BIT(INT_REG_OFFSET, 7U), /*!< HXTAL clock stuck interrupt flag */
  564. RCU_INT_FLAG_IRC48MSTB = RCU_REGIDX_BIT(ADDINT_REG_OFFSET, 6U), /*!< IRC48M stabilization interrupt flag */
  565. }rcu_int_flag_enum;
  566. /* clock stabilization and stuck interrupt flags clear */
  567. typedef enum
  568. {
  569. RCU_INT_FLAG_IRC40KSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 16U), /*!< IRC40K stabilization interrupt flags clear */
  570. RCU_INT_FLAG_LXTALSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 17U), /*!< LXTAL stabilization interrupt flags clear */
  571. RCU_INT_FLAG_IRC8MSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 18U), /*!< IRC8M stabilization interrupt flags clear */
  572. RCU_INT_FLAG_HXTALSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 19U), /*!< HXTAL stabilization interrupt flags clear */
  573. RCU_INT_FLAG_PLLSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 20U), /*!< PLL stabilization interrupt flags clear */
  574. #ifdef GD32F30X_CL
  575. RCU_INT_FLAG_PLL1STB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 21U), /*!< PLL1 stabilization interrupt flags clear */
  576. RCU_INT_FLAG_PLL2STB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 22U), /*!< PLL2 stabilization interrupt flags clear */
  577. #endif /* GD32F30X_CL */
  578. RCU_INT_FLAG_CKM_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 23U), /*!< CKM interrupt flags clear */
  579. RCU_INT_FLAG_IRC48MSTB_CLR = RCU_REGIDX_BIT(ADDINT_REG_OFFSET, 22U), /*!< internal 48 MHz RC oscillator stabilization interrupt clear */
  580. }rcu_int_flag_clear_enum;
  581. /* clock stabilization interrupt enable or disable */
  582. typedef enum
  583. {
  584. RCU_INT_IRC40KSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 8U), /*!< IRC40K stabilization interrupt */
  585. RCU_INT_LXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 9U), /*!< LXTAL stabilization interrupt */
  586. RCU_INT_IRC8MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 10U), /*!< IRC8M stabilization interrupt */
  587. RCU_INT_HXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 11U), /*!< HXTAL stabilization interrupt */
  588. RCU_INT_PLLSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 12U), /*!< PLL stabilization interrupt */
  589. #ifdef GD32F30X_CL
  590. RCU_INT_PLL1STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 13U), /*!< PLL1 stabilization interrupt */
  591. RCU_INT_PLL2STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 14U), /*!< PLL2 stabilization interrupt */
  592. #endif /* GD32F30X_CL */
  593. RCU_INT_IRC48MSTB = RCU_REGIDX_BIT(ADDINT_REG_OFFSET, 14U), /*!< internal 48 MHz RC oscillator stabilization interrupt */
  594. }rcu_int_enum;
  595. /* oscillator types */
  596. typedef enum
  597. {
  598. RCU_HXTAL = RCU_REGIDX_BIT(CTL_REG_OFFSET, 16U), /*!< HXTAL */
  599. RCU_LXTAL = RCU_REGIDX_BIT(BDCTL_REG_OFFSET, 0U), /*!< LXTAL */
  600. RCU_IRC8M = RCU_REGIDX_BIT(CTL_REG_OFFSET, 0U), /*!< IRC8M */
  601. RCU_IRC48M = RCU_REGIDX_BIT(ADDCTL_REG_OFFSET, 16U), /*!< IRC48M */
  602. RCU_IRC40K = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 0U), /*!< IRC40K */
  603. RCU_PLL_CK = RCU_REGIDX_BIT(CTL_REG_OFFSET, 24U), /*!< PLL */
  604. #ifdef GD32F30X_CL
  605. RCU_PLL1_CK = RCU_REGIDX_BIT(CTL_REG_OFFSET, 26U), /*!< PLL1 */
  606. RCU_PLL2_CK = RCU_REGIDX_BIT(CTL_REG_OFFSET, 28U), /*!< PLL2 */
  607. #endif /* GD32F30X_CL */
  608. }rcu_osci_type_enum;
  609. /* rcu clock frequency */
  610. typedef enum
  611. {
  612. CK_SYS = 0, /*!< system clock */
  613. CK_AHB, /*!< AHB clock */
  614. CK_APB1, /*!< APB1 clock */
  615. CK_APB2, /*!< APB2 clock */
  616. }rcu_clock_freq_enum;
  617. /* RCU_CFG0 register bit define */
  618. /* system clock source select */
  619. #define CFG0_SCS(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
  620. #define RCU_CKSYSSRC_IRC8M CFG0_SCS(0) /*!< system clock source select IRC8M */
  621. #define RCU_CKSYSSRC_HXTAL CFG0_SCS(1) /*!< system clock source select HXTAL */
  622. #define RCU_CKSYSSRC_PLL CFG0_SCS(2) /*!< system clock source select PLL */
  623. /* system clock source select status */
  624. #define CFG0_SCSS(regval) (BITS(2,3) & ((uint32_t)(regval) << 2))
  625. #define RCU_SCSS_IRC8M CFG0_SCSS(0) /*!< system clock source select IRC8M */
  626. #define RCU_SCSS_HXTAL CFG0_SCSS(1) /*!< system clock source select HXTAL */
  627. #define RCU_SCSS_PLL CFG0_SCSS(2) /*!< system clock source select PLLP */
  628. /* AHB prescaler selection */
  629. #define CFG0_AHBPSC(regval) (BITS(4,7) & ((uint32_t)(regval) << 4))
  630. #define RCU_AHB_CKSYS_DIV1 CFG0_AHBPSC(0) /*!< AHB prescaler select CK_SYS */
  631. #define RCU_AHB_CKSYS_DIV2 CFG0_AHBPSC(8) /*!< AHB prescaler select CK_SYS/2 */
  632. #define RCU_AHB_CKSYS_DIV4 CFG0_AHBPSC(9) /*!< AHB prescaler select CK_SYS/4 */
  633. #define RCU_AHB_CKSYS_DIV8 CFG0_AHBPSC(10) /*!< AHB prescaler select CK_SYS/8 */
  634. #define RCU_AHB_CKSYS_DIV16 CFG0_AHBPSC(11) /*!< AHB prescaler select CK_SYS/16 */
  635. #define RCU_AHB_CKSYS_DIV64 CFG0_AHBPSC(12) /*!< AHB prescaler select CK_SYS/64 */
  636. #define RCU_AHB_CKSYS_DIV128 CFG0_AHBPSC(13) /*!< AHB prescaler select CK_SYS/128 */
  637. #define RCU_AHB_CKSYS_DIV256 CFG0_AHBPSC(14) /*!< AHB prescaler select CK_SYS/256 */
  638. #define RCU_AHB_CKSYS_DIV512 CFG0_AHBPSC(15) /*!< AHB prescaler select CK_SYS/512 */
  639. /* APB1 prescaler selection */
  640. #define CFG0_APB1PSC(regval) (BITS(8,10) & ((uint32_t)(regval) << 8))
  641. #define RCU_APB1_CKAHB_DIV1 CFG0_APB1PSC(0) /*!< APB1 prescaler select CK_AHB */
  642. #define RCU_APB1_CKAHB_DIV2 CFG0_APB1PSC(4) /*!< APB1 prescaler select CK_AHB/2 */
  643. #define RCU_APB1_CKAHB_DIV4 CFG0_APB1PSC(5) /*!< APB1 prescaler select CK_AHB/4 */
  644. #define RCU_APB1_CKAHB_DIV8 CFG0_APB1PSC(6) /*!< APB1 prescaler select CK_AHB/8 */
  645. #define RCU_APB1_CKAHB_DIV16 CFG0_APB1PSC(7) /*!< APB1 prescaler select CK_AHB/16 */
  646. /* APB2 prescaler selection */
  647. #define CFG0_APB2PSC(regval) (BITS(11,13) & ((uint32_t)(regval) << 11))
  648. #define RCU_APB2_CKAHB_DIV1 CFG0_APB2PSC(0) /*!< APB2 prescaler select CK_AHB */
  649. #define RCU_APB2_CKAHB_DIV2 CFG0_APB2PSC(4) /*!< APB2 prescaler select CK_AHB/2 */
  650. #define RCU_APB2_CKAHB_DIV4 CFG0_APB2PSC(5) /*!< APB2 prescaler select CK_AHB/4 */
  651. #define RCU_APB2_CKAHB_DIV8 CFG0_APB2PSC(6) /*!< APB2 prescaler select CK_AHB/8 */
  652. #define RCU_APB2_CKAHB_DIV16 CFG0_APB2PSC(7) /*!< APB2 prescaler select CK_AHB/16 */
  653. /* ADC prescaler select */
  654. #define RCU_CKADC_CKAPB2_DIV2 ((uint32_t)0x00000000U) /*!< ADC prescaler select CK_APB2/2 */
  655. #define RCU_CKADC_CKAPB2_DIV4 ((uint32_t)0x00000001U) /*!< ADC prescaler select CK_APB2/4 */
  656. #define RCU_CKADC_CKAPB2_DIV6 ((uint32_t)0x00000002U) /*!< ADC prescaler select CK_APB2/6 */
  657. #define RCU_CKADC_CKAPB2_DIV8 ((uint32_t)0x00000003U) /*!< ADC prescaler select CK_APB2/8 */
  658. #define RCU_CKADC_CKAPB2_DIV12 ((uint32_t)0x00000005U) /*!< ADC prescaler select CK_APB2/12 */
  659. #define RCU_CKADC_CKAPB2_DIV16 ((uint32_t)0x00000007U) /*!< ADC prescaler select CK_APB2/16 */
  660. #define RCU_CKADC_CKAHB_DIV5 ((uint32_t)0x00000008U) /*!< ADC prescaler select CK_AHB/5 */
  661. #define RCU_CKADC_CKAHB_DIV6 ((uint32_t)0x00000009U) /*!< ADC prescaler select CK_AHB/6 */
  662. #define RCU_CKADC_CKAHB_DIV10 ((uint32_t)0x0000000AU) /*!< ADC prescaler select CK_AHB/10 */
  663. #define RCU_CKADC_CKAHB_DIV20 ((uint32_t)0x0000000BU) /*!< ADC prescaler select CK_AHB/20 */
  664. /* PLL clock source selection */
  665. #define RCU_PLLSRC_IRC8M_DIV2 ((uint32_t)0x00000000U) /*!< IRC8M/2 clock selected as source clock of PLL */
  666. #define RCU_PLLSRC_HXTAL_IRC48M RCU_CFG0_PLLSEL /*!< HXTAL or IRC48M selected as source clock of PLL */
  667. /* PLL clock multiplication factor */
  668. #define PLLMF_4 RCU_CFG0_PLLMF_4 /* bit 4 of PLLMF */
  669. #define PLLMF_5 RCU_CFG0_PLLMF_5 /* bit 5 of PLLMF */
  670. #define PLLMF_4_5 (PLLMF_4 | PLLMF_5) /* bit 4 and 5 of PLLMF */
  671. #define CFG0_PLLMF(regval) (BITS(18,21) & ((uint32_t)(regval) << 18))
  672. #define RCU_PLL_MUL2 CFG0_PLLMF(0) /*!< PLL source clock multiply by 2 */
  673. #define RCU_PLL_MUL3 CFG0_PLLMF(1) /*!< PLL source clock multiply by 3 */
  674. #define RCU_PLL_MUL4 CFG0_PLLMF(2) /*!< PLL source clock multiply by 4 */
  675. #define RCU_PLL_MUL5 CFG0_PLLMF(3) /*!< PLL source clock multiply by 5 */
  676. #define RCU_PLL_MUL6 CFG0_PLLMF(4) /*!< PLL source clock multiply by 6 */
  677. #define RCU_PLL_MUL7 CFG0_PLLMF(5) /*!< PLL source clock multiply by 7 */
  678. #define RCU_PLL_MUL8 CFG0_PLLMF(6) /*!< PLL source clock multiply by 8 */
  679. #define RCU_PLL_MUL9 CFG0_PLLMF(7) /*!< PLL source clock multiply by 9 */
  680. #define RCU_PLL_MUL10 CFG0_PLLMF(8) /*!< PLL source clock multiply by 10 */
  681. #define RCU_PLL_MUL11 CFG0_PLLMF(9) /*!< PLL source clock multiply by 11 */
  682. #define RCU_PLL_MUL12 CFG0_PLLMF(10) /*!< PLL source clock multiply by 12 */
  683. #define RCU_PLL_MUL13 CFG0_PLLMF(11) /*!< PLL source clock multiply by 13 */
  684. #define RCU_PLL_MUL14 CFG0_PLLMF(12) /*!< PLL source clock multiply by 14 */
  685. #if(defined(GD32F30X_HD) || defined(GD32F30X_XD))
  686. #define RCU_PLL_MUL15 CFG0_PLLMF(13) /*!< PLL source clock multiply by 15 */
  687. #elif defined(GD32F30X_CL)
  688. #define RCU_PLL_MUL6_5 CFG0_PLLMF(13) /*!< PLL source clock multiply by 6.5 */
  689. #endif /* GD32F30X_HD and GD32F30X_XD */
  690. #define RCU_PLL_MUL16 CFG0_PLLMF(14) /*!< PLL source clock multiply by 16 */
  691. #define RCU_PLL_MUL17 (PLLMF_4 | CFG0_PLLMF(0)) /*!< PLL source clock multiply by 17 */
  692. #define RCU_PLL_MUL18 (PLLMF_4 | CFG0_PLLMF(1)) /*!< PLL source clock multiply by 18 */
  693. #define RCU_PLL_MUL19 (PLLMF_4 | CFG0_PLLMF(2)) /*!< PLL source clock multiply by 19 */
  694. #define RCU_PLL_MUL20 (PLLMF_4 | CFG0_PLLMF(3)) /*!< PLL source clock multiply by 20 */
  695. #define RCU_PLL_MUL21 (PLLMF_4 | CFG0_PLLMF(4)) /*!< PLL source clock multiply by 21 */
  696. #define RCU_PLL_MUL22 (PLLMF_4 | CFG0_PLLMF(5)) /*!< PLL source clock multiply by 22 */
  697. #define RCU_PLL_MUL23 (PLLMF_4 | CFG0_PLLMF(6)) /*!< PLL source clock multiply by 23 */
  698. #define RCU_PLL_MUL24 (PLLMF_4 | CFG0_PLLMF(7)) /*!< PLL source clock multiply by 24 */
  699. #define RCU_PLL_MUL25 (PLLMF_4 | CFG0_PLLMF(8)) /*!< PLL source clock multiply by 25 */
  700. #define RCU_PLL_MUL26 (PLLMF_4 | CFG0_PLLMF(9)) /*!< PLL source clock multiply by 26 */
  701. #define RCU_PLL_MUL27 (PLLMF_4 | CFG0_PLLMF(10)) /*!< PLL source clock multiply by 27 */
  702. #define RCU_PLL_MUL28 (PLLMF_4 | CFG0_PLLMF(11)) /*!< PLL source clock multiply by 28 */
  703. #define RCU_PLL_MUL29 (PLLMF_4 | CFG0_PLLMF(12)) /*!< PLL source clock multiply by 29 */
  704. #define RCU_PLL_MUL30 (PLLMF_4 | CFG0_PLLMF(13)) /*!< PLL source clock multiply by 30 */
  705. #define RCU_PLL_MUL31 (PLLMF_4 | CFG0_PLLMF(14)) /*!< PLL source clock multiply by 31 */
  706. #define RCU_PLL_MUL32 (PLLMF_4 | CFG0_PLLMF(15)) /*!< PLL source clock multiply by 32 */
  707. #define RCU_PLL_MUL33 (PLLMF_5 | CFG0_PLLMF(0)) /*!< PLL source clock multiply by 33 */
  708. #define RCU_PLL_MUL34 (PLLMF_5 | CFG0_PLLMF(1)) /*!< PLL source clock multiply by 34 */
  709. #define RCU_PLL_MUL35 (PLLMF_5 | CFG0_PLLMF(2)) /*!< PLL source clock multiply by 35 */
  710. #define RCU_PLL_MUL36 (PLLMF_5 | CFG0_PLLMF(3)) /*!< PLL source clock multiply by 36 */
  711. #define RCU_PLL_MUL37 (PLLMF_5 | CFG0_PLLMF(4)) /*!< PLL source clock multiply by 37 */
  712. #define RCU_PLL_MUL38 (PLLMF_5 | CFG0_PLLMF(5)) /*!< PLL source clock multiply by 38 */
  713. #define RCU_PLL_MUL39 (PLLMF_5 | CFG0_PLLMF(6)) /*!< PLL source clock multiply by 39 */
  714. #define RCU_PLL_MUL40 (PLLMF_5 | CFG0_PLLMF(7)) /*!< PLL source clock multiply by 40 */
  715. #define RCU_PLL_MUL41 (PLLMF_5 | CFG0_PLLMF(8)) /*!< PLL source clock multiply by 41 */
  716. #define RCU_PLL_MUL42 (PLLMF_5 | CFG0_PLLMF(9)) /*!< PLL source clock multiply by 42 */
  717. #define RCU_PLL_MUL43 (PLLMF_5 | CFG0_PLLMF(10)) /*!< PLL source clock multiply by 43 */
  718. #define RCU_PLL_MUL44 (PLLMF_5 | CFG0_PLLMF(11)) /*!< PLL source clock multiply by 44 */
  719. #define RCU_PLL_MUL45 (PLLMF_5 | CFG0_PLLMF(12)) /*!< PLL source clock multiply by 45 */
  720. #define RCU_PLL_MUL46 (PLLMF_5 | CFG0_PLLMF(13)) /*!< PLL source clock multiply by 46 */
  721. #define RCU_PLL_MUL47 (PLLMF_5 | CFG0_PLLMF(14)) /*!< PLL source clock multiply by 47 */
  722. #define RCU_PLL_MUL48 (PLLMF_5 | CFG0_PLLMF(15)) /*!< PLL source clock multiply by 48 */
  723. #define RCU_PLL_MUL49 (PLLMF_4_5 | CFG0_PLLMF(0)) /*!< PLL source clock multiply by 49 */
  724. #define RCU_PLL_MUL50 (PLLMF_4_5 | CFG0_PLLMF(1)) /*!< PLL source clock multiply by 50 */
  725. #define RCU_PLL_MUL51 (PLLMF_4_5 | CFG0_PLLMF(2)) /*!< PLL source clock multiply by 51 */
  726. #define RCU_PLL_MUL52 (PLLMF_4_5 | CFG0_PLLMF(3)) /*!< PLL source clock multiply by 52 */
  727. #define RCU_PLL_MUL53 (PLLMF_4_5 | CFG0_PLLMF(4)) /*!< PLL source clock multiply by 53 */
  728. #define RCU_PLL_MUL54 (PLLMF_4_5 | CFG0_PLLMF(5)) /*!< PLL source clock multiply by 54 */
  729. #define RCU_PLL_MUL55 (PLLMF_4_5 | CFG0_PLLMF(6)) /*!< PLL source clock multiply by 55 */
  730. #define RCU_PLL_MUL56 (PLLMF_4_5 | CFG0_PLLMF(7)) /*!< PLL source clock multiply by 56 */
  731. #define RCU_PLL_MUL57 (PLLMF_4_5 | CFG0_PLLMF(8)) /*!< PLL source clock multiply by 57 */
  732. #define RCU_PLL_MUL58 (PLLMF_4_5 | CFG0_PLLMF(9)) /*!< PLL source clock multiply by 58 */
  733. #define RCU_PLL_MUL59 (PLLMF_4_5 | CFG0_PLLMF(10)) /*!< PLL source clock multiply by 59 */
  734. #define RCU_PLL_MUL60 (PLLMF_4_5 | CFG0_PLLMF(11)) /*!< PLL source clock multiply by 60 */
  735. #define RCU_PLL_MUL61 (PLLMF_4_5 | CFG0_PLLMF(12)) /*!< PLL source clock multiply by 61 */
  736. #define RCU_PLL_MUL62 (PLLMF_4_5 | CFG0_PLLMF(13)) /*!< PLL source clock multiply by 62 */
  737. #define RCU_PLL_MUL63 (PLLMF_4_5 | CFG0_PLLMF(14)) /*!< PLL source clock multiply by 63 */
  738. #if(defined(GD32F30X_HD) || defined(GD32F30X_XD))
  739. #define USBPSC_2 RCU_CFG0_USBDPSC_2
  740. #elif defined(GD32F30X_CL)
  741. #define USBPSC_2 RCU_CFG0_USBFSPSC_2
  742. #endif /* GD32F30X_HD and GD32F30X_XD */
  743. /* USBD/USBFS prescaler select */
  744. #define CFG0_USBPSC(regval) (BITS(22,23) & ((uint32_t)(regval) << 22))
  745. #define RCU_CKUSB_CKPLL_DIV1_5 CFG0_USBPSC(0) /*!< USBD/USBFS prescaler select CK_PLL/1.5 */
  746. #define RCU_CKUSB_CKPLL_DIV1 CFG0_USBPSC(1) /*!< USBD/USBFS prescaler select CK_PLL/1 */
  747. #define RCU_CKUSB_CKPLL_DIV2_5 CFG0_USBPSC(2) /*!< USBD/USBFS prescaler select CK_PLL/2.5 */
  748. #define RCU_CKUSB_CKPLL_DIV2 CFG0_USBPSC(3) /*!< USBD/USBFS prescaler select CK_PLL/2 */
  749. #define RCU_CKUSB_CKPLL_DIV3 (USBPSC_2 |CFG0_USBPSC(0)) /*!< USBD/USBFS prescaler select CK_PLL/3 */
  750. #define RCU_CKUSB_CKPLL_DIV3_5 (USBPSC_2 |CFG0_USBPSC(1)) /*!< USBD/USBFS prescaler select CK_PLL/3.5 */
  751. #define RCU_CKUSB_CKPLL_DIV4 (USBPSC_2 |CFG0_USBPSC(2)) /*!< USBD/USBFS prescaler select CK_PLL/4 */
  752. /* CKOUT0 Clock source selection */
  753. #define CFG0_CKOUT0SEL(regval) (BITS(24,27) & ((uint32_t)(regval) << 24))
  754. #define RCU_CKOUT0SRC_NONE CFG0_CKOUT0SEL(0) /*!< no clock selected */
  755. #define RCU_CKOUT0SRC_CKSYS CFG0_CKOUT0SEL(4) /*!< system clock selected */
  756. #define RCU_CKOUT0SRC_IRC8M CFG0_CKOUT0SEL(5) /*!< internal 8M RC oscillator clock selected */
  757. #define RCU_CKOUT0SRC_HXTAL CFG0_CKOUT0SEL(6) /*!< high speed crystal oscillator clock (HXTAL) selected */
  758. #define RCU_CKOUT0SRC_CKPLL_DIV2 CFG0_CKOUT0SEL(7) /*!< CK_PLL/2 clock selected */
  759. #ifdef GD32F30X_CL
  760. #define RCU_CKOUT0SRC_CKPLL1 CFG0_CKOUT0SEL(8) /*!< CK_PLL1 clock selected */
  761. #define RCU_CKOUT0SRC_CKPLL2_DIV2 CFG0_CKOUT0SEL(9) /*!< CK_PLL2/2 clock selected */
  762. #define RCU_CKOUT0SRC_EXT1 CFG0_CKOUT0SEL(10) /*!< EXT1 selected, to provide the external clock for ENET */
  763. #define RCU_CKOUT0SRC_CKPLL2 CFG0_CKOUT0SEL(11) /*!< CK_PLL2 clock selected */
  764. #endif /* GD32F30X_CL */
  765. /* LXTAL drive capability */
  766. #define BDCTL_LXTALDRI(regval) (BITS(3,4) & ((uint32_t)(regval) << 3))
  767. #define RCU_LXTAL_LOWDRI BDCTL_LXTALDRI(0) /*!< lower driving capability */
  768. #define RCU_LXTAL_MED_LOWDRI BDCTL_LXTALDRI(1) /*!< medium low driving capability */
  769. #define RCU_LXTAL_MED_HIGHDRI BDCTL_LXTALDRI(2) /*!< medium high driving capability */
  770. #define RCU_LXTAL_HIGHDRI BDCTL_LXTALDRI(3) /*!< higher driving capability */
  771. /* RTC clock entry selection */
  772. #define BDCTL_RTCSRC(regval) (BITS(8,9) & ((uint32_t)(regval) << 8))
  773. #define RCU_RTCSRC_NONE BDCTL_RTCSRC(0) /*!< no clock selected */
  774. #define RCU_RTCSRC_LXTAL BDCTL_RTCSRC(1) /*!< RTC source clock select LXTAL */
  775. #define RCU_RTCSRC_IRC40K BDCTL_RTCSRC(2) /*!< RTC source clock select IRC40K */
  776. #define RCU_RTCSRC_HXTAL_DIV_128 BDCTL_RTCSRC(3) /*!< RTC source clock select HXTAL/128 */
  777. /* PREDV0 division factor */
  778. #define CFG1_PREDV0(regval) (BITS(0,3) & ((uint32_t)(regval) << 0))
  779. #define RCU_PREDV0_DIV1 CFG1_PREDV0(0) /*!< PREDV0 input source clock not divided */
  780. #define RCU_PREDV0_DIV2 CFG1_PREDV0(1) /*!< PREDV0 input source clock divided by 2 */
  781. #define RCU_PREDV0_DIV3 CFG1_PREDV0(2) /*!< PREDV0 input source clock divided by 3 */
  782. #define RCU_PREDV0_DIV4 CFG1_PREDV0(3) /*!< PREDV0 input source clock divided by 4 */
  783. #define RCU_PREDV0_DIV5 CFG1_PREDV0(4) /*!< PREDV0 input source clock divided by 5 */
  784. #define RCU_PREDV0_DIV6 CFG1_PREDV0(5) /*!< PREDV0 input source clock divided by 6 */
  785. #define RCU_PREDV0_DIV7 CFG1_PREDV0(6) /*!< PREDV0 input source clock divided by 7 */
  786. #define RCU_PREDV0_DIV8 CFG1_PREDV0(7) /*!< PREDV0 input source clock divided by 8 */
  787. #define RCU_PREDV0_DIV9 CFG1_PREDV0(8) /*!< PREDV0 input source clock divided by 9 */
  788. #define RCU_PREDV0_DIV10 CFG1_PREDV0(9) /*!< PREDV0 input source clock divided by 10 */
  789. #define RCU_PREDV0_DIV11 CFG1_PREDV0(10) /*!< PREDV0 input source clock divided by 11 */
  790. #define RCU_PREDV0_DIV12 CFG1_PREDV0(11) /*!< PREDV0 input source clock divided by 12 */
  791. #define RCU_PREDV0_DIV13 CFG1_PREDV0(12) /*!< PREDV0 input source clock divided by 13 */
  792. #define RCU_PREDV0_DIV14 CFG1_PREDV0(13) /*!< PREDV0 input source clock divided by 14 */
  793. #define RCU_PREDV0_DIV15 CFG1_PREDV0(14) /*!< PREDV0 input source clock divided by 15 */
  794. #define RCU_PREDV0_DIV16 CFG1_PREDV0(15) /*!< PREDV0 input source clock divided by 16 */
  795. /* PREDV1 division factor */
  796. #define CFG1_PREDV1(regval) (BITS(4,7) & ((uint32_t)(regval) << 4))
  797. #define RCU_PREDV1_DIV1 CFG1_PREDV1(0) /*!< PREDV1 input source clock not divided */
  798. #define RCU_PREDV1_DIV2 CFG1_PREDV1(1) /*!< PREDV1 input source clock divided by 2 */
  799. #define RCU_PREDV1_DIV3 CFG1_PREDV1(2) /*!< PREDV1 input source clock divided by 3 */
  800. #define RCU_PREDV1_DIV4 CFG1_PREDV1(3) /*!< PREDV1 input source clock divided by 4 */
  801. #define RCU_PREDV1_DIV5 CFG1_PREDV1(4) /*!< PREDV1 input source clock divided by 5 */
  802. #define RCU_PREDV1_DIV6 CFG1_PREDV1(5) /*!< PREDV1 input source clock divided by 6 */
  803. #define RCU_PREDV1_DIV7 CFG1_PREDV1(6) /*!< PREDV1 input source clock divided by 7 */
  804. #define RCU_PREDV1_DIV8 CFG1_PREDV1(7) /*!< PREDV1 input source clock divided by 8 */
  805. #define RCU_PREDV1_DIV9 CFG1_PREDV1(8) /*!< PREDV1 input source clock divided by 9 */
  806. #define RCU_PREDV1_DIV10 CFG1_PREDV1(9) /*!< PREDV1 input source clock divided by 10 */
  807. #define RCU_PREDV1_DIV11 CFG1_PREDV1(10) /*!< PREDV1 input source clock divided by 11 */
  808. #define RCU_PREDV1_DIV12 CFG1_PREDV1(11) /*!< PREDV1 input source clock divided by 12 */
  809. #define RCU_PREDV1_DIV13 CFG1_PREDV1(12) /*!< PREDV1 input source clock divided by 13 */
  810. #define RCU_PREDV1_DIV14 CFG1_PREDV1(13) /*!< PREDV1 input source clock divided by 14 */
  811. #define RCU_PREDV1_DIV15 CFG1_PREDV1(14) /*!< PREDV1 input source clock divided by 15 */
  812. #define RCU_PREDV1_DIV16 CFG1_PREDV1(15) /*!< PREDV1 input source clock divided by 16 */
  813. /* PLL1 clock multiplication factor */
  814. #define CFG1_PLL1MF(regval) (BITS(8,11) & ((uint32_t)(regval) << 8))
  815. #define RCU_PLL1_MUL8 CFG1_PLL1MF(6) /*!< PLL1 source clock multiply by 8 */
  816. #define RCU_PLL1_MUL9 CFG1_PLL1MF(7) /*!< PLL1 source clock multiply by 9 */
  817. #define RCU_PLL1_MUL10 CFG1_PLL1MF(8) /*!< PLL1 source clock multiply by 10 */
  818. #define RCU_PLL1_MUL11 CFG1_PLL1MF(9) /*!< PLL1 source clock multiply by 11 */
  819. #define RCU_PLL1_MUL12 CFG1_PLL1MF(10) /*!< PLL1 source clock multiply by 12 */
  820. #define RCU_PLL1_MUL13 CFG1_PLL1MF(11) /*!< PLL1 source clock multiply by 13 */
  821. #define RCU_PLL1_MUL14 CFG1_PLL1MF(12) /*!< PLL1 source clock multiply by 14 */
  822. #define RCU_PLL1_MUL15 CFG1_PLL1MF(13) /*!< PLL1 source clock multiply by 15 */
  823. #define RCU_PLL1_MUL16 CFG1_PLL1MF(14) /*!< PLL1 source clock multiply by 16 */
  824. #define RCU_PLL1_MUL20 CFG1_PLL1MF(15) /*!< PLL1 source clock multiply by 20 */
  825. /* PLL2 clock multiplication factor */
  826. #define PLL2MF_4 RCU_CFG1_PLL2MF_4 /* bit 4 of PLL2MF */
  827. #define CFG1_PLL2MF(regval) (BITS(12,15) & ((uint32_t)(regval) << 12))
  828. #define RCU_PLL2_MUL8 CFG1_PLL2MF(6) /*!< PLL2 source clock multiply by 8 */
  829. #define RCU_PLL2_MUL9 CFG1_PLL2MF(7) /*!< PLL2 source clock multiply by 9 */
  830. #define RCU_PLL2_MUL10 CFG1_PLL2MF(8) /*!< PLL2 source clock multiply by 10 */
  831. #define RCU_PLL2_MUL11 CFG1_PLL2MF(9) /*!< PLL2 source clock multiply by 11 */
  832. #define RCU_PLL2_MUL12 CFG1_PLL2MF(10) /*!< PLL2 source clock multiply by 12 */
  833. #define RCU_PLL2_MUL13 CFG1_PLL2MF(11) /*!< PLL2 source clock multiply by 13 */
  834. #define RCU_PLL2_MUL14 CFG1_PLL2MF(12) /*!< PLL2 source clock multiply by 14 */
  835. #define RCU_PLL2_MUL15 CFG1_PLL2MF(13) /*!< PLL2 source clock multiply by 15 */
  836. #define RCU_PLL2_MUL16 CFG1_PLL2MF(14) /*!< PLL2 source clock multiply by 16 */
  837. #define RCU_PLL2_MUL20 CFG1_PLL2MF(15) /*!< PLL2 source clock multiply by 20 */
  838. #define RCU_PLL2_MUL18 (PLL2MF_4 | CFG1_PLL2MF(0)) /*!< PLL2 source clock multiply by 18 */
  839. #define RCU_PLL2_MUL19 (PLL2MF_4 | CFG1_PLL2MF(1)) /*!< PLL2 source clock multiply by 19 */
  840. #define RCU_PLL2_MUL21 (PLL2MF_4 | CFG1_PLL2MF(3)) /*!< PLL2 source clock multiply by 21 */
  841. #define RCU_PLL2_MUL22 (PLL2MF_4 | CFG1_PLL2MF(4)) /*!< PLL2 source clock multiply by 22 */
  842. #define RCU_PLL2_MUL23 (PLL2MF_4 | CFG1_PLL2MF(5)) /*!< PLL2 source clock multiply by 23 */
  843. #define RCU_PLL2_MUL24 (PLL2MF_4 | CFG1_PLL2MF(6)) /*!< PLL2 source clock multiply by 24 */
  844. #define RCU_PLL2_MUL25 (PLL2MF_4 | CFG1_PLL2MF(7)) /*!< PLL2 source clock multiply by 25 */
  845. #define RCU_PLL2_MUL26 (PLL2MF_4 | CFG1_PLL2MF(8)) /*!< PLL2 source clock multiply by 26 */
  846. #define RCU_PLL2_MUL27 (PLL2MF_4 | CFG1_PLL2MF(9)) /*!< PLL2 source clock multiply by 27 */
  847. #define RCU_PLL2_MUL28 (PLL2MF_4 | CFG1_PLL2MF(10)) /*!< PLL2 source clock multiply by 28 */
  848. #define RCU_PLL2_MUL29 (PLL2MF_4 | CFG1_PLL2MF(11)) /*!< PLL2 source clock multiply by 29 */
  849. #define RCU_PLL2_MUL30 (PLL2MF_4 | CFG1_PLL2MF(12)) /*!< PLL2 source clock multiply by 30 */
  850. #define RCU_PLL2_MUL31 (PLL2MF_4 | CFG1_PLL2MF(13)) /*!< PLL2 source clock multiply by 31 */
  851. #define RCU_PLL2_MUL32 (PLL2MF_4 | CFG1_PLL2MF(14)) /*!< PLL2 source clock multiply by 32 */
  852. #define RCU_PLL2_MUL40 (PLL2MF_4 | CFG1_PLL2MF(15)) /*!< PLL2 source clock multiply by 40 */
  853. #ifdef GD32F30X_CL
  854. /* PREDV0 input clock source selection */
  855. #define RCU_PREDV0SRC_HXTAL_IRC48M ((uint32_t)0x00000000U) /*!< HXTAL or IRC48M selected as PREDV0 input source clock */
  856. #define RCU_PREDV0SRC_CKPLL1 RCU_CFG1_PREDV0SEL /*!< CK_PLL1 selected as PREDV0 input source clock */
  857. /* I2S1 clock source selection */
  858. #define RCU_I2S1SRC_CKSYS ((uint32_t)0x00000000U) /*!< system clock selected as I2S1 source clock */
  859. #define RCU_I2S1SRC_CKPLL2_MUL2 RCU_CFG1_I2S1SEL /*!< (CK_PLL2 x 2) selected as I2S1 source clock */
  860. /* I2S2 clock source selection */
  861. #define RCU_I2S2SRC_CKSYS ((uint32_t)0x00000000U) /*!< system clock selected as I2S2 source clock */
  862. #define RCU_I2S2SRC_CKPLL2_MUL2 RCU_CFG1_I2S2SEL /*!< (CK_PLL2 x 2) selected as I2S2 source clock */
  863. #endif /* GD32F30X_CL */
  864. /* PLL input clock source selection */
  865. #define RCU_PLLPRESRC_HXTAL ((uint32_t)0x00000000U) /*!< HXTAL selected as PLL source clock */
  866. #define RCU_PLLPRESRC_IRC48M RCU_CFG1_PLLPRESEL /*!< CK_PLL selected as PREDV0 input source clock */
  867. /* deep-sleep mode voltage */
  868. #define DSV_DSLPVS(regval) (BITS(0,2) & ((uint32_t)(regval) << 0))
  869. #define RCU_DEEPSLEEP_V_0 DSV_DSLPVS(0) /*!< core voltage is default value in deep-sleep mode */
  870. #define RCU_DEEPSLEEP_V_1 DSV_DSLPVS(1) /*!< core voltage is (default value-0.1)V in deep-sleep mode(customers are not recommended to use it) */
  871. #define RCU_DEEPSLEEP_V_2 DSV_DSLPVS(2) /*!< core voltage is (default value-0.2)V in deep-sleep mode(customers are not recommended to use it) */
  872. #define RCU_DEEPSLEEP_V_3 DSV_DSLPVS(3) /*!< core voltage is (default value-0.3)V in deep-sleep mode(customers are not recommended to use it) */
  873. /* 48MHz clock selection */
  874. #define RCU_CK48MSRC_CKPLL ((uint32_t)0x00000000U) /*!< use CK_PLL clock */
  875. #define RCU_CK48MSRC_IRC48M RCU_ADDCTL_CK48MSEL /*!< select IRC48M clock */
  876. /* function declarations */
  877. /* peripherals clock configure functions */
  878. /* deinitialize the RCU */
  879. void rcu_deinit(void);
  880. /* enable the peripherals clock */
  881. void rcu_periph_clock_enable(rcu_periph_enum periph);
  882. /* disable the peripherals clock */
  883. void rcu_periph_clock_disable(rcu_periph_enum periph);
  884. /* enable the peripherals clock when sleep mode */
  885. void rcu_periph_clock_sleep_enable(rcu_periph_sleep_enum periph);
  886. /* disable the peripherals clock when sleep mode */
  887. void rcu_periph_clock_sleep_disable(rcu_periph_sleep_enum periph);
  888. /* reset the peripherals */
  889. void rcu_periph_reset_enable(rcu_periph_reset_enum periph_reset);
  890. /* disable reset the peripheral */
  891. void rcu_periph_reset_disable(rcu_periph_reset_enum periph_reset);
  892. /* reset the BKP domain */
  893. void rcu_bkp_reset_enable(void);
  894. /* disable the BKP domain reset */
  895. void rcu_bkp_reset_disable(void);
  896. /* system and peripherals clock source, system reset configure functions */
  897. /* configure the system clock source */
  898. void rcu_system_clock_source_config(uint32_t ck_sys);
  899. /* get the system clock source */
  900. uint32_t rcu_system_clock_source_get(void);
  901. /* configure the AHB prescaler selection */
  902. void rcu_ahb_clock_config(uint32_t ck_ahb);
  903. /* configure the APB1 prescaler selection */
  904. void rcu_apb1_clock_config(uint32_t ck_apb1);
  905. /* configure the APB2 prescaler selection */
  906. void rcu_apb2_clock_config(uint32_t ck_apb2);
  907. /* configure the CK_OUT0 clock source and divider */
  908. void rcu_ckout0_config(uint32_t ckout0_src);
  909. /* configure the PLL clock source selection and PLL multiply factor */
  910. void rcu_pll_config(uint32_t pll_src, uint32_t pll_mul);
  911. /* configure the PLL clock source preselection */
  912. void rcu_pllpresel_config(uint32_t pll_presel);
  913. #if(defined(GD32F30X_HD) || defined(GD32F30X_XD))
  914. /* configure the PREDV0 division factor and clock source */
  915. void rcu_predv0_config(uint32_t predv0_div);
  916. #elif defined(GD32F30X_CL)
  917. /* configure the PREDV0 division factor and clock source */
  918. void rcu_predv0_config(uint32_t predv0_source, uint32_t predv0_div);
  919. /* configure the PREDV1 division factor */
  920. void rcu_predv1_config(uint32_t predv1_div);
  921. /* configure the PLL1 clock */
  922. void rcu_pll1_config(uint32_t pll_mul);
  923. /* configure the PLL2 clock */
  924. void rcu_pll2_config(uint32_t pll_mul);
  925. #endif /* GD32F30X_HD and GD32F30X_XD */
  926. /* configure the ADC division factor */
  927. void rcu_adc_clock_config(uint32_t adc_psc);
  928. /* configure the USBD/USBFS prescaler factor */
  929. void rcu_usb_clock_config(uint32_t usb_psc);
  930. /* configure the RTC clock source selection */
  931. void rcu_rtc_clock_config(uint32_t rtc_clock_source);
  932. #ifdef GD32F30X_CL
  933. /* configure the I2S1 clock source selection */
  934. void rcu_i2s1_clock_config(uint32_t i2s_clock_source);
  935. /* configure the I2S2 clock source selection */
  936. void rcu_i2s2_clock_config(uint32_t i2s_clock_source);
  937. #endif /* GD32F30X_CL */
  938. /* configure the CK48M clock selection */
  939. void rcu_ck48m_clock_config(uint32_t ck48m_clock_source);
  940. /* get the clock stabilization and periphral reset flags */
  941. FlagStatus rcu_flag_get(rcu_flag_enum flag);
  942. /* clear the reset flag */
  943. void rcu_all_reset_flag_clear(void);
  944. /* get the clock stabilization interrupt and ckm flags */
  945. FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag);
  946. /* clear the interrupt flags */
  947. void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag);
  948. /* enable the stabilization interrupt */
  949. void rcu_interrupt_enable(rcu_int_enum interrupt);
  950. /* disable the stabilization interrupt */
  951. void rcu_interrupt_disable(rcu_int_enum interrupt);
  952. /* LXTAL, IRC8M, PLL and other oscillator configure functions */
  953. /* configure the LXTAL drive capability */
  954. void rcu_lxtal_drive_capability_config(uint32_t lxtal_dricap);
  955. /* wait for oscillator stabilization flags is SET or oscillator startup is timeout */
  956. ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci);
  957. /* turn on the oscillator */
  958. void rcu_osci_on(rcu_osci_type_enum osci);
  959. /* turn off the oscillator */
  960. void rcu_osci_off(rcu_osci_type_enum osci);
  961. /* enable the oscillator bypass mode, HXTALEN or LXTALEN must be reset before it */
  962. void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci);
  963. /* disable the oscillator bypass mode, HXTALEN or LXTALEN must be reset before it */
  964. void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci);
  965. /* set the IRC8M adjust value */
  966. void rcu_irc8m_adjust_value_set(uint32_t irc8m_adjval);
  967. /* clock monitor configure functions */
  968. /* enable the HXTAL clock monitor */
  969. void rcu_hxtal_clock_monitor_enable(void);
  970. /* disable the HXTAL clock monitor */
  971. void rcu_hxtal_clock_monitor_disable(void);
  972. /* voltage configure and clock frequency get functions */
  973. /* set the deep sleep mode voltage */
  974. void rcu_deepsleep_voltage_set(uint32_t dsvol);
  975. /* get the system clock, bus and peripheral clock frequency */
  976. uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock);
  977. /* flag & interrupt functions */
  978. /* get the clock stabilization and periphral reset flags */
  979. FlagStatus rcu_flag_get(rcu_flag_enum flag);
  980. /* clear the reset flag */
  981. void rcu_all_reset_flag_clear(void);
  982. /* get the clock stabilization interrupt and ckm flags */
  983. FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag);
  984. /* clear the interrupt flags */
  985. void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag);
  986. /* enable the stabilization interrupt */
  987. void rcu_interrupt_enable(rcu_int_enum interrupt);
  988. /* disable the stabilization interrupt */
  989. void rcu_interrupt_disable(rcu_int_enum interrupt);
  990. #endif /* GD32F30X_RCU_H */