stm32f10x_rcc.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_rcc.h
  4. * @author MCD Application Team
  5. * @version V3.5.0
  6. * @date 11-March-2011
  7. * @brief This file contains all the functions prototypes for the RCC firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  20. ******************************************************************************
  21. */
  22. /* Define to prevent recursive inclusion -------------------------------------*/
  23. #ifndef __STM32F10x_RCC_H
  24. #define __STM32F10x_RCC_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32f10x.h"
  30. /** @addtogroup STM32F10x_StdPeriph_Driver
  31. * @{
  32. */
  33. /** @addtogroup RCC
  34. * @{
  35. */
  36. /** @defgroup RCC_Exported_Types
  37. * @{
  38. */
  39. typedef struct
  40. {
  41. uint32_t SYSCLK_Frequency; /*!< returns SYSCLK clock frequency expressed in Hz */
  42. uint32_t HCLK_Frequency; /*!< returns HCLK clock frequency expressed in Hz */
  43. uint32_t PCLK1_Frequency; /*!< returns PCLK1 clock frequency expressed in Hz */
  44. uint32_t PCLK2_Frequency; /*!< returns PCLK2 clock frequency expressed in Hz */
  45. uint32_t ADCCLK_Frequency; /*!< returns ADCCLK clock frequency expressed in Hz */
  46. }RCC_ClocksTypeDef;
  47. /**
  48. * @}
  49. */
  50. /** @defgroup RCC_Exported_Constants
  51. * @{
  52. */
  53. /** @defgroup HSE_configuration
  54. * @{
  55. */
  56. #define RCC_HSE_OFF ((uint32_t)0x00000000)
  57. #define RCC_HSE_ON ((uint32_t)0x00010000)
  58. #define RCC_HSE_Bypass ((uint32_t)0x00040000)
  59. #define IS_RCC_HSE(HSE) (((HSE) == RCC_HSE_OFF) || ((HSE) == RCC_HSE_ON) || \
  60. ((HSE) == RCC_HSE_Bypass))
  61. /**
  62. * @}
  63. */
  64. /** @defgroup PLL_entry_clock_source
  65. * @{
  66. */
  67. #define RCC_PLLSource_HSI_Div2 ((uint32_t)0x00000000)
  68. #if !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_CL)
  69. #define RCC_PLLSource_HSE_Div1 ((uint32_t)0x00010000)
  70. #define RCC_PLLSource_HSE_Div2 ((uint32_t)0x00030000)
  71. #define IS_RCC_PLL_SOURCE(SOURCE) (((SOURCE) == RCC_PLLSource_HSI_Div2) || \
  72. ((SOURCE) == RCC_PLLSource_HSE_Div1) || \
  73. ((SOURCE) == RCC_PLLSource_HSE_Div2))
  74. #else
  75. #define RCC_PLLSource_PREDIV1 ((uint32_t)0x00010000)
  76. #define IS_RCC_PLL_SOURCE(SOURCE) (((SOURCE) == RCC_PLLSource_HSI_Div2) || \
  77. ((SOURCE) == RCC_PLLSource_PREDIV1))
  78. #endif /* STM32F10X_CL */
  79. /**
  80. * @}
  81. */
  82. /** @defgroup PLL_multiplication_factor
  83. * @{
  84. */
  85. #ifndef STM32F10X_CL
  86. #define RCC_PLLMul_2 ((uint32_t)0x00000000)
  87. #define RCC_PLLMul_3 ((uint32_t)0x00040000)
  88. #define RCC_PLLMul_4 ((uint32_t)0x00080000)
  89. #define RCC_PLLMul_5 ((uint32_t)0x000C0000)
  90. #define RCC_PLLMul_6 ((uint32_t)0x00100000)
  91. #define RCC_PLLMul_7 ((uint32_t)0x00140000)
  92. #define RCC_PLLMul_8 ((uint32_t)0x00180000)
  93. #define RCC_PLLMul_9 ((uint32_t)0x001C0000)
  94. #define RCC_PLLMul_10 ((uint32_t)0x00200000)
  95. #define RCC_PLLMul_11 ((uint32_t)0x00240000)
  96. #define RCC_PLLMul_12 ((uint32_t)0x00280000)
  97. #define RCC_PLLMul_13 ((uint32_t)0x002C0000)
  98. #define RCC_PLLMul_14 ((uint32_t)0x00300000)
  99. #define RCC_PLLMul_15 ((uint32_t)0x00340000)
  100. #define RCC_PLLMul_16 ((uint32_t)0x00380000)
  101. #define IS_RCC_PLL_MUL(MUL) (((MUL) == RCC_PLLMul_2) || ((MUL) == RCC_PLLMul_3) || \
  102. ((MUL) == RCC_PLLMul_4) || ((MUL) == RCC_PLLMul_5) || \
  103. ((MUL) == RCC_PLLMul_6) || ((MUL) == RCC_PLLMul_7) || \
  104. ((MUL) == RCC_PLLMul_8) || ((MUL) == RCC_PLLMul_9) || \
  105. ((MUL) == RCC_PLLMul_10) || ((MUL) == RCC_PLLMul_11) || \
  106. ((MUL) == RCC_PLLMul_12) || ((MUL) == RCC_PLLMul_13) || \
  107. ((MUL) == RCC_PLLMul_14) || ((MUL) == RCC_PLLMul_15) || \
  108. ((MUL) == RCC_PLLMul_16))
  109. #else
  110. #define RCC_PLLMul_4 ((uint32_t)0x00080000)
  111. #define RCC_PLLMul_5 ((uint32_t)0x000C0000)
  112. #define RCC_PLLMul_6 ((uint32_t)0x00100000)
  113. #define RCC_PLLMul_7 ((uint32_t)0x00140000)
  114. #define RCC_PLLMul_8 ((uint32_t)0x00180000)
  115. #define RCC_PLLMul_9 ((uint32_t)0x001C0000)
  116. #define RCC_PLLMul_6_5 ((uint32_t)0x00340000)
  117. #define IS_RCC_PLL_MUL(MUL) (((MUL) == RCC_PLLMul_4) || ((MUL) == RCC_PLLMul_5) || \
  118. ((MUL) == RCC_PLLMul_6) || ((MUL) == RCC_PLLMul_7) || \
  119. ((MUL) == RCC_PLLMul_8) || ((MUL) == RCC_PLLMul_9) || \
  120. ((MUL) == RCC_PLLMul_6_5))
  121. #endif /* STM32F10X_CL */
  122. /**
  123. * @}
  124. */
  125. /** @defgroup PREDIV1_division_factor
  126. * @{
  127. */
  128. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
  129. #define RCC_PREDIV1_Div1 ((uint32_t)0x00000000)
  130. #define RCC_PREDIV1_Div2 ((uint32_t)0x00000001)
  131. #define RCC_PREDIV1_Div3 ((uint32_t)0x00000002)
  132. #define RCC_PREDIV1_Div4 ((uint32_t)0x00000003)
  133. #define RCC_PREDIV1_Div5 ((uint32_t)0x00000004)
  134. #define RCC_PREDIV1_Div6 ((uint32_t)0x00000005)
  135. #define RCC_PREDIV1_Div7 ((uint32_t)0x00000006)
  136. #define RCC_PREDIV1_Div8 ((uint32_t)0x00000007)
  137. #define RCC_PREDIV1_Div9 ((uint32_t)0x00000008)
  138. #define RCC_PREDIV1_Div10 ((uint32_t)0x00000009)
  139. #define RCC_PREDIV1_Div11 ((uint32_t)0x0000000A)
  140. #define RCC_PREDIV1_Div12 ((uint32_t)0x0000000B)
  141. #define RCC_PREDIV1_Div13 ((uint32_t)0x0000000C)
  142. #define RCC_PREDIV1_Div14 ((uint32_t)0x0000000D)
  143. #define RCC_PREDIV1_Div15 ((uint32_t)0x0000000E)
  144. #define RCC_PREDIV1_Div16 ((uint32_t)0x0000000F)
  145. #define IS_RCC_PREDIV1(PREDIV1) (((PREDIV1) == RCC_PREDIV1_Div1) || ((PREDIV1) == RCC_PREDIV1_Div2) || \
  146. ((PREDIV1) == RCC_PREDIV1_Div3) || ((PREDIV1) == RCC_PREDIV1_Div4) || \
  147. ((PREDIV1) == RCC_PREDIV1_Div5) || ((PREDIV1) == RCC_PREDIV1_Div6) || \
  148. ((PREDIV1) == RCC_PREDIV1_Div7) || ((PREDIV1) == RCC_PREDIV1_Div8) || \
  149. ((PREDIV1) == RCC_PREDIV1_Div9) || ((PREDIV1) == RCC_PREDIV1_Div10) || \
  150. ((PREDIV1) == RCC_PREDIV1_Div11) || ((PREDIV1) == RCC_PREDIV1_Div12) || \
  151. ((PREDIV1) == RCC_PREDIV1_Div13) || ((PREDIV1) == RCC_PREDIV1_Div14) || \
  152. ((PREDIV1) == RCC_PREDIV1_Div15) || ((PREDIV1) == RCC_PREDIV1_Div16))
  153. #endif
  154. /**
  155. * @}
  156. */
  157. /** @defgroup PREDIV1_clock_source
  158. * @{
  159. */
  160. #ifdef STM32F10X_CL
  161. /* PREDIV1 clock source (for STM32 connectivity line devices) */
  162. #define RCC_PREDIV1_Source_HSE ((uint32_t)0x00000000)
  163. #define RCC_PREDIV1_Source_PLL2 ((uint32_t)0x00010000)
  164. #define IS_RCC_PREDIV1_SOURCE(SOURCE) (((SOURCE) == RCC_PREDIV1_Source_HSE) || \
  165. ((SOURCE) == RCC_PREDIV1_Source_PLL2))
  166. #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  167. /* PREDIV1 clock source (for STM32 Value line devices) */
  168. #define RCC_PREDIV1_Source_HSE ((uint32_t)0x00000000)
  169. #define IS_RCC_PREDIV1_SOURCE(SOURCE) (((SOURCE) == RCC_PREDIV1_Source_HSE))
  170. #endif
  171. /**
  172. * @}
  173. */
  174. #ifdef STM32F10X_CL
  175. /** @defgroup PREDIV2_division_factor
  176. * @{
  177. */
  178. #define RCC_PREDIV2_Div1 ((uint32_t)0x00000000)
  179. #define RCC_PREDIV2_Div2 ((uint32_t)0x00000010)
  180. #define RCC_PREDIV2_Div3 ((uint32_t)0x00000020)
  181. #define RCC_PREDIV2_Div4 ((uint32_t)0x00000030)
  182. #define RCC_PREDIV2_Div5 ((uint32_t)0x00000040)
  183. #define RCC_PREDIV2_Div6 ((uint32_t)0x00000050)
  184. #define RCC_PREDIV2_Div7 ((uint32_t)0x00000060)
  185. #define RCC_PREDIV2_Div8 ((uint32_t)0x00000070)
  186. #define RCC_PREDIV2_Div9 ((uint32_t)0x00000080)
  187. #define RCC_PREDIV2_Div10 ((uint32_t)0x00000090)
  188. #define RCC_PREDIV2_Div11 ((uint32_t)0x000000A0)
  189. #define RCC_PREDIV2_Div12 ((uint32_t)0x000000B0)
  190. #define RCC_PREDIV2_Div13 ((uint32_t)0x000000C0)
  191. #define RCC_PREDIV2_Div14 ((uint32_t)0x000000D0)
  192. #define RCC_PREDIV2_Div15 ((uint32_t)0x000000E0)
  193. #define RCC_PREDIV2_Div16 ((uint32_t)0x000000F0)
  194. #define IS_RCC_PREDIV2(PREDIV2) (((PREDIV2) == RCC_PREDIV2_Div1) || ((PREDIV2) == RCC_PREDIV2_Div2) || \
  195. ((PREDIV2) == RCC_PREDIV2_Div3) || ((PREDIV2) == RCC_PREDIV2_Div4) || \
  196. ((PREDIV2) == RCC_PREDIV2_Div5) || ((PREDIV2) == RCC_PREDIV2_Div6) || \
  197. ((PREDIV2) == RCC_PREDIV2_Div7) || ((PREDIV2) == RCC_PREDIV2_Div8) || \
  198. ((PREDIV2) == RCC_PREDIV2_Div9) || ((PREDIV2) == RCC_PREDIV2_Div10) || \
  199. ((PREDIV2) == RCC_PREDIV2_Div11) || ((PREDIV2) == RCC_PREDIV2_Div12) || \
  200. ((PREDIV2) == RCC_PREDIV2_Div13) || ((PREDIV2) == RCC_PREDIV2_Div14) || \
  201. ((PREDIV2) == RCC_PREDIV2_Div15) || ((PREDIV2) == RCC_PREDIV2_Div16))
  202. /**
  203. * @}
  204. */
  205. /** @defgroup PLL2_multiplication_factor
  206. * @{
  207. */
  208. #define RCC_PLL2Mul_8 ((uint32_t)0x00000600)
  209. #define RCC_PLL2Mul_9 ((uint32_t)0x00000700)
  210. #define RCC_PLL2Mul_10 ((uint32_t)0x00000800)
  211. #define RCC_PLL2Mul_11 ((uint32_t)0x00000900)
  212. #define RCC_PLL2Mul_12 ((uint32_t)0x00000A00)
  213. #define RCC_PLL2Mul_13 ((uint32_t)0x00000B00)
  214. #define RCC_PLL2Mul_14 ((uint32_t)0x00000C00)
  215. #define RCC_PLL2Mul_16 ((uint32_t)0x00000E00)
  216. #define RCC_PLL2Mul_20 ((uint32_t)0x00000F00)
  217. #define IS_RCC_PLL2_MUL(MUL) (((MUL) == RCC_PLL2Mul_8) || ((MUL) == RCC_PLL2Mul_9) || \
  218. ((MUL) == RCC_PLL2Mul_10) || ((MUL) == RCC_PLL2Mul_11) || \
  219. ((MUL) == RCC_PLL2Mul_12) || ((MUL) == RCC_PLL2Mul_13) || \
  220. ((MUL) == RCC_PLL2Mul_14) || ((MUL) == RCC_PLL2Mul_16) || \
  221. ((MUL) == RCC_PLL2Mul_20))
  222. /**
  223. * @}
  224. */
  225. /** @defgroup PLL3_multiplication_factor
  226. * @{
  227. */
  228. #define RCC_PLL3Mul_8 ((uint32_t)0x00006000)
  229. #define RCC_PLL3Mul_9 ((uint32_t)0x00007000)
  230. #define RCC_PLL3Mul_10 ((uint32_t)0x00008000)
  231. #define RCC_PLL3Mul_11 ((uint32_t)0x00009000)
  232. #define RCC_PLL3Mul_12 ((uint32_t)0x0000A000)
  233. #define RCC_PLL3Mul_13 ((uint32_t)0x0000B000)
  234. #define RCC_PLL3Mul_14 ((uint32_t)0x0000C000)
  235. #define RCC_PLL3Mul_16 ((uint32_t)0x0000E000)
  236. #define RCC_PLL3Mul_20 ((uint32_t)0x0000F000)
  237. #define IS_RCC_PLL3_MUL(MUL) (((MUL) == RCC_PLL3Mul_8) || ((MUL) == RCC_PLL3Mul_9) || \
  238. ((MUL) == RCC_PLL3Mul_10) || ((MUL) == RCC_PLL3Mul_11) || \
  239. ((MUL) == RCC_PLL3Mul_12) || ((MUL) == RCC_PLL3Mul_13) || \
  240. ((MUL) == RCC_PLL3Mul_14) || ((MUL) == RCC_PLL3Mul_16) || \
  241. ((MUL) == RCC_PLL3Mul_20))
  242. /**
  243. * @}
  244. */
  245. #endif /* STM32F10X_CL */
  246. /** @defgroup System_clock_source
  247. * @{
  248. */
  249. #define RCC_SYSCLKSource_HSI ((uint32_t)0x00000000)
  250. #define RCC_SYSCLKSource_HSE ((uint32_t)0x00000001)
  251. #define RCC_SYSCLKSource_PLLCLK ((uint32_t)0x00000002)
  252. #define IS_RCC_SYSCLK_SOURCE(SOURCE) (((SOURCE) == RCC_SYSCLKSource_HSI) || \
  253. ((SOURCE) == RCC_SYSCLKSource_HSE) || \
  254. ((SOURCE) == RCC_SYSCLKSource_PLLCLK))
  255. /**
  256. * @}
  257. */
  258. /** @defgroup AHB_clock_source
  259. * @{
  260. */
  261. #define RCC_SYSCLK_Div1 ((uint32_t)0x00000000)
  262. #define RCC_SYSCLK_Div2 ((uint32_t)0x00000080)
  263. #define RCC_SYSCLK_Div4 ((uint32_t)0x00000090)
  264. #define RCC_SYSCLK_Div8 ((uint32_t)0x000000A0)
  265. #define RCC_SYSCLK_Div16 ((uint32_t)0x000000B0)
  266. #define RCC_SYSCLK_Div64 ((uint32_t)0x000000C0)
  267. #define RCC_SYSCLK_Div128 ((uint32_t)0x000000D0)
  268. #define RCC_SYSCLK_Div256 ((uint32_t)0x000000E0)
  269. #define RCC_SYSCLK_Div512 ((uint32_t)0x000000F0)
  270. #define IS_RCC_HCLK(HCLK) (((HCLK) == RCC_SYSCLK_Div1) || ((HCLK) == RCC_SYSCLK_Div2) || \
  271. ((HCLK) == RCC_SYSCLK_Div4) || ((HCLK) == RCC_SYSCLK_Div8) || \
  272. ((HCLK) == RCC_SYSCLK_Div16) || ((HCLK) == RCC_SYSCLK_Div64) || \
  273. ((HCLK) == RCC_SYSCLK_Div128) || ((HCLK) == RCC_SYSCLK_Div256) || \
  274. ((HCLK) == RCC_SYSCLK_Div512))
  275. /**
  276. * @}
  277. */
  278. /** @defgroup APB1_APB2_clock_source
  279. * @{
  280. */
  281. #define RCC_HCLK_Div1 ((uint32_t)0x00000000)
  282. #define RCC_HCLK_Div2 ((uint32_t)0x00000400)
  283. #define RCC_HCLK_Div4 ((uint32_t)0x00000500)
  284. #define RCC_HCLK_Div8 ((uint32_t)0x00000600)
  285. #define RCC_HCLK_Div16 ((uint32_t)0x00000700)
  286. #define IS_RCC_PCLK(PCLK) (((PCLK) == RCC_HCLK_Div1) || ((PCLK) == RCC_HCLK_Div2) || \
  287. ((PCLK) == RCC_HCLK_Div4) || ((PCLK) == RCC_HCLK_Div8) || \
  288. ((PCLK) == RCC_HCLK_Div16))
  289. /**
  290. * @}
  291. */
  292. /** @defgroup RCC_Interrupt_source
  293. * @{
  294. */
  295. #define RCC_IT_LSIRDY ((uint8_t)0x01)
  296. #define RCC_IT_LSERDY ((uint8_t)0x02)
  297. #define RCC_IT_HSIRDY ((uint8_t)0x04)
  298. #define RCC_IT_HSERDY ((uint8_t)0x08)
  299. #define RCC_IT_PLLRDY ((uint8_t)0x10)
  300. #define RCC_IT_CSS ((uint8_t)0x80)
  301. #ifndef STM32F10X_CL
  302. #define IS_RCC_IT(IT) ((((IT) & (uint8_t)0xE0) == 0x00) && ((IT) != 0x00))
  303. #define IS_RCC_GET_IT(IT) (((IT) == RCC_IT_LSIRDY) || ((IT) == RCC_IT_LSERDY) || \
  304. ((IT) == RCC_IT_HSIRDY) || ((IT) == RCC_IT_HSERDY) || \
  305. ((IT) == RCC_IT_PLLRDY) || ((IT) == RCC_IT_CSS))
  306. #define IS_RCC_CLEAR_IT(IT) ((((IT) & (uint8_t)0x60) == 0x00) && ((IT) != 0x00))
  307. #else
  308. #define RCC_IT_PLL2RDY ((uint8_t)0x20)
  309. #define RCC_IT_PLL3RDY ((uint8_t)0x40)
  310. #define IS_RCC_IT(IT) ((((IT) & (uint8_t)0x80) == 0x00) && ((IT) != 0x00))
  311. #define IS_RCC_GET_IT(IT) (((IT) == RCC_IT_LSIRDY) || ((IT) == RCC_IT_LSERDY) || \
  312. ((IT) == RCC_IT_HSIRDY) || ((IT) == RCC_IT_HSERDY) || \
  313. ((IT) == RCC_IT_PLLRDY) || ((IT) == RCC_IT_CSS) || \
  314. ((IT) == RCC_IT_PLL2RDY) || ((IT) == RCC_IT_PLL3RDY))
  315. #define IS_RCC_CLEAR_IT(IT) ((IT) != 0x00)
  316. #endif /* STM32F10X_CL */
  317. /**
  318. * @}
  319. */
  320. #ifndef STM32F10X_CL
  321. /** @defgroup USB_Device_clock_source
  322. * @{
  323. */
  324. #define RCC_USBCLKSource_PLLCLK_1Div5 ((uint8_t)0x00)
  325. #define RCC_USBCLKSource_PLLCLK_Div1 ((uint8_t)0x01)
  326. #define IS_RCC_USBCLK_SOURCE(SOURCE) (((SOURCE) == RCC_USBCLKSource_PLLCLK_1Div5) || \
  327. ((SOURCE) == RCC_USBCLKSource_PLLCLK_Div1))
  328. /**
  329. * @}
  330. */
  331. #else
  332. /** @defgroup USB_OTG_FS_clock_source
  333. * @{
  334. */
  335. #define RCC_OTGFSCLKSource_PLLVCO_Div3 ((uint8_t)0x00)
  336. #define RCC_OTGFSCLKSource_PLLVCO_Div2 ((uint8_t)0x01)
  337. #define IS_RCC_OTGFSCLK_SOURCE(SOURCE) (((SOURCE) == RCC_OTGFSCLKSource_PLLVCO_Div3) || \
  338. ((SOURCE) == RCC_OTGFSCLKSource_PLLVCO_Div2))
  339. /**
  340. * @}
  341. */
  342. #endif /* STM32F10X_CL */
  343. #ifdef STM32F10X_CL
  344. /** @defgroup I2S2_clock_source
  345. * @{
  346. */
  347. #define RCC_I2S2CLKSource_SYSCLK ((uint8_t)0x00)
  348. #define RCC_I2S2CLKSource_PLL3_VCO ((uint8_t)0x01)
  349. #define IS_RCC_I2S2CLK_SOURCE(SOURCE) (((SOURCE) == RCC_I2S2CLKSource_SYSCLK) || \
  350. ((SOURCE) == RCC_I2S2CLKSource_PLL3_VCO))
  351. /**
  352. * @}
  353. */
  354. /** @defgroup I2S3_clock_source
  355. * @{
  356. */
  357. #define RCC_I2S3CLKSource_SYSCLK ((uint8_t)0x00)
  358. #define RCC_I2S3CLKSource_PLL3_VCO ((uint8_t)0x01)
  359. #define IS_RCC_I2S3CLK_SOURCE(SOURCE) (((SOURCE) == RCC_I2S3CLKSource_SYSCLK) || \
  360. ((SOURCE) == RCC_I2S3CLKSource_PLL3_VCO))
  361. /**
  362. * @}
  363. */
  364. #endif /* STM32F10X_CL */
  365. /** @defgroup ADC_clock_source
  366. * @{
  367. */
  368. #define RCC_PCLK2_Div2 ((uint32_t)0x00000000)
  369. #define RCC_PCLK2_Div4 ((uint32_t)0x00004000)
  370. #define RCC_PCLK2_Div6 ((uint32_t)0x00008000)
  371. #define RCC_PCLK2_Div8 ((uint32_t)0x0000C000)
  372. #define IS_RCC_ADCCLK(ADCCLK) (((ADCCLK) == RCC_PCLK2_Div2) || ((ADCCLK) == RCC_PCLK2_Div4) || \
  373. ((ADCCLK) == RCC_PCLK2_Div6) || ((ADCCLK) == RCC_PCLK2_Div8))
  374. /**
  375. * @}
  376. */
  377. /** @defgroup LSE_configuration
  378. * @{
  379. */
  380. #define RCC_LSE_OFF ((uint8_t)0x00)
  381. #define RCC_LSE_ON ((uint8_t)0x01)
  382. #define RCC_LSE_Bypass ((uint8_t)0x04)
  383. #define IS_RCC_LSE(LSE) (((LSE) == RCC_LSE_OFF) || ((LSE) == RCC_LSE_ON) || \
  384. ((LSE) == RCC_LSE_Bypass))
  385. /**
  386. * @}
  387. */
  388. /** @defgroup RTC_clock_source
  389. * @{
  390. */
  391. #define RCC_RTCCLKSource_LSE ((uint32_t)0x00000100)
  392. #define RCC_RTCCLKSource_LSI ((uint32_t)0x00000200)
  393. #define RCC_RTCCLKSource_HSE_Div128 ((uint32_t)0x00000300)
  394. #define IS_RCC_RTCCLK_SOURCE(SOURCE) (((SOURCE) == RCC_RTCCLKSource_LSE) || \
  395. ((SOURCE) == RCC_RTCCLKSource_LSI) || \
  396. ((SOURCE) == RCC_RTCCLKSource_HSE_Div128))
  397. /**
  398. * @}
  399. */
  400. /** @defgroup AHB_peripheral
  401. * @{
  402. */
  403. #define RCC_AHBPeriph_DMA1 ((uint32_t)0x00000001)
  404. #define RCC_AHBPeriph_DMA2 ((uint32_t)0x00000002)
  405. #define RCC_AHBPeriph_SRAM ((uint32_t)0x00000004)
  406. #define RCC_AHBPeriph_FLITF ((uint32_t)0x00000010)
  407. #define RCC_AHBPeriph_CRC ((uint32_t)0x00000040)
  408. #ifndef STM32F10X_CL
  409. #define RCC_AHBPeriph_FSMC ((uint32_t)0x00000100)
  410. #define RCC_AHBPeriph_SDIO ((uint32_t)0x00000400)
  411. #define IS_RCC_AHB_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFFAA8) == 0x00) && ((PERIPH) != 0x00))
  412. #else
  413. #define RCC_AHBPeriph_OTG_FS ((uint32_t)0x00001000)
  414. #define RCC_AHBPeriph_ETH_MAC ((uint32_t)0x00004000)
  415. #define RCC_AHBPeriph_ETH_MAC_Tx ((uint32_t)0x00008000)
  416. #define RCC_AHBPeriph_ETH_MAC_Rx ((uint32_t)0x00010000)
  417. #define IS_RCC_AHB_PERIPH(PERIPH) ((((PERIPH) & 0xFFFE2FA8) == 0x00) && ((PERIPH) != 0x00))
  418. #define IS_RCC_AHB_PERIPH_RESET(PERIPH) ((((PERIPH) & 0xFFFFAFFF) == 0x00) && ((PERIPH) != 0x00))
  419. #endif /* STM32F10X_CL */
  420. /**
  421. * @}
  422. */
  423. /** @defgroup APB2_peripheral
  424. * @{
  425. */
  426. #define RCC_APB2Periph_AFIO ((uint32_t)0x00000001)
  427. #define RCC_APB2Periph_GPIOA ((uint32_t)0x00000004)
  428. #define RCC_APB2Periph_GPIOB ((uint32_t)0x00000008)
  429. #define RCC_APB2Periph_GPIOC ((uint32_t)0x00000010)
  430. #define RCC_APB2Periph_GPIOD ((uint32_t)0x00000020)
  431. #define RCC_APB2Periph_GPIOE ((uint32_t)0x00000040)
  432. #define RCC_APB2Periph_GPIOF ((uint32_t)0x00000080)
  433. #define RCC_APB2Periph_GPIOG ((uint32_t)0x00000100)
  434. #define RCC_APB2Periph_ADC1 ((uint32_t)0x00000200)
  435. #define RCC_APB2Periph_ADC2 ((uint32_t)0x00000400)
  436. #define RCC_APB2Periph_TIM1 ((uint32_t)0x00000800)
  437. #define RCC_APB2Periph_SPI1 ((uint32_t)0x00001000)
  438. #define RCC_APB2Periph_TIM8 ((uint32_t)0x00002000)
  439. #define RCC_APB2Periph_USART1 ((uint32_t)0x00004000)
  440. #define RCC_APB2Periph_ADC3 ((uint32_t)0x00008000)
  441. #define RCC_APB2Periph_TIM15 ((uint32_t)0x00010000)
  442. #define RCC_APB2Periph_TIM16 ((uint32_t)0x00020000)
  443. #define RCC_APB2Periph_TIM17 ((uint32_t)0x00040000)
  444. #define RCC_APB2Periph_TIM9 ((uint32_t)0x00080000)
  445. #define RCC_APB2Periph_TIM10 ((uint32_t)0x00100000)
  446. #define RCC_APB2Periph_TIM11 ((uint32_t)0x00200000)
  447. #define IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH) & 0xFFC00002) == 0x00) && ((PERIPH) != 0x00))
  448. /**
  449. * @}
  450. */
  451. /** @defgroup APB1_peripheral
  452. * @{
  453. */
  454. #define RCC_APB1Periph_TIM2 ((uint32_t)0x00000001)
  455. #define RCC_APB1Periph_TIM3 ((uint32_t)0x00000002)
  456. #define RCC_APB1Periph_TIM4 ((uint32_t)0x00000004)
  457. #define RCC_APB1Periph_TIM5 ((uint32_t)0x00000008)
  458. #define RCC_APB1Periph_TIM6 ((uint32_t)0x00000010)
  459. #define RCC_APB1Periph_TIM7 ((uint32_t)0x00000020)
  460. #define RCC_APB1Periph_TIM12 ((uint32_t)0x00000040)
  461. #define RCC_APB1Periph_TIM13 ((uint32_t)0x00000080)
  462. #define RCC_APB1Periph_TIM14 ((uint32_t)0x00000100)
  463. #define RCC_APB1Periph_WWDG ((uint32_t)0x00000800)
  464. #define RCC_APB1Periph_SPI2 ((uint32_t)0x00004000)
  465. #define RCC_APB1Periph_SPI3 ((uint32_t)0x00008000)
  466. #define RCC_APB1Periph_USART2 ((uint32_t)0x00020000)
  467. #define RCC_APB1Periph_USART3 ((uint32_t)0x00040000)
  468. #define RCC_APB1Periph_UART4 ((uint32_t)0x00080000)
  469. #define RCC_APB1Periph_UART5 ((uint32_t)0x00100000)
  470. #define RCC_APB1Periph_I2C1 ((uint32_t)0x00200000)
  471. #define RCC_APB1Periph_I2C2 ((uint32_t)0x00400000)
  472. #define RCC_APB1Periph_USB ((uint32_t)0x00800000)
  473. #define RCC_APB1Periph_CAN1 ((uint32_t)0x02000000)
  474. #define RCC_APB1Periph_CAN2 ((uint32_t)0x04000000)
  475. #define RCC_APB1Periph_BKP ((uint32_t)0x08000000)
  476. #define RCC_APB1Periph_PWR ((uint32_t)0x10000000)
  477. #define RCC_APB1Periph_DAC ((uint32_t)0x20000000)
  478. #define RCC_APB1Periph_CEC ((uint32_t)0x40000000)
  479. #define IS_RCC_APB1_PERIPH(PERIPH) ((((PERIPH) & 0x81013600) == 0x00) && ((PERIPH) != 0x00))
  480. /**
  481. * @}
  482. */
  483. /** @defgroup Clock_source_to_output_on_MCO_pin
  484. * @{
  485. */
  486. #define RCC_MCO_NoClock ((uint8_t)0x00)
  487. #define RCC_MCO_SYSCLK ((uint8_t)0x04)
  488. #define RCC_MCO_HSI ((uint8_t)0x05)
  489. #define RCC_MCO_HSE ((uint8_t)0x06)
  490. #define RCC_MCO_PLLCLK_Div2 ((uint8_t)0x07)
  491. #ifndef STM32F10X_CL
  492. #define IS_RCC_MCO(MCO) (((MCO) == RCC_MCO_NoClock) || ((MCO) == RCC_MCO_HSI) || \
  493. ((MCO) == RCC_MCO_SYSCLK) || ((MCO) == RCC_MCO_HSE) || \
  494. ((MCO) == RCC_MCO_PLLCLK_Div2))
  495. #else
  496. #define RCC_MCO_PLL2CLK ((uint8_t)0x08)
  497. #define RCC_MCO_PLL3CLK_Div2 ((uint8_t)0x09)
  498. #define RCC_MCO_XT1 ((uint8_t)0x0A)
  499. #define RCC_MCO_PLL3CLK ((uint8_t)0x0B)
  500. #define IS_RCC_MCO(MCO) (((MCO) == RCC_MCO_NoClock) || ((MCO) == RCC_MCO_HSI) || \
  501. ((MCO) == RCC_MCO_SYSCLK) || ((MCO) == RCC_MCO_HSE) || \
  502. ((MCO) == RCC_MCO_PLLCLK_Div2) || ((MCO) == RCC_MCO_PLL2CLK) || \
  503. ((MCO) == RCC_MCO_PLL3CLK_Div2) || ((MCO) == RCC_MCO_XT1) || \
  504. ((MCO) == RCC_MCO_PLL3CLK))
  505. #endif /* STM32F10X_CL */
  506. /**
  507. * @}
  508. */
  509. /** @defgroup RCC_Flag
  510. * @{
  511. */
  512. #define RCC_FLAG_HSIRDY ((uint8_t)0x21)
  513. #define RCC_FLAG_HSERDY ((uint8_t)0x31)
  514. #define RCC_FLAG_PLLRDY ((uint8_t)0x39)
  515. #define RCC_FLAG_LSERDY ((uint8_t)0x41)
  516. #define RCC_FLAG_LSIRDY ((uint8_t)0x61)
  517. #define RCC_FLAG_PINRST ((uint8_t)0x7A)
  518. #define RCC_FLAG_PORRST ((uint8_t)0x7B)
  519. #define RCC_FLAG_SFTRST ((uint8_t)0x7C)
  520. #define RCC_FLAG_IWDGRST ((uint8_t)0x7D)
  521. #define RCC_FLAG_WWDGRST ((uint8_t)0x7E)
  522. #define RCC_FLAG_LPWRRST ((uint8_t)0x7F)
  523. #ifndef STM32F10X_CL
  524. #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \
  525. ((FLAG) == RCC_FLAG_PLLRDY) || ((FLAG) == RCC_FLAG_LSERDY) || \
  526. ((FLAG) == RCC_FLAG_LSIRDY) || ((FLAG) == RCC_FLAG_PINRST) || \
  527. ((FLAG) == RCC_FLAG_PORRST) || ((FLAG) == RCC_FLAG_SFTRST) || \
  528. ((FLAG) == RCC_FLAG_IWDGRST)|| ((FLAG) == RCC_FLAG_WWDGRST)|| \
  529. ((FLAG) == RCC_FLAG_LPWRRST))
  530. #else
  531. #define RCC_FLAG_PLL2RDY ((uint8_t)0x3B)
  532. #define RCC_FLAG_PLL3RDY ((uint8_t)0x3D)
  533. #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \
  534. ((FLAG) == RCC_FLAG_PLLRDY) || ((FLAG) == RCC_FLAG_LSERDY) || \
  535. ((FLAG) == RCC_FLAG_PLL2RDY) || ((FLAG) == RCC_FLAG_PLL3RDY) || \
  536. ((FLAG) == RCC_FLAG_LSIRDY) || ((FLAG) == RCC_FLAG_PINRST) || \
  537. ((FLAG) == RCC_FLAG_PORRST) || ((FLAG) == RCC_FLAG_SFTRST) || \
  538. ((FLAG) == RCC_FLAG_IWDGRST)|| ((FLAG) == RCC_FLAG_WWDGRST)|| \
  539. ((FLAG) == RCC_FLAG_LPWRRST))
  540. #endif /* STM32F10X_CL */
  541. #define IS_RCC_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x1F)
  542. /**
  543. * @}
  544. */
  545. /**
  546. * @}
  547. */
  548. /** @defgroup RCC_Exported_Macros
  549. * @{
  550. */
  551. /**
  552. * @}
  553. */
  554. /** @defgroup RCC_Exported_Functions
  555. * @{
  556. */
  557. void RCC_DeInit(void);
  558. void RCC_HSEConfig(uint32_t RCC_HSE);
  559. ErrorStatus RCC_WaitForHSEStartUp(void);
  560. void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue);
  561. void RCC_HSICmd(FunctionalState NewState);
  562. void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul);
  563. void RCC_PLLCmd(FunctionalState NewState);
  564. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
  565. void RCC_PREDIV1Config(uint32_t RCC_PREDIV1_Source, uint32_t RCC_PREDIV1_Div);
  566. #endif
  567. #ifdef STM32F10X_CL
  568. void RCC_PREDIV2Config(uint32_t RCC_PREDIV2_Div);
  569. void RCC_PLL2Config(uint32_t RCC_PLL2Mul);
  570. void RCC_PLL2Cmd(FunctionalState NewState);
  571. void RCC_PLL3Config(uint32_t RCC_PLL3Mul);
  572. void RCC_PLL3Cmd(FunctionalState NewState);
  573. #endif /* STM32F10X_CL */
  574. void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource);
  575. uint8_t RCC_GetSYSCLKSource(void);
  576. void RCC_HCLKConfig(uint32_t RCC_SYSCLK);
  577. void RCC_PCLK1Config(uint32_t RCC_HCLK);
  578. void RCC_PCLK2Config(uint32_t RCC_HCLK);
  579. void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState);
  580. #ifndef STM32F10X_CL
  581. void RCC_USBCLKConfig(uint32_t RCC_USBCLKSource);
  582. #else
  583. void RCC_OTGFSCLKConfig(uint32_t RCC_OTGFSCLKSource);
  584. #endif /* STM32F10X_CL */
  585. void RCC_ADCCLKConfig(uint32_t RCC_PCLK2);
  586. #ifdef STM32F10X_CL
  587. void RCC_I2S2CLKConfig(uint32_t RCC_I2S2CLKSource);
  588. void RCC_I2S3CLKConfig(uint32_t RCC_I2S3CLKSource);
  589. #endif /* STM32F10X_CL */
  590. void RCC_LSEConfig(uint8_t RCC_LSE);
  591. void RCC_LSICmd(FunctionalState NewState);
  592. void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource);
  593. void RCC_RTCCLKCmd(FunctionalState NewState);
  594. void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks);
  595. void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
  596. void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
  597. void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
  598. #ifdef STM32F10X_CL
  599. void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
  600. #endif /* STM32F10X_CL */
  601. void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
  602. void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
  603. void RCC_BackupResetCmd(FunctionalState NewState);
  604. void RCC_ClockSecuritySystemCmd(FunctionalState NewState);
  605. void RCC_MCOConfig(uint8_t RCC_MCO);
  606. FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG);
  607. void RCC_ClearFlag(void);
  608. ITStatus RCC_GetITStatus(uint8_t RCC_IT);
  609. void RCC_ClearITPendingBit(uint8_t RCC_IT);
  610. #ifdef __cplusplus
  611. }
  612. #endif
  613. #endif /* __STM32F10x_RCC_H */
  614. /**
  615. * @}
  616. */
  617. /**
  618. * @}
  619. */
  620. /**
  621. * @}
  622. */
  623. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/