hk32f0xx_rcc.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /**
  2. ******************************************************************************
  3. * @file hk32f0xx_rcc.h
  4. * @version V1.0.1
  5. * @date 2019-08-15
  6. ******************************************************************************
  7. */
  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #ifndef __HK32F0XX_RCC_H
  10. #define __HK32F0XX_RCC_H
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /* Includes ------------------------------------------------------------------*/
  15. #include "hk32f0xx.h"
  16. /** @addtogroup HK32F0xx_StdPeriph_Driver
  17. * @{
  18. */
  19. /** @addtogroup RCC
  20. * @{
  21. */
  22. /* Exported types ------------------------------------------------------------*/
  23. typedef struct
  24. {
  25. uint32_t SYSCLK_Frequency;
  26. uint32_t HCLK_Frequency;
  27. uint32_t PCLK_Frequency;
  28. uint32_t ADCCLK_Frequency;
  29. uint32_t CECCLK_Frequency;
  30. uint32_t I2C1CLK_Frequency;
  31. uint32_t USART1CLK_Frequency;
  32. uint32_t USART2CLK_Frequency;
  33. }RCC_ClocksTypeDef;
  34. /* Exported constants --------------------------------------------------------*/
  35. /** @defgroup RCC_Exported_Constants
  36. * @{
  37. */
  38. /** @defgroup RCC_HSE_configuration
  39. * @{
  40. */
  41. #define RCC_HSE_OFF ((uint8_t)0x00)
  42. #define RCC_HSE_ON ((uint8_t)0x01)
  43. #define RCC_HSE_Bypass ((uint8_t)0x05)
  44. #define IS_RCC_HSE(HSE) (((HSE) == RCC_HSE_OFF) || ((HSE) == RCC_HSE_ON) || \
  45. ((HSE) == RCC_HSE_Bypass))
  46. /**
  47. * @}
  48. */
  49. /** @defgroup RCC_PLL_Clock_Source
  50. * @{
  51. */
  52. #define RCC_PLLSource_HSI_Div2 RCC_CFGR_PLLSRC_HSI_Div2
  53. #define RCC_PLLSource_PREDIV1 RCC_CFGR_PLLSRC_HSE_PREDIV /* Old HSEPREDIV1 bit definition, maintained for legacy purpose */
  54. #define RCC_PLLSource_HSE RCC_CFGR_PLLSRC_HSE_PREDIV
  55. #define RCC_PLLSource_HSI RCC_CFGR_PLLSRC_HSI_PREDIV
  56. #define IS_RCC_PLL_SOURCE(SOURCE) (((SOURCE) == RCC_PLLSource_HSI_Div2) || \
  57. ((SOURCE) == RCC_PLLSource_HSI) || \
  58. ((SOURCE) == RCC_PLLSource_HSE) || \
  59. ((SOURCE) == RCC_PLLSource_PREDIV1))
  60. /**
  61. * @}
  62. */
  63. /** @defgroup RCC_PLL_Multiplication_Factor
  64. * @{
  65. */
  66. #define RCC_PLLMul_2 RCC_CFGR_PLLMULL2
  67. #define RCC_PLLMul_3 RCC_CFGR_PLLMULL3
  68. #define RCC_PLLMul_4 RCC_CFGR_PLLMULL4
  69. #define RCC_PLLMul_5 RCC_CFGR_PLLMULL5
  70. #define RCC_PLLMul_6 RCC_CFGR_PLLMULL6
  71. #define RCC_PLLMul_7 RCC_CFGR_PLLMULL7
  72. #define RCC_PLLMul_8 RCC_CFGR_PLLMULL8
  73. #define RCC_PLLMul_9 RCC_CFGR_PLLMULL9
  74. #define RCC_PLLMul_10 RCC_CFGR_PLLMULL10
  75. #define RCC_PLLMul_11 RCC_CFGR_PLLMULL11
  76. #define RCC_PLLMul_12 RCC_CFGR_PLLMULL12
  77. #define RCC_PLLMul_13 RCC_CFGR_PLLMULL13
  78. #define RCC_PLLMul_14 RCC_CFGR_PLLMULL14
  79. #define RCC_PLLMul_15 RCC_CFGR_PLLMULL15
  80. #define RCC_PLLMul_16 RCC_CFGR_PLLMULL16
  81. #define IS_RCC_PLL_MUL(MUL) (((MUL) == RCC_PLLMul_2) || ((MUL) == RCC_PLLMul_3) || \
  82. ((MUL) == RCC_PLLMul_4) || ((MUL) == RCC_PLLMul_5) || \
  83. ((MUL) == RCC_PLLMul_6) || ((MUL) == RCC_PLLMul_7) || \
  84. ((MUL) == RCC_PLLMul_8) || ((MUL) == RCC_PLLMul_9) || \
  85. ((MUL) == RCC_PLLMul_10) || ((MUL) == RCC_PLLMul_11) || \
  86. ((MUL) == RCC_PLLMul_12) || ((MUL) == RCC_PLLMul_13) || \
  87. ((MUL) == RCC_PLLMul_14) || ((MUL) == RCC_PLLMul_15) || \
  88. ((MUL) == RCC_PLLMul_16))
  89. /**
  90. * @}
  91. */
  92. /** @defgroup RCC_PREDIV1_division_factor
  93. * @{
  94. */
  95. #define RCC_PREDIV1_Div1 RCC_CFGR2_PREDIV1_DIV1
  96. #define RCC_PREDIV1_Div2 RCC_CFGR2_PREDIV1_DIV2
  97. #define RCC_PREDIV1_Div3 RCC_CFGR2_PREDIV1_DIV3
  98. #define RCC_PREDIV1_Div4 RCC_CFGR2_PREDIV1_DIV4
  99. #define RCC_PREDIV1_Div5 RCC_CFGR2_PREDIV1_DIV5
  100. #define RCC_PREDIV1_Div6 RCC_CFGR2_PREDIV1_DIV6
  101. #define RCC_PREDIV1_Div7 RCC_CFGR2_PREDIV1_DIV7
  102. #define RCC_PREDIV1_Div8 RCC_CFGR2_PREDIV1_DIV8
  103. #define RCC_PREDIV1_Div9 RCC_CFGR2_PREDIV1_DIV9
  104. #define RCC_PREDIV1_Div10 RCC_CFGR2_PREDIV1_DIV10
  105. #define RCC_PREDIV1_Div11 RCC_CFGR2_PREDIV1_DIV11
  106. #define RCC_PREDIV1_Div12 RCC_CFGR2_PREDIV1_DIV12
  107. #define RCC_PREDIV1_Div13 RCC_CFGR2_PREDIV1_DIV13
  108. #define RCC_PREDIV1_Div14 RCC_CFGR2_PREDIV1_DIV14
  109. #define RCC_PREDIV1_Div15 RCC_CFGR2_PREDIV1_DIV15
  110. #define RCC_PREDIV1_Div16 RCC_CFGR2_PREDIV1_DIV16
  111. #define IS_RCC_PREDIV1(PREDIV1) (((PREDIV1) == RCC_PREDIV1_Div1) || ((PREDIV1) == RCC_PREDIV1_Div2) || \
  112. ((PREDIV1) == RCC_PREDIV1_Div3) || ((PREDIV1) == RCC_PREDIV1_Div4) || \
  113. ((PREDIV1) == RCC_PREDIV1_Div5) || ((PREDIV1) == RCC_PREDIV1_Div6) || \
  114. ((PREDIV1) == RCC_PREDIV1_Div7) || ((PREDIV1) == RCC_PREDIV1_Div8) || \
  115. ((PREDIV1) == RCC_PREDIV1_Div9) || ((PREDIV1) == RCC_PREDIV1_Div10) || \
  116. ((PREDIV1) == RCC_PREDIV1_Div11) || ((PREDIV1) == RCC_PREDIV1_Div12) || \
  117. ((PREDIV1) == RCC_PREDIV1_Div13) || ((PREDIV1) == RCC_PREDIV1_Div14) || \
  118. ((PREDIV1) == RCC_PREDIV1_Div15) || ((PREDIV1) == RCC_PREDIV1_Div16))
  119. /**
  120. * @}
  121. */
  122. /** @defgroup RCC_System_Clock_Source
  123. * @{
  124. */
  125. #define RCC_SYSCLKSource_HSI RCC_CFGR_SW_HSI
  126. #define RCC_SYSCLKSource_HSE RCC_CFGR_SW_HSE
  127. #define RCC_SYSCLKSource_PLLCLK RCC_CFGR_SW_PLL
  128. #define IS_RCC_SYSCLK_SOURCE(SOURCE) (((SOURCE) == RCC_SYSCLKSource_HSI) || \
  129. ((SOURCE) == RCC_SYSCLKSource_HSE) || \
  130. ((SOURCE) == RCC_SYSCLKSource_PLLCLK))
  131. /**
  132. * @}
  133. */
  134. /** @defgroup RCC_AHB_Clock_Source
  135. * @{
  136. */
  137. #define RCC_SYSCLK_Div1 RCC_CFGR_HPRE_DIV1
  138. #define RCC_SYSCLK_Div2 RCC_CFGR_HPRE_DIV2
  139. #define RCC_SYSCLK_Div4 RCC_CFGR_HPRE_DIV4
  140. #define RCC_SYSCLK_Div8 RCC_CFGR_HPRE_DIV8
  141. #define RCC_SYSCLK_Div16 RCC_CFGR_HPRE_DIV16
  142. #define RCC_SYSCLK_Div64 RCC_CFGR_HPRE_DIV64
  143. #define RCC_SYSCLK_Div128 RCC_CFGR_HPRE_DIV128
  144. #define RCC_SYSCLK_Div256 RCC_CFGR_HPRE_DIV256
  145. #define RCC_SYSCLK_Div512 RCC_CFGR_HPRE_DIV512
  146. #define IS_RCC_HCLK(HCLK) (((HCLK) == RCC_SYSCLK_Div1) || ((HCLK) == RCC_SYSCLK_Div2) || \
  147. ((HCLK) == RCC_SYSCLK_Div4) || ((HCLK) == RCC_SYSCLK_Div8) || \
  148. ((HCLK) == RCC_SYSCLK_Div16) || ((HCLK) == RCC_SYSCLK_Div64) || \
  149. ((HCLK) == RCC_SYSCLK_Div128) || ((HCLK) == RCC_SYSCLK_Div256) || \
  150. ((HCLK) == RCC_SYSCLK_Div512))
  151. /**
  152. * @}
  153. */
  154. /** @defgroup RCC_APB_Clock_Source
  155. * @{
  156. */
  157. #define RCC_HCLK_Div1 RCC_CFGR_PPRE_DIV1
  158. #define RCC_HCLK_Div2 RCC_CFGR_PPRE_DIV2
  159. #define RCC_HCLK_Div4 RCC_CFGR_PPRE_DIV4
  160. #define RCC_HCLK_Div8 RCC_CFGR_PPRE_DIV8
  161. #define RCC_HCLK_Div16 RCC_CFGR_PPRE_DIV16
  162. #define IS_RCC_PCLK(PCLK) (((PCLK) == RCC_HCLK_Div1) || ((PCLK) == RCC_HCLK_Div2) || \
  163. ((PCLK) == RCC_HCLK_Div4) || ((PCLK) == RCC_HCLK_Div8) || \
  164. ((PCLK) == RCC_HCLK_Div16))
  165. /**
  166. * @}
  167. */
  168. /** @defgroup RCC_ADC_clock_source
  169. * @{
  170. */
  171. /* These defines are obsolete and kept for legacy purpose only.
  172. Proper ADC clock selection is done within ADC driver by mean of the ADC_ClockModeConfig() function */
  173. #define RCC_ADCCLK_HSI14 ((uint32_t)0x00000000)
  174. #define RCC_ADCCLK_PCLK_Div2 ((uint32_t)0x01000000)
  175. #define RCC_ADCCLK_PCLK_Div4 ((uint32_t)0x01004000)
  176. #define IS_RCC_ADCCLK(ADCCLK) (((ADCCLK) == RCC_ADCCLK_HSI14) || ((ADCCLK) == RCC_ADCCLK_PCLK_Div2) || \
  177. ((ADCCLK) == RCC_ADCCLK_PCLK_Div4))
  178. /**
  179. * @}
  180. */
  181. /** @defgroup RCC_CEC_clock_source
  182. * @{
  183. */
  184. #define RCC_CECCLK_HSI_Div244 ((uint32_t)0x00000000)
  185. #define RCC_CECCLK_LSE RCC_CFGR3_CECSW
  186. #define IS_RCC_CECCLK(CECCLK) (((CECCLK) == RCC_CECCLK_HSI_Div244) || ((CECCLK) == RCC_CECCLK_LSE))
  187. /**
  188. * @}
  189. */
  190. /** @defgroup RCC_I2C_clock_source
  191. * @{
  192. */
  193. #define RCC_I2C1CLK_HSI ((uint32_t)0x00000000)
  194. #define RCC_I2C1CLK_SYSCLK RCC_CFGR3_I2C1SW
  195. #define IS_RCC_I2CCLK(I2CCLK) (((I2CCLK) == RCC_I2C1CLK_HSI) || ((I2CCLK) == RCC_I2C1CLK_SYSCLK))
  196. /**
  197. * @}
  198. */
  199. /** @defgroup RCC_USART_clock_source
  200. * @{
  201. */
  202. #define RCC_USART1CLK_PCLK ((uint32_t)0x10000000)
  203. #define RCC_USART1CLK_SYSCLK ((uint32_t)0x10000001)
  204. #define RCC_USART1CLK_LSE ((uint32_t)0x10000002)
  205. #define RCC_USART1CLK_HSI ((uint32_t)0x10000003)
  206. #define RCC_USART2CLK_PCLK ((uint32_t)0x20000000)
  207. #define RCC_USART2CLK_SYSCLK ((uint32_t)0x20010000)
  208. #define RCC_USART2CLK_LSE ((uint32_t)0x20020000)
  209. #define RCC_USART2CLK_HSI ((uint32_t)0x20030000)
  210. #define IS_RCC_USARTCLK(USARTCLK) (((USARTCLK) == RCC_USART1CLK_PCLK) || \
  211. ((USARTCLK) == RCC_USART1CLK_SYSCLK) || \
  212. ((USARTCLK) == RCC_USART1CLK_LSE) || \
  213. ((USARTCLK) == RCC_USART1CLK_HSI) || \
  214. ((USARTCLK) == RCC_USART2CLK_PCLK) || \
  215. ((USARTCLK) == RCC_USART2CLK_SYSCLK) || \
  216. ((USARTCLK) == RCC_USART2CLK_LSE) || \
  217. ((USARTCLK) == RCC_USART2CLK_HSI))
  218. /**
  219. * @}
  220. */
  221. /** @defgroup RCC_Interrupt_Source
  222. * @{
  223. */
  224. #define RCC_IT_LSIRDY ((uint8_t)0x01)
  225. #define RCC_IT_LSERDY ((uint8_t)0x02)
  226. #define RCC_IT_HSIRDY ((uint8_t)0x04)
  227. #define RCC_IT_HSERDY ((uint8_t)0x08)
  228. #define RCC_IT_PLLRDY ((uint8_t)0x10)
  229. #define RCC_IT_HSI14RDY ((uint8_t)0x20)
  230. #define RCC_IT_CSS ((uint8_t)0x80)
  231. #define IS_RCC_IT(IT) ((((IT) & (uint8_t)0x80) == 0x00) && ((IT) != 0x00))
  232. #define IS_RCC_GET_IT(IT) (((IT) == RCC_IT_LSIRDY) || ((IT) == RCC_IT_LSERDY) || \
  233. ((IT) == RCC_IT_HSIRDY) || ((IT) == RCC_IT_HSERDY) || \
  234. ((IT) == RCC_IT_PLLRDY) || ((IT) == RCC_IT_HSI14RDY) || \
  235. ((IT) == RCC_IT_CSS) )
  236. #define IS_RCC_CLEAR_IT(IT) ((IT) != 0x00)
  237. /**
  238. * @}
  239. */
  240. /** @defgroup RCC_LSE_Configuration
  241. * @{
  242. */
  243. #define RCC_LSE_OFF ((uint32_t)0x00000000)
  244. #define RCC_LSE_ON RCC_BDCR_LSEON
  245. #define RCC_LSE_Bypass ((uint32_t)(RCC_BDCR_LSEON | RCC_BDCR_LSEBYP))
  246. #define IS_RCC_LSE(LSE) (((LSE) == RCC_LSE_OFF) || ((LSE) == RCC_LSE_ON) || \
  247. ((LSE) == RCC_LSE_Bypass))
  248. /**
  249. * @}
  250. */
  251. /** @defgroup RCC_RTC_Clock_Source
  252. * @{
  253. */
  254. #define RCC_RTCCLKSource_LSE RCC_BDCR_RTCSEL_LSE
  255. #define RCC_RTCCLKSource_LSI RCC_BDCR_RTCSEL_LSI
  256. #define RCC_RTCCLKSource_HSE_Div32 RCC_BDCR_RTCSEL_HSE
  257. #define IS_RCC_RTCCLK_SOURCE(SOURCE) (((SOURCE) == RCC_RTCCLKSource_LSE) || \
  258. ((SOURCE) == RCC_RTCCLKSource_LSI) || \
  259. ((SOURCE) == RCC_RTCCLKSource_HSE_Div32))
  260. /**
  261. * @}
  262. */
  263. /** @defgroup RCC_LSE_Drive_Configuration
  264. * @{
  265. */
  266. #define RCC_LSEDrive_Low ((uint32_t)0x00000000)
  267. #define RCC_LSEDrive_MediumLow RCC_BDCR_LSEDRV_0
  268. #define RCC_LSEDrive_MediumHigh RCC_BDCR_LSEDRV_1
  269. #define RCC_LSEDrive_High RCC_BDCR_LSEDRV
  270. #define IS_RCC_LSE_DRIVE(DRIVE) (((DRIVE) == RCC_LSEDrive_Low) || ((DRIVE) == RCC_LSEDrive_MediumLow) || \
  271. ((DRIVE) == RCC_LSEDrive_MediumHigh) || ((DRIVE) == RCC_LSEDrive_High))
  272. /**
  273. * @}
  274. */
  275. /** @defgroup RCC_AHB_Peripherals
  276. * @{
  277. */
  278. #define RCC_AHBPeriph_GPIOA RCC_AHBENR_GPIOAEN
  279. #define RCC_AHBPeriph_GPIOB RCC_AHBENR_GPIOBEN
  280. #define RCC_AHBPeriph_GPIOC RCC_AHBENR_GPIOCEN
  281. #define RCC_AHBPeriph_GPIOD RCC_AHBENR_GPIODEN
  282. #define RCC_AHBPeriph_GPIOF RCC_AHBENR_GPIOFEN
  283. #define RCC_AHBPeriph_TS RCC_AHBENR_TSEN
  284. #define RCC_AHBPeriph_CRC RCC_AHBENR_CRCEN
  285. #define RCC_AHBPeriph_FLITF RCC_AHBENR_FLITFEN
  286. #define RCC_AHBPeriph_SRAM RCC_AHBENR_SRAMEN
  287. #define RCC_AHBPeriph_DMA1 RCC_AHBENR_DMA1EN
  288. #define RCC_AHBPeriph_DMA2 RCC_AHBENR_DMA2EN
  289. #define IS_RCC_AHB_PERIPH(PERIPH) ((((PERIPH) & 0xFE81FFA8) == 0x00) && ((PERIPH) != 0x00))
  290. #define IS_RCC_AHB_RST_PERIPH(PERIPH) ((((PERIPH) & 0xFE81FFA8) == 0x00) && ((PERIPH) != 0x00))
  291. /**
  292. * @}
  293. */
  294. /** @defgroup RCC_APB2_Peripherals
  295. * @{
  296. */
  297. #define RCC_APB2Periph_SYSCFG RCC_APB2ENR_SYSCFGEN
  298. #define RCC_APB2Periph_USART6 RCC_APB2ENR_USART6EN
  299. #define RCC_APB2Periph_USART7 RCC_APB2ENR_USART7EN
  300. #define RCC_APB2Periph_USART8 RCC_APB2ENR_USART8EN
  301. #define RCC_APB2Periph_ADC1 RCC_APB2ENR_ADC1EN
  302. #define RCC_APB2Periph_TIM1 RCC_APB2ENR_TIM1EN
  303. #define RCC_APB2Periph_SPI1 RCC_APB2ENR_SPI1EN
  304. #define RCC_APB2Periph_USART1 RCC_APB2ENR_USART1EN
  305. #define RCC_APB2Periph_TIM15 RCC_APB2ENR_TIM15EN
  306. #define RCC_APB2Periph_TIM16 RCC_APB2ENR_TIM16EN
  307. #define RCC_APB2Periph_TIM17 RCC_APB2ENR_TIM17EN
  308. #define RCC_APB2Periph_DBGMCU RCC_APB2ENR_DBGMCUEN
  309. #define IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH) & 0xFFB8A51E) == 0x00) && ((PERIPH) != 0x00))
  310. /**
  311. * @}
  312. */
  313. /** @defgroup RCC_APB1_Peripherals
  314. * @{
  315. */
  316. #define RCC_APB1Periph_TIM2 RCC_APB1ENR_TIM2EN
  317. #define RCC_APB1Periph_TIM3 RCC_APB1ENR_TIM3EN
  318. #define RCC_APB1Periph_TIM6 RCC_APB1ENR_TIM6EN
  319. #define RCC_APB1Periph_TIM14 RCC_APB1ENR_TIM14EN
  320. #define RCC_APB1Periph_WWDG RCC_APB1ENR_WWDGEN
  321. #define RCC_APB1Periph_SPI2 RCC_APB1ENR_SPI2EN
  322. #define RCC_APB1Periph_USART2 RCC_APB1ENR_USART2EN
  323. #define RCC_APB1Periph_I2C1 RCC_APB1ENR_I2C1EN
  324. #define RCC_APB1Periph_I2C2 RCC_APB1ENR_I2C2EN
  325. #define RCC_APB1Periph_PWR RCC_APB1ENR_PWREN
  326. #define IS_RCC_APB1_PERIPH(PERIPH) ((((PERIPH) & 0x8581B6CC) == 0x00) && ((PERIPH) != 0x00))
  327. /**
  328. * @}
  329. */
  330. /** @defgroup RCC_MCO_Clock_Source
  331. * @{
  332. */
  333. #define RCC_MCOSource_NoClock ((uint8_t)0x00)
  334. #define RCC_MCOSource_HSI14 ((uint8_t)0x01)
  335. #define RCC_MCOSource_LSI ((uint8_t)0x02)
  336. #define RCC_MCOSource_LSE ((uint8_t)0x03)
  337. #define RCC_MCOSource_SYSCLK ((uint8_t)0x04)
  338. #define RCC_MCOSource_HSI ((uint8_t)0x05)
  339. #define RCC_MCOSource_HSE ((uint8_t)0x06)
  340. #define RCC_MCOSource_PLLCLK_Div2 ((uint8_t)0x07)
  341. #define RCC_MCOSource_PLLCLK ((uint8_t)0x87)
  342. #define IS_RCC_MCO_SOURCE(SOURCE) (((SOURCE) == RCC_MCOSource_NoClock) || ((SOURCE) == RCC_MCOSource_HSI14) || \
  343. ((SOURCE) == RCC_MCOSource_SYSCLK) || ((SOURCE) == RCC_MCOSource_HSI) || \
  344. ((SOURCE) == RCC_MCOSource_HSE) || ((SOURCE) == RCC_MCOSource_PLLCLK_Div2)|| \
  345. ((SOURCE) == RCC_MCOSource_LSI) || \
  346. ((SOURCE) == RCC_MCOSource_PLLCLK) || ((SOURCE) == RCC_MCOSource_LSE))
  347. /**
  348. * @}
  349. */
  350. /** @defgroup RCC_MCOPrescaler
  351. * @{
  352. */
  353. #if !defined (HK32F030x8)
  354. #define RCC_MCOPrescaler_1 RCC_CFGR_MCO_PRE_1
  355. #define RCC_MCOPrescaler_2 RCC_CFGR_MCO_PRE_2
  356. #define RCC_MCOPrescaler_4 RCC_CFGR_MCO_PRE_4
  357. #define RCC_MCOPrescaler_8 RCC_CFGR_MCO_PRE_8
  358. #define RCC_MCOPrescaler_16 RCC_CFGR_MCO_PRE_16
  359. #define RCC_MCOPrescaler_32 RCC_CFGR_MCO_PRE_32
  360. #define RCC_MCOPrescaler_64 RCC_CFGR_MCO_PRE_64
  361. #define RCC_MCOPrescaler_128 RCC_CFGR_MCO_PRE_128
  362. #define IS_RCC_MCO_PRESCALER(PRESCALER) (((PRESCALER) == RCC_MCOPrescaler_1) || \
  363. ((PRESCALER) == RCC_MCOPrescaler_2) || \
  364. ((PRESCALER) == RCC_MCOPrescaler_4) || \
  365. ((PRESCALER) == RCC_MCOPrescaler_8) || \
  366. ((PRESCALER) == RCC_MCOPrescaler_16) || \
  367. ((PRESCALER) == RCC_MCOPrescaler_32) || \
  368. ((PRESCALER) == RCC_MCOPrescaler_64) || \
  369. ((PRESCALER) == RCC_MCOPrescaler_128))
  370. #endif /* HK32F030x8 */
  371. /**
  372. * @}
  373. */
  374. /** @defgroup RCC_Flag
  375. * @{
  376. */
  377. #define RCC_FLAG_HSIRDY ((uint8_t)0x01)
  378. #define RCC_FLAG_HSERDY ((uint8_t)0x11)
  379. #define RCC_FLAG_PLLRDY ((uint8_t)0x19)
  380. #define RCC_FLAG_LSERDY ((uint8_t)0x21)
  381. #define RCC_FLAG_LSIRDY ((uint8_t)0x41)
  382. #define RCC_FLAG_V18PWRRSTF ((uint8_t)0x57)
  383. #define RCC_FLAG_OBLRST ((uint8_t)0x59)
  384. #define RCC_FLAG_PINRST ((uint8_t)0x5A)
  385. #define RCC_FLAG_PORRST ((uint8_t)0x5B)
  386. #define RCC_FLAG_SFTRST ((uint8_t)0x5C)
  387. #define RCC_FLAG_IWDGRST ((uint8_t)0x5D)
  388. #define RCC_FLAG_WWDGRST ((uint8_t)0x5E)
  389. #define RCC_FLAG_LPWRRST ((uint8_t)0x5F)
  390. #define RCC_FLAG_HSI14RDY ((uint8_t)0x61)
  391. #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \
  392. ((FLAG) == RCC_FLAG_PLLRDY) || ((FLAG) == RCC_FLAG_LSERDY) || \
  393. ((FLAG) == RCC_FLAG_LSIRDY) || ((FLAG) == RCC_FLAG_OBLRST) || \
  394. ((FLAG) == RCC_FLAG_PINRST) || ((FLAG) == RCC_FLAG_PORRST) || \
  395. ((FLAG) == RCC_FLAG_SFTRST) || ((FLAG) == RCC_FLAG_IWDGRST) || \
  396. ((FLAG) == RCC_FLAG_WWDGRST) || ((FLAG) == RCC_FLAG_LPWRRST) || \
  397. ((FLAG) == RCC_FLAG_HSI14RDY)|| ((FLAG) == RCC_FLAG_HSI48RDY)|| \
  398. ((FLAG) == RCC_FLAG_V18PWRRSTF))
  399. #define IS_RCC_HSI_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x1F)
  400. #define IS_RCC_HSI14_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x1F)
  401. /**
  402. * @}
  403. */
  404. /**
  405. * @}
  406. */
  407. /* Exported macro ------------------------------------------------------------*/
  408. /* Exported functions ------------------------------------------------------- */
  409. /* Function used to set the RCC clock configuration to the default reset state */
  410. void RCC_DeInit(void);
  411. /* Internal/external clocks, PLL, CSS and MCO configuration functions *********/
  412. void RCC_HSEConfig(uint8_t RCC_HSE);
  413. ErrorStatus RCC_WaitForHSEStartUp(void);
  414. void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue);
  415. void RCC_HSICmd(FunctionalState NewState);
  416. void RCC_AdjustHSI14CalibrationValue(uint8_t HSI14CalibrationValue);
  417. void RCC_HSI14Cmd(FunctionalState NewState);
  418. void RCC_HSI14ADCRequestCmd(FunctionalState NewState);
  419. void RCC_LSEConfig(uint32_t RCC_LSE);
  420. void RCC_LSEDriveConfig(uint32_t RCC_LSEDrive);
  421. void RCC_LSICmd(FunctionalState NewState);
  422. void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul);
  423. void RCC_PLLCmd(FunctionalState NewState);
  424. void RCC_PREDIV1Config(uint32_t RCC_PREDIV1_Div);
  425. void RCC_ClockSecuritySystemCmd(FunctionalState NewState);
  426. #ifdef HK32F030x8
  427. void RCC_MCOConfig(uint8_t RCC_MCOSource);
  428. #else
  429. void RCC_MCOConfig(uint8_t RCC_MCOSource,uint32_t RCC_MCOPrescaler);
  430. #endif /* HK32F030x8 */
  431. /* System, AHB and APB busses clocks configuration functions ******************/
  432. void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource);
  433. uint8_t RCC_GetSYSCLKSource(void);
  434. void RCC_HCLKConfig(uint32_t RCC_SYSCLK);
  435. void RCC_PCLKConfig(uint32_t RCC_HCLK);
  436. void RCC_ADCCLKConfig(uint32_t RCC_ADCCLK); /* This function is obsolete.
  437. For proper ADC clock selection, refer to
  438. ADC_ClockModeConfig() in the ADC driver */
  439. void RCC_CECCLKConfig(uint32_t RCC_CECCLK);
  440. void RCC_I2CCLKConfig(uint32_t RCC_I2CCLK);
  441. void RCC_USARTCLKConfig(uint32_t RCC_USARTCLK);
  442. void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks);
  443. /* Peripheral clocks configuration functions **********************************/
  444. void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource);
  445. void RCC_RTCCLKCmd(FunctionalState NewState);
  446. void RCC_BackupResetCmd(FunctionalState NewState);
  447. void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
  448. void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
  449. void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
  450. void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
  451. void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
  452. void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
  453. /* Interrupts and flags management functions **********************************/
  454. void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState);
  455. FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG);
  456. void RCC_ClearFlag(void);
  457. ITStatus RCC_GetITStatus(uint8_t RCC_IT);
  458. void RCC_ClearITPendingBit(uint8_t RCC_IT);
  459. #ifdef __cplusplus
  460. }
  461. #endif
  462. #endif /* __HK32F0XX_RCC_H */
  463. /**
  464. * @}
  465. */
  466. /**
  467. * @}
  468. */