gd32f10x_rcu.h 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. /*!
  2. \file gd32f10x_rcu.h
  3. \brief definitions for the RCU
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. \version 2020-09-30, V2.2.0, firmware for GD32F10x
  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 GD32F10X_RCU_H
  33. #define GD32F10X_RCU_H
  34. #include "gd32f10x.h"
  35. /* RCU definitions */
  36. #define RCU RCU_BASE
  37. /* registers definitions */
  38. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_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_DSV REG32(RCU + 0x34U) /*!< deep-sleep mode voltage register */
  50. #elif defined(GD32F10X_CL)
  51. #define RCU_CTL REG32(RCU + 0x00U) /*!< control register */
  52. #define RCU_CFG0 REG32(RCU + 0x04U) /*!< clock configuration register 0 */
  53. #define RCU_INT REG32(RCU + 0x08U) /*!< clock interrupt register */
  54. #define RCU_APB2RST REG32(RCU + 0x0CU) /*!< APB2 reset register */
  55. #define RCU_APB1RST REG32(RCU + 0x10U) /*!< APB1 reset register */
  56. #define RCU_AHBEN REG32(RCU + 0x14U) /*!< AHB1 enable register */
  57. #define RCU_APB2EN REG32(RCU + 0x18U) /*!< APB2 enable register */
  58. #define RCU_APB1EN REG32(RCU + 0x1CU) /*!< APB1 enable register */
  59. #define RCU_BDCTL REG32(RCU + 0x20U) /*!< backup domain control register */
  60. #define RCU_RSTSCK REG32(RCU + 0x24U) /*!< reset source / clock register */
  61. #define RCU_AHBRST REG32(RCU + 0x28U) /*!< AHB reset register */
  62. #define RCU_CFG1 REG32(RCU + 0x2CU) /*!< clock configuration register 1 */
  63. #define RCU_DSV REG32(RCU + 0x34U) /*!< deep-sleep mode voltage register */
  64. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  65. /* bits definitions */
  66. /* RCU_CTL */
  67. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  68. #define RCU_CTL_IRC8MEN BIT(0) /*!< internal high speed oscillator enable */
  69. #define RCU_CTL_IRC8MSTB BIT(1) /*!< IRC8M high speed internal oscillator stabilization flag */
  70. #define RCU_CTL_IRC8MADJ BITS(3,7) /*!< high speed internal oscillator clock trim adjust value */
  71. #define RCU_CTL_IRC8MCALIB BITS(8,15) /*!< high speed internal oscillator calibration value register */
  72. #define RCU_CTL_HXTALEN BIT(16) /*!< external high speed oscillator enable */
  73. #define RCU_CTL_HXTALSTB BIT(17) /*!< external crystal oscillator clock stabilization flag */
  74. #define RCU_CTL_HXTALBPS BIT(18) /*!< external crystal oscillator clock bypass mode enable */
  75. #define RCU_CTL_CKMEN BIT(19) /*!< HXTAL clock monitor enable */
  76. #define RCU_CTL_PLLEN BIT(24) /*!< PLL enable */
  77. #define RCU_CTL_PLLSTB BIT(25) /*!< PLL clock stabilization flag */
  78. #elif defined(GD32F10X_CL)
  79. #define RCU_CTL_IRC8MEN BIT(0) /*!< internal high speed oscillator enable */
  80. #define RCU_CTL_IRC8MSTB BIT(1) /*!< IRC8M high speed internal oscillator stabilization flag */
  81. #define RCU_CTL_IRC8MADJ BITS(3,7) /*!< high speed internal oscillator clock trim adjust value */
  82. #define RCU_CTL_IRC8MCALIB BITS(8,15) /*!< high speed internal oscillator calibration value register */
  83. #define RCU_CTL_HXTALEN BIT(16) /*!< external high speed oscillator enable */
  84. #define RCU_CTL_HXTALSTB BIT(17) /*!< external crystal oscillator clock stabilization flag */
  85. #define RCU_CTL_HXTALBPS BIT(18) /*!< external crystal oscillator clock bypass mode enable */
  86. #define RCU_CTL_CKMEN BIT(19) /*!< HXTAL clock monitor enable */
  87. #define RCU_CTL_PLLEN BIT(24) /*!< PLL enable */
  88. #define RCU_CTL_PLLSTB BIT(25) /*!< PLL clock stabilization flag */
  89. #define RCU_CTL_PLL1EN BIT(26) /*!< PLL1 enable */
  90. #define RCU_CTL_PLL1STB BIT(27) /*!< PLL1 clock stabilization flag */
  91. #define RCU_CTL_PLL2EN BIT(28) /*!< PLL2 enable */
  92. #define RCU_CTL_PLL2STB BIT(29) /*!< PLL2 clock stabilization flag */
  93. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  94. /* RCU_CFG0 */
  95. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  96. #define RCU_CFG0_SCS BITS(0,1) /*!< system clock switch */
  97. #define RCU_CFG0_SCSS BITS(2,3) /*!< system clock switch status */
  98. #define RCU_CFG0_AHBPSC BITS(4,7) /*!< AHB prescaler selection */
  99. #define RCU_CFG0_APB1PSC BITS(8,10) /*!< APB1 prescaler selection */
  100. #define RCU_CFG0_APB2PSC BITS(11,13) /*!< APB2 prescaler selection */
  101. #define RCU_CFG0_ADCPSC BITS(14,15) /*!< ADC prescaler selection */
  102. #define RCU_CFG0_PLLSEL BIT(16) /*!< PLL clock source selection */
  103. #define RCU_CFG0_PREDV0 BIT(17) /*!< PREDV0 division factor */
  104. #define RCU_CFG0_PLLMF BITS(18,21) /*!< PLL clock multiplication factor */
  105. #define RCU_CFG0_USBDPSC BITS(22,23) /*!< USBD clock prescaler selection */
  106. #define RCU_CFG0_CKOUT0SEL BITS(24,26) /*!< CKOUT0 clock source selection */
  107. #define RCU_CFG0_PLLMF_4 BIT(27) /*!< bit 4 of PLLMF */
  108. #define RCU_CFG0_ADCPSC_2 BIT(28) /*!< bit 2 of ADCPSC */
  109. #elif defined(GD32F10X_CL)
  110. #define RCU_CFG0_SCS BITS(0,1) /*!< system clock switch */
  111. #define RCU_CFG0_SCSS BITS(2,3) /*!< system clock switch status */
  112. #define RCU_CFG0_AHBPSC BITS(4,7) /*!< AHB prescaler selection */
  113. #define RCU_CFG0_APB1PSC BITS(8,10) /*!< APB1 prescaler selection */
  114. #define RCU_CFG0_APB2PSC BITS(11,13) /*!< APB2 prescaler selection */
  115. #define RCU_CFG0_ADCPSC BITS(14,15) /*!< ADC prescaler selection */
  116. #define RCU_CFG0_PLLSEL BIT(16) /*!< PLL clock source selection */
  117. #define RCU_CFG0_PREDV0_LSB BIT(17) /*!< the LSB of PREDV0 division factor */
  118. #define RCU_CFG0_PLLMF BITS(18,21) /*!< PLL clock multiplication factor */
  119. #define RCU_CFG0_USBFSPSC BITS(22,23) /*!< USBFS clock prescaler selection */
  120. #define RCU_CFG0_CKOUT0SEL BITS(24,27) /*!< CKOUT0 clock source selection */
  121. #define RCU_CFG0_ADCPSC_2 BIT(28) /*!< bit 2 of ADCPSC */
  122. #define RCU_CFG0_PLLMF_4 BIT(29) /*!< bit 4 of PLLMF */
  123. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  124. /* RCU_INT */
  125. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  126. #define RCU_INT_IRC40KSTBIF BIT(0) /*!< IRC40K stabilization interrupt flag */
  127. #define RCU_INT_LXTALSTBIF BIT(1) /*!< LXTAL stabilization interrupt flag */
  128. #define RCU_INT_IRC8MSTBIF BIT(2) /*!< IRC8M stabilization interrupt flag */
  129. #define RCU_INT_HXTALSTBIF BIT(3) /*!< HXTAL stabilization interrupt flag */
  130. #define RCU_INT_PLLSTBIF BIT(4) /*!< PLL stabilization interrupt flag */
  131. #define RCU_INT_CKMIF BIT(7) /*!< HXTAL clock stuck interrupt flag */
  132. #define RCU_INT_IRC40KSTBIE BIT(8) /*!< IRC40K stabilization interrupt enable */
  133. #define RCU_INT_LXTALSTBIE BIT(9) /*!< LXTAL stabilization interrupt enable */
  134. #define RCU_INT_IRC8MSTBIE BIT(10) /*!< IRC8M stabilization interrupt enable */
  135. #define RCU_INT_HXTALSTBIE BIT(11) /*!< HXTAL stabilization interrupt enable */
  136. #define RCU_INT_PLLSTBIE BIT(12) /*!< PLL stabilization interrupt enable */
  137. #define RCU_INT_IRC40KSTBIC BIT(16) /*!< IRC40K Stabilization interrupt clear */
  138. #define RCU_INT_LXTALSTBIC BIT(17) /*!< LXTAL Stabilization interrupt clear */
  139. #define RCU_INT_IRC8MSTBIC BIT(18) /*!< IRC8M Stabilization interrupt clear */
  140. #define RCU_INT_HXTALSTBIC BIT(19) /*!< HXTAL Stabilization interrupt clear */
  141. #define RCU_INT_PLLSTBIC BIT(20) /*!< PLL stabilization interrupt clear */
  142. #define RCU_INT_CKMIC BIT(23) /*!< HXTAL clock stuck interrupt clear */
  143. #elif defined(GD32F10X_CL)
  144. #define RCU_INT_IRC40KSTBIF BIT(0) /*!< IRC40K stabilization interrupt flag */
  145. #define RCU_INT_LXTALSTBIF BIT(1) /*!< LXTAL stabilization interrupt flag */
  146. #define RCU_INT_IRC8MSTBIF BIT(2) /*!< IRC8M stabilization interrupt flag */
  147. #define RCU_INT_HXTALSTBIF BIT(3) /*!< HXTAL stabilization interrupt flag */
  148. #define RCU_INT_PLLSTBIF BIT(4) /*!< PLL stabilization interrupt flag */
  149. #define RCU_INT_PLL1STBIF BIT(5) /*!< PLL1 stabilization interrupt flag */
  150. #define RCU_INT_PLL2STBIF BIT(6) /*!< PLL2 stabilization interrupt flag */
  151. #define RCU_INT_CKMIF BIT(7) /*!< HXTAL clock stuck interrupt flag */
  152. #define RCU_INT_IRC40KSTBIE BIT(8) /*!< IRC40K stabilization interrupt enable */
  153. #define RCU_INT_LXTALSTBIE BIT(9) /*!< LXTAL stabilization interrupt enable */
  154. #define RCU_INT_IRC8MSTBIE BIT(10) /*!< IRC8M stabilization interrupt enable */
  155. #define RCU_INT_HXTALSTBIE BIT(11) /*!< HXTAL stabilization interrupt enable */
  156. #define RCU_INT_PLLSTBIE BIT(12) /*!< PLL stabilization interrupt enable */
  157. #define RCU_INT_PLL1STBIE BIT(13) /*!< PLL1 stabilization interrupt enable */
  158. #define RCU_INT_PLL2STBIE BIT(14) /*!< PLL2 stabilization interrupt enable */
  159. #define RCU_INT_IRC40KSTBIC BIT(16) /*!< IRC40K stabilization interrupt clear */
  160. #define RCU_INT_LXTALSTBIC BIT(17) /*!< LXTAL stabilization interrupt clear */
  161. #define RCU_INT_IRC8MSTBIC BIT(18) /*!< IRC8M stabilization interrupt clear */
  162. #define RCU_INT_HXTALSTBIC BIT(19) /*!< HXTAL stabilization interrupt clear */
  163. #define RCU_INT_PLLSTBIC BIT(20) /*!< PLL stabilization interrupt clear */
  164. #define RCU_INT_PLL1STBIC BIT(21) /*!< PLL1 stabilization interrupt clear */
  165. #define RCU_INT_PLL2STBIC BIT(22) /*!< PLL2 stabilization interrupt clear */
  166. #define RCU_INT_CKMIC BIT(23) /*!< HXTAL clock stuck interrupt clear */
  167. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  168. /* RCU_APB2RST */
  169. #define RCU_APB2RST_AFRST BIT(0) /*!< alternate function I/O reset */
  170. #define RCU_APB2RST_PARST BIT(2) /*!< GPIO port A reset */
  171. #define RCU_APB2RST_PBRST BIT(3) /*!< GPIO port B reset */
  172. #define RCU_APB2RST_PCRST BIT(4) /*!< GPIO port C reset */
  173. #define RCU_APB2RST_PDRST BIT(5) /*!< GPIO port D reset */
  174. #define RCU_APB2RST_PERST BIT(6) /*!< GPIO port E reset */
  175. #define RCU_APB2RST_PFRST BIT(7) /*!< GPIO port F reset */
  176. #define RCU_APB2RST_PGRST BIT(8) /*!< GPIO port G reset */
  177. #define RCU_APB2RST_ADC0RST BIT(9) /*!< ADC0 reset */
  178. #define RCU_APB2RST_ADC1RST BIT(10) /*!< ADC1 reset */
  179. #define RCU_APB2RST_TIMER0RST BIT(11) /*!< TIMER0 reset */
  180. #define RCU_APB2RST_SPI0RST BIT(12) /*!< SPI0 reset */
  181. #define RCU_APB2RST_TIMER7RST BIT(13) /*!< TIMER7 reset */
  182. #define RCU_APB2RST_USART0RST BIT(14) /*!< USART0 reset */
  183. #ifndef GD32F10X_CL
  184. #define RCU_APB2RST_ADC2RST BIT(15) /*!< ADC2 reset */
  185. #endif /* GD32F10X_CL */
  186. #ifdef GD32F10X_XD
  187. #define RCU_APB2RST_TIMER8RST BIT(19) /*!< TIMER8 reset */
  188. #define RCU_APB2RST_TIMER9RST BIT(20) /*!< TIMER9 reset */
  189. #define RCU_APB2RST_TIMER10RST BIT(21) /*!< TIMER10 reset */
  190. #endif /* GD32F10X_XD */
  191. /* RCU_APB1RST */
  192. #define RCU_APB1RST_TIMER1RST BIT(0) /*!< TIMER1 reset */
  193. #define RCU_APB1RST_TIMER2RST BIT(1) /*!< TIMER2 reset */
  194. #define RCU_APB1RST_TIMER3RST BIT(2) /*!< TIMER3 reset */
  195. #define RCU_APB1RST_TIMER4RST BIT(3) /*!< TIMER4 reset */
  196. #define RCU_APB1RST_TIMER5RST BIT(4) /*!< TIMER5 reset */
  197. #define RCU_APB1RST_TIMER6RST BIT(5) /*!< TIMER6 reset */
  198. #ifdef GD32F10X_XD
  199. #define RCU_APB1RST_TIMER11RST BIT(6) /*!< TIMER11 reset */
  200. #define RCU_APB1RST_TIMER12RST BIT(7) /*!< TIMER12 reset */
  201. #define RCU_APB1RST_TIMER13RST BIT(8) /*!< TIMER13 reset */
  202. #endif /* GD32F10X_XD */
  203. #define RCU_APB1RST_WWDGTRST BIT(11) /*!< WWDGT reset */
  204. #define RCU_APB1RST_SPI1RST BIT(14) /*!< SPI1 reset */
  205. #define RCU_APB1RST_SPI2RST BIT(15) /*!< SPI2 reset */
  206. #define RCU_APB1RST_USART1RST BIT(17) /*!< USART1 reset */
  207. #define RCU_APB1RST_USART2RST BIT(18) /*!< USART2 reset */
  208. #define RCU_APB1RST_UART3RST BIT(19) /*!< UART3 reset */
  209. #define RCU_APB1RST_UART4RST BIT(20) /*!< UART4 reset */
  210. #define RCU_APB1RST_I2C0RST BIT(21) /*!< I2C0 reset */
  211. #define RCU_APB1RST_I2C1RST BIT(22) /*!< I2C1 reset */
  212. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  213. #define RCU_APB1RST_USBDRST BIT(23) /*!< USBD reset */
  214. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  215. #define RCU_APB1RST_CAN0RST BIT(25) /*!< CAN0 reset */
  216. #ifdef GD32F10X_CL
  217. #define RCU_APB1RST_CAN1RST BIT(26) /*!< CAN1 reset */
  218. #endif /* GD32F10X_CL */
  219. #define RCU_APB1RST_BKPIRST BIT(27) /*!< backup interface reset */
  220. #define RCU_APB1RST_PMURST BIT(28) /*!< PMU reset */
  221. #define RCU_APB1RST_DACRST BIT(29) /*!< DAC reset */
  222. /* RCU_AHBEN */
  223. #define RCU_AHBEN_DMA0EN BIT(0) /*!< DMA0 clock enable */
  224. #define RCU_AHBEN_DMA1EN BIT(1) /*!< DMA1 clock enable */
  225. #define RCU_AHBEN_SRAMSPEN BIT(2) /*!< SRAM clock enable when sleep mode */
  226. #define RCU_AHBEN_FMCSPEN BIT(4) /*!< FMC clock enable when sleep mode */
  227. #define RCU_AHBEN_CRCEN BIT(6) /*!< CRC clock enable */
  228. #define RCU_AHBEN_EXMCEN BIT(8) /*!< EXMC clock enable */
  229. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  230. #define RCU_AHBEN_SDIOEN BIT(10) /*!< SDIO clock enable */
  231. #elif defined(GD32F10X_CL)
  232. #define RCU_AHBEN_USBFSEN BIT(12) /*!< USBFS clock enable */
  233. #define RCU_AHBEN_ENETEN BIT(14) /*!< ENET clock enable */
  234. #define RCU_AHBEN_ENETTXEN BIT(15) /*!< Ethernet TX clock enable */
  235. #define RCU_AHBEN_ENETRXEN BIT(16) /*!< Ethernet RX clock enable */
  236. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  237. /* RCU_APB2EN */
  238. #define RCU_APB2EN_AFEN BIT(0) /*!< alternate function IO clock enable */
  239. #define RCU_APB2EN_PAEN BIT(2) /*!< GPIO port A clock enable */
  240. #define RCU_APB2EN_PBEN BIT(3) /*!< GPIO port B clock enable */
  241. #define RCU_APB2EN_PCEN BIT(4) /*!< GPIO port C clock enable */
  242. #define RCU_APB2EN_PDEN BIT(5) /*!< GPIO port D clock enable */
  243. #define RCU_APB2EN_PEEN BIT(6) /*!< GPIO port E clock enable */
  244. #define RCU_APB2EN_PFEN BIT(7) /*!< GPIO port F clock enable */
  245. #define RCU_APB2EN_PGEN BIT(8) /*!< GPIO port G clock enable */
  246. #define RCU_APB2EN_ADC0EN BIT(9) /*!< ADC0 clock enable */
  247. #define RCU_APB2EN_ADC1EN BIT(10) /*!< ADC1 clock enable */
  248. #define RCU_APB2EN_TIMER0EN BIT(11) /*!< TIMER0 clock enable */
  249. #define RCU_APB2EN_SPI0EN BIT(12) /*!< SPI0 clock enable */
  250. #define RCU_APB2EN_TIMER7EN BIT(13) /*!< TIMER7 clock enable */
  251. #define RCU_APB2EN_USART0EN BIT(14) /*!< USART0 clock enable */
  252. #ifndef GD32F10X_CL
  253. #define RCU_APB2EN_ADC2EN BIT(15) /*!< ADC2 clock enable */
  254. #endif /* GD32F10X_CL */
  255. #ifdef GD32F10X_XD
  256. #define RCU_APB2EN_TIMER8EN BIT(19) /*!< TIMER8 clock enable */
  257. #define RCU_APB2EN_TIMER9EN BIT(20) /*!< TIMER9 clock enable */
  258. #define RCU_APB2EN_TIMER10EN BIT(21) /*!< TIMER10 clock enable */
  259. #endif /* GD32F10X_XD */
  260. /* RCU_APB1EN */
  261. #define RCU_APB1EN_TIMER1EN BIT(0) /*!< TIMER1 clock enable */
  262. #define RCU_APB1EN_TIMER2EN BIT(1) /*!< TIMER2 clock enable */
  263. #define RCU_APB1EN_TIMER3EN BIT(2) /*!< TIMER3 clock enable */
  264. #define RCU_APB1EN_TIMER4EN BIT(3) /*!< TIMER4 clock enable */
  265. #define RCU_APB1EN_TIMER5EN BIT(4) /*!< TIMER5 clock enable */
  266. #define RCU_APB1EN_TIMER6EN BIT(5) /*!< TIMER6 clock enable */
  267. #ifdef GD32F10X_XD
  268. #define RCU_APB1EN_TIMER11EN BIT(6) /*!< TIMER11 clock enable */
  269. #define RCU_APB1EN_TIMER12EN BIT(7) /*!< TIMER12 clock enable */
  270. #define RCU_APB1EN_TIMER13EN BIT(8) /*!< TIMER13 clock enable */
  271. #endif /* GD32F10X_XD */
  272. #define RCU_APB1EN_WWDGTEN BIT(11) /*!< WWDGT clock enable */
  273. #define RCU_APB1EN_SPI1EN BIT(14) /*!< SPI1 clock enable */
  274. #define RCU_APB1EN_SPI2EN BIT(15) /*!< SPI2 clock enable */
  275. #define RCU_APB1EN_USART1EN BIT(17) /*!< USART1 clock enable */
  276. #define RCU_APB1EN_USART2EN BIT(18) /*!< USART2 clock enable */
  277. #define RCU_APB1EN_UART3EN BIT(19) /*!< UART3 clock enable */
  278. #define RCU_APB1EN_UART4EN BIT(20) /*!< UART4 clock enable */
  279. #define RCU_APB1EN_I2C0EN BIT(21) /*!< I2C0 clock enable */
  280. #define RCU_APB1EN_I2C1EN BIT(22) /*!< I2C1 clock enable */
  281. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  282. #define RCU_APB1EN_USBDEN BIT(23) /*!< USBD clock enable */
  283. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  284. #define RCU_APB1EN_CAN0EN BIT(25) /*!< CAN0 clock enable */
  285. #ifdef GD32F10X_CL
  286. #define RCU_APB1EN_CAN1EN BIT(26) /*!< CAN1 clock enable */
  287. #endif /* GD32F10X_CL */
  288. #define RCU_APB1EN_BKPIEN BIT(27) /*!< backup interface clock enable */
  289. #define RCU_APB1EN_PMUEN BIT(28) /*!< PMU clock enable */
  290. #define RCU_APB1EN_DACEN BIT(29) /*!< DAC clock enable */
  291. /* RCU_BDCTL */
  292. #define RCU_BDCTL_LXTALEN BIT(0) /*!< LXTAL enable */
  293. #define RCU_BDCTL_LXTALSTB BIT(1) /*!< low speed crystal oscillator stabilization flag */
  294. #define RCU_BDCTL_LXTALBPS BIT(2) /*!< LXTAL bypass mode enable */
  295. #define RCU_BDCTL_RTCSRC BITS(8,9) /*!< RTC clock entry selection */
  296. #define RCU_BDCTL_RTCEN BIT(15) /*!< RTC clock enable */
  297. #define RCU_BDCTL_BKPRST BIT(16) /*!< backup domain reset */
  298. /* RCU_RSTSCK */
  299. #define RCU_RSTSCK_IRC40KEN BIT(0) /*!< IRC40K enable */
  300. #define RCU_RSTSCK_IRC40KSTB BIT(1) /*!< IRC40K stabilization flag */
  301. #define RCU_RSTSCK_RSTFC BIT(24) /*!< reset flag clear */
  302. #define RCU_RSTSCK_EPRSTF BIT(26) /*!< external pin reset flag */
  303. #define RCU_RSTSCK_PORRSTF BIT(27) /*!< power reset flag */
  304. #define RCU_RSTSCK_SWRSTF BIT(28) /*!< software reset flag */
  305. #define RCU_RSTSCK_FWDGTRSTF BIT(29) /*!< free watchdog timer reset flag */
  306. #define RCU_RSTSCK_WWDGTRSTF BIT(30) /*!< window watchdog timer reset flag */
  307. #define RCU_RSTSCK_LPRSTF BIT(31) /*!< low-power reset flag */
  308. #ifdef GD32F10X_CL
  309. /* RCU_AHBRST */
  310. #define RCU_AHBRST_USBFSRST BIT(12) /*!< USBFS reset */
  311. #define RCU_AHBRST_ENETRST BIT(14) /*!< ENET reset */
  312. #endif /* GD32F10X_CL */
  313. #if defined(GD32F10X_CL)
  314. /* RCU_CFG1 */
  315. #define RCU_CFG1_PREDV0 BITS(0,3) /*!< PREDV0 division factor */
  316. #define RCU_CFG1_PREDV1 BITS(4,7) /*!< PREDV1 division factor */
  317. #define RCU_CFG1_PLL1MF BITS(8,11) /*!< PLL1 clock multiplication factor */
  318. #define RCU_CFG1_PLL2MF BITS(12,15) /*!< PLL2 clock multiplication factor */
  319. #define RCU_CFG1_PREDV0SEL BIT(16) /*!< PREDV0 input clock source selection */
  320. #define RCU_CFG1_I2S1SEL BIT(17) /*!< I2S1 clock source selection */
  321. #define RCU_CFG1_I2S2SEL BIT(18) /*!< I2S2 clock source selection */
  322. #endif /* GD32F10X_CL */
  323. /* RCU_DSV */
  324. #define RCU_DSV_DSLPVS BITS(0,2) /*!< deep-sleep mode voltage select */
  325. /* constants definitions */
  326. /* define the peripheral clock enable bit position and its register index offset */
  327. #define RCU_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
  328. #define RCU_REG_VAL(periph) (REG32(RCU + ((uint32_t)(periph) >> 6)))
  329. #define RCU_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
  330. /* register offset */
  331. /* peripherals enable */
  332. #define AHBEN_REG_OFFSET 0x14U /*!< AHB enable register offset */
  333. #define APB1EN_REG_OFFSET 0x1CU /*!< APB1 enable register offset */
  334. #define APB2EN_REG_OFFSET 0x18U /*!< APB2 enable register offset */
  335. /* peripherals reset */
  336. #define AHBRST_REG_OFFSET 0x28U /*!< AHB reset register offset */
  337. #define APB1RST_REG_OFFSET 0x10U /*!< APB1 reset register offset */
  338. #define APB2RST_REG_OFFSET 0x0CU /*!< APB2 reset register offset */
  339. #define RSTSCK_REG_OFFSET 0x24U /*!< reset source/clock register offset */
  340. /* clock control */
  341. #define CTL_REG_OFFSET 0x00U /*!< control register offset */
  342. #define BDCTL_REG_OFFSET 0x20U /*!< backup domain control register offset */
  343. /* clock stabilization and stuck interrupt */
  344. #define INT_REG_OFFSET 0x08U /*!< clock interrupt register offset */
  345. /* configuration register */
  346. #define CFG0_REG_OFFSET 0x04U /*!< clock configuration register 0 offset */
  347. #define CFG1_REG_OFFSET 0x2CU /*!< clock configuration register 1 offset */
  348. /* peripheral clock enable */
  349. typedef enum
  350. {
  351. /* AHB peripherals */
  352. RCU_DMA0 = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 0U), /*!< DMA0 clock */
  353. RCU_DMA1 = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 1U), /*!< DMA1 clock */
  354. RCU_CRC = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 6U), /*!< CRC clock */
  355. RCU_EXMC = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 8U), /*!< EXMC clock */
  356. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  357. RCU_SDIO = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 10U), /*!< SDIO clock */
  358. #elif defined(GD32F10X_CL)
  359. RCU_USBFS = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 12U), /*!< USBFS clock */
  360. RCU_ENET = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 14U), /*!< ENET clock */
  361. RCU_ENETTX = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 15U), /*!< ENETTX clock */
  362. RCU_ENETRX = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 16U), /*!< ENETRX clock */
  363. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  364. /* APB1 peripherals */
  365. RCU_TIMER1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 0U), /*!< TIMER1 clock */
  366. RCU_TIMER2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 1U), /*!< TIMER2 clock */
  367. RCU_TIMER3 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 2U), /*!< TIMER3 clock */
  368. RCU_TIMER4 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 3U), /*!< TIMER4 clock */
  369. RCU_TIMER5 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 4U), /*!< TIMER5 clock */
  370. RCU_TIMER6 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 5U), /*!< TIMER6 clock */
  371. #if defined(GD32F10X_XD)
  372. RCU_TIMER11 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 6U), /*!< TIMER11 clock */
  373. RCU_TIMER12 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 7U), /*!< TIMER12 clock */
  374. RCU_TIMER13 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 8U), /*!< TIMER13 clock */
  375. #endif /* GD32F10X_XD */
  376. RCU_WWDGT = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 11U), /*!< WWDGT clock */
  377. RCU_SPI1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 14U), /*!< SPI1 clock */
  378. RCU_SPI2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 15U), /*!< SPI2 clock */
  379. RCU_USART1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 17U), /*!< USART1 clock */
  380. RCU_USART2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 18U), /*!< USART2 clock */
  381. RCU_UART3 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 19U), /*!< UART3 clock */
  382. RCU_UART4 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 20U), /*!< UART4 clock */
  383. RCU_I2C0 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 21U), /*!< I2C0 clock */
  384. RCU_I2C1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 22U), /*!< I2C1 clock */
  385. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  386. RCU_USBD = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 23U), /*!< USBD clock */
  387. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  388. RCU_CAN0 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 25U), /*!< CAN0 clock */
  389. #ifdef GD32F10X_CL
  390. RCU_CAN1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 26U), /*!< CAN1 clock */
  391. #endif /* GD32F10X_CL */
  392. RCU_BKPI = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 27U), /*!< BKPI clock */
  393. RCU_PMU = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 28U), /*!< PMU clock */
  394. RCU_DAC = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 29U), /*!< DAC clock */
  395. RCU_RTC = RCU_REGIDX_BIT(BDCTL_REG_OFFSET, 15U), /*!< RTC clock */
  396. /* APB2 peripherals */
  397. RCU_AF = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 0U), /*!< alternate function clock */
  398. RCU_GPIOA = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 2U), /*!< GPIOA clock */
  399. RCU_GPIOB = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 3U), /*!< GPIOB clock */
  400. RCU_GPIOC = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 4U), /*!< GPIOC clock */
  401. RCU_GPIOD = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 5U), /*!< GPIOD clock */
  402. RCU_GPIOE = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 6U), /*!< GPIOE clock */
  403. RCU_GPIOF = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 7U), /*!< GPIOF clock */
  404. RCU_GPIOG = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 8U), /*!< GPIOG clock */
  405. RCU_ADC0 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 9U), /*!< ADC0 clock */
  406. RCU_ADC1 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 10U), /*!< ADC1 clock */
  407. RCU_TIMER0 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 11U), /*!< TIMER0 clock */
  408. RCU_SPI0 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 12U), /*!< SPI0 clock */
  409. RCU_TIMER7 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 13U), /*!< TIMER7 clock */
  410. RCU_USART0 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 14U), /*!< USART0 clock */
  411. #ifndef GD32F10X_CL
  412. RCU_ADC2 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 15U), /*!< ADC2 clock */
  413. #endif /* GD32F10X_CL */
  414. #ifdef GD32F10X_XD
  415. RCU_TIMER8 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 19U), /*!< TIMER8 clock */
  416. RCU_TIMER9 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 20U), /*!< TIMER9 clock */
  417. RCU_TIMER10 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 21U), /*!< TIMER10 clock */
  418. #endif /* GD32F10X_XD */
  419. }rcu_periph_enum;
  420. /* peripheral clock enable when sleep mode*/
  421. typedef enum
  422. {
  423. /* AHB peripherals */
  424. RCU_SRAM_SLP = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 2U), /*!< SRAM clock */
  425. RCU_FMC_SLP = RCU_REGIDX_BIT(AHBEN_REG_OFFSET, 4U), /*!< FMC clock */
  426. }rcu_periph_sleep_enum;
  427. /* peripherals reset */
  428. typedef enum
  429. {
  430. /* AHB peripherals */
  431. #ifdef GD32F10X_CL
  432. RCU_USBFSRST = RCU_REGIDX_BIT(AHBRST_REG_OFFSET, 12U), /*!< USBFS clock reset */
  433. RCU_ENETRST = RCU_REGIDX_BIT(AHBRST_REG_OFFSET, 14U), /*!< ENET clock reset */
  434. #endif /* GD32F10X_CL */
  435. /* APB1 peripherals */
  436. RCU_TIMER1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 0U), /*!< TIMER1 clock reset */
  437. RCU_TIMER2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 1U), /*!< TIMER2 clock reset */
  438. RCU_TIMER3RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 2U), /*!< TIMER3 clock reset */
  439. RCU_TIMER4RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 3U), /*!< TIMER4 clock reset */
  440. RCU_TIMER5RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 4U), /*!< TIMER5 clock reset */
  441. RCU_TIMER6RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 5U), /*!< TIMER6 clock reset */
  442. #ifdef GD32F10X_XD
  443. RCU_TIMER11RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 6U), /*!< TIMER11 clock reset */
  444. RCU_TIMER12RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 7U), /*!< TIMER12 clock reset */
  445. RCU_TIMER13RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 8U), /*!< TIMER13 clock reset */
  446. #endif /* GD32F10X_XD */
  447. RCU_WWDGTRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 11U), /*!< WWDGT clock reset */
  448. RCU_SPI1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 14U), /*!< SPI1 clock reset */
  449. RCU_SPI2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 15U), /*!< SPI2 clock reset */
  450. RCU_USART1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 17U), /*!< USART1 clock reset */
  451. RCU_USART2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 18U), /*!< USART2 clock reset */
  452. RCU_UART3RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 19U), /*!< UART3 clock reset */
  453. RCU_UART4RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 20U), /*!< UART4 clock reset */
  454. RCU_I2C0RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 21U), /*!< I2C0 clock reset */
  455. RCU_I2C1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 22U), /*!< I2C1 clock reset */
  456. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  457. RCU_USBDRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 23U), /*!< USBD clock reset */
  458. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  459. RCU_CAN0RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 25U), /*!< CAN0 clock reset */
  460. #ifdef GD32F10X_CL
  461. RCU_CAN1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 26U), /*!< CAN1 clock reset */
  462. #endif /* GD32F10X_CL */
  463. RCU_BKPIRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 27U), /*!< BKPI clock reset */
  464. RCU_PMURST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 28U), /*!< PMU clock reset */
  465. RCU_DACRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 29U), /*!< DAC clock reset */
  466. /* APB2 peripherals */
  467. RCU_AFRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 0U), /*!< alternate function clock reset */
  468. RCU_GPIOARST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 2U), /*!< GPIOA clock reset */
  469. RCU_GPIOBRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 3U), /*!< GPIOB clock reset */
  470. RCU_GPIOCRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 4U), /*!< GPIOC clock reset */
  471. RCU_GPIODRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 5U), /*!< GPIOD clock reset */
  472. RCU_GPIOERST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 6U), /*!< GPIOE clock reset */
  473. RCU_GPIOFRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 7U), /*!< GPIOF clock reset */
  474. RCU_GPIOGRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 8U), /*!< GPIOG clock reset */
  475. RCU_ADC0RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 9U), /*!< ADC0 clock reset */
  476. RCU_ADC1RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 10U), /*!< ADC1 clock reset */
  477. RCU_TIMER0RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 11U), /*!< TIMER0 clock reset */
  478. RCU_SPI0RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 12U), /*!< SPI0 clock reset */
  479. RCU_TIMER7RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 13U), /*!< TIMER7 clock reset */
  480. RCU_USART0RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 14U), /*!< USART0 clock reset */
  481. #ifndef GD32F10X_CL
  482. RCU_ADC2RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 15U), /*!< ADC2 clock reset */
  483. #endif /* GD32F10X_CL */
  484. #ifdef GD32F10X_XD
  485. RCU_TIMER8RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 19U), /*!< TIMER8 clock reset */
  486. RCU_TIMER9RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 20U), /*!< TIMER9 clock reset */
  487. RCU_TIMER10RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 21U), /*!< TIMER10 clock reset */
  488. #endif /* GD32F10X_XD */
  489. }rcu_periph_reset_enum;
  490. /* clock stabilization and peripheral reset flags */
  491. typedef enum
  492. {
  493. /* clock stabilization flags */
  494. RCU_FLAG_IRC8MSTB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 1U), /*!< IRC8M stabilization flags */
  495. RCU_FLAG_HXTALSTB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 17U), /*!< HXTAL stabilization flags */
  496. RCU_FLAG_PLLSTB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 25U), /*!< PLL stabilization flags */
  497. #ifdef GD32F10X_CL
  498. RCU_FLAG_PLL1STB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 27U), /*!< PLL1 stabilization flags */
  499. RCU_FLAG_PLL2STB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 29U), /*!< PLL2 stabilization flags */
  500. #endif /* GD32F10X_CL */
  501. RCU_FLAG_LXTALSTB = RCU_REGIDX_BIT(BDCTL_REG_OFFSET, 1U), /*!< LXTAL stabilization flags */
  502. RCU_FLAG_IRC40KSTB = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 1U), /*!< IRC40K stabilization flags */
  503. /* reset source flags */
  504. RCU_FLAG_EPRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 26U), /*!< external PIN reset flags */
  505. RCU_FLAG_PORRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 27U), /*!< power reset flags */
  506. RCU_FLAG_SWRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 28U), /*!< software reset flags */
  507. RCU_FLAG_FWDGTRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 29U), /*!< FWDGT reset flags */
  508. RCU_FLAG_WWDGTRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 30U), /*!< WWDGT reset flags */
  509. RCU_FLAG_LPRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 31U), /*!< low-power reset flags */
  510. }rcu_flag_enum;
  511. /* clock stabilization and ckm interrupt flags */
  512. typedef enum
  513. {
  514. RCU_INT_FLAG_IRC40KSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 0U), /*!< IRC40K stabilization interrupt flag */
  515. RCU_INT_FLAG_LXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 1U), /*!< LXTAL stabilization interrupt flag */
  516. RCU_INT_FLAG_IRC8MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 2U), /*!< IRC8M stabilization interrupt flag */
  517. RCU_INT_FLAG_HXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 3U), /*!< HXTAL stabilization interrupt flag */
  518. RCU_INT_FLAG_PLLSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 4U), /*!< PLL stabilization interrupt flag */
  519. #ifdef GD32F10X_CL
  520. RCU_INT_FLAG_PLL1STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 5U), /*!< PLL1 stabilization interrupt flag */
  521. RCU_INT_FLAG_PLL2STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 6U), /*!< PLL2 stabilization interrupt flag */
  522. #endif /* GD32F10X_CL */
  523. RCU_INT_FLAG_CKM = RCU_REGIDX_BIT(INT_REG_OFFSET, 7U), /*!< HXTAL clock stuck interrupt flag */
  524. }rcu_int_flag_enum;
  525. /* clock stabilization and stuck interrupt flags clear */
  526. typedef enum
  527. {
  528. RCU_INT_FLAG_IRC40KSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 16U), /*!< IRC40K stabilization interrupt flags clear */
  529. RCU_INT_FLAG_LXTALSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 17U), /*!< LXTAL stabilization interrupt flags clear */
  530. RCU_INT_FLAG_IRC8MSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 18U), /*!< IRC8M stabilization interrupt flags clear */
  531. RCU_INT_FLAG_HXTALSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 19U), /*!< HXTAL stabilization interrupt flags clear */
  532. RCU_INT_FLAG_PLLSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 20U), /*!< PLL stabilization interrupt flags clear */
  533. #ifdef GD32F10X_CL
  534. RCU_INT_FLAG_PLL1STB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 21U), /*!< PLL1 stabilization interrupt flags clear */
  535. RCU_INT_FLAG_PLL2STB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 22U), /*!< PLL2 stabilization interrupt flags clear */
  536. #endif /* GD32F10X_CL */
  537. RCU_INT_FLAG_CKM_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 23U), /*!< CKM interrupt flags clear */
  538. }rcu_int_flag_clear_enum;
  539. /* clock stabilization interrupt enable or disable */
  540. typedef enum
  541. {
  542. RCU_INT_IRC40KSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 8U), /*!< IRC40K stabilization interrupt */
  543. RCU_INT_LXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 9U), /*!< LXTAL stabilization interrupt */
  544. RCU_INT_IRC8MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 10U), /*!< IRC8M stabilization interrupt */
  545. RCU_INT_HXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 11U), /*!< HXTAL stabilization interrupt */
  546. RCU_INT_PLLSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 12U), /*!< PLL stabilization interrupt */
  547. #ifdef GD32F10X_CL
  548. RCU_INT_PLL1STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 13U), /*!< PLL1 stabilization interrupt */
  549. RCU_INT_PLL2STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 14U), /*!< PLL2 stabilization interrupt */
  550. #endif /* GD32F10X_CL */
  551. }rcu_int_enum;
  552. /* oscillator types */
  553. typedef enum
  554. {
  555. RCU_HXTAL = RCU_REGIDX_BIT(CTL_REG_OFFSET, 16U), /*!< HXTAL */
  556. RCU_LXTAL = RCU_REGIDX_BIT(BDCTL_REG_OFFSET, 0U), /*!< LXTAL */
  557. RCU_IRC8M = RCU_REGIDX_BIT(CTL_REG_OFFSET, 0U), /*!< IRC8M */
  558. RCU_IRC40K = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 0U), /*!< IRC40K */
  559. RCU_PLL_CK = RCU_REGIDX_BIT(CTL_REG_OFFSET, 24U), /*!< PLL */
  560. #ifdef GD32F10X_CL
  561. RCU_PLL1_CK = RCU_REGIDX_BIT(CTL_REG_OFFSET, 26U), /*!< PLL1 */
  562. RCU_PLL2_CK = RCU_REGIDX_BIT(CTL_REG_OFFSET, 28U), /*!< PLL2 */
  563. #endif /* GD32F10X_CL */
  564. }rcu_osci_type_enum;
  565. /* rcu clock frequency */
  566. typedef enum
  567. {
  568. CK_SYS = 0, /*!< system clock */
  569. CK_AHB, /*!< AHB clock */
  570. CK_APB1, /*!< APB1 clock */
  571. CK_APB2, /*!< APB2 clock */
  572. }rcu_clock_freq_enum;
  573. /* RCU_CFG0 register bit define */
  574. /* system clock source select */
  575. #define CFG0_SCS(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
  576. #define RCU_CKSYSSRC_IRC8M CFG0_SCS(0) /*!< system clock source select IRC8M */
  577. #define RCU_CKSYSSRC_HXTAL CFG0_SCS(1) /*!< system clock source select HXTAL */
  578. #define RCU_CKSYSSRC_PLL CFG0_SCS(2) /*!< system clock source select PLL */
  579. /* system clock source select status */
  580. #define CFG0_SCSS(regval) (BITS(2,3) & ((uint32_t)(regval) << 2))
  581. #define RCU_SCSS_IRC8M CFG0_SCSS(0) /*!< system clock source select IRC8M */
  582. #define RCU_SCSS_HXTAL CFG0_SCSS(1) /*!< system clock source select HXTAL */
  583. #define RCU_SCSS_PLL CFG0_SCSS(2) /*!< system clock source select PLLP */
  584. /* AHB prescaler selection */
  585. #define CFG0_AHBPSC(regval) (BITS(4,7) & ((uint32_t)(regval) << 4))
  586. #define RCU_AHB_CKSYS_DIV1 CFG0_AHBPSC(0) /*!< AHB prescaler select CK_SYS */
  587. #define RCU_AHB_CKSYS_DIV2 CFG0_AHBPSC(8) /*!< AHB prescaler select CK_SYS/2 */
  588. #define RCU_AHB_CKSYS_DIV4 CFG0_AHBPSC(9) /*!< AHB prescaler select CK_SYS/4 */
  589. #define RCU_AHB_CKSYS_DIV8 CFG0_AHBPSC(10) /*!< AHB prescaler select CK_SYS/8 */
  590. #define RCU_AHB_CKSYS_DIV16 CFG0_AHBPSC(11) /*!< AHB prescaler select CK_SYS/16 */
  591. #define RCU_AHB_CKSYS_DIV64 CFG0_AHBPSC(12) /*!< AHB prescaler select CK_SYS/64 */
  592. #define RCU_AHB_CKSYS_DIV128 CFG0_AHBPSC(13) /*!< AHB prescaler select CK_SYS/128 */
  593. #define RCU_AHB_CKSYS_DIV256 CFG0_AHBPSC(14) /*!< AHB prescaler select CK_SYS/256 */
  594. #define RCU_AHB_CKSYS_DIV512 CFG0_AHBPSC(15) /*!< AHB prescaler select CK_SYS/512 */
  595. /* APB1 prescaler selection */
  596. #define CFG0_APB1PSC(regval) (BITS(8,10) & ((uint32_t)(regval) << 8))
  597. #define RCU_APB1_CKAHB_DIV1 CFG0_APB1PSC(0) /*!< APB1 prescaler select CK_AHB */
  598. #define RCU_APB1_CKAHB_DIV2 CFG0_APB1PSC(4) /*!< APB1 prescaler select CK_AHB/2 */
  599. #define RCU_APB1_CKAHB_DIV4 CFG0_APB1PSC(5) /*!< APB1 prescaler select CK_AHB/4 */
  600. #define RCU_APB1_CKAHB_DIV8 CFG0_APB1PSC(6) /*!< APB1 prescaler select CK_AHB/8 */
  601. #define RCU_APB1_CKAHB_DIV16 CFG0_APB1PSC(7) /*!< APB1 prescaler select CK_AHB/16 */
  602. /* APB2 prescaler selection */
  603. #define CFG0_APB2PSC(regval) (BITS(11,13) & ((uint32_t)(regval) << 11))
  604. #define RCU_APB2_CKAHB_DIV1 CFG0_APB2PSC(0) /*!< APB2 prescaler select CK_AHB */
  605. #define RCU_APB2_CKAHB_DIV2 CFG0_APB2PSC(4) /*!< APB2 prescaler select CK_AHB/2 */
  606. #define RCU_APB2_CKAHB_DIV4 CFG0_APB2PSC(5) /*!< APB2 prescaler select CK_AHB/4 */
  607. #define RCU_APB2_CKAHB_DIV8 CFG0_APB2PSC(6) /*!< APB2 prescaler select CK_AHB/8 */
  608. #define RCU_APB2_CKAHB_DIV16 CFG0_APB2PSC(7) /*!< APB2 prescaler select CK_AHB/16 */
  609. /* ADC prescaler select */
  610. #define RCU_CKADC_CKAPB2_DIV2 ((uint32_t)0x00000000U) /*!< ADC prescaler select CK_APB2/2 */
  611. #define RCU_CKADC_CKAPB2_DIV4 ((uint32_t)0x00000001U) /*!< ADC prescaler select CK_APB2/4 */
  612. #define RCU_CKADC_CKAPB2_DIV6 ((uint32_t)0x00000002U) /*!< ADC prescaler select CK_APB2/6 */
  613. #define RCU_CKADC_CKAPB2_DIV8 ((uint32_t)0x00000003U) /*!< ADC prescaler select CK_APB2/8 */
  614. #define RCU_CKADC_CKAPB2_DIV12 ((uint32_t)0x00000005U) /*!< ADC prescaler select CK_APB2/12 */
  615. #define RCU_CKADC_CKAPB2_DIV16 ((uint32_t)0x00000007U) /*!< ADC prescaler select CK_APB2/16 */
  616. /* PLL clock source selection */
  617. #define RCU_PLLSRC_IRC8M_DIV2 ((uint32_t)0x00000000U) /*!< IRC8M/2 clock selected as source clock of PLL */
  618. #define RCU_PLLSRC_HXTAL RCU_CFG0_PLLSEL /*!< HXTAL clock selected as source clock of PLL */
  619. /* PLL clock multiplication factor */
  620. #define PLLMF_4 RCU_CFG0_PLLMF_4 /* bit 4 of PLLMF */
  621. #define CFG0_PLLMF(regval) (BITS(18,21) & ((uint32_t)(regval) << 18))
  622. #define RCU_PLL_MUL2 CFG0_PLLMF(0) /*!< PLL source clock multiply by 2 */
  623. #define RCU_PLL_MUL3 CFG0_PLLMF(1) /*!< PLL source clock multiply by 3 */
  624. #define RCU_PLL_MUL4 CFG0_PLLMF(2) /*!< PLL source clock multiply by 4 */
  625. #define RCU_PLL_MUL5 CFG0_PLLMF(3) /*!< PLL source clock multiply by 5 */
  626. #define RCU_PLL_MUL6 CFG0_PLLMF(4) /*!< PLL source clock multiply by 6 */
  627. #define RCU_PLL_MUL7 CFG0_PLLMF(5) /*!< PLL source clock multiply by 7 */
  628. #define RCU_PLL_MUL8 CFG0_PLLMF(6) /*!< PLL source clock multiply by 8 */
  629. #define RCU_PLL_MUL9 CFG0_PLLMF(7) /*!< PLL source clock multiply by 9 */
  630. #define RCU_PLL_MUL10 CFG0_PLLMF(8) /*!< PLL source clock multiply by 10 */
  631. #define RCU_PLL_MUL11 CFG0_PLLMF(9) /*!< PLL source clock multiply by 11 */
  632. #define RCU_PLL_MUL12 CFG0_PLLMF(10) /*!< PLL source clock multiply by 12 */
  633. #define RCU_PLL_MUL13 CFG0_PLLMF(11) /*!< PLL source clock multiply by 13 */
  634. #define RCU_PLL_MUL14 CFG0_PLLMF(12) /*!< PLL source clock multiply by 14 */
  635. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  636. #define RCU_PLL_MUL15 CFG0_PLLMF(13) /*!< PLL source clock multiply by 15 */
  637. #elif defined(GD32F10X_CL)
  638. #define RCU_PLL_MUL6_5 CFG0_PLLMF(13) /*!< PLL source clock multiply by 6.5 */
  639. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  640. #define RCU_PLL_MUL16 CFG0_PLLMF(14) /*!< PLL source clock multiply by 16 */
  641. #define RCU_PLL_MUL17 (PLLMF_4 | CFG0_PLLMF(0)) /*!< PLL source clock multiply by 17 */
  642. #define RCU_PLL_MUL18 (PLLMF_4 | CFG0_PLLMF(1)) /*!< PLL source clock multiply by 18 */
  643. #define RCU_PLL_MUL19 (PLLMF_4 | CFG0_PLLMF(2)) /*!< PLL source clock multiply by 19 */
  644. #define RCU_PLL_MUL20 (PLLMF_4 | CFG0_PLLMF(3)) /*!< PLL source clock multiply by 20 */
  645. #define RCU_PLL_MUL21 (PLLMF_4 | CFG0_PLLMF(4)) /*!< PLL source clock multiply by 21 */
  646. #define RCU_PLL_MUL22 (PLLMF_4 | CFG0_PLLMF(5)) /*!< PLL source clock multiply by 22 */
  647. #define RCU_PLL_MUL23 (PLLMF_4 | CFG0_PLLMF(6)) /*!< PLL source clock multiply by 23 */
  648. #define RCU_PLL_MUL24 (PLLMF_4 | CFG0_PLLMF(7)) /*!< PLL source clock multiply by 24 */
  649. #define RCU_PLL_MUL25 (PLLMF_4 | CFG0_PLLMF(8)) /*!< PLL source clock multiply by 25 */
  650. #define RCU_PLL_MUL26 (PLLMF_4 | CFG0_PLLMF(9)) /*!< PLL source clock multiply by 26 */
  651. #define RCU_PLL_MUL27 (PLLMF_4 | CFG0_PLLMF(10)) /*!< PLL source clock multiply by 27 */
  652. #define RCU_PLL_MUL28 (PLLMF_4 | CFG0_PLLMF(11)) /*!< PLL source clock multiply by 28 */
  653. #define RCU_PLL_MUL29 (PLLMF_4 | CFG0_PLLMF(12)) /*!< PLL source clock multiply by 29 */
  654. #define RCU_PLL_MUL30 (PLLMF_4 | CFG0_PLLMF(13)) /*!< PLL source clock multiply by 30 */
  655. #define RCU_PLL_MUL31 (PLLMF_4 | CFG0_PLLMF(14)) /*!< PLL source clock multiply by 31 */
  656. #define RCU_PLL_MUL32 (PLLMF_4 | CFG0_PLLMF(15)) /*!< PLL source clock multiply by 32 */
  657. /* USBD/USBFS prescaler select */
  658. #define CFG0_USBPSC(regval) (BITS(22,23) & ((uint32_t)(regval) << 22))
  659. #define RCU_CKUSB_CKPLL_DIV1_5 CFG0_USBPSC(0) /*!< USBD/USBFS prescaler select CK_PLL/1.5 */
  660. #define RCU_CKUSB_CKPLL_DIV1 CFG0_USBPSC(1) /*!< USBD/USBFS prescaler select CK_PLL/1 */
  661. #define RCU_CKUSB_CKPLL_DIV2_5 CFG0_USBPSC(2) /*!< USBD/USBFS prescaler select CK_PLL/2.5 */
  662. #define RCU_CKUSB_CKPLL_DIV2 CFG0_USBPSC(3) /*!< USBD/USBFS prescaler select CK_PLL/2 */
  663. /* CKOUT0 clock source selection */
  664. #define CFG0_CKOUT0SEL(regval) (BITS(24,27) & ((uint32_t)(regval) << 24))
  665. #define RCU_CKOUT0SRC_NONE CFG0_CKOUT0SEL(0) /*!< no clock selected */
  666. #define RCU_CKOUT0SRC_CKSYS CFG0_CKOUT0SEL(4) /*!< system clock selected */
  667. #define RCU_CKOUT0SRC_IRC8M CFG0_CKOUT0SEL(5) /*!< internal 8M RC oscillator clock selected */
  668. #define RCU_CKOUT0SRC_HXTAL CFG0_CKOUT0SEL(6) /*!< high speed crystal oscillator clock (HXTAL) selected */
  669. #define RCU_CKOUT0SRC_CKPLL_DIV2 CFG0_CKOUT0SEL(7) /*!< CK_PLL/2 clock selected */
  670. #ifdef GD32F10X_CL
  671. #define RCU_CKOUT0SRC_CKPLL1 CFG0_CKOUT0SEL(8) /*!< CK_PLL1 clock selected */
  672. #define RCU_CKOUT0SRC_CKPLL2_DIV2 CFG0_CKOUT0SEL(9) /*!< CK_PLL2/2 clock selected */
  673. #define RCU_CKOUT0SRC_EXT1 CFG0_CKOUT0SEL(10) /*!< EXT1 selected, to provide the external clock for ENET */
  674. #define RCU_CKOUT0SRC_CKPLL2 CFG0_CKOUT0SEL(11) /*!< CK_PLL2 clock selected */
  675. #endif /* GD32F10X_CL */
  676. /* RTC clock entry selection */
  677. #define BDCTL_RTCSRC(regval) (BITS(8,9) & ((uint32_t)(regval) << 8))
  678. #define RCU_RTCSRC_NONE BDCTL_RTCSRC(0) /*!< no clock selected */
  679. #define RCU_RTCSRC_LXTAL BDCTL_RTCSRC(1) /*!< RTC source clock select LXTAL */
  680. #define RCU_RTCSRC_IRC40K BDCTL_RTCSRC(2) /*!< RTC source clock select IRC40K */
  681. #define RCU_RTCSRC_HXTAL_DIV_128 BDCTL_RTCSRC(3) /*!< RTC source clock select HXTAL/128 */
  682. /* PREDV0 division factor */
  683. #define CFG1_PREDV0(regval) (BITS(0,3) & ((uint32_t)(regval) << 0))
  684. #define RCU_PREDV0_DIV1 CFG1_PREDV0(0) /*!< PREDV0 input source clock not divided */
  685. #define RCU_PREDV0_DIV2 CFG1_PREDV0(1) /*!< PREDV0 input source clock divided by 2 */
  686. #define RCU_PREDV0_DIV3 CFG1_PREDV0(2) /*!< PREDV0 input source clock divided by 3 */
  687. #define RCU_PREDV0_DIV4 CFG1_PREDV0(3) /*!< PREDV0 input source clock divided by 4 */
  688. #define RCU_PREDV0_DIV5 CFG1_PREDV0(4) /*!< PREDV0 input source clock divided by 5 */
  689. #define RCU_PREDV0_DIV6 CFG1_PREDV0(5) /*!< PREDV0 input source clock divided by 6 */
  690. #define RCU_PREDV0_DIV7 CFG1_PREDV0(6) /*!< PREDV0 input source clock divided by 7 */
  691. #define RCU_PREDV0_DIV8 CFG1_PREDV0(7) /*!< PREDV0 input source clock divided by 8 */
  692. #define RCU_PREDV0_DIV9 CFG1_PREDV0(8) /*!< PREDV0 input source clock divided by 9 */
  693. #define RCU_PREDV0_DIV10 CFG1_PREDV0(9) /*!< PREDV0 input source clock divided by 10 */
  694. #define RCU_PREDV0_DIV11 CFG1_PREDV0(10) /*!< PREDV0 input source clock divided by 11 */
  695. #define RCU_PREDV0_DIV12 CFG1_PREDV0(11) /*!< PREDV0 input source clock divided by 12 */
  696. #define RCU_PREDV0_DIV13 CFG1_PREDV0(12) /*!< PREDV0 input source clock divided by 13 */
  697. #define RCU_PREDV0_DIV14 CFG1_PREDV0(13) /*!< PREDV0 input source clock divided by 14 */
  698. #define RCU_PREDV0_DIV15 CFG1_PREDV0(14) /*!< PREDV0 input source clock divided by 15 */
  699. #define RCU_PREDV0_DIV16 CFG1_PREDV0(15) /*!< PREDV0 input source clock divided by 16 */
  700. /* PREDV1 division factor */
  701. #define CFG1_PREDV1(regval) (BITS(4,7) & ((uint32_t)(regval) << 4))
  702. #define RCU_PREDV1_DIV1 CFG1_PREDV1(0) /*!< PREDV1 input source clock not divided */
  703. #define RCU_PREDV1_DIV2 CFG1_PREDV1(1) /*!< PREDV1 input source clock divided by 2 */
  704. #define RCU_PREDV1_DIV3 CFG1_PREDV1(2) /*!< PREDV1 input source clock divided by 3 */
  705. #define RCU_PREDV1_DIV4 CFG1_PREDV1(3) /*!< PREDV1 input source clock divided by 4 */
  706. #define RCU_PREDV1_DIV5 CFG1_PREDV1(4) /*!< PREDV1 input source clock divided by 5 */
  707. #define RCU_PREDV1_DIV6 CFG1_PREDV1(5) /*!< PREDV1 input source clock divided by 6 */
  708. #define RCU_PREDV1_DIV7 CFG1_PREDV1(6) /*!< PREDV1 input source clock divided by 7 */
  709. #define RCU_PREDV1_DIV8 CFG1_PREDV1(7) /*!< PREDV1 input source clock divided by 8 */
  710. #define RCU_PREDV1_DIV9 CFG1_PREDV1(8) /*!< PREDV1 input source clock divided by 9 */
  711. #define RCU_PREDV1_DIV10 CFG1_PREDV1(9) /*!< PREDV1 input source clock divided by 10 */
  712. #define RCU_PREDV1_DIV11 CFG1_PREDV1(10) /*!< PREDV1 input source clock divided by 11 */
  713. #define RCU_PREDV1_DIV12 CFG1_PREDV1(11) /*!< PREDV1 input source clock divided by 12 */
  714. #define RCU_PREDV1_DIV13 CFG1_PREDV1(12) /*!< PREDV1 input source clock divided by 13 */
  715. #define RCU_PREDV1_DIV14 CFG1_PREDV1(13) /*!< PREDV1 input source clock divided by 14 */
  716. #define RCU_PREDV1_DIV15 CFG1_PREDV1(14) /*!< PREDV1 input source clock divided by 15 */
  717. #define RCU_PREDV1_DIV16 CFG1_PREDV1(15) /*!< PREDV1 input source clock divided by 16 */
  718. /* PLL1 clock multiplication factor */
  719. #define CFG1_PLL1MF(regval) (BITS(8,11) & ((uint32_t)(regval) << 8))
  720. #define RCU_PLL1_MUL8 CFG1_PLL1MF(6) /*!< PLL1 source clock multiply by 8 */
  721. #define RCU_PLL1_MUL9 CFG1_PLL1MF(7) /*!< PLL1 source clock multiply by 9 */
  722. #define RCU_PLL1_MUL10 CFG1_PLL1MF(8) /*!< PLL1 source clock multiply by 10 */
  723. #define RCU_PLL1_MUL11 CFG1_PLL1MF(9) /*!< PLL1 source clock multiply by 11 */
  724. #define RCU_PLL1_MUL12 CFG1_PLL1MF(10) /*!< PLL1 source clock multiply by 12 */
  725. #define RCU_PLL1_MUL13 CFG1_PLL1MF(11) /*!< PLL1 source clock multiply by 13 */
  726. #define RCU_PLL1_MUL14 CFG1_PLL1MF(12) /*!< PLL1 source clock multiply by 14 */
  727. #define RCU_PLL1_MUL15 CFG1_PLL1MF(13) /*!< PLL1 source clock multiply by 15 */
  728. #define RCU_PLL1_MUL16 CFG1_PLL1MF(14) /*!< PLL1 source clock multiply by 16 */
  729. #define RCU_PLL1_MUL20 CFG1_PLL1MF(15) /*!< PLL1 source clock multiply by 20 */
  730. /* PLL2 clock multiplication factor */
  731. #define CFG1_PLL2MF(regval) (BITS(12,15) & ((uint32_t)(regval) << 12))
  732. #define RCU_PLL2_MUL8 CFG1_PLL2MF(6) /*!< PLL2 source clock multiply by 8 */
  733. #define RCU_PLL2_MUL9 CFG1_PLL2MF(7) /*!< PLL2 source clock multiply by 9 */
  734. #define RCU_PLL2_MUL10 CFG1_PLL2MF(8) /*!< PLL2 source clock multiply by 10 */
  735. #define RCU_PLL2_MUL11 CFG1_PLL2MF(9) /*!< PLL2 source clock multiply by 11 */
  736. #define RCU_PLL2_MUL12 CFG1_PLL2MF(10) /*!< PLL2 source clock multiply by 12 */
  737. #define RCU_PLL2_MUL13 CFG1_PLL2MF(11) /*!< PLL2 source clock multiply by 13 */
  738. #define RCU_PLL2_MUL14 CFG1_PLL2MF(12) /*!< PLL2 source clock multiply by 14 */
  739. #define RCU_PLL2_MUL15 CFG1_PLL2MF(13) /*!< PLL2 source clock multiply by 15 */
  740. #define RCU_PLL2_MUL16 CFG1_PLL2MF(14) /*!< PLL2 source clock multiply by 16 */
  741. #define RCU_PLL2_MUL20 CFG1_PLL2MF(15) /*!< PLL2 source clock multiply by 20 */
  742. #ifdef GD32F10X_CL
  743. /* PREDV0 input clock source selection */
  744. #define RCU_PREDV0SRC_HXTAL ((uint32_t)0x00000000U) /*!< HXTAL selected as PREDV0 input source clock */
  745. #define RCU_PREDV0SRC_CKPLL1 RCU_CFG1_PREDV0SEL /*!< CK_PLL1 selected as PREDV0 input source clock */
  746. /* I2S1 clock source selection */
  747. #define RCU_I2S1SRC_CKSYS ((uint32_t)0x00000000U) /*!< system clock selected as I2S1 source clock */
  748. #define RCU_I2S1SRC_CKPLL2_MUL2 RCU_CFG1_I2S1SEL /*!< (CK_PLL2 x 2) selected as I2S1 source clock */
  749. /* I2S2 clock source selection */
  750. #define RCU_I2S2SRC_CKSYS ((uint32_t)0x00000000U) /*!< system clock selected as I2S2 source clock */
  751. #define RCU_I2S2SRC_CKPLL2_MUL2 RCU_CFG1_I2S2SEL /*!< (CK_PLL2 x 2) selected as I2S2 source clock */
  752. #endif /* GD32F10X_CL */
  753. /* deep-sleep mode voltage */
  754. #define DSV_DSLPVS(regval) (BITS(0,2) & ((uint32_t)(regval) << 0))
  755. #define RCU_DEEPSLEEP_V_1_2 DSV_DSLPVS(0) /*!< core voltage is 1.2V in deep-sleep mode */
  756. #define RCU_DEEPSLEEP_V_1_1 DSV_DSLPVS(1) /*!< core voltage is 1.1V in deep-sleep mode */
  757. #define RCU_DEEPSLEEP_V_1_0 DSV_DSLPVS(2) /*!< core voltage is 1.0V in deep-sleep mode */
  758. #define RCU_DEEPSLEEP_V_0_9 DSV_DSLPVS(3) /*!< core voltage is 0.9V in deep-sleep mode */
  759. /* function declarations */
  760. /* initialization, peripheral clock enable/disable functions */
  761. /* deinitialize the RCU */
  762. void rcu_deinit(void);
  763. /* enable the peripherals clock */
  764. void rcu_periph_clock_enable(rcu_periph_enum periph);
  765. /* disable the peripherals clock */
  766. void rcu_periph_clock_disable(rcu_periph_enum periph);
  767. /* enable the peripherals clock when sleep mode */
  768. void rcu_periph_clock_sleep_enable(rcu_periph_sleep_enum periph);
  769. /* disable the peripherals clock when sleep mode */
  770. void rcu_periph_clock_sleep_disable(rcu_periph_sleep_enum periph);
  771. /* reset the peripherals */
  772. void rcu_periph_reset_enable(rcu_periph_reset_enum periph_reset);
  773. /* disable reset the peripheral */
  774. void rcu_periph_reset_disable(rcu_periph_reset_enum periph_reset);
  775. /* reset the BKP domain */
  776. void rcu_bkp_reset_enable(void);
  777. /* disable the BKP domain reset */
  778. void rcu_bkp_reset_disable(void);
  779. /* clock configuration functions */
  780. /* configure the system clock source */
  781. void rcu_system_clock_source_config(uint32_t ck_sys);
  782. /* get the system clock source */
  783. uint32_t rcu_system_clock_source_get(void);
  784. /* configure the AHB prescaler selection */
  785. void rcu_ahb_clock_config(uint32_t ck_ahb);
  786. /* configure the APB1 prescaler selection */
  787. void rcu_apb1_clock_config(uint32_t ck_apb1);
  788. /* configure the APB2 prescaler selection */
  789. void rcu_apb2_clock_config(uint32_t ck_apb2);
  790. /* configure the CK_OUT0 clock source and divider */
  791. void rcu_ckout0_config(uint32_t ckout0_src);
  792. /* configure the PLL clock source selection and PLL multiply factor */
  793. void rcu_pll_config(uint32_t pll_src, uint32_t pll_mul);
  794. #if (defined(GD32F10X_MD) || defined(GD32F10X_HD) || defined(GD32F10X_XD))
  795. /* configure the PREDV0 division factor and clock source */
  796. void rcu_predv0_config(uint32_t predv0_div);
  797. #elif defined(GD32F10X_CL)
  798. /* configure the PREDV0 division factor and clock source */
  799. void rcu_predv0_config(uint32_t predv0_source, uint32_t predv0_div);
  800. /* configure the PREDV1 division factor */
  801. void rcu_predv1_config(uint32_t predv1_div);
  802. /* configure the PLL1 clock */
  803. void rcu_pll1_config(uint32_t pll_mul);
  804. /* configure the PLL2 clock */
  805. void rcu_pll2_config(uint32_t pll_mul);
  806. #endif /* GD32F10X_MD and GD32F10X_HD and GD32F10X_XD */
  807. /* peripheral clock configuration functions */
  808. /* configure the ADC division factor */
  809. void rcu_adc_clock_config(uint32_t adc_psc);
  810. /* configure the USBD/USBFS prescaler factor */
  811. void rcu_usb_clock_config(uint32_t usb_psc);
  812. /* configure the RTC clock source selection */
  813. void rcu_rtc_clock_config(uint32_t rtc_clock_source);
  814. #ifdef GD32F10X_CL
  815. /* configure the I2S1 clock source selection */
  816. void rcu_i2s1_clock_config(uint32_t i2s_clock_source);
  817. /* configure the I2S2 clock source selection */
  818. void rcu_i2s2_clock_config(uint32_t i2s_clock_source);
  819. #endif /* GD32F10X_CL */
  820. /* oscillator configuration functions */
  821. /* wait for oscillator stabilization flags is SET or oscillator startup is timeout */
  822. ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci);
  823. /* turn on the oscillator */
  824. void rcu_osci_on(rcu_osci_type_enum osci);
  825. /* turn off the oscillator */
  826. void rcu_osci_off(rcu_osci_type_enum osci);
  827. /* enable the oscillator bypass mode, HXTALEN or LXTALEN must be reset before it */
  828. void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci);
  829. /* disable the oscillator bypass mode, HXTALEN or LXTALEN must be reset before it */
  830. void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci);
  831. /* enable the HXTAL clock monitor */
  832. void rcu_hxtal_clock_monitor_enable(void);
  833. /* disable the HXTAL clock monitor */
  834. void rcu_hxtal_clock_monitor_disable(void);
  835. /* set the IRC8M adjust value */
  836. void rcu_irc8m_adjust_value_set(uint8_t irc8m_adjval);
  837. /* set the deep sleep mode voltage */
  838. void rcu_deepsleep_voltage_set(uint32_t dsvol);
  839. /* get the system clock, bus and peripheral clock frequency */
  840. uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock);
  841. /* interrupt & flag functions */
  842. /* get the clock stabilization and periphral reset flags */
  843. FlagStatus rcu_flag_get(rcu_flag_enum flag);
  844. /* clear the reset flag */
  845. void rcu_all_reset_flag_clear(void);
  846. /* get the clock stabilization interrupt and ckm flags */
  847. FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag);
  848. /* clear the interrupt flags */
  849. void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear);
  850. /* enable the stabilization interrupt */
  851. void rcu_interrupt_enable(rcu_int_enum stab_int);
  852. /* disable the stabilization interrupt */
  853. void rcu_interrupt_disable(rcu_int_enum stab_int);
  854. #endif /* GD32F10X_RCU_H */