ft32f0xx_rcc.h 24 KB

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