stm32f10x_rcc.h 30 KB

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