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.
 
 
 

1703 lines
82 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_rcc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RCC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F0xx_HAL_RCC_H
  37. #define __STM32F0xx_HAL_RCC_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f0xx_hal_def.h"
  43. /** @addtogroup STM32F0xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup RCC
  47. * @{
  48. */
  49. /** @addtogroup RCC_Private_Constants
  50. * @{
  51. */
  52. /** @defgroup RCC_Timeout RCC Timeout
  53. * @{
  54. */
  55. /* Disable Backup domain write protection state change timeout */
  56. #define RCC_DBP_TIMEOUT_VALUE (100U) /* 100 ms */
  57. /* LSE state change timeout */
  58. #define RCC_LSE_TIMEOUT_VALUE LSE_STARTUP_TIMEOUT
  59. #define CLOCKSWITCH_TIMEOUT_VALUE (5000U) /* 5 s */
  60. #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
  61. #define HSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  62. #define LSI_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  63. #define PLL_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  64. #define HSI14_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  65. #if defined(RCC_HSI48_SUPPORT)
  66. #define HSI48_TIMEOUT_VALUE (2U) /* 2 ms (minimum Tick + 1U) */
  67. #endif /* RCC_HSI48_SUPPORT */
  68. /**
  69. * @}
  70. */
  71. /** @defgroup RCC_Register_Offset Register offsets
  72. * @{
  73. */
  74. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  75. #define RCC_CR_OFFSET 0x00
  76. #define RCC_CFGR_OFFSET 0x04
  77. #define RCC_CIR_OFFSET 0x08
  78. #define RCC_BDCR_OFFSET 0x20
  79. #define RCC_CSR_OFFSET 0x24
  80. /**
  81. * @}
  82. */
  83. /* CR register byte 2 (Bits[23:16]) base address */
  84. #define RCC_CR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CR_OFFSET + 0x02U))
  85. /* CIR register byte 1 (Bits[15:8]) base address */
  86. #define RCC_CIR_BYTE1_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x01U))
  87. /* CIR register byte 2 (Bits[23:16]) base address */
  88. #define RCC_CIR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + RCC_CIR_OFFSET + 0x02U))
  89. /* Defines used for Flags */
  90. #define CR_REG_INDEX ((uint8_t)1U)
  91. #define CR2_REG_INDEX ((uint8_t)2U)
  92. #define BDCR_REG_INDEX ((uint8_t)3U)
  93. #define CSR_REG_INDEX ((uint8_t)4U)
  94. /* Bits position in in the CFGR register */
  95. #define RCC_CFGR_PLLMUL_BITNUMBER 18U
  96. #define RCC_CFGR_HPRE_BITNUMBER 4U
  97. #define RCC_CFGR_PPRE_BITNUMBER 8U
  98. /* Flags in the CFGR2 register */
  99. #define RCC_CFGR2_PREDIV_BITNUMBER 0
  100. /* Flags in the CR register */
  101. #define RCC_CR_HSIRDY_BitNumber 1
  102. #define RCC_CR_HSERDY_BitNumber 17
  103. #define RCC_CR_PLLRDY_BitNumber 25
  104. /* Flags in the CR2 register */
  105. #define RCC_CR2_HSI14RDY_BitNumber 1
  106. #define RCC_CR2_HSI48RDY_BitNumber 16
  107. /* Flags in the BDCR register */
  108. #define RCC_BDCR_LSERDY_BitNumber 1
  109. /* Flags in the CSR register */
  110. #define RCC_CSR_LSIRDY_BitNumber 1
  111. #define RCC_CSR_V18PWRRSTF_BitNumber 23
  112. #define RCC_CSR_RMVF_BitNumber 24
  113. #define RCC_CSR_OBLRSTF_BitNumber 25
  114. #define RCC_CSR_PINRSTF_BitNumber 26
  115. #define RCC_CSR_PORRSTF_BitNumber 27
  116. #define RCC_CSR_SFTRSTF_BitNumber 28
  117. #define RCC_CSR_IWDGRSTF_BitNumber 29
  118. #define RCC_CSR_WWDGRSTF_BitNumber 30
  119. #define RCC_CSR_LPWRRSTF_BitNumber 31
  120. /* Flags in the HSITRIM register */
  121. #define RCC_CR_HSITRIM_BitNumber 3
  122. #define RCC_HSI14TRIM_BIT_NUMBER 3
  123. #define RCC_FLAG_MASK ((uint8_t)0x1FU)
  124. /**
  125. * @}
  126. */
  127. /** @addtogroup RCC_Private_Macros
  128. * @{
  129. */
  130. #define IS_RCC_HSE(__HSE__) (((__HSE__) == RCC_HSE_OFF) || ((__HSE__) == RCC_HSE_ON) || \
  131. ((__HSE__) == RCC_HSE_BYPASS))
  132. #define IS_RCC_LSE(__LSE__) (((__LSE__) == RCC_LSE_OFF) || ((__LSE__) == RCC_LSE_ON) || \
  133. ((__LSE__) == RCC_LSE_BYPASS))
  134. #define IS_RCC_HSI(__HSI__) (((__HSI__) == RCC_HSI_OFF) || ((__HSI__) == RCC_HSI_ON))
  135. #define IS_RCC_HSI14(__HSI14__) (((__HSI14__) == RCC_HSI14_OFF) || ((__HSI14__) == RCC_HSI14_ON) || ((__HSI14__) == RCC_HSI14_ADC_CONTROL))
  136. #define IS_RCC_CALIBRATION_VALUE(__VALUE__) ((__VALUE__) <= 0x1FU)
  137. #define IS_RCC_LSI(__LSI__) (((__LSI__) == RCC_LSI_OFF) || ((__LSI__) == RCC_LSI_ON))
  138. #define IS_RCC_PLL(__PLL__) (((__PLL__) == RCC_PLL_NONE) || ((__PLL__) == RCC_PLL_OFF) || \
  139. ((__PLL__) == RCC_PLL_ON))
  140. #define IS_RCC_PREDIV(__PREDIV__) (((__PREDIV__) == RCC_PREDIV_DIV1) || ((__PREDIV__) == RCC_PREDIV_DIV2) || \
  141. ((__PREDIV__) == RCC_PREDIV_DIV3) || ((__PREDIV__) == RCC_PREDIV_DIV4) || \
  142. ((__PREDIV__) == RCC_PREDIV_DIV5) || ((__PREDIV__) == RCC_PREDIV_DIV6) || \
  143. ((__PREDIV__) == RCC_PREDIV_DIV7) || ((__PREDIV__) == RCC_PREDIV_DIV8) || \
  144. ((__PREDIV__) == RCC_PREDIV_DIV9) || ((__PREDIV__) == RCC_PREDIV_DIV10) || \
  145. ((__PREDIV__) == RCC_PREDIV_DIV11) || ((__PREDIV__) == RCC_PREDIV_DIV12) || \
  146. ((__PREDIV__) == RCC_PREDIV_DIV13) || ((__PREDIV__) == RCC_PREDIV_DIV14) || \
  147. ((__PREDIV__) == RCC_PREDIV_DIV15) || ((__PREDIV__) == RCC_PREDIV_DIV16))
  148. #define IS_RCC_PLL_MUL(__MUL__) (((__MUL__) == RCC_PLL_MUL2) || ((__MUL__) == RCC_PLL_MUL3) || \
  149. ((__MUL__) == RCC_PLL_MUL4) || ((__MUL__) == RCC_PLL_MUL5) || \
  150. ((__MUL__) == RCC_PLL_MUL6) || ((__MUL__) == RCC_PLL_MUL7) || \
  151. ((__MUL__) == RCC_PLL_MUL8) || ((__MUL__) == RCC_PLL_MUL9) || \
  152. ((__MUL__) == RCC_PLL_MUL10) || ((__MUL__) == RCC_PLL_MUL11) || \
  153. ((__MUL__) == RCC_PLL_MUL12) || ((__MUL__) == RCC_PLL_MUL13) || \
  154. ((__MUL__) == RCC_PLL_MUL14) || ((__MUL__) == RCC_PLL_MUL15) || \
  155. ((__MUL__) == RCC_PLL_MUL16))
  156. #define IS_RCC_CLOCKTYPE(__CLK__) ((((__CLK__) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) || \
  157. (((__CLK__) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) || \
  158. (((__CLK__) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1))
  159. #define IS_RCC_HCLK(__HCLK__) (((__HCLK__) == RCC_SYSCLK_DIV1) || ((__HCLK__) == RCC_SYSCLK_DIV2) || \
  160. ((__HCLK__) == RCC_SYSCLK_DIV4) || ((__HCLK__) == RCC_SYSCLK_DIV8) || \
  161. ((__HCLK__) == RCC_SYSCLK_DIV16) || ((__HCLK__) == RCC_SYSCLK_DIV64) || \
  162. ((__HCLK__) == RCC_SYSCLK_DIV128) || ((__HCLK__) == RCC_SYSCLK_DIV256) || \
  163. ((__HCLK__) == RCC_SYSCLK_DIV512))
  164. #define IS_RCC_PCLK(__PCLK__) (((__PCLK__) == RCC_HCLK_DIV1) || ((__PCLK__) == RCC_HCLK_DIV2) || \
  165. ((__PCLK__) == RCC_HCLK_DIV4) || ((__PCLK__) == RCC_HCLK_DIV8) || \
  166. ((__PCLK__) == RCC_HCLK_DIV16))
  167. #define IS_RCC_MCO(__MCO__) ((__MCO__) == RCC_MCO)
  168. #define IS_RCC_RTCCLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_RTCCLKSOURCE_NO_CLK) || \
  169. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSE) || \
  170. ((__SOURCE__) == RCC_RTCCLKSOURCE_LSI) || \
  171. ((__SOURCE__) == RCC_RTCCLKSOURCE_HSE_DIV32))
  172. #define IS_RCC_USART1CLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_USART1CLKSOURCE_PCLK1) || \
  173. ((__SOURCE__) == RCC_USART1CLKSOURCE_SYSCLK) || \
  174. ((__SOURCE__) == RCC_USART1CLKSOURCE_LSE) || \
  175. ((__SOURCE__) == RCC_USART1CLKSOURCE_HSI))
  176. #define IS_RCC_I2C1CLKSOURCE(__SOURCE__) (((__SOURCE__) == RCC_I2C1CLKSOURCE_HSI) || \
  177. ((__SOURCE__) == RCC_I2C1CLKSOURCE_SYSCLK))
  178. /**
  179. * @}
  180. */
  181. /* Exported types ------------------------------------------------------------*/
  182. /** @defgroup RCC_Exported_Types RCC Exported Types
  183. * @{
  184. */
  185. /**
  186. * @brief RCC PLL configuration structure definition
  187. */
  188. typedef struct
  189. {
  190. uint32_t PLLState; /*!< PLLState: The new state of the PLL.
  191. This parameter can be a value of @ref RCC_PLL_Config */
  192. uint32_t PLLSource; /*!< PLLSource: PLL entry clock source.
  193. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  194. uint32_t PLLMUL; /*!< PLLMUL: Multiplication factor for PLL VCO input clock
  195. This parameter must be a value of @ref RCC_PLL_Multiplication_Factor*/
  196. uint32_t PREDIV; /*!< PREDIV: Predivision factor for PLL VCO input clock
  197. This parameter must be a value of @ref RCC_PLL_Prediv_Factor */
  198. } RCC_PLLInitTypeDef;
  199. /**
  200. * @brief RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition
  201. */
  202. typedef struct
  203. {
  204. uint32_t OscillatorType; /*!< The oscillators to be configured.
  205. This parameter can be a value of @ref RCC_Oscillator_Type */
  206. uint32_t HSEState; /*!< The new state of the HSE.
  207. This parameter can be a value of @ref RCC_HSE_Config */
  208. uint32_t LSEState; /*!< The new state of the LSE.
  209. This parameter can be a value of @ref RCC_LSE_Config */
  210. uint32_t HSIState; /*!< The new state of the HSI.
  211. This parameter can be a value of @ref RCC_HSI_Config */
  212. uint32_t HSICalibrationValue; /*!< The HSI calibration trimming value (default is RCC_HSICALIBRATION_DEFAULT).
  213. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1FU */
  214. uint32_t HSI14State; /*!< The new state of the HSI14.
  215. This parameter can be a value of @ref RCC_HSI14_Config */
  216. uint32_t HSI14CalibrationValue; /*!< The HSI14 calibration trimming value (default is RCC_HSI14CALIBRATION_DEFAULT).
  217. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1FU */
  218. uint32_t LSIState; /*!< The new state of the LSI.
  219. This parameter can be a value of @ref RCC_LSI_Config */
  220. #if defined(RCC_HSI48_SUPPORT)
  221. uint32_t HSI48State; /*!< The new state of the HSI48.
  222. This parameter can be a value of @ref RCC_HSI48_Config */
  223. #endif /* RCC_HSI48_SUPPORT */
  224. RCC_PLLInitTypeDef PLL; /*!< PLL structure parameters */
  225. } RCC_OscInitTypeDef;
  226. /**
  227. * @brief RCC System, AHB and APB busses clock configuration structure definition
  228. */
  229. typedef struct
  230. {
  231. uint32_t ClockType; /*!< The clock to be configured.
  232. This parameter can be a value of @ref RCC_System_Clock_Type */
  233. uint32_t SYSCLKSource; /*!< The clock source (SYSCLKS) used as system clock.
  234. This parameter can be a value of @ref RCC_System_Clock_Source */
  235. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  236. This parameter can be a value of @ref RCC_AHB_Clock_Source */
  237. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  238. This parameter can be a value of @ref RCC_APB1_Clock_Source */
  239. } RCC_ClkInitTypeDef;
  240. /**
  241. * @}
  242. */
  243. /* Exported constants --------------------------------------------------------*/
  244. /** @defgroup RCC_Exported_Constants RCC Exported Constants
  245. * @{
  246. */
  247. /** @defgroup RCC_PLL_Clock_Source PLL Clock Source
  248. * @{
  249. */
  250. #define RCC_PLLSOURCE_HSE RCC_CFGR_PLLSRC_HSE_PREDIV /*!< HSE clock selected as PLL entry clock source */
  251. /**
  252. * @}
  253. */
  254. /** @defgroup RCC_Oscillator_Type Oscillator Type
  255. * @{
  256. */
  257. #define RCC_OSCILLATORTYPE_NONE (0x00000000U)
  258. #define RCC_OSCILLATORTYPE_HSE (0x00000001U)
  259. #define RCC_OSCILLATORTYPE_HSI (0x00000002U)
  260. #define RCC_OSCILLATORTYPE_LSE (0x00000004U)
  261. #define RCC_OSCILLATORTYPE_LSI (0x00000008U)
  262. #define RCC_OSCILLATORTYPE_HSI14 (0x00000010U)
  263. #if defined(RCC_HSI48_SUPPORT)
  264. #define RCC_OSCILLATORTYPE_HSI48 (0x00000020U)
  265. #endif /* RCC_HSI48_SUPPORT */
  266. /**
  267. * @}
  268. */
  269. /** @defgroup RCC_HSE_Config HSE Config
  270. * @{
  271. */
  272. #define RCC_HSE_OFF (0x00000000U) /*!< HSE clock deactivation */
  273. #define RCC_HSE_ON (0x00000001U) /*!< HSE clock activation */
  274. #define RCC_HSE_BYPASS (0x00000005U) /*!< External clock source for HSE clock */
  275. /**
  276. * @}
  277. */
  278. /** @defgroup RCC_LSE_Config LSE Config
  279. * @{
  280. */
  281. #define RCC_LSE_OFF (0x00000000U) /*!< LSE clock deactivation */
  282. #define RCC_LSE_ON (0x00000001U) /*!< LSE clock activation */
  283. #define RCC_LSE_BYPASS (0x00000005U) /*!< External clock source for LSE clock */
  284. /**
  285. * @}
  286. */
  287. /** @defgroup RCC_HSI_Config HSI Config
  288. * @{
  289. */
  290. #define RCC_HSI_OFF (0x00000000U) /*!< HSI clock deactivation */
  291. #define RCC_HSI_ON RCC_CR_HSION /*!< HSI clock activation */
  292. #define RCC_HSICALIBRATION_DEFAULT (0x10U) /* Default HSI calibration trimming value */
  293. /**
  294. * @}
  295. */
  296. /** @defgroup RCC_HSI14_Config RCC HSI14 Config
  297. * @{
  298. */
  299. #define RCC_HSI14_OFF (0x00000000U)
  300. #define RCC_HSI14_ON RCC_CR2_HSI14ON
  301. #define RCC_HSI14_ADC_CONTROL (~RCC_CR2_HSI14DIS)
  302. #define RCC_HSI14CALIBRATION_DEFAULT (0x10U) /* Default HSI14 calibration trimming value */
  303. /**
  304. * @}
  305. */
  306. /** @defgroup RCC_LSI_Config LSI Config
  307. * @{
  308. */
  309. #define RCC_LSI_OFF (0x00000000U) /*!< LSI clock deactivation */
  310. #define RCC_LSI_ON RCC_CSR_LSION /*!< LSI clock activation */
  311. /**
  312. * @}
  313. */
  314. #if defined(RCC_HSI48_SUPPORT)
  315. /** @defgroup RCC_HSI48_Config HSI48 Config
  316. * @{
  317. */
  318. #define RCC_HSI48_OFF ((uint8_t)0x00U)
  319. #define RCC_HSI48_ON ((uint8_t)0x01U)
  320. /**
  321. * @}
  322. */
  323. #endif /* RCC_HSI48_SUPPORT */
  324. /** @defgroup RCC_PLL_Config PLL Config
  325. * @{
  326. */
  327. #define RCC_PLL_NONE (0x00000000U) /*!< PLL is not configured */
  328. #define RCC_PLL_OFF (0x00000001U) /*!< PLL deactivation */
  329. #define RCC_PLL_ON (0x00000002U) /*!< PLL activation */
  330. /**
  331. * @}
  332. */
  333. /** @defgroup RCC_System_Clock_Type System Clock Type
  334. * @{
  335. */
  336. #define RCC_CLOCKTYPE_SYSCLK (0x00000001U) /*!< SYSCLK to configure */
  337. #define RCC_CLOCKTYPE_HCLK (0x00000002U) /*!< HCLK to configure */
  338. #define RCC_CLOCKTYPE_PCLK1 (0x00000004U) /*!< PCLK1 to configure */
  339. /**
  340. * @}
  341. */
  342. /** @defgroup RCC_System_Clock_Source System Clock Source
  343. * @{
  344. */
  345. #define RCC_SYSCLKSOURCE_HSI RCC_CFGR_SW_HSI /*!< HSI selected as system clock */
  346. #define RCC_SYSCLKSOURCE_HSE RCC_CFGR_SW_HSE /*!< HSE selected as system clock */
  347. #define RCC_SYSCLKSOURCE_PLLCLK RCC_CFGR_SW_PLL /*!< PLL selected as system clock */
  348. /**
  349. * @}
  350. */
  351. /** @defgroup RCC_System_Clock_Source_Status System Clock Source Status
  352. * @{
  353. */
  354. #define RCC_SYSCLKSOURCE_STATUS_HSI RCC_CFGR_SWS_HSI /*!< HSI used as system clock */
  355. #define RCC_SYSCLKSOURCE_STATUS_HSE RCC_CFGR_SWS_HSE /*!< HSE used as system clock */
  356. #define RCC_SYSCLKSOURCE_STATUS_PLLCLK RCC_CFGR_SWS_PLL /*!< PLL used as system clock */
  357. /**
  358. * @}
  359. */
  360. /** @defgroup RCC_AHB_Clock_Source AHB Clock Source
  361. * @{
  362. */
  363. #define RCC_SYSCLK_DIV1 RCC_CFGR_HPRE_DIV1 /*!< SYSCLK not divided */
  364. #define RCC_SYSCLK_DIV2 RCC_CFGR_HPRE_DIV2 /*!< SYSCLK divided by 2 */
  365. #define RCC_SYSCLK_DIV4 RCC_CFGR_HPRE_DIV4 /*!< SYSCLK divided by 4 */
  366. #define RCC_SYSCLK_DIV8 RCC_CFGR_HPRE_DIV8 /*!< SYSCLK divided by 8 */
  367. #define RCC_SYSCLK_DIV16 RCC_CFGR_HPRE_DIV16 /*!< SYSCLK divided by 16 */
  368. #define RCC_SYSCLK_DIV64 RCC_CFGR_HPRE_DIV64 /*!< SYSCLK divided by 64 */
  369. #define RCC_SYSCLK_DIV128 RCC_CFGR_HPRE_DIV128 /*!< SYSCLK divided by 128 */
  370. #define RCC_SYSCLK_DIV256 RCC_CFGR_HPRE_DIV256 /*!< SYSCLK divided by 256 */
  371. #define RCC_SYSCLK_DIV512 RCC_CFGR_HPRE_DIV512 /*!< SYSCLK divided by 512 */
  372. /**
  373. * @}
  374. */
  375. /** @defgroup RCC_APB1_Clock_Source RCC APB1 Clock Source
  376. * @{
  377. */
  378. #define RCC_HCLK_DIV1 RCC_CFGR_PPRE_DIV1 /*!< HCLK not divided */
  379. #define RCC_HCLK_DIV2 RCC_CFGR_PPRE_DIV2 /*!< HCLK divided by 2 */
  380. #define RCC_HCLK_DIV4 RCC_CFGR_PPRE_DIV4 /*!< HCLK divided by 4 */
  381. #define RCC_HCLK_DIV8 RCC_CFGR_PPRE_DIV8 /*!< HCLK divided by 8 */
  382. #define RCC_HCLK_DIV16 RCC_CFGR_PPRE_DIV16 /*!< HCLK divided by 16 */
  383. /**
  384. * @}
  385. */
  386. /** @defgroup RCC_RTC_Clock_Source RTC Clock Source
  387. * @{
  388. */
  389. #define RCC_RTCCLKSOURCE_NO_CLK (0x00000000U) /*!< No clock */
  390. #define RCC_RTCCLKSOURCE_LSE RCC_BDCR_RTCSEL_LSE /*!< LSE oscillator clock used as RTC clock */
  391. #define RCC_RTCCLKSOURCE_LSI RCC_BDCR_RTCSEL_LSI /*!< LSI oscillator clock used as RTC clock */
  392. #define RCC_RTCCLKSOURCE_HSE_DIV32 RCC_BDCR_RTCSEL_HSE /*!< HSE oscillator clock divided by 32 used as RTC clock */
  393. /**
  394. * @}
  395. */
  396. /** @defgroup RCC_PLL_Multiplication_Factor RCC PLL Multiplication Factor
  397. * @{
  398. */
  399. #define RCC_PLL_MUL2 RCC_CFGR_PLLMUL2
  400. #define RCC_PLL_MUL3 RCC_CFGR_PLLMUL3
  401. #define RCC_PLL_MUL4 RCC_CFGR_PLLMUL4
  402. #define RCC_PLL_MUL5 RCC_CFGR_PLLMUL5
  403. #define RCC_PLL_MUL6 RCC_CFGR_PLLMUL6
  404. #define RCC_PLL_MUL7 RCC_CFGR_PLLMUL7
  405. #define RCC_PLL_MUL8 RCC_CFGR_PLLMUL8
  406. #define RCC_PLL_MUL9 RCC_CFGR_PLLMUL9
  407. #define RCC_PLL_MUL10 RCC_CFGR_PLLMUL10
  408. #define RCC_PLL_MUL11 RCC_CFGR_PLLMUL11
  409. #define RCC_PLL_MUL12 RCC_CFGR_PLLMUL12
  410. #define RCC_PLL_MUL13 RCC_CFGR_PLLMUL13
  411. #define RCC_PLL_MUL14 RCC_CFGR_PLLMUL14
  412. #define RCC_PLL_MUL15 RCC_CFGR_PLLMUL15
  413. #define RCC_PLL_MUL16 RCC_CFGR_PLLMUL16
  414. /**
  415. * @}
  416. */
  417. /** @defgroup RCC_PLL_Prediv_Factor RCC PLL Prediv Factor
  418. * @{
  419. */
  420. #define RCC_PREDIV_DIV1 RCC_CFGR2_PREDIV_DIV1
  421. #define RCC_PREDIV_DIV2 RCC_CFGR2_PREDIV_DIV2
  422. #define RCC_PREDIV_DIV3 RCC_CFGR2_PREDIV_DIV3
  423. #define RCC_PREDIV_DIV4 RCC_CFGR2_PREDIV_DIV4
  424. #define RCC_PREDIV_DIV5 RCC_CFGR2_PREDIV_DIV5
  425. #define RCC_PREDIV_DIV6 RCC_CFGR2_PREDIV_DIV6
  426. #define RCC_PREDIV_DIV7 RCC_CFGR2_PREDIV_DIV7
  427. #define RCC_PREDIV_DIV8 RCC_CFGR2_PREDIV_DIV8
  428. #define RCC_PREDIV_DIV9 RCC_CFGR2_PREDIV_DIV9
  429. #define RCC_PREDIV_DIV10 RCC_CFGR2_PREDIV_DIV10
  430. #define RCC_PREDIV_DIV11 RCC_CFGR2_PREDIV_DIV11
  431. #define RCC_PREDIV_DIV12 RCC_CFGR2_PREDIV_DIV12
  432. #define RCC_PREDIV_DIV13 RCC_CFGR2_PREDIV_DIV13
  433. #define RCC_PREDIV_DIV14 RCC_CFGR2_PREDIV_DIV14
  434. #define RCC_PREDIV_DIV15 RCC_CFGR2_PREDIV_DIV15
  435. #define RCC_PREDIV_DIV16 RCC_CFGR2_PREDIV_DIV16
  436. /**
  437. * @}
  438. */
  439. /** @defgroup RCC_USART1_Clock_Source RCC USART1 Clock Source
  440. * @{
  441. */
  442. #define RCC_USART1CLKSOURCE_PCLK1 RCC_CFGR3_USART1SW_PCLK
  443. #define RCC_USART1CLKSOURCE_SYSCLK RCC_CFGR3_USART1SW_SYSCLK
  444. #define RCC_USART1CLKSOURCE_LSE RCC_CFGR3_USART1SW_LSE
  445. #define RCC_USART1CLKSOURCE_HSI RCC_CFGR3_USART1SW_HSI
  446. /**
  447. * @}
  448. */
  449. /** @defgroup RCC_I2C1_Clock_Source RCC I2C1 Clock Source
  450. * @{
  451. */
  452. #define RCC_I2C1CLKSOURCE_HSI RCC_CFGR3_I2C1SW_HSI
  453. #define RCC_I2C1CLKSOURCE_SYSCLK RCC_CFGR3_I2C1SW_SYSCLK
  454. /**
  455. * @}
  456. */
  457. /** @defgroup RCC_MCO_Index MCO Index
  458. * @{
  459. */
  460. #define RCC_MCO1 (0x00000000U)
  461. #define RCC_MCO RCC_MCO1 /*!< MCO1 to be compliant with other families with 2 MCOs*/
  462. /**
  463. * @}
  464. */
  465. /** @defgroup RCC_MCO_Clock_Source RCC MCO Clock Source
  466. * @{
  467. */
  468. #define RCC_MCO1SOURCE_NOCLOCK RCC_CFGR_MCO_NOCLOCK
  469. #define RCC_MCO1SOURCE_LSI RCC_CFGR_MCO_LSI
  470. #define RCC_MCO1SOURCE_LSE RCC_CFGR_MCO_LSE
  471. #define RCC_MCO1SOURCE_SYSCLK RCC_CFGR_MCO_SYSCLK
  472. #define RCC_MCO1SOURCE_HSI RCC_CFGR_MCO_HSI
  473. #define RCC_MCO1SOURCE_HSE RCC_CFGR_MCO_HSE
  474. #define RCC_MCO1SOURCE_PLLCLK_DIV2 RCC_CFGR_MCO_PLL
  475. #define RCC_MCO1SOURCE_HSI14 RCC_CFGR_MCO_HSI14
  476. /**
  477. * @}
  478. */
  479. /** @defgroup RCC_Interrupt Interrupts
  480. * @{
  481. */
  482. #define RCC_IT_LSIRDY ((uint8_t)RCC_CIR_LSIRDYF) /*!< LSI Ready Interrupt flag */
  483. #define RCC_IT_LSERDY ((uint8_t)RCC_CIR_LSERDYF) /*!< LSE Ready Interrupt flag */
  484. #define RCC_IT_HSIRDY ((uint8_t)RCC_CIR_HSIRDYF) /*!< HSI Ready Interrupt flag */
  485. #define RCC_IT_HSERDY ((uint8_t)RCC_CIR_HSERDYF) /*!< HSE Ready Interrupt flag */
  486. #define RCC_IT_PLLRDY ((uint8_t)RCC_CIR_PLLRDYF) /*!< PLL Ready Interrupt flag */
  487. #define RCC_IT_HSI14RDY ((uint8_t)RCC_CIR_HSI14RDYF) /*!< HSI14 Ready Interrupt flag */
  488. #if defined(RCC_CIR_HSI48RDYF)
  489. #define RCC_IT_HSI48RDY ((uint8_t)RCC_CIR_HSI48RDYF) /*!< HSI48 Ready Interrupt flag */
  490. #endif
  491. #define RCC_IT_CSS ((uint8_t)RCC_CIR_CSSF) /*!< Clock Security System Interrupt flag */
  492. /**
  493. * @}
  494. */
  495. /** @defgroup RCC_Flag Flags
  496. * Elements values convention: XXXYYYYYb
  497. * - YYYYY : Flag position in the register
  498. * - XXX : Register index
  499. * - 001: CR register
  500. * - 010: CR2 register
  501. * - 011: BDCR register
  502. * - 0100: CSR register
  503. * @{
  504. */
  505. /* Flags in the CR register */
  506. #define RCC_FLAG_HSIRDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_HSIRDY_BitNumber))
  507. #define RCC_FLAG_HSERDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_HSERDY_BitNumber))
  508. #define RCC_FLAG_PLLRDY ((uint8_t)((CR_REG_INDEX << 5U) | RCC_CR_PLLRDY_BitNumber))
  509. /* Flags in the CR2 register */
  510. #define RCC_FLAG_HSI14RDY ((uint8_t)((CR2_REG_INDEX << 5U) | RCC_CR2_HSI14RDY_BitNumber))
  511. /* Flags in the CSR register */
  512. #define RCC_FLAG_LSIRDY ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LSIRDY_BitNumber))
  513. #if defined(RCC_CSR_V18PWRRSTF)
  514. #define RCC_FLAG_V18PWRRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_V18PWRRSTF_BitNumber))
  515. #endif
  516. #define RCC_FLAG_OBLRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_OBLRSTF_BitNumber))
  517. #define RCC_FLAG_PINRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_PINRSTF_BitNumber)) /*!< PIN reset flag */
  518. #define RCC_FLAG_PORRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_PORRSTF_BitNumber)) /*!< POR/PDR reset flag */
  519. #define RCC_FLAG_SFTRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_SFTRSTF_BitNumber)) /*!< Software Reset flag */
  520. #define RCC_FLAG_IWDGRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_IWDGRSTF_BitNumber)) /*!< Independent Watchdog reset flag */
  521. #define RCC_FLAG_WWDGRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_WWDGRSTF_BitNumber)) /*!< Window watchdog reset flag */
  522. #define RCC_FLAG_LPWRRST ((uint8_t)((CSR_REG_INDEX << 5U) | RCC_CSR_LPWRRSTF_BitNumber)) /*!< Low-Power reset flag */
  523. /* Flags in the BDCR register */
  524. #define RCC_FLAG_LSERDY ((uint8_t)((BDCR_REG_INDEX << 5U) | RCC_BDCR_LSERDY_BitNumber)) /*!< External Low Speed oscillator Ready */
  525. /**
  526. * @}
  527. */
  528. /**
  529. * @}
  530. */
  531. /* Exported macro ------------------------------------------------------------*/
  532. /** @defgroup RCC_Exported_Macros RCC Exported Macros
  533. * @{
  534. */
  535. /** @defgroup RCC_AHB_Clock_Enable_Disable RCC AHB Clock Enable Disable
  536. * @brief Enable or disable the AHB peripheral clock.
  537. * @note After reset, the peripheral clock (used for registers read/write access)
  538. * is disabled and the application software has to enable this clock before
  539. * using it.
  540. * @{
  541. */
  542. #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
  543. __IO uint32_t tmpreg; \
  544. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOAEN);\
  545. /* Delay after an RCC peripheral clock enabling */\
  546. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOAEN);\
  547. UNUSED(tmpreg); \
  548. } while(0U)
  549. #define __HAL_RCC_GPIOB_CLK_ENABLE() do { \
  550. __IO uint32_t tmpreg; \
  551. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOBEN);\
  552. /* Delay after an RCC peripheral clock enabling */\
  553. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOBEN);\
  554. UNUSED(tmpreg); \
  555. } while(0U)
  556. #define __HAL_RCC_GPIOC_CLK_ENABLE() do { \
  557. __IO uint32_t tmpreg; \
  558. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOCEN);\
  559. /* Delay after an RCC peripheral clock enabling */\
  560. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOCEN);\
  561. UNUSED(tmpreg); \
  562. } while(0U)
  563. #define __HAL_RCC_GPIOF_CLK_ENABLE() do { \
  564. __IO uint32_t tmpreg; \
  565. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOFEN);\
  566. /* Delay after an RCC peripheral clock enabling */\
  567. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOFEN);\
  568. UNUSED(tmpreg); \
  569. } while(0U)
  570. #define __HAL_RCC_CRC_CLK_ENABLE() do { \
  571. __IO uint32_t tmpreg; \
  572. SET_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  573. /* Delay after an RCC peripheral clock enabling */\
  574. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_CRCEN);\
  575. UNUSED(tmpreg); \
  576. } while(0U)
  577. #define __HAL_RCC_DMA1_CLK_ENABLE() do { \
  578. __IO uint32_t tmpreg; \
  579. SET_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  580. /* Delay after an RCC peripheral clock enabling */\
  581. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA1EN);\
  582. UNUSED(tmpreg); \
  583. } while(0U)
  584. #define __HAL_RCC_SRAM_CLK_ENABLE() do { \
  585. __IO uint32_t tmpreg; \
  586. SET_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
  587. /* Delay after an RCC peripheral clock enabling */\
  588. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_SRAMEN);\
  589. UNUSED(tmpreg); \
  590. } while(0U)
  591. #define __HAL_RCC_FLITF_CLK_ENABLE() do { \
  592. __IO uint32_t tmpreg; \
  593. SET_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  594. /* Delay after an RCC peripheral clock enabling */\
  595. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FLITFEN);\
  596. UNUSED(tmpreg); \
  597. } while(0U)
  598. #define __HAL_RCC_GPIOA_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOAEN))
  599. #define __HAL_RCC_GPIOB_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOBEN))
  600. #define __HAL_RCC_GPIOC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOCEN))
  601. #define __HAL_RCC_GPIOF_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOFEN))
  602. #define __HAL_RCC_CRC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_CRCEN))
  603. #define __HAL_RCC_DMA1_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_DMA1EN))
  604. #define __HAL_RCC_SRAM_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_SRAMEN))
  605. #define __HAL_RCC_FLITF_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_FLITFEN))
  606. /**
  607. * @}
  608. */
  609. /** @defgroup RCC_AHB_Peripheral_Clock_Enable_Disable_Status AHB Peripheral Clock Enable Disable Status
  610. * @brief Get the enable or disable status of the AHB peripheral clock.
  611. * @note After reset, the peripheral clock (used for registers read/write access)
  612. * is disabled and the application software has to enable this clock before
  613. * using it.
  614. * @{
  615. */
  616. #define __HAL_RCC_GPIOA_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOAEN)) != RESET)
  617. #define __HAL_RCC_GPIOB_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOBEN)) != RESET)
  618. #define __HAL_RCC_GPIOC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOCEN)) != RESET)
  619. #define __HAL_RCC_GPIOF_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOFEN)) != RESET)
  620. #define __HAL_RCC_CRC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) != RESET)
  621. #define __HAL_RCC_DMA1_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) != RESET)
  622. #define __HAL_RCC_SRAM_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) != RESET)
  623. #define __HAL_RCC_FLITF_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) != RESET)
  624. #define __HAL_RCC_GPIOA_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOAEN)) == RESET)
  625. #define __HAL_RCC_GPIOB_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOBEN)) == RESET)
  626. #define __HAL_RCC_GPIOC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOCEN)) == RESET)
  627. #define __HAL_RCC_GPIOF_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOFEN)) == RESET)
  628. #define __HAL_RCC_CRC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_CRCEN)) == RESET)
  629. #define __HAL_RCC_DMA1_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA1EN)) == RESET)
  630. #define __HAL_RCC_SRAM_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_SRAMEN)) == RESET)
  631. #define __HAL_RCC_FLITF_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_FLITFEN)) == RESET)
  632. /**
  633. * @}
  634. */
  635. /** @defgroup RCC_APB1_Clock_Enable_Disable RCC APB1 Clock Enable Disable
  636. * @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  637. * @note After reset, the peripheral clock (used for registers read/write access)
  638. * is disabled and the application software has to enable this clock before
  639. * using it.
  640. * @{
  641. */
  642. #define __HAL_RCC_TIM3_CLK_ENABLE() do { \
  643. __IO uint32_t tmpreg; \
  644. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  645. /* Delay after an RCC peripheral clock enabling */\
  646. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM3EN);\
  647. UNUSED(tmpreg); \
  648. } while(0U)
  649. #define __HAL_RCC_TIM14_CLK_ENABLE() do { \
  650. __IO uint32_t tmpreg; \
  651. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM14EN);\
  652. /* Delay after an RCC peripheral clock enabling */\
  653. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM14EN);\
  654. UNUSED(tmpreg); \
  655. } while(0U)
  656. #define __HAL_RCC_WWDG_CLK_ENABLE() do { \
  657. __IO uint32_t tmpreg; \
  658. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  659. /* Delay after an RCC peripheral clock enabling */\
  660. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_WWDGEN);\
  661. UNUSED(tmpreg); \
  662. } while(0U)
  663. #define __HAL_RCC_I2C1_CLK_ENABLE() do { \
  664. __IO uint32_t tmpreg; \
  665. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  666. /* Delay after an RCC peripheral clock enabling */\
  667. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C1EN);\
  668. UNUSED(tmpreg); \
  669. } while(0U)
  670. #define __HAL_RCC_PWR_CLK_ENABLE() do { \
  671. __IO uint32_t tmpreg; \
  672. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  673. /* Delay after an RCC peripheral clock enabling */\
  674. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_PWREN);\
  675. UNUSED(tmpreg); \
  676. } while(0U)
  677. #define __HAL_RCC_TIM3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN))
  678. #define __HAL_RCC_TIM14_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM14EN))
  679. #define __HAL_RCC_WWDG_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_WWDGEN))
  680. #define __HAL_RCC_I2C1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN))
  681. #define __HAL_RCC_PWR_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_PWREN))
  682. /**
  683. * @}
  684. */
  685. /** @defgroup RCC_APB1_Peripheral_Clock_Enable_Disable_Status APB1 Peripheral Clock Enable Disable Status
  686. * @brief Get the enable or disable status of the APB1 peripheral clock.
  687. * @note After reset, the peripheral clock (used for registers read/write access)
  688. * is disabled and the application software has to enable this clock before
  689. * using it.
  690. * @{
  691. */
  692. #define __HAL_RCC_TIM3_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) != RESET)
  693. #define __HAL_RCC_TIM14_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM14EN)) != RESET)
  694. #define __HAL_RCC_WWDG_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) != RESET)
  695. #define __HAL_RCC_I2C1_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) != RESET)
  696. #define __HAL_RCC_PWR_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) != RESET)
  697. #define __HAL_RCC_TIM3_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM3EN)) == RESET)
  698. #define __HAL_RCC_TIM14_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM14EN)) == RESET)
  699. #define __HAL_RCC_WWDG_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_WWDGEN)) == RESET)
  700. #define __HAL_RCC_I2C1_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C1EN)) == RESET)
  701. #define __HAL_RCC_PWR_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_PWREN)) == RESET)
  702. /**
  703. * @}
  704. */
  705. /** @defgroup RCC_APB2_Clock_Enable_Disable RCC APB2 Clock Enable Disable
  706. * @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  707. * @note After reset, the peripheral clock (used for registers read/write access)
  708. * is disabled and the application software has to enable this clock before
  709. * using it.
  710. * @{
  711. */
  712. #define __HAL_RCC_SYSCFG_CLK_ENABLE() do { \
  713. __IO uint32_t tmpreg; \
  714. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);\
  715. /* Delay after an RCC peripheral clock enabling */\
  716. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);\
  717. UNUSED(tmpreg); \
  718. } while(0U)
  719. #define __HAL_RCC_ADC1_CLK_ENABLE() do { \
  720. __IO uint32_t tmpreg; \
  721. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  722. /* Delay after an RCC peripheral clock enabling */\
  723. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);\
  724. UNUSED(tmpreg); \
  725. } while(0U)
  726. #define __HAL_RCC_TIM1_CLK_ENABLE() do { \
  727. __IO uint32_t tmpreg; \
  728. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
  729. /* Delay after an RCC peripheral clock enabling */\
  730. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN);\
  731. UNUSED(tmpreg); \
  732. } while(0U)
  733. #define __HAL_RCC_SPI1_CLK_ENABLE() do { \
  734. __IO uint32_t tmpreg; \
  735. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  736. /* Delay after an RCC peripheral clock enabling */\
  737. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SPI1EN);\
  738. UNUSED(tmpreg); \
  739. } while(0U)
  740. #define __HAL_RCC_TIM16_CLK_ENABLE() do { \
  741. __IO uint32_t tmpreg; \
  742. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM16EN);\
  743. /* Delay after an RCC peripheral clock enabling */\
  744. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM16EN);\
  745. UNUSED(tmpreg); \
  746. } while(0U)
  747. #define __HAL_RCC_TIM17_CLK_ENABLE() do { \
  748. __IO uint32_t tmpreg; \
  749. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM17EN);\
  750. /* Delay after an RCC peripheral clock enabling */\
  751. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM17EN);\
  752. UNUSED(tmpreg); \
  753. } while(0U)
  754. #define __HAL_RCC_USART1_CLK_ENABLE() do { \
  755. __IO uint32_t tmpreg; \
  756. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  757. /* Delay after an RCC peripheral clock enabling */\
  758. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN);\
  759. UNUSED(tmpreg); \
  760. } while(0U)
  761. #define __HAL_RCC_DBGMCU_CLK_ENABLE() do { \
  762. __IO uint32_t tmpreg; \
  763. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_DBGMCUEN);\
  764. /* Delay after an RCC peripheral clock enabling */\
  765. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_DBGMCUEN);\
  766. UNUSED(tmpreg); \
  767. } while(0U)
  768. #define __HAL_RCC_SYSCFG_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SYSCFGEN))
  769. #define __HAL_RCC_ADC1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN))
  770. #define __HAL_RCC_TIM1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM1EN))
  771. #define __HAL_RCC_SPI1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI1EN))
  772. #define __HAL_RCC_TIM16_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM16EN))
  773. #define __HAL_RCC_TIM17_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM17EN))
  774. #define __HAL_RCC_USART1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
  775. #define __HAL_RCC_DBGMCU_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_DBGMCUEN))
  776. /**
  777. * @}
  778. */
  779. /** @defgroup RCC_APB2_Peripheral_Clock_Enable_Disable_Status APB2 Peripheral Clock Enable Disable Status
  780. * @brief Get the enable or disable status of the APB2 peripheral clock.
  781. * @note After reset, the peripheral clock (used for registers read/write access)
  782. * is disabled and the application software has to enable this clock before
  783. * using it.
  784. * @{
  785. */
  786. #define __HAL_RCC_SYSCFG_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SYSCFGEN)) != RESET)
  787. #define __HAL_RCC_ADC1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) != RESET)
  788. #define __HAL_RCC_TIM1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM1EN)) != RESET)
  789. #define __HAL_RCC_SPI1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) != RESET)
  790. #define __HAL_RCC_TIM16_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM16EN)) != RESET)
  791. #define __HAL_RCC_TIM17_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM17EN)) != RESET)
  792. #define __HAL_RCC_USART1_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) != RESET)
  793. #define __HAL_RCC_DBGMCU_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_DBGMCUEN)) != RESET)
  794. #define __HAL_RCC_SYSCFG_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SYSCFGEN)) == RESET)
  795. #define __HAL_RCC_ADC1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN)) == RESET)
  796. #define __HAL_RCC_TIM1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM1EN)) == RESET)
  797. #define __HAL_RCC_SPI1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_SPI1EN)) == RESET)
  798. #define __HAL_RCC_TIM16_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM16EN)) == RESET)
  799. #define __HAL_RCC_TIM17_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM17EN)) == RESET)
  800. #define __HAL_RCC_USART1_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART1EN)) == RESET)
  801. #define __HAL_RCC_DBGMCU_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_DBGMCUEN)) == RESET)
  802. /**
  803. * @}
  804. */
  805. /** @defgroup RCC_AHB_Force_Release_Reset RCC AHB Force Release Reset
  806. * @brief Force or release AHB peripheral reset.
  807. * @{
  808. */
  809. #define __HAL_RCC_AHB_FORCE_RESET() (RCC->AHBRSTR = 0xFFFFFFFFU)
  810. #define __HAL_RCC_GPIOA_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOARST))
  811. #define __HAL_RCC_GPIOB_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOBRST))
  812. #define __HAL_RCC_GPIOC_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOCRST))
  813. #define __HAL_RCC_GPIOF_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOFRST))
  814. #define __HAL_RCC_AHB_RELEASE_RESET() (RCC->AHBRSTR = 0x00000000U)
  815. #define __HAL_RCC_GPIOA_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOARST))
  816. #define __HAL_RCC_GPIOB_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOBRST))
  817. #define __HAL_RCC_GPIOC_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOCRST))
  818. #define __HAL_RCC_GPIOF_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOFRST))
  819. /**
  820. * @}
  821. */
  822. /** @defgroup RCC_APB1_Force_Release_Reset RCC APB1 Force Release Reset
  823. * @brief Force or release APB1 peripheral reset.
  824. * @{
  825. */
  826. #define __HAL_RCC_APB1_FORCE_RESET() (RCC->APB1RSTR = 0xFFFFFFFFU)
  827. #define __HAL_RCC_TIM3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM3RST))
  828. #define __HAL_RCC_TIM14_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM14RST))
  829. #define __HAL_RCC_WWDG_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_WWDGRST))
  830. #define __HAL_RCC_I2C1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C1RST))
  831. #define __HAL_RCC_PWR_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_PWRRST))
  832. #define __HAL_RCC_APB1_RELEASE_RESET() (RCC->APB1RSTR = 0x00000000U)
  833. #define __HAL_RCC_TIM3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM3RST))
  834. #define __HAL_RCC_TIM14_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM14RST))
  835. #define __HAL_RCC_WWDG_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_WWDGRST))
  836. #define __HAL_RCC_I2C1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C1RST))
  837. #define __HAL_RCC_PWR_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_PWRRST))
  838. /**
  839. * @}
  840. */
  841. /** @defgroup RCC_APB2_Force_Release_Reset RCC APB2 Force Release Reset
  842. * @brief Force or release APB2 peripheral reset.
  843. * @{
  844. */
  845. #define __HAL_RCC_APB2_FORCE_RESET() (RCC->APB2RSTR = 0xFFFFFFFFU)
  846. #define __HAL_RCC_SYSCFG_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SYSCFGRST))
  847. #define __HAL_RCC_ADC1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_ADC1RST))
  848. #define __HAL_RCC_TIM1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM1RST))
  849. #define __HAL_RCC_SPI1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_SPI1RST))
  850. #define __HAL_RCC_USART1_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART1RST))
  851. #define __HAL_RCC_TIM16_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM16RST))
  852. #define __HAL_RCC_TIM17_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM17RST))
  853. #define __HAL_RCC_DBGMCU_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_DBGMCURST))
  854. #define __HAL_RCC_APB2_RELEASE_RESET() (RCC->APB2RSTR = 0x00000000U)
  855. #define __HAL_RCC_SYSCFG_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SYSCFGRST))
  856. #define __HAL_RCC_ADC1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_ADC1RST))
  857. #define __HAL_RCC_TIM1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM1RST))
  858. #define __HAL_RCC_SPI1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_SPI1RST))
  859. #define __HAL_RCC_USART1_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART1RST))
  860. #define __HAL_RCC_TIM16_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM16RST))
  861. #define __HAL_RCC_TIM17_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM17RST))
  862. #define __HAL_RCC_DBGMCU_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_DBGMCURST))
  863. /**
  864. * @}
  865. */
  866. /** @defgroup RCC_HSI_Configuration HSI Configuration
  867. * @{
  868. */
  869. /** @brief Macros to enable or disable the Internal High Speed oscillator (HSI).
  870. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  871. * @note HSI can not be stopped if it is used as system clock source. In this case,
  872. * you have to select another source of the system clock then stop the HSI.
  873. * @note After enabling the HSI, the application software should wait on HSIRDY
  874. * flag to be set indicating that HSI clock is stable and can be used as
  875. * system clock source.
  876. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  877. * clock cycles.
  878. */
  879. #define __HAL_RCC_HSI_ENABLE() SET_BIT(RCC->CR, RCC_CR_HSION)
  880. #define __HAL_RCC_HSI_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_HSION)
  881. /** @brief Macro to adjust the Internal High Speed oscillator (HSI) calibration value.
  882. * @note The calibration is used to compensate for the variations in voltage
  883. * and temperature that influence the frequency of the internal HSI RC.
  884. * @param _HSICALIBRATIONVALUE_ specifies the calibration trimming value.
  885. * (default is RCC_HSICALIBRATION_DEFAULT).
  886. * This parameter must be a number between 0 and 0x1F.
  887. */
  888. #define __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(_HSICALIBRATIONVALUE_) \
  889. MODIFY_REG(RCC->CR, RCC_CR_HSITRIM, (uint32_t)(_HSICALIBRATIONVALUE_) << RCC_CR_HSITRIM_BitNumber)
  890. /**
  891. * @}
  892. */
  893. /** @defgroup RCC_LSI_Configuration LSI Configuration
  894. * @{
  895. */
  896. /** @brief Macro to enable the Internal Low Speed oscillator (LSI).
  897. * @note After enabling the LSI, the application software should wait on
  898. * LSIRDY flag to be set indicating that LSI clock is stable and can
  899. * be used to clock the IWDG and/or the RTC.
  900. */
  901. #define __HAL_RCC_LSI_ENABLE() SET_BIT(RCC->CSR, RCC_CSR_LSION)
  902. /** @brief Macro to disable the Internal Low Speed oscillator (LSI).
  903. * @note LSI can not be disabled if the IWDG is running.
  904. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  905. * clock cycles.
  906. */
  907. #define __HAL_RCC_LSI_DISABLE() CLEAR_BIT(RCC->CSR, RCC_CSR_LSION)
  908. /**
  909. * @}
  910. */
  911. /** @defgroup RCC_HSE_Configuration HSE Configuration
  912. * @{
  913. */
  914. /**
  915. * @brief Macro to configure the External High Speed oscillator (HSE).
  916. * @note Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not
  917. * supported by this macro. User should request a transition to HSE Off
  918. * first and then HSE On or HSE Bypass.
  919. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  920. * software should wait on HSERDY flag to be set indicating that HSE clock
  921. * is stable and can be used to clock the PLL and/or system clock.
  922. * @note HSE state can not be changed if it is used directly or through the
  923. * PLL as system clock. In this case, you have to select another source
  924. * of the system clock then change the HSE state (ex. disable it).
  925. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  926. * @note This function reset the CSSON bit, so if the clock security system(CSS)
  927. * was previously enabled you have to enable it again after calling this
  928. * function.
  929. * @param __STATE__ specifies the new state of the HSE.
  930. * This parameter can be one of the following values:
  931. * @arg @ref RCC_HSE_OFF turn OFF the HSE oscillator, HSERDY flag goes low after
  932. * 6 HSE oscillator clock cycles.
  933. * @arg @ref RCC_HSE_ON turn ON the HSE oscillator
  934. * @arg @ref RCC_HSE_BYPASS HSE oscillator bypassed with external clock
  935. */
  936. #define __HAL_RCC_HSE_CONFIG(__STATE__) \
  937. do{ \
  938. if ((__STATE__) == RCC_HSE_ON) \
  939. { \
  940. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  941. } \
  942. else if ((__STATE__) == RCC_HSE_OFF) \
  943. { \
  944. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  945. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  946. } \
  947. else if ((__STATE__) == RCC_HSE_BYPASS) \
  948. { \
  949. SET_BIT(RCC->CR, RCC_CR_HSEBYP); \
  950. SET_BIT(RCC->CR, RCC_CR_HSEON); \
  951. } \
  952. else \
  953. { \
  954. CLEAR_BIT(RCC->CR, RCC_CR_HSEON); \
  955. CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); \
  956. } \
  957. }while(0U)
  958. /**
  959. * @brief Macro to configure the External High Speed oscillator (HSE) Predivision factor for PLL.
  960. * @note Predivision factor can not be changed if PLL is used as system clock
  961. * In this case, you have to select another source of the system clock, disable the PLL and
  962. * then change the HSE predivision factor.
  963. * @param __HSE_PREDIV_VALUE__ specifies the division value applied to HSE.
  964. * This parameter must be a number between RCC_HSE_PREDIV_DIV1 and RCC_HSE_PREDIV_DIV16.
  965. */
  966. #define __HAL_RCC_HSE_PREDIV_CONFIG(__HSE_PREDIV_VALUE__) \
  967. MODIFY_REG(RCC->CFGR2, RCC_CFGR2_PREDIV, (uint32_t)(__HSE_PREDIV_VALUE__))
  968. /**
  969. * @}
  970. */
  971. /** @defgroup RCC_LSE_Configuration LSE Configuration
  972. * @{
  973. */
  974. /**
  975. * @brief Macro to configure the External Low Speed oscillator (LSE).
  976. * @note Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not supported by this macro.
  977. * @note As the LSE is in the Backup domain and write access is denied to
  978. * this domain after reset, you have to enable write access using
  979. * @ref HAL_PWR_EnableBkUpAccess() function before to configure the LSE
  980. * (to be done once after reset).
  981. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_BYPASS), the application
  982. * software should wait on LSERDY flag to be set indicating that LSE clock
  983. * is stable and can be used to clock the RTC.
  984. * @param __STATE__ specifies the new state of the LSE.
  985. * This parameter can be one of the following values:
  986. * @arg @ref RCC_LSE_OFF turn OFF the LSE oscillator, LSERDY flag goes low after
  987. * 6 LSE oscillator clock cycles.
  988. * @arg @ref RCC_LSE_ON turn ON the LSE oscillator.
  989. * @arg @ref RCC_LSE_BYPASS LSE oscillator bypassed with external clock.
  990. */
  991. #define __HAL_RCC_LSE_CONFIG(__STATE__) \
  992. do{ \
  993. if ((__STATE__) == RCC_LSE_ON) \
  994. { \
  995. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  996. } \
  997. else if ((__STATE__) == RCC_LSE_OFF) \
  998. { \
  999. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  1000. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  1001. } \
  1002. else if ((__STATE__) == RCC_LSE_BYPASS) \
  1003. { \
  1004. SET_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  1005. SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  1006. } \
  1007. else \
  1008. { \
  1009. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); \
  1010. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); \
  1011. } \
  1012. }while(0U)
  1013. /**
  1014. * @}
  1015. */
  1016. /** @defgroup RCC_HSI14_Configuration RCC_HSI14_Configuration
  1017. * @{
  1018. */
  1019. /** @brief Macro to enable the Internal 14Mhz High Speed oscillator (HSI14).
  1020. * @note After enabling the HSI14 with @ref __HAL_RCC_HSI14_ENABLE(), the application software
  1021. * should wait on HSI14RDY flag to be set indicating that HSI clock is stable and can be
  1022. * used as system clock source. This is not necessary if @ref HAL_RCC_OscConfig() is used.
  1023. * clock cycles.
  1024. */
  1025. #define __HAL_RCC_HSI14_ENABLE() SET_BIT(RCC->CR2, RCC_CR2_HSI14ON)
  1026. /** @brief Macro to disable the Internal 14Mhz High Speed oscillator (HSI14).
  1027. * @note The HSI14 is stopped by hardware when entering STOP and STANDBY modes.
  1028. * @note HSI14 can not be stopped if it is used as system clock source. In this case,
  1029. * you have to select another source of the system clock then stop the HSI14.
  1030. * @note When the HSI14 is stopped, HSI14RDY flag goes low after 6 HSI14 oscillator
  1031. * clock cycles.
  1032. */
  1033. #define __HAL_RCC_HSI14_DISABLE() CLEAR_BIT(RCC->CR2, RCC_CR2_HSI14ON)
  1034. /** @brief Macro to enable the Internal 14Mhz High Speed oscillator (HSI14) used by ADC.
  1035. */
  1036. #define __HAL_RCC_HSI14ADC_ENABLE() CLEAR_BIT(RCC->CR2, RCC_CR2_HSI14DIS)
  1037. /** @brief Macro to disable the Internal 14Mhz High Speed oscillator (HSI14) used by ADC.
  1038. */
  1039. #define __HAL_RCC_HSI14ADC_DISABLE() SET_BIT(RCC->CR2, RCC_CR2_HSI14DIS)
  1040. /** @brief Macro to adjust the Internal 14Mhz High Speed oscillator (HSI) calibration value.
  1041. * @note The calibration is used to compensate for the variations in voltage
  1042. * and temperature that influence the frequency of the internal HSI14 RC.
  1043. * @param __HSI14CALIBRATIONVALUE__ specifies the calibration trimming value
  1044. * (default is RCC_HSI14CALIBRATION_DEFAULT).
  1045. * This parameter must be a number between 0 and 0x1F.
  1046. */
  1047. #define __HAL_RCC_HSI14_CALIBRATIONVALUE_ADJUST(__HSI14CALIBRATIONVALUE__) \
  1048. MODIFY_REG(RCC->CR2, RCC_CR2_HSI14TRIM, (uint32_t)(__HSI14CALIBRATIONVALUE__) << RCC_HSI14TRIM_BIT_NUMBER)
  1049. /**
  1050. * @}
  1051. */
  1052. /** @defgroup RCC_USARTx_Clock_Config RCC USARTx Clock Config
  1053. * @{
  1054. */
  1055. /** @brief Macro to configure the USART1 clock (USART1CLK).
  1056. * @param __USART1CLKSOURCE__ specifies the USART1 clock source.
  1057. * This parameter can be one of the following values:
  1058. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1059. * @arg @ref RCC_USART1CLKSOURCE_HSI HSI selected as USART1 clock
  1060. * @arg @ref RCC_USART1CLKSOURCE_SYSCLK System Clock selected as USART1 clock
  1061. * @arg @ref RCC_USART1CLKSOURCE_LSE LSE selected as USART1 clock
  1062. */
  1063. #define __HAL_RCC_USART1_CONFIG(__USART1CLKSOURCE__) \
  1064. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_USART1SW, (uint32_t)(__USART1CLKSOURCE__))
  1065. /** @brief Macro to get the USART1 clock source.
  1066. * @retval The clock source can be one of the following values:
  1067. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  1068. * @arg @ref RCC_USART1CLKSOURCE_HSI HSI selected as USART1 clock
  1069. * @arg @ref RCC_USART1CLKSOURCE_SYSCLK System Clock selected as USART1 clock
  1070. * @arg @ref RCC_USART1CLKSOURCE_LSE LSE selected as USART1 clock
  1071. */
  1072. #define __HAL_RCC_GET_USART1_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_USART1SW)))
  1073. /**
  1074. * @}
  1075. */
  1076. /** @defgroup RCC_I2Cx_Clock_Config RCC I2Cx Clock Config
  1077. * @{
  1078. */
  1079. /** @brief Macro to configure the I2C1 clock (I2C1CLK).
  1080. * @param __I2C1CLKSOURCE__ specifies the I2C1 clock source.
  1081. * This parameter can be one of the following values:
  1082. * @arg @ref RCC_I2C1CLKSOURCE_HSI HSI selected as I2C1 clock
  1083. * @arg @ref RCC_I2C1CLKSOURCE_SYSCLK System Clock selected as I2C1 clock
  1084. */
  1085. #define __HAL_RCC_I2C1_CONFIG(__I2C1CLKSOURCE__) \
  1086. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_I2C1SW, (uint32_t)(__I2C1CLKSOURCE__))
  1087. /** @brief Macro to get the I2C1 clock source.
  1088. * @retval The clock source can be one of the following values:
  1089. * @arg @ref RCC_I2C1CLKSOURCE_HSI HSI selected as I2C1 clock
  1090. * @arg @ref RCC_I2C1CLKSOURCE_SYSCLK System Clock selected as I2C1 clock
  1091. */
  1092. #define __HAL_RCC_GET_I2C1_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_I2C1SW)))
  1093. /**
  1094. * @}
  1095. */
  1096. /** @defgroup RCC_PLL_Configuration PLL Configuration
  1097. * @{
  1098. */
  1099. /** @brief Macro to enable the main PLL.
  1100. * @note After enabling the main PLL, the application software should wait on
  1101. * PLLRDY flag to be set indicating that PLL clock is stable and can
  1102. * be used as system clock source.
  1103. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  1104. */
  1105. #define __HAL_RCC_PLL_ENABLE() SET_BIT(RCC->CR, RCC_CR_PLLON)
  1106. /** @brief Macro to disable the main PLL.
  1107. * @note The main PLL can not be disabled if it is used as system clock source
  1108. */
  1109. #define __HAL_RCC_PLL_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_PLLON)
  1110. /** @brief Macro to configure the PLL clock source, multiplication and division factors.
  1111. * @note This function must be used only when the main PLL is disabled.
  1112. *
  1113. * @param __RCC_PLLSOURCE__ specifies the PLL entry clock source.
  1114. * This parameter can be one of the following values:
  1115. * @arg @ref RCC_PLLSOURCE_HSI HSI oscillator clock selected as PLL clock entry
  1116. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL clock entry
  1117. * @param __PLLMUL__ specifies the multiplication factor for PLL VCO output clock
  1118. * This parameter can be one of the following values:
  1119. * This parameter must be a number between RCC_PLL_MUL2 and RCC_PLL_MUL16.
  1120. * @param __PREDIV__ specifies the predivider factor for PLL VCO input clock
  1121. * This parameter must be a number between RCC_PREDIV_DIV1 and RCC_PREDIV_DIV16.
  1122. *
  1123. */
  1124. #define __HAL_RCC_PLL_CONFIG(__RCC_PLLSOURCE__ , __PREDIV__, __PLLMUL__) \
  1125. do { \
  1126. MODIFY_REG(RCC->CFGR2, RCC_CFGR2_PREDIV, (__PREDIV__)); \
  1127. MODIFY_REG(RCC->CFGR, RCC_CFGR_PLLMUL | RCC_CFGR_PLLSRC, (uint32_t)((__PLLMUL__)|(__RCC_PLLSOURCE__))); \
  1128. } while(0U)
  1129. /** @brief Get oscillator clock selected as PLL input clock
  1130. * @retval The clock source used for PLL entry. The returned value can be one
  1131. * of the following:
  1132. * @arg @ref RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL input clock
  1133. */
  1134. #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLSRC)))
  1135. /**
  1136. * @}
  1137. */
  1138. /** @defgroup RCC_Get_Clock_source Get Clock source
  1139. * @{
  1140. */
  1141. /**
  1142. * @brief Macro to configure the system clock source.
  1143. * @param __SYSCLKSOURCE__ specifies the system clock source.
  1144. * This parameter can be one of the following values:
  1145. * @arg @ref RCC_SYSCLKSOURCE_HSI HSI oscillator is used as system clock source.
  1146. * @arg @ref RCC_SYSCLKSOURCE_HSE HSE oscillator is used as system clock source.
  1147. * @arg @ref RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source.
  1148. */
  1149. #define __HAL_RCC_SYSCLK_CONFIG(__SYSCLKSOURCE__) \
  1150. MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, (__SYSCLKSOURCE__))
  1151. /** @brief Macro to get the clock source used as system clock.
  1152. * @retval The clock source used as system clock. The returned value can be one
  1153. * of the following:
  1154. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock
  1155. * @arg @ref RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock
  1156. * @arg @ref RCC_SYSCLKSOURCE_STATUS_PLLCLK PLL used as system clock
  1157. */
  1158. #define __HAL_RCC_GET_SYSCLK_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR,RCC_CFGR_SWS)))
  1159. /**
  1160. * @}
  1161. */
  1162. /** @defgroup RCCEx_MCOx_Clock_Config RCC Extended MCOx Clock Config
  1163. * @{
  1164. */
  1165. #if defined(RCC_CFGR_MCOPRE)
  1166. /** @brief Macro to configure the MCO clock.
  1167. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  1168. * This parameter can be one of the following values:
  1169. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  1170. * @arg @ref RCC_MCO1SOURCE_SYSCLK System Clock selected as MCO clock
  1171. * @arg @ref RCC_MCO1SOURCE_HSI HSI oscillator clock selected as MCO clock
  1172. * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
  1173. * @arg @ref RCC_MCO1SOURCE_LSI LSI selected as MCO clock
  1174. * @arg @ref RCC_MCO1SOURCE_LSE LSE selected as MCO clock
  1175. * @arg @ref RCC_MCO1SOURCE_HSI14 HSI14 selected as MCO clock
  1176. @if STM32F042x6
  1177. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 selected as MCO clock
  1178. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1179. @elseif STM32F048xx
  1180. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 selected as MCO clock
  1181. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1182. @elseif STM32F071xB
  1183. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 selected as MCO clock
  1184. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1185. @elseif STM32F072xB
  1186. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 selected as MCO clock
  1187. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1188. @elseif STM32F078xx
  1189. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 selected as MCO clock
  1190. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1191. @elseif STM32F091xC
  1192. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 selected as MCO clock
  1193. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1194. @elseif STM32F098xx
  1195. * @arg @ref RCC_MCO1SOURCE_HSI48 HSI48 selected as MCO clock
  1196. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1197. @elseif STM32F030x6
  1198. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1199. @elseif STM32F030xC
  1200. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1201. @elseif STM32F031x6
  1202. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1203. @elseif STM32F038xx
  1204. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1205. @elseif STM32F070x6
  1206. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1207. @elseif STM32F070xB
  1208. * @arg @ref RCC_MCO1SOURCE_PLLCLK PLLCLK selected as MCO clock
  1209. @endif
  1210. * @arg @ref RCC_MCO1SOURCE_PLLCLK_DIV2 PLLCLK Divided by 2 selected as MCO clock
  1211. * @param __MCODIV__ specifies the MCO clock prescaler.
  1212. * This parameter can be one of the following values:
  1213. * @arg @ref RCC_MCODIV_1 MCO clock source is divided by 1
  1214. * @arg @ref RCC_MCODIV_2 MCO clock source is divided by 2
  1215. * @arg @ref RCC_MCODIV_4 MCO clock source is divided by 4
  1216. * @arg @ref RCC_MCODIV_8 MCO clock source is divided by 8
  1217. * @arg @ref RCC_MCODIV_16 MCO clock source is divided by 16
  1218. * @arg @ref RCC_MCODIV_32 MCO clock source is divided by 32
  1219. * @arg @ref RCC_MCODIV_64 MCO clock source is divided by 64
  1220. * @arg @ref RCC_MCODIV_128 MCO clock source is divided by 128
  1221. */
  1222. #else
  1223. /** @brief Macro to configure the MCO clock.
  1224. * @param __MCOCLKSOURCE__ specifies the MCO clock source.
  1225. * This parameter can be one of the following values:
  1226. * @arg @ref RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock
  1227. * @arg @ref RCC_MCO1SOURCE_SYSCLK System Clock selected as MCO clock
  1228. * @arg @ref RCC_MCO1SOURCE_HSI HSI selected as MCO clock
  1229. * @arg @ref RCC_MCO1SOURCE_HSE HSE selected as MCO clock
  1230. * @arg @ref RCC_MCO1SOURCE_LSI LSI selected as MCO clock
  1231. * @arg @ref RCC_MCO1SOURCE_LSE LSE selected as MCO clock
  1232. * @arg @ref RCC_MCO1SOURCE_HSI14 HSI14 selected as MCO clock
  1233. * @arg @ref RCC_MCO1SOURCE_PLLCLK_DIV2 PLLCLK Divided by 2 selected as MCO clock
  1234. * @param __MCODIV__ specifies the MCO clock prescaler.
  1235. * This parameter can be one of the following values:
  1236. * @arg @ref RCC_MCODIV_1 No division applied on MCO clock source
  1237. */
  1238. #endif
  1239. #if defined(RCC_CFGR_MCOPRE)
  1240. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  1241. MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO | RCC_CFGR_MCOPRE), ((__MCOCLKSOURCE__) | (__MCODIV__)))
  1242. #else
  1243. #define __HAL_RCC_MCO1_CONFIG(__MCOCLKSOURCE__, __MCODIV__) \
  1244. MODIFY_REG(RCC->CFGR, RCC_CFGR_MCO, (__MCOCLKSOURCE__))
  1245. #endif
  1246. /**
  1247. * @}
  1248. */
  1249. /** @defgroup RCC_RTC_Clock_Configuration RCC RTC Clock Configuration
  1250. * @{
  1251. */
  1252. /** @brief Macro to configure the RTC clock (RTCCLK).
  1253. * @note As the RTC clock configuration bits are in the Backup domain and write
  1254. * access is denied to this domain after reset, you have to enable write
  1255. * access using the Power Backup Access macro before to configure
  1256. * the RTC clock source (to be done once after reset).
  1257. * @note Once the RTC clock is configured it cannot be changed unless the
  1258. * Backup domain is reset using @ref __HAL_RCC_BACKUPRESET_FORCE() macro, or by
  1259. * a Power On Reset (POR).
  1260. *
  1261. * @param __RTC_CLKSOURCE__ specifies the RTC clock source.
  1262. * This parameter can be one of the following values:
  1263. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1264. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1265. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1266. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV32 HSE clock divided by 32
  1267. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  1268. * work in STOP and STANDBY modes, and can be used as wakeup source.
  1269. * However, when the LSI clock and HSE clock divided by 32 is used as RTC clock source,
  1270. * the RTC cannot be used in STOP and STANDBY modes.
  1271. * @note The system must always be configured so as to get a PCLK frequency greater than or
  1272. * equal to the RTCCLK frequency for a proper operation of the RTC.
  1273. */
  1274. #define __HAL_RCC_RTC_CONFIG(__RTC_CLKSOURCE__) MODIFY_REG(RCC->BDCR, RCC_BDCR_RTCSEL, (__RTC_CLKSOURCE__))
  1275. /** @brief Macro to get the RTC clock source.
  1276. * @retval The clock source can be one of the following values:
  1277. * @arg @ref RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock
  1278. * @arg @ref RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock
  1279. * @arg @ref RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock
  1280. * @arg @ref RCC_RTCCLKSOURCE_HSE_DIV32 HSE clock divided by 32
  1281. */
  1282. #define __HAL_RCC_GET_RTC_SOURCE() (READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL))
  1283. /** @brief Macro to enable the the RTC clock.
  1284. * @note These macros must be used only after the RTC clock source was selected.
  1285. */
  1286. #define __HAL_RCC_RTC_ENABLE() SET_BIT(RCC->BDCR, RCC_BDCR_RTCEN)
  1287. /** @brief Macro to disable the the RTC clock.
  1288. * @note These macros must be used only after the RTC clock source was selected.
  1289. */
  1290. #define __HAL_RCC_RTC_DISABLE() CLEAR_BIT(RCC->BDCR, RCC_BDCR_RTCEN)
  1291. /** @brief Macro to force the Backup domain reset.
  1292. * @note This function resets the RTC peripheral (including the backup registers)
  1293. * and the RTC clock source selection in RCC_BDCR register.
  1294. */
  1295. #define __HAL_RCC_BACKUPRESET_FORCE() SET_BIT(RCC->BDCR, RCC_BDCR_BDRST)
  1296. /** @brief Macros to release the Backup domain reset.
  1297. */
  1298. #define __HAL_RCC_BACKUPRESET_RELEASE() CLEAR_BIT(RCC->BDCR, RCC_BDCR_BDRST)
  1299. /**
  1300. * @}
  1301. */
  1302. /** @defgroup RCC_Flags_Interrupts_Management Flags Interrupts Management
  1303. * @brief macros to manage the specified RCC Flags and interrupts.
  1304. * @{
  1305. */
  1306. /** @brief Enable RCC interrupt.
  1307. * @param __INTERRUPT__ specifies the RCC interrupt sources to be enabled.
  1308. * This parameter can be any combination of the following values:
  1309. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1310. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1311. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1312. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1313. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1314. * @arg @ref RCC_IT_HSI14RDY HSI14 ready interrupt
  1315. @if STM32F042x6
  1316. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1317. @elseif STM32F048xx
  1318. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1319. @elseif STM32F071xB
  1320. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1321. @elseif STM32F072xB
  1322. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1323. @elseif STM32F078xx
  1324. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1325. @elseif STM32F091xC
  1326. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1327. @elseif STM32F098xx
  1328. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1329. @endif
  1330. */
  1331. #define __HAL_RCC_ENABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS |= (__INTERRUPT__))
  1332. /** @brief Disable RCC interrupt.
  1333. * @param __INTERRUPT__ specifies the RCC interrupt sources to be disabled.
  1334. * This parameter can be any combination of the following values:
  1335. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt
  1336. * @arg @ref RCC_IT_LSERDY LSE ready interrupt
  1337. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt
  1338. * @arg @ref RCC_IT_HSERDY HSE ready interrupt
  1339. * @arg @ref RCC_IT_PLLRDY main PLL ready interrupt
  1340. * @arg @ref RCC_IT_HSI14RDY HSI14 ready interrupt
  1341. @if STM32F042x6
  1342. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1343. @elseif STM32F048xx
  1344. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1345. @elseif STM32F071xB
  1346. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1347. @elseif STM32F072xB
  1348. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1349. @elseif STM32F078xx
  1350. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1351. @elseif STM32F091xC
  1352. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1353. @elseif STM32F098xx
  1354. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1355. @endif
  1356. */
  1357. #define __HAL_RCC_DISABLE_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE1_ADDRESS &= (uint8_t)(~(__INTERRUPT__)))
  1358. /** @brief Clear the RCC's interrupt pending bits.
  1359. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1360. * This parameter can be any combination of the following values:
  1361. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1362. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1363. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1364. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1365. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1366. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1367. * @arg @ref RCC_IT_HSI14RDY HSI14 ready interrupt
  1368. @if STM32F042x6
  1369. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1370. @elseif STM32F048xx
  1371. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1372. @elseif STM32F071xB
  1373. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1374. @elseif STM32F072xB
  1375. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1376. @elseif STM32F078xx
  1377. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1378. @elseif STM32F091xC
  1379. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1380. @elseif STM32F098xx
  1381. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1382. @endif
  1383. */
  1384. #define __HAL_RCC_CLEAR_IT(__INTERRUPT__) (*(__IO uint8_t *) RCC_CIR_BYTE2_ADDRESS = (__INTERRUPT__))
  1385. /** @brief Check the RCC's interrupt has occurred or not.
  1386. * @param __INTERRUPT__ specifies the RCC interrupt source to check.
  1387. * This parameter can be one of the following values:
  1388. * @arg @ref RCC_IT_LSIRDY LSI ready interrupt.
  1389. * @arg @ref RCC_IT_LSERDY LSE ready interrupt.
  1390. * @arg @ref RCC_IT_HSIRDY HSI ready interrupt.
  1391. * @arg @ref RCC_IT_HSERDY HSE ready interrupt.
  1392. * @arg @ref RCC_IT_PLLRDY Main PLL ready interrupt.
  1393. * @arg @ref RCC_IT_CSS Clock Security System interrupt
  1394. * @arg @ref RCC_IT_HSI14RDY HSI14 ready interrupt enable
  1395. @if STM32F042x6
  1396. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1397. @elseif STM32F048xx
  1398. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1399. @elseif STM32F071xB
  1400. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1401. @elseif STM32F072xB
  1402. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1403. @elseif STM32F078xx
  1404. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1405. @elseif STM32F091xC
  1406. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1407. @elseif STM32F098xx
  1408. * @arg @ref RCC_IT_HSI48RDY HSI48 ready interrupt
  1409. @endif
  1410. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  1411. */
  1412. #define __HAL_RCC_GET_IT(__INTERRUPT__) ((RCC->CIR & (__INTERRUPT__)) == (__INTERRUPT__))
  1413. /** @brief Set RMVF bit to clear the reset flags.
  1414. * The reset flags are RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  1415. * RCC_FLAG_OBLRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  1416. */
  1417. #define __HAL_RCC_CLEAR_RESET_FLAGS() (RCC->CSR |= RCC_CSR_RMVF)
  1418. /** @brief Check RCC flag is set or not.
  1419. * @param __FLAG__ specifies the flag to check.
  1420. * This parameter can be one of the following values:
  1421. * @arg @ref RCC_FLAG_HSIRDY HSI oscillator clock ready.
  1422. * @arg @ref RCC_FLAG_HSERDY HSE oscillator clock ready.
  1423. * @arg @ref RCC_FLAG_PLLRDY Main PLL clock ready.
  1424. * @arg @ref RCC_FLAG_HSI14RDY HSI14 oscillator clock ready
  1425. @if STM32F038xx
  1426. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1427. @elseif STM32F042x6
  1428. * @arg @ref RCC_FLAG_HSI48RDY HSI48 oscillator clock ready
  1429. @elseif STM32F048xx
  1430. * @arg @ref RCC_FLAG_HSI48RDY HSI48 oscillator clock ready
  1431. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1432. @elseif STM32F058xx
  1433. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1434. @elseif STM32F071xB
  1435. * @arg @ref RCC_FLAG_HSI48RDY HSI48 oscillator clock ready
  1436. @elseif STM32F072xB
  1437. * @arg @ref RCC_FLAG_HSI48RDY HSI48 oscillator clock ready
  1438. @elseif STM32F078xx
  1439. * @arg @ref RCC_FLAG_HSI48RDY HSI48 oscillator clock ready
  1440. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1441. @elseif STM32F091xC
  1442. * @arg @ref RCC_FLAG_HSI48RDY HSI48 oscillator clock ready
  1443. @elseif STM32F098xx
  1444. * @arg @ref RCC_FLAG_HSI48RDY HSI48 oscillator clock ready
  1445. * @arg @ref RCC_FLAG_V18PWRRST Reset flag of the 1.8 V domain
  1446. @endif
  1447. * @arg @ref RCC_FLAG_LSERDY LSE oscillator clock ready.
  1448. * @arg @ref RCC_FLAG_LSIRDY LSI oscillator clock ready.
  1449. * @arg @ref RCC_FLAG_OBLRST Option Byte Load reset
  1450. * @arg @ref RCC_FLAG_PINRST Pin reset.
  1451. * @arg @ref RCC_FLAG_PORRST POR/PDR reset.
  1452. * @arg @ref RCC_FLAG_SFTRST Software reset.
  1453. * @arg @ref RCC_FLAG_IWDGRST Independent Watchdog reset.
  1454. * @arg @ref RCC_FLAG_WWDGRST Window Watchdog reset.
  1455. * @arg @ref RCC_FLAG_LPWRRST Low Power reset.
  1456. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1457. */
  1458. #define __HAL_RCC_GET_FLAG(__FLAG__) (((((__FLAG__) >> 5U) == CR_REG_INDEX)? RCC->CR : \
  1459. (((__FLAG__) >> 5U) == CR2_REG_INDEX)? RCC->CR2 : \
  1460. (((__FLAG__) >> 5U) == BDCR_REG_INDEX) ? RCC->BDCR : \
  1461. RCC->CSR) & (1U << ((__FLAG__) & RCC_FLAG_MASK)))
  1462. /**
  1463. * @}
  1464. */
  1465. /**
  1466. * @}
  1467. */
  1468. /* Include RCC HAL Extension module */
  1469. #include "stm32f0xx_hal_rcc_ex.h"
  1470. /* Exported functions --------------------------------------------------------*/
  1471. /** @addtogroup RCC_Exported_Functions
  1472. * @{
  1473. */
  1474. /** @addtogroup RCC_Exported_Functions_Group1
  1475. * @{
  1476. */
  1477. /* Initialization and de-initialization functions ******************************/
  1478. void HAL_RCC_DeInit(void);
  1479. HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1480. HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency);
  1481. /**
  1482. * @}
  1483. */
  1484. /** @addtogroup RCC_Exported_Functions_Group2
  1485. * @{
  1486. */
  1487. /* Peripheral Control functions ************************************************/
  1488. void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv);
  1489. void HAL_RCC_EnableCSS(void);
  1490. /* CSS NMI IRQ handler */
  1491. void HAL_RCC_NMI_IRQHandler(void);
  1492. /* User Callbacks in non blocking mode (IT mode) */
  1493. void HAL_RCC_CSSCallback(void);
  1494. void HAL_RCC_DisableCSS(void);
  1495. uint32_t HAL_RCC_GetSysClockFreq(void);
  1496. uint32_t HAL_RCC_GetHCLKFreq(void);
  1497. uint32_t HAL_RCC_GetPCLK1Freq(void);
  1498. void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct);
  1499. void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency);
  1500. /**
  1501. * @}
  1502. */
  1503. /**
  1504. * @}
  1505. */
  1506. /**
  1507. * @}
  1508. */
  1509. /**
  1510. * @}
  1511. */
  1512. #ifdef __cplusplus
  1513. }
  1514. #endif
  1515. #endif /* __STM32F0xx_HAL_RCC_H */
  1516. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/