stm32f0xx_rcc.h 27 KB

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