A bundled STM32F10x Std Periph and CMSIS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

566 lines
28 KiB

  1. /*
  2. * stm32f10x_rcc.c
  3. *
  4. * Copyright (C) 2013 Houtouridis Christos <houtouridis.ch@gmail.com>
  5. *
  6. * All Rights Reserved.
  7. *
  8. * NOTICE: All information contained herein is, and remains
  9. * the property of Houtouridis Christos. The intellectual
  10. * and technical concepts contained herein are proprietary to
  11. * Houtouridis Christos and are protected by copyright law.
  12. * Dissemination of this information or reproduction of this material
  13. * is strictly forbidden unless prior written permission is obtained
  14. * from Houtouridis Christos.
  15. *
  16. * Author: Houtouridis Christos <houtouridis.ch@gmail.com>
  17. * Date: 4 Áðñ 2013
  18. *
  19. */
  20. #ifndef __STM32F10x_RCC_H__
  21. #define __STM32F10x_RCC_H__
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #include "stm32f10x.h"
  26. #include "stm32f10x_assert.h"
  27. /* ========================= User Defines ============================*/
  28. #define RCC_USE_IT (0)
  29. /* HSE_configuration */
  30. #define RCC_HSE_OFF ((uint32_t)0x00000000)
  31. #define RCC_HSE_ON ((uint32_t)0x00010000)
  32. #define RCC_HSE_Bypass ((uint32_t)0x00040000)
  33. #define IS_RCC_HSE(HSE) (((HSE) == RCC_HSE_OFF) || ((HSE) == RCC_HSE_ON) || \
  34. ((HSE) == RCC_HSE_Bypass))
  35. // PLL_entry_clock_source
  36. #define RCC_PLLSource_HSI_Div2 ((uint32_t)0x00000000)
  37. #if !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_CL)
  38. #define RCC_PLLSource_HSE_Div1 ((uint32_t)0x00010000)
  39. #define RCC_PLLSource_HSE_Div2 ((uint32_t)0x00030000)
  40. #define IS_RCC_PLL_SOURCE(SOURCE) (((SOURCE) == RCC_PLLSource_HSI_Div2) || \
  41. ((SOURCE) == RCC_PLLSource_HSE_Div1) || \
  42. ((SOURCE) == RCC_PLLSource_HSE_Div2))
  43. #else
  44. #define RCC_PLLSource_PREDIV1 ((uint32_t)0x00010000)
  45. #define IS_RCC_PLL_SOURCE(SOURCE) (((SOURCE) == RCC_PLLSource_HSI_Div2) || \
  46. ((SOURCE) == RCC_PLLSource_PREDIV1))
  47. #endif /* STM32F10X_CL */
  48. // PLL_multiplication_factor
  49. #ifndef STM32F10X_CL
  50. #define RCC_PLLMul_2 ((uint32_t)0x00000000)
  51. #define RCC_PLLMul_3 ((uint32_t)0x00040000)
  52. #define RCC_PLLMul_4 ((uint32_t)0x00080000)
  53. #define RCC_PLLMul_5 ((uint32_t)0x000C0000)
  54. #define RCC_PLLMul_6 ((uint32_t)0x00100000)
  55. #define RCC_PLLMul_7 ((uint32_t)0x00140000)
  56. #define RCC_PLLMul_8 ((uint32_t)0x00180000)
  57. #define RCC_PLLMul_9 ((uint32_t)0x001C0000)
  58. #define RCC_PLLMul_10 ((uint32_t)0x00200000)
  59. #define RCC_PLLMul_11 ((uint32_t)0x00240000)
  60. #define RCC_PLLMul_12 ((uint32_t)0x00280000)
  61. #define RCC_PLLMul_13 ((uint32_t)0x002C0000)
  62. #define RCC_PLLMul_14 ((uint32_t)0x00300000)
  63. #define RCC_PLLMul_15 ((uint32_t)0x00340000)
  64. #define RCC_PLLMul_16 ((uint32_t)0x00380000)
  65. #define IS_RCC_PLL_MUL(MUL) (((MUL) == RCC_PLLMul_2) || ((MUL) == RCC_PLLMul_3) || \
  66. ((MUL) == RCC_PLLMul_4) || ((MUL) == RCC_PLLMul_5) || \
  67. ((MUL) == RCC_PLLMul_6) || ((MUL) == RCC_PLLMul_7) || \
  68. ((MUL) == RCC_PLLMul_8) || ((MUL) == RCC_PLLMul_9) || \
  69. ((MUL) == RCC_PLLMul_10) || ((MUL) == RCC_PLLMul_11) || \
  70. ((MUL) == RCC_PLLMul_12) || ((MUL) == RCC_PLLMul_13) || \
  71. ((MUL) == RCC_PLLMul_14) || ((MUL) == RCC_PLLMul_15) || \
  72. ((MUL) == RCC_PLLMul_16))
  73. #else
  74. #define RCC_PLLMul_4 ((uint32_t)0x00080000)
  75. #define RCC_PLLMul_5 ((uint32_t)0x000C0000)
  76. #define RCC_PLLMul_6 ((uint32_t)0x00100000)
  77. #define RCC_PLLMul_7 ((uint32_t)0x00140000)
  78. #define RCC_PLLMul_8 ((uint32_t)0x00180000)
  79. #define RCC_PLLMul_9 ((uint32_t)0x001C0000)
  80. #define RCC_PLLMul_6_5 ((uint32_t)0x00340000)
  81. #define IS_RCC_PLL_MUL(MUL) (((MUL) == RCC_PLLMul_4) || ((MUL) == RCC_PLLMul_5) || \
  82. ((MUL) == RCC_PLLMul_6) || ((MUL) == RCC_PLLMul_7) || \
  83. ((MUL) == RCC_PLLMul_8) || ((MUL) == RCC_PLLMul_9) || \
  84. ((MUL) == RCC_PLLMul_6_5))
  85. #endif /* STM32F10X_CL */
  86. //PREDIV1_division_factor
  87. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
  88. #define RCC_PREDIV1_Div1 ((uint32_t)0x00000000)
  89. #define RCC_PREDIV1_Div2 ((uint32_t)0x00000001)
  90. #define RCC_PREDIV1_Div3 ((uint32_t)0x00000002)
  91. #define RCC_PREDIV1_Div4 ((uint32_t)0x00000003)
  92. #define RCC_PREDIV1_Div5 ((uint32_t)0x00000004)
  93. #define RCC_PREDIV1_Div6 ((uint32_t)0x00000005)
  94. #define RCC_PREDIV1_Div7 ((uint32_t)0x00000006)
  95. #define RCC_PREDIV1_Div8 ((uint32_t)0x00000007)
  96. #define RCC_PREDIV1_Div9 ((uint32_t)0x00000008)
  97. #define RCC_PREDIV1_Div10 ((uint32_t)0x00000009)
  98. #define RCC_PREDIV1_Div11 ((uint32_t)0x0000000A)
  99. #define RCC_PREDIV1_Div12 ((uint32_t)0x0000000B)
  100. #define RCC_PREDIV1_Div13 ((uint32_t)0x0000000C)
  101. #define RCC_PREDIV1_Div14 ((uint32_t)0x0000000D)
  102. #define RCC_PREDIV1_Div15 ((uint32_t)0x0000000E)
  103. #define RCC_PREDIV1_Div16 ((uint32_t)0x0000000F)
  104. #define IS_RCC_PREDIV1(PREDIV1) (((PREDIV1) == RCC_PREDIV1_Div1) || ((PREDIV1) == RCC_PREDIV1_Div2) || \
  105. ((PREDIV1) == RCC_PREDIV1_Div3) || ((PREDIV1) == RCC_PREDIV1_Div4) || \
  106. ((PREDIV1) == RCC_PREDIV1_Div5) || ((PREDIV1) == RCC_PREDIV1_Div6) || \
  107. ((PREDIV1) == RCC_PREDIV1_Div7) || ((PREDIV1) == RCC_PREDIV1_Div8) || \
  108. ((PREDIV1) == RCC_PREDIV1_Div9) || ((PREDIV1) == RCC_PREDIV1_Div10) || \
  109. ((PREDIV1) == RCC_PREDIV1_Div11) || ((PREDIV1) == RCC_PREDIV1_Div12) || \
  110. ((PREDIV1) == RCC_PREDIV1_Div13) || ((PREDIV1) == RCC_PREDIV1_Div14) || \
  111. ((PREDIV1) == RCC_PREDIV1_Div15) || ((PREDIV1) == RCC_PREDIV1_Div16))
  112. #endif
  113. // PREDIV1_clock_source
  114. #ifdef STM32F10X_CL
  115. /* PREDIV1 clock source (for STM32 connectivity line devices) */
  116. #define RCC_PREDIV1_Source_HSE ((uint32_t)0x00000000)
  117. #define RCC_PREDIV1_Source_PLL2 ((uint32_t)0x00010000)
  118. #define IS_RCC_PREDIV1_SOURCE(SOURCE) (((SOURCE) == RCC_PREDIV1_Source_HSE) || \
  119. ((SOURCE) == RCC_PREDIV1_Source_PLL2))
  120. #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  121. /* PREDIV1 clock source (for STM32 Value line devices) */
  122. #define RCC_PREDIV1_Source_HSE ((uint32_t)0x00000000)
  123. #define IS_RCC_PREDIV1_SOURCE(SOURCE) (((SOURCE) == RCC_PREDIV1_Source_HSE))
  124. #endif
  125. /**
  126. * @}
  127. */
  128. #ifdef STM32F10X_CL
  129. // PREDIV2_division_factor
  130. #define RCC_PREDIV2_Div1 ((uint32_t)0x00000000)
  131. #define RCC_PREDIV2_Div2 ((uint32_t)0x00000010)
  132. #define RCC_PREDIV2_Div3 ((uint32_t)0x00000020)
  133. #define RCC_PREDIV2_Div4 ((uint32_t)0x00000030)
  134. #define RCC_PREDIV2_Div5 ((uint32_t)0x00000040)
  135. #define RCC_PREDIV2_Div6 ((uint32_t)0x00000050)
  136. #define RCC_PREDIV2_Div7 ((uint32_t)0x00000060)
  137. #define RCC_PREDIV2_Div8 ((uint32_t)0x00000070)
  138. #define RCC_PREDIV2_Div9 ((uint32_t)0x00000080)
  139. #define RCC_PREDIV2_Div10 ((uint32_t)0x00000090)
  140. #define RCC_PREDIV2_Div11 ((uint32_t)0x000000A0)
  141. #define RCC_PREDIV2_Div12 ((uint32_t)0x000000B0)
  142. #define RCC_PREDIV2_Div13 ((uint32_t)0x000000C0)
  143. #define RCC_PREDIV2_Div14 ((uint32_t)0x000000D0)
  144. #define RCC_PREDIV2_Div15 ((uint32_t)0x000000E0)
  145. #define RCC_PREDIV2_Div16 ((uint32_t)0x000000F0)
  146. #define IS_RCC_PREDIV2(PREDIV2) (((PREDIV2) == RCC_PREDIV2_Div1) || ((PREDIV2) == RCC_PREDIV2_Div2) || \
  147. ((PREDIV2) == RCC_PREDIV2_Div3) || ((PREDIV2) == RCC_PREDIV2_Div4) || \
  148. ((PREDIV2) == RCC_PREDIV2_Div5) || ((PREDIV2) == RCC_PREDIV2_Div6) || \
  149. ((PREDIV2) == RCC_PREDIV2_Div7) || ((PREDIV2) == RCC_PREDIV2_Div8) || \
  150. ((PREDIV2) == RCC_PREDIV2_Div9) || ((PREDIV2) == RCC_PREDIV2_Div10) || \
  151. ((PREDIV2) == RCC_PREDIV2_Div11) || ((PREDIV2) == RCC_PREDIV2_Div12) || \
  152. ((PREDIV2) == RCC_PREDIV2_Div13) || ((PREDIV2) == RCC_PREDIV2_Div14) || \
  153. ((PREDIV2) == RCC_PREDIV2_Div15) || ((PREDIV2) == RCC_PREDIV2_Div16))
  154. // PLL2_multiplication_factor
  155. #define RCC_PLL2Mul_8 ((uint32_t)0x00000600)
  156. #define RCC_PLL2Mul_9 ((uint32_t)0x00000700)
  157. #define RCC_PLL2Mul_10 ((uint32_t)0x00000800)
  158. #define RCC_PLL2Mul_11 ((uint32_t)0x00000900)
  159. #define RCC_PLL2Mul_12 ((uint32_t)0x00000A00)
  160. #define RCC_PLL2Mul_13 ((uint32_t)0x00000B00)
  161. #define RCC_PLL2Mul_14 ((uint32_t)0x00000C00)
  162. #define RCC_PLL2Mul_16 ((uint32_t)0x00000E00)
  163. #define RCC_PLL2Mul_20 ((uint32_t)0x00000F00)
  164. #define IS_RCC_PLL2_MUL(MUL) (((MUL) == RCC_PLL2Mul_8) || ((MUL) == RCC_PLL2Mul_9) || \
  165. ((MUL) == RCC_PLL2Mul_10) || ((MUL) == RCC_PLL2Mul_11) || \
  166. ((MUL) == RCC_PLL2Mul_12) || ((MUL) == RCC_PLL2Mul_13) || \
  167. ((MUL) == RCC_PLL2Mul_14) || ((MUL) == RCC_PLL2Mul_16) || \
  168. ((MUL) == RCC_PLL2Mul_20))
  169. // PLL3_multiplication_factor
  170. #define RCC_PLL3Mul_8 ((uint32_t)0x00006000)
  171. #define RCC_PLL3Mul_9 ((uint32_t)0x00007000)
  172. #define RCC_PLL3Mul_10 ((uint32_t)0x00008000)
  173. #define RCC_PLL3Mul_11 ((uint32_t)0x00009000)
  174. #define RCC_PLL3Mul_12 ((uint32_t)0x0000A000)
  175. #define RCC_PLL3Mul_13 ((uint32_t)0x0000B000)
  176. #define RCC_PLL3Mul_14 ((uint32_t)0x0000C000)
  177. #define RCC_PLL3Mul_16 ((uint32_t)0x0000E000)
  178. #define RCC_PLL3Mul_20 ((uint32_t)0x0000F000)
  179. #define IS_RCC_PLL3_MUL(MUL) (((MUL) == RCC_PLL3Mul_8) || ((MUL) == RCC_PLL3Mul_9) || \
  180. ((MUL) == RCC_PLL3Mul_10) || ((MUL) == RCC_PLL3Mul_11) || \
  181. ((MUL) == RCC_PLL3Mul_12) || ((MUL) == RCC_PLL3Mul_13) || \
  182. ((MUL) == RCC_PLL3Mul_14) || ((MUL) == RCC_PLL3Mul_16) || \
  183. ((MUL) == RCC_PLL3Mul_20))
  184. #endif /* STM32F10X_CL */
  185. // System_clock_source
  186. #define RCC_SYSCLKSource_HSI ((uint32_t)0x00000000)
  187. #define RCC_SYSCLKSource_HSE ((uint32_t)0x00000001)
  188. #define RCC_SYSCLKSource_PLLCLK ((uint32_t)0x00000002)
  189. #define IS_RCC_SYSCLK_SOURCE(SOURCE) (((SOURCE) == RCC_SYSCLKSource_HSI) || \
  190. ((SOURCE) == RCC_SYSCLKSource_HSE) || \
  191. ((SOURCE) == RCC_SYSCLKSource_PLLCLK))
  192. // AHB_clock_source
  193. #define RCC_SYSCLK_Div1 ((uint32_t)0x00000000)
  194. #define RCC_SYSCLK_Div2 ((uint32_t)0x00000080)
  195. #define RCC_SYSCLK_Div4 ((uint32_t)0x00000090)
  196. #define RCC_SYSCLK_Div8 ((uint32_t)0x000000A0)
  197. #define RCC_SYSCLK_Div16 ((uint32_t)0x000000B0)
  198. #define RCC_SYSCLK_Div64 ((uint32_t)0x000000C0)
  199. #define RCC_SYSCLK_Div128 ((uint32_t)0x000000D0)
  200. #define RCC_SYSCLK_Div256 ((uint32_t)0x000000E0)
  201. #define RCC_SYSCLK_Div512 ((uint32_t)0x000000F0)
  202. #define IS_RCC_HCLK(HCLK) (((HCLK) == RCC_SYSCLK_Div1) || ((HCLK) == RCC_SYSCLK_Div2) || \
  203. ((HCLK) == RCC_SYSCLK_Div4) || ((HCLK) == RCC_SYSCLK_Div8) || \
  204. ((HCLK) == RCC_SYSCLK_Div16) || ((HCLK) == RCC_SYSCLK_Div64) || \
  205. ((HCLK) == RCC_SYSCLK_Div128) || ((HCLK) == RCC_SYSCLK_Div256) || \
  206. ((HCLK) == RCC_SYSCLK_Div512))
  207. // APB1_APB2_clock_source
  208. #define RCC_HCLK_Div1 ((uint32_t)0x00000000)
  209. #define RCC_HCLK_Div2 ((uint32_t)0x00000400)
  210. #define RCC_HCLK_Div4 ((uint32_t)0x00000500)
  211. #define RCC_HCLK_Div8 ((uint32_t)0x00000600)
  212. #define RCC_HCLK_Div16 ((uint32_t)0x00000700)
  213. #define IS_RCC_PCLK(PCLK) (((PCLK) == RCC_HCLK_Div1) || ((PCLK) == RCC_HCLK_Div2) || \
  214. ((PCLK) == RCC_HCLK_Div4) || ((PCLK) == RCC_HCLK_Div8) || \
  215. ((PCLK) == RCC_HCLK_Div16))
  216. // RCC_Interrupt_source
  217. #define RCC_IT_LSIRDY ((uint8_t)0x01)
  218. #define RCC_IT_LSERDY ((uint8_t)0x02)
  219. #define RCC_IT_HSIRDY ((uint8_t)0x04)
  220. #define RCC_IT_HSERDY ((uint8_t)0x08)
  221. #define RCC_IT_PLLRDY ((uint8_t)0x10)
  222. #define RCC_IT_CSS ((uint8_t)0x80)
  223. #ifndef STM32F10X_CL
  224. #define IS_RCC_IT(IT) ((((IT) & (uint8_t)0xE0) == 0x00) && ((IT) != 0x00))
  225. #define IS_RCC_GET_IT(IT) (((IT) == RCC_IT_LSIRDY) || ((IT) == RCC_IT_LSERDY) || \
  226. ((IT) == RCC_IT_HSIRDY) || ((IT) == RCC_IT_HSERDY) || \
  227. ((IT) == RCC_IT_PLLRDY) || ((IT) == RCC_IT_CSS))
  228. #define IS_RCC_CLEAR_IT(IT) ((((IT) & (uint8_t)0x60) == 0x00) && ((IT) != 0x00))
  229. #else
  230. #define RCC_IT_PLL2RDY ((uint8_t)0x20)
  231. #define RCC_IT_PLL3RDY ((uint8_t)0x40)
  232. #define IS_RCC_IT(IT) ((((IT) & (uint8_t)0x80) == 0x00) && ((IT) != 0x00))
  233. #define IS_RCC_GET_IT(IT) (((IT) == RCC_IT_LSIRDY) || ((IT) == RCC_IT_LSERDY) || \
  234. ((IT) == RCC_IT_HSIRDY) || ((IT) == RCC_IT_HSERDY) || \
  235. ((IT) == RCC_IT_PLLRDY) || ((IT) == RCC_IT_CSS) || \
  236. ((IT) == RCC_IT_PLL2RDY) || ((IT) == RCC_IT_PLL3RDY))
  237. #define IS_RCC_CLEAR_IT(IT) ((IT) != 0x00)
  238. #endif /* STM32F10X_CL */
  239. #ifndef STM32F10X_CL
  240. // USB_Device_clock_source
  241. #define RCC_USBCLKSource_PLLCLK_1Div5 ((uint8_t)0x00)
  242. #define RCC_USBCLKSource_PLLCLK_Div1 ((uint8_t)0x01)
  243. #define IS_RCC_USBCLK_SOURCE(SOURCE) (((SOURCE) == RCC_USBCLKSource_PLLCLK_1Div5) || \
  244. ((SOURCE) == RCC_USBCLKSource_PLLCLK_Div1))
  245. #else
  246. // USB_OTG_FS_clock_source
  247. #define RCC_OTGFSCLKSource_PLLVCO_Div3 ((uint8_t)0x00)
  248. #define RCC_OTGFSCLKSource_PLLVCO_Div2 ((uint8_t)0x01)
  249. #define IS_RCC_OTGFSCLK_SOURCE(SOURCE) (((SOURCE) == RCC_OTGFSCLKSource_PLLVCO_Div3) || \
  250. ((SOURCE) == RCC_OTGFSCLKSource_PLLVCO_Div2))
  251. #endif /* STM32F10X_CL */
  252. #ifdef STM32F10X_CL
  253. // I2S2_clock_source
  254. #define RCC_I2S2CLKSource_SYSCLK ((uint8_t)0x00)
  255. #define RCC_I2S2CLKSource_PLL3_VCO ((uint8_t)0x01)
  256. #define IS_RCC_I2S2CLK_SOURCE(SOURCE) (((SOURCE) == RCC_I2S2CLKSource_SYSCLK) || \
  257. ((SOURCE) == RCC_I2S2CLKSource_PLL3_VCO))
  258. // I2S3_clock_source
  259. #define RCC_I2S3CLKSource_SYSCLK ((uint8_t)0x00)
  260. #define RCC_I2S3CLKSource_PLL3_VCO ((uint8_t)0x01)
  261. #define IS_RCC_I2S3CLK_SOURCE(SOURCE) (((SOURCE) == RCC_I2S3CLKSource_SYSCLK) || \
  262. ((SOURCE) == RCC_I2S3CLKSource_PLL3_VCO))
  263. #endif /* STM32F10X_CL */
  264. // ADC_clock_source
  265. #define RCC_PCLK2_Div2 ((uint32_t)0x00000000)
  266. #define RCC_PCLK2_Div4 ((uint32_t)0x00004000)
  267. #define RCC_PCLK2_Div6 ((uint32_t)0x00008000)
  268. #define RCC_PCLK2_Div8 ((uint32_t)0x0000C000)
  269. #define IS_RCC_ADCCLK(ADCCLK) (((ADCCLK) == RCC_PCLK2_Div2) || ((ADCCLK) == RCC_PCLK2_Div4) || \
  270. ((ADCCLK) == RCC_PCLK2_Div6) || ((ADCCLK) == RCC_PCLK2_Div8))
  271. // LSE_configuration
  272. #define RCC_LSE_OFF ((uint8_t)0x00)
  273. #define RCC_LSE_ON ((uint8_t)0x01)
  274. #define RCC_LSE_Bypass ((uint8_t)0x04)
  275. #define IS_RCC_LSE(LSE) (((LSE) == RCC_LSE_OFF) || ((LSE) == RCC_LSE_ON) || \
  276. ((LSE) == RCC_LSE_Bypass))
  277. // RTC_clock_source
  278. #define RCC_RTCCLKSource_LSE ((uint32_t)0x00000100)
  279. #define RCC_RTCCLKSource_LSI ((uint32_t)0x00000200)
  280. #define RCC_RTCCLKSource_HSE_Div128 ((uint32_t)0x00000300)
  281. #define IS_RCC_RTCCLK_SOURCE(SOURCE) (((SOURCE) == RCC_RTCCLKSource_LSE) || \
  282. ((SOURCE) == RCC_RTCCLKSource_LSI) || \
  283. ((SOURCE) == RCC_RTCCLKSource_HSE_Div128))
  284. // AHB_peripheral
  285. #define RCC_AHBPeriph_DMA1 ((uint32_t)0x00000001)
  286. #define RCC_AHBPeriph_DMA2 ((uint32_t)0x00000002)
  287. #define RCC_AHBPeriph_SRAM ((uint32_t)0x00000004)
  288. #define RCC_AHBPeriph_FLITF ((uint32_t)0x00000010)
  289. #define RCC_AHBPeriph_CRC ((uint32_t)0x00000040)
  290. #ifndef STM32F10X_CL
  291. #define RCC_AHBPeriph_FSMC ((uint32_t)0x00000100)
  292. #define RCC_AHBPeriph_SDIO ((uint32_t)0x00000400)
  293. #define IS_RCC_AHB_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFFAA8) == 0x00) && ((PERIPH) != 0x00))
  294. #else
  295. #define RCC_AHBPeriph_OTG_FS ((uint32_t)0x00001000)
  296. #define RCC_AHBPeriph_ETH_MAC ((uint32_t)0x00004000)
  297. #define RCC_AHBPeriph_ETH_MAC_Tx ((uint32_t)0x00008000)
  298. #define RCC_AHBPeriph_ETH_MAC_Rx ((uint32_t)0x00010000)
  299. #define IS_RCC_AHB_PERIPH(PERIPH) ((((PERIPH) & 0xFFFE2FA8) == 0x00) && ((PERIPH) != 0x00))
  300. #define IS_RCC_AHB_PERIPH_RESET(PERIPH) ((((PERIPH) & 0xFFFFAFFF) == 0x00) && ((PERIPH) != 0x00))
  301. #endif /* STM32F10X_CL */
  302. // APB2_peripheral
  303. #define RCC_APB2Periph_AFIO ((uint32_t)0x00000001)
  304. #define RCC_APB2Periph_GPIOA ((uint32_t)0x00000004)
  305. #define RCC_APB2Periph_GPIOB ((uint32_t)0x00000008)
  306. #define RCC_APB2Periph_GPIOC ((uint32_t)0x00000010)
  307. #define RCC_APB2Periph_GPIOD ((uint32_t)0x00000020)
  308. #define RCC_APB2Periph_GPIOE ((uint32_t)0x00000040)
  309. #define RCC_APB2Periph_GPIOF ((uint32_t)0x00000080)
  310. #define RCC_APB2Periph_GPIOG ((uint32_t)0x00000100)
  311. #define RCC_APB2Periph_ADC1 ((uint32_t)0x00000200)
  312. #define RCC_APB2Periph_ADC2 ((uint32_t)0x00000400)
  313. #define RCC_APB2Periph_TIM1 ((uint32_t)0x00000800)
  314. #define RCC_APB2Periph_SPI1 ((uint32_t)0x00001000)
  315. #define RCC_APB2Periph_TIM8 ((uint32_t)0x00002000)
  316. #define RCC_APB2Periph_USART1 ((uint32_t)0x00004000)
  317. #define RCC_APB2Periph_ADC3 ((uint32_t)0x00008000)
  318. #define RCC_APB2Periph_TIM15 ((uint32_t)0x00010000)
  319. #define RCC_APB2Periph_TIM16 ((uint32_t)0x00020000)
  320. #define RCC_APB2Periph_TIM17 ((uint32_t)0x00040000)
  321. #define RCC_APB2Periph_TIM9 ((uint32_t)0x00080000)
  322. #define RCC_APB2Periph_TIM10 ((uint32_t)0x00100000)
  323. #define RCC_APB2Periph_TIM11 ((uint32_t)0x00200000)
  324. #define IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH) & 0xFFC00002) == 0x00) && ((PERIPH) != 0x00))
  325. // APB1_peripheral
  326. #define RCC_APB1Periph_TIM2 ((uint32_t)0x00000001)
  327. #define RCC_APB1Periph_TIM3 ((uint32_t)0x00000002)
  328. #define RCC_APB1Periph_TIM4 ((uint32_t)0x00000004)
  329. #define RCC_APB1Periph_TIM5 ((uint32_t)0x00000008)
  330. #define RCC_APB1Periph_TIM6 ((uint32_t)0x00000010)
  331. #define RCC_APB1Periph_TIM7 ((uint32_t)0x00000020)
  332. #define RCC_APB1Periph_TIM12 ((uint32_t)0x00000040)
  333. #define RCC_APB1Periph_TIM13 ((uint32_t)0x00000080)
  334. #define RCC_APB1Periph_TIM14 ((uint32_t)0x00000100)
  335. #define RCC_APB1Periph_WWDG ((uint32_t)0x00000800)
  336. #define RCC_APB1Periph_SPI2 ((uint32_t)0x00004000)
  337. #define RCC_APB1Periph_SPI3 ((uint32_t)0x00008000)
  338. #define RCC_APB1Periph_USART2 ((uint32_t)0x00020000)
  339. #define RCC_APB1Periph_USART3 ((uint32_t)0x00040000)
  340. #define RCC_APB1Periph_UART4 ((uint32_t)0x00080000)
  341. #define RCC_APB1Periph_UART5 ((uint32_t)0x00100000)
  342. #define RCC_APB1Periph_I2C1 ((uint32_t)0x00200000)
  343. #define RCC_APB1Periph_I2C2 ((uint32_t)0x00400000)
  344. #define RCC_APB1Periph_USB ((uint32_t)0x00800000)
  345. #define RCC_APB1Periph_CAN1 ((uint32_t)0x02000000)
  346. #define RCC_APB1Periph_CAN2 ((uint32_t)0x04000000)
  347. #define RCC_APB1Periph_BKP ((uint32_t)0x08000000)
  348. #define RCC_APB1Periph_PWR ((uint32_t)0x10000000)
  349. #define RCC_APB1Periph_DAC ((uint32_t)0x20000000)
  350. #define RCC_APB1Periph_CEC ((uint32_t)0x40000000)
  351. #define IS_RCC_APB1_PERIPH(PERIPH) ((((PERIPH) & 0x81013600) == 0x00) && ((PERIPH) != 0x00))
  352. // Clock_source_to_output_on_MCO_pin
  353. #define RCC_MCO_NoClock ((uint8_t)0x00)
  354. #define RCC_MCO_SYSCLK ((uint8_t)0x04)
  355. #define RCC_MCO_HSI ((uint8_t)0x05)
  356. #define RCC_MCO_HSE ((uint8_t)0x06)
  357. #define RCC_MCO_PLLCLK_Div2 ((uint8_t)0x07)
  358. #ifndef STM32F10X_CL
  359. #define IS_RCC_MCO(MCO) (((MCO) == RCC_MCO_NoClock) || ((MCO) == RCC_MCO_HSI) || \
  360. ((MCO) == RCC_MCO_SYSCLK) || ((MCO) == RCC_MCO_HSE) || \
  361. ((MCO) == RCC_MCO_PLLCLK_Div2))
  362. #else
  363. #define RCC_MCO_PLL2CLK ((uint8_t)0x08)
  364. #define RCC_MCO_PLL3CLK_Div2 ((uint8_t)0x09)
  365. #define RCC_MCO_XT1 ((uint8_t)0x0A)
  366. #define RCC_MCO_PLL3CLK ((uint8_t)0x0B)
  367. #define IS_RCC_MCO(MCO) (((MCO) == RCC_MCO_NoClock) || ((MCO) == RCC_MCO_HSI) || \
  368. ((MCO) == RCC_MCO_SYSCLK) || ((MCO) == RCC_MCO_HSE) || \
  369. ((MCO) == RCC_MCO_PLLCLK_Div2) || ((MCO) == RCC_MCO_PLL2CLK) || \
  370. ((MCO) == RCC_MCO_PLL3CLK_Div2) || ((MCO) == RCC_MCO_XT1) || \
  371. ((MCO) == RCC_MCO_PLL3CLK))
  372. #endif /* STM32F10X_CL */
  373. // RCC_Flag
  374. #define RCC_FLAG_HSIRDY ((uint8_t)0x21)
  375. #define RCC_FLAG_HSERDY ((uint8_t)0x31)
  376. #define RCC_FLAG_PLLRDY ((uint8_t)0x39)
  377. #define RCC_FLAG_LSERDY ((uint8_t)0x41)
  378. #define RCC_FLAG_LSIRDY ((uint8_t)0x61)
  379. #define RCC_FLAG_PINRST ((uint8_t)0x7A)
  380. #define RCC_FLAG_PORRST ((uint8_t)0x7B)
  381. #define RCC_FLAG_SFTRST ((uint8_t)0x7C)
  382. #define RCC_FLAG_IWDGRST ((uint8_t)0x7D)
  383. #define RCC_FLAG_WWDGRST ((uint8_t)0x7E)
  384. #define RCC_FLAG_LPWRRST ((uint8_t)0x7F)
  385. #ifndef STM32F10X_CL
  386. #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \
  387. ((FLAG) == RCC_FLAG_PLLRDY) || ((FLAG) == RCC_FLAG_LSERDY) || \
  388. ((FLAG) == RCC_FLAG_LSIRDY) || ((FLAG) == RCC_FLAG_PINRST) || \
  389. ((FLAG) == RCC_FLAG_PORRST) || ((FLAG) == RCC_FLAG_SFTRST) || \
  390. ((FLAG) == RCC_FLAG_IWDGRST)|| ((FLAG) == RCC_FLAG_WWDGRST)|| \
  391. ((FLAG) == RCC_FLAG_LPWRRST))
  392. #else
  393. #define RCC_FLAG_PLL2RDY ((uint8_t)0x3B)
  394. #define RCC_FLAG_PLL3RDY ((uint8_t)0x3D)
  395. #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \
  396. ((FLAG) == RCC_FLAG_PLLRDY) || ((FLAG) == RCC_FLAG_LSERDY) || \
  397. ((FLAG) == RCC_FLAG_PLL2RDY) || ((FLAG) == RCC_FLAG_PLL3RDY) || \
  398. ((FLAG) == RCC_FLAG_LSIRDY) || ((FLAG) == RCC_FLAG_PINRST) || \
  399. ((FLAG) == RCC_FLAG_PORRST) || ((FLAG) == RCC_FLAG_SFTRST) || \
  400. ((FLAG) == RCC_FLAG_IWDGRST)|| ((FLAG) == RCC_FLAG_WWDGRST)|| \
  401. ((FLAG) == RCC_FLAG_LPWRRST))
  402. #endif /* STM32F10X_CL */
  403. #define IS_RCC_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x1F)
  404. /* ======================== Data types ========================= */
  405. /* RCC_Exported_Types*/
  406. typedef struct
  407. {
  408. uint32_t SYSCLK_Frequency; /*!< returns SYSCLK clock frequency expressed in Hz */
  409. uint32_t HCLK_Frequency; /*!< returns HCLK clock frequency expressed in Hz */
  410. uint32_t PCLK1_Frequency; /*!< returns PCLK1 clock frequency expressed in Hz */
  411. uint32_t PCLK2_Frequency; /*!< returns PCLK2 clock frequency expressed in Hz */
  412. uint32_t ADCCLK_Frequency; /*!< returns ADCCLK clock frequency expressed in Hz */
  413. }RCC_ClocksTypeDef;
  414. /* ======================== Exported API ========================= */
  415. void RCC_DeInit(void);
  416. void RCC_HSEConfig(uint32_t RCC_HSE);
  417. ErrorStatus RCC_WaitForHSEStartUp(void);
  418. void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue);
  419. void RCC_HSICmd(FunctionalState NewState);
  420. void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul);
  421. void RCC_PLLCmd(FunctionalState NewState);
  422. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
  423. void RCC_PREDIV1Config(uint32_t RCC_PREDIV1_Source, uint32_t RCC_PREDIV1_Div);
  424. #endif
  425. #ifdef STM32F10X_CL
  426. void RCC_PREDIV2Config(uint32_t RCC_PREDIV2_Div);
  427. void RCC_PLL2Config(uint32_t RCC_PLL2Mul);
  428. void RCC_PLL2Cmd(FunctionalState NewState);
  429. void RCC_PLL3Config(uint32_t RCC_PLL3Mul);
  430. void RCC_PLL3Cmd(FunctionalState NewState);
  431. #endif /* STM32F10X_CL */
  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_PCLK1Config(uint32_t RCC_HCLK);
  436. void RCC_PCLK2Config(uint32_t RCC_HCLK);
  437. void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState);
  438. #ifndef STM32F10X_CL
  439. void RCC_USBCLKConfig(uint32_t RCC_USBCLKSource);
  440. #else
  441. void RCC_OTGFSCLKConfig(uint32_t RCC_OTGFSCLKSource);
  442. #endif /* STM32F10X_CL */
  443. void RCC_ADCCLKConfig(uint32_t RCC_PCLK2);
  444. #ifdef STM32F10X_CL
  445. void RCC_I2S2CLKConfig(uint32_t RCC_I2S2CLKSource);
  446. void RCC_I2S3CLKConfig(uint32_t RCC_I2S3CLKSource);
  447. #endif /* STM32F10X_CL */
  448. void RCC_LSEConfig(uint8_t RCC_LSE);
  449. void RCC_LSICmd(FunctionalState NewState);
  450. void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource);
  451. void RCC_RTCCLKCmd(FunctionalState NewState);
  452. void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks);
  453. void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
  454. void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
  455. void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
  456. #ifdef STM32F10X_CL
  457. void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
  458. #endif /* STM32F10X_CL */
  459. void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
  460. void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
  461. void RCC_BackupResetCmd(FunctionalState NewState);
  462. void RCC_ClockSecuritySystemCmd(FunctionalState NewState);
  463. void RCC_MCOConfig(uint8_t RCC_MCO);
  464. FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG);
  465. void RCC_ClearFlag(void);
  466. #if RCC_USE_IT == 1
  467. ITStatus RCC_GetITStatus(uint8_t RCC_IT);
  468. void RCC_ClearITPendingBit(uint8_t RCC_IT);
  469. #endif
  470. #ifdef __cplusplus
  471. }
  472. #endif
  473. #endif /* __STM32F10x_RCC_H__ */
  474. /*****END OF FILE****/