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.
 
 
 

2102 lines
91 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_rcc_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of RCC HAL Extension 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_EX_H
  37. #define __STM32F0xx_HAL_RCC_EX_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_Macros
  50. * @{
  51. */
  52. #if defined(RCC_HSI48_SUPPORT)
  53. #define IS_RCC_OSCILLATORTYPE(OSCILLATOR) (((OSCILLATOR) == RCC_OSCILLATORTYPE_NONE) || \
  54. (((OSCILLATOR) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  55. (((OSCILLATOR) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  56. (((OSCILLATOR) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  57. (((OSCILLATOR) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) || \
  58. (((OSCILLATOR) & RCC_OSCILLATORTYPE_HSI14) == RCC_OSCILLATORTYPE_HSI14) || \
  59. (((OSCILLATOR) & RCC_OSCILLATORTYPE_HSI48) == RCC_OSCILLATORTYPE_HSI48))
  60. #define IS_RCC_SYSCLKSOURCE(SOURCE) (((SOURCE) == RCC_SYSCLKSOURCE_HSI) || \
  61. ((SOURCE) == RCC_SYSCLKSOURCE_HSE) || \
  62. ((SOURCE) == RCC_SYSCLKSOURCE_PLLCLK) || \
  63. ((SOURCE) == RCC_SYSCLKSOURCE_HSI48))
  64. #define IS_RCC_SYSCLKSOURCE_STATUS(SOURCE) (((SOURCE) == RCC_SYSCLKSOURCE_STATUS_HSI) || \
  65. ((SOURCE) == RCC_SYSCLKSOURCE_STATUS_HSE) || \
  66. ((SOURCE) == RCC_SYSCLKSOURCE_STATUS_PLLCLK) || \
  67. ((SOURCE) == RCC_SYSCLKSOURCE_STATUS_HSI48))
  68. #define IS_RCC_PLLSOURCE(SOURCE) (((SOURCE) == RCC_PLLSOURCE_HSI) || \
  69. ((SOURCE) == RCC_PLLSOURCE_HSI48) || \
  70. ((SOURCE) == RCC_PLLSOURCE_HSE))
  71. #define IS_RCC_HSI48(HSI48) (((HSI48) == RCC_HSI48_OFF) || ((HSI48) == RCC_HSI48_ON))
  72. #else
  73. #define IS_RCC_OSCILLATORTYPE(OSCILLATOR) (((OSCILLATOR) == RCC_OSCILLATORTYPE_NONE) || \
  74. (((OSCILLATOR) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE) || \
  75. (((OSCILLATOR) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) || \
  76. (((OSCILLATOR) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) || \
  77. (((OSCILLATOR) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) || \
  78. (((OSCILLATOR) & RCC_OSCILLATORTYPE_HSI14) == RCC_OSCILLATORTYPE_HSI14))
  79. #define IS_RCC_SYSCLKSOURCE(SOURCE) (((SOURCE) == RCC_SYSCLKSOURCE_HSI) || \
  80. ((SOURCE) == RCC_SYSCLKSOURCE_HSE) || \
  81. ((SOURCE) == RCC_SYSCLKSOURCE_PLLCLK))
  82. #define IS_RCC_SYSCLKSOURCE_STATUS(SOURCE) (((SOURCE) == RCC_SYSCLKSOURCE_STATUS_HSI) || \
  83. ((SOURCE) == RCC_SYSCLKSOURCE_STATUS_HSE) || \
  84. ((SOURCE) == RCC_SYSCLKSOURCE_STATUS_PLLCLK))
  85. #define IS_RCC_PLLSOURCE(SOURCE) (((SOURCE) == RCC_PLLSOURCE_HSI) || \
  86. ((SOURCE) == RCC_PLLSOURCE_HSE))
  87. #endif /* RCC_HSI48_SUPPORT */
  88. #if defined(RCC_CFGR_PLLNODIV) && !defined(RCC_CFGR_MCO_HSI48)
  89. #define IS_RCC_MCO1SOURCE(SOURCE) (((SOURCE) == RCC_MCO1SOURCE_NOCLOCK) || \
  90. ((SOURCE) == RCC_MCO1SOURCE_LSI) || \
  91. ((SOURCE) == RCC_MCO1SOURCE_LSE) || \
  92. ((SOURCE) == RCC_MCO1SOURCE_SYSCLK) || \
  93. ((SOURCE) == RCC_MCO1SOURCE_HSI) || \
  94. ((SOURCE) == RCC_MCO1SOURCE_HSE) || \
  95. ((SOURCE) == RCC_MCO1SOURCE_PLLCLK) || \
  96. ((SOURCE) == RCC_MCO1SOURCE_PLLCLK_DIV2) || \
  97. ((SOURCE) == RCC_MCO1SOURCE_HSI14))
  98. #elif defined(RCC_CFGR_PLLNODIV) && defined(RCC_CFGR_MCO_HSI48)
  99. #define IS_RCC_MCO1SOURCE(SOURCE) (((SOURCE) == RCC_MCO1SOURCE_NOCLOCK) || \
  100. ((SOURCE) == RCC_MCO1SOURCE_LSI) || \
  101. ((SOURCE) == RCC_MCO1SOURCE_LSE) || \
  102. ((SOURCE) == RCC_MCO1SOURCE_SYSCLK) || \
  103. ((SOURCE) == RCC_MCO1SOURCE_HSI) || \
  104. ((SOURCE) == RCC_MCO1SOURCE_HSE) || \
  105. ((SOURCE) == RCC_MCO1SOURCE_PLLCLK) || \
  106. ((SOURCE) == RCC_MCO1SOURCE_PLLCLK_DIV2) || \
  107. ((SOURCE) == RCC_MCO1SOURCE_HSI14) || \
  108. ((SOURCE) == RCC_MCO1SOURCE_HSI48))
  109. #elif !defined(RCC_CFGR_PLLNODIV) && !defined(RCC_CFGR_MCO_HSI48)
  110. #define IS_RCC_MCO1SOURCE(SOURCE) (((SOURCE) == RCC_MCO1SOURCE_NOCLOCK) || \
  111. ((SOURCE) == RCC_MCO1SOURCE_LSI) || \
  112. ((SOURCE) == RCC_MCO1SOURCE_LSE) || \
  113. ((SOURCE) == RCC_MCO1SOURCE_SYSCLK) || \
  114. ((SOURCE) == RCC_MCO1SOURCE_HSI) || \
  115. ((SOURCE) == RCC_MCO1SOURCE_HSE) || \
  116. ((SOURCE) == RCC_MCO1SOURCE_PLLCLK_DIV2) || \
  117. ((SOURCE) == RCC_MCO1SOURCE_HSI14))
  118. #endif /* RCC_CFGR_PLLNODIV && !RCC_CFGR_MCO_HSI48 */
  119. /**
  120. * @}
  121. */
  122. /** @addtogroup RCC_Exported_Constants
  123. * @{
  124. */
  125. #if defined(RCC_HSI48_SUPPORT)
  126. /** @addtogroup RCC_PLL_Clock_Source
  127. * @{
  128. */
  129. #define RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI_PREDIV
  130. #define RCC_PLLSOURCE_HSI48 RCC_CFGR_PLLSRC_HSI48_PREDIV
  131. /**
  132. * @}
  133. */
  134. /** @addtogroup RCC_Interrupt
  135. * @{
  136. */
  137. #define RCC_IT_HSI48 RCC_CIR_HSI48RDYF /*!< HSI48 Ready Interrupt flag */
  138. /**
  139. * @}
  140. */
  141. /** @addtogroup RCC_Flag
  142. * @{
  143. */
  144. #define RCC_FLAG_HSI48RDY ((uint8_t)((CR2_REG_INDEX << 5U) | RCC_CR2_HSI48RDY_BitNumber))
  145. /**
  146. * @}
  147. */
  148. /** @addtogroup RCC_System_Clock_Source
  149. * @{
  150. */
  151. #define RCC_SYSCLKSOURCE_HSI48 RCC_CFGR_SW_HSI48
  152. /**
  153. * @}
  154. */
  155. /** @addtogroup RCC_System_Clock_Source_Status
  156. * @{
  157. */
  158. #define RCC_SYSCLKSOURCE_STATUS_HSI48 RCC_CFGR_SWS_HSI48
  159. /**
  160. * @}
  161. */
  162. #else
  163. /** @addtogroup RCC_PLL_Clock_Source
  164. * @{
  165. */
  166. #if defined(STM32F070xB) || defined(STM32F070x6) || defined(STM32F030xC)
  167. #define RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI_PREDIV
  168. #else
  169. #define RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI_DIV2
  170. #endif
  171. /**
  172. * @}
  173. */
  174. #endif /* RCC_HSI48_SUPPORT */
  175. /** @addtogroup RCC_MCO_Clock_Source
  176. * @{
  177. */
  178. #if defined(RCC_CFGR_PLLNODIV)
  179. #define RCC_MCO1SOURCE_PLLCLK (RCC_CFGR_MCO_PLL | RCC_CFGR_PLLNODIV)
  180. #endif /* RCC_CFGR_PLLNODIV */
  181. #if defined(RCC_CFGR_MCO_HSI48)
  182. #define RCC_MCO1SOURCE_HSI48 RCC_CFGR_MCO_HSI48
  183. #endif /* SRCC_CFGR_MCO_HSI48 */
  184. /**
  185. * @}
  186. */
  187. /**
  188. * @}
  189. */
  190. /**
  191. * @}
  192. */
  193. /** @addtogroup RCCEx
  194. * @{
  195. */
  196. /* Private Constants -------------------------------------------------------------*/
  197. #if defined(CRS)
  198. /** @addtogroup RCCEx_Private_Constants
  199. * @{
  200. */
  201. /* CRS IT Error Mask */
  202. #define RCC_CRS_IT_ERROR_MASK ((uint32_t)(RCC_CRS_IT_TRIMOVF | RCC_CRS_IT_SYNCERR | RCC_CRS_IT_SYNCMISS))
  203. /* CRS Flag Error Mask */
  204. #define RCC_CRS_FLAG_ERROR_MASK ((uint32_t)(RCC_CRS_FLAG_TRIMOVF | RCC_CRS_FLAG_SYNCERR | RCC_CRS_FLAG_SYNCMISS))
  205. /**
  206. * @}
  207. */
  208. #endif /* CRS */
  209. /* Private macro -------------------------------------------------------------*/
  210. /** @defgroup RCCEx_Private_Macros RCCEx Private Macros
  211. * @{
  212. */
  213. #if defined(STM32F030x6) || defined(STM32F030x8) || defined(STM32F031x6) || defined(STM32F038xx)\
  214. || defined(STM32F030xC)
  215. #define IS_RCC_PERIPHCLOCK(SELECTION) ((SELECTION) <= (RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_I2C1 | \
  216. RCC_PERIPHCLK_RTC))
  217. #endif /* STM32F030x6 || STM32F030x8 || STM32F031x6 || STM32F038xx ||
  218. STM32F030xC */
  219. #if defined(STM32F070x6) || defined(STM32F070xB)
  220. #define IS_RCC_PERIPHCLOCK(SELECTION) ((SELECTION) <= (RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_I2C1 | \
  221. RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_USB))
  222. #endif /* STM32F070x6 || STM32F070xB */
  223. #if defined(STM32F042x6) || defined(STM32F048xx)
  224. #define IS_RCC_PERIPHCLOCK(SELECTION) ((SELECTION) <= (RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_I2C1 | \
  225. RCC_PERIPHCLK_CEC | RCC_PERIPHCLK_RTC | \
  226. RCC_PERIPHCLK_USB))
  227. #endif /* STM32F042x6 || STM32F048xx */
  228. #if defined(STM32F051x8) || defined(STM32F058xx)
  229. #define IS_RCC_PERIPHCLOCK(SELECTION) ((SELECTION) <= (RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_I2C1 | \
  230. RCC_PERIPHCLK_CEC | RCC_PERIPHCLK_RTC))
  231. #endif /* STM32F051x8 || STM32F058xx */
  232. #if defined(STM32F071xB)
  233. #define IS_RCC_PERIPHCLOCK(SELECTION) ((SELECTION) <= (RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | \
  234. RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_CEC | \
  235. RCC_PERIPHCLK_RTC))
  236. #endif /* STM32F071xB */
  237. #if defined(STM32F072xB) || defined(STM32F078xx)
  238. #define IS_RCC_PERIPHCLOCK(SELECTION) ((SELECTION) <= (RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | \
  239. RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_CEC | \
  240. RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_USB))
  241. #endif /* STM32F072xB || STM32F078xx */
  242. #if defined(STM32F091xC) || defined(STM32F098xx)
  243. #define IS_RCC_PERIPHCLOCK(SELECTION) ((SELECTION) <= (RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | \
  244. RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_CEC | \
  245. RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_USART3 ))
  246. #endif /* STM32F091xC || STM32F098xx */
  247. #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx)
  248. #define IS_RCC_USBCLKSOURCE(SOURCE) (((SOURCE) == RCC_USBCLKSOURCE_HSI48) || \
  249. ((SOURCE) == RCC_USBCLKSOURCE_PLL))
  250. #endif /* STM32F042x6 || STM32F048xx || STM32F072xB || STM32F078xx */
  251. #if defined(STM32F070x6) || defined(STM32F070xB)
  252. #define IS_RCC_USBCLKSOURCE(SOURCE) (((SOURCE) == RCC_USBCLKSOURCE_NONE) || \
  253. ((SOURCE) == RCC_USBCLKSOURCE_PLL))
  254. #endif /* STM32F070x6 || STM32F070xB */
  255. #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  256. || defined(STM32F091xC) || defined(STM32F098xx)
  257. #define IS_RCC_USART2CLKSOURCE(SOURCE) (((SOURCE) == RCC_USART2CLKSOURCE_PCLK1) || \
  258. ((SOURCE) == RCC_USART2CLKSOURCE_SYSCLK) || \
  259. ((SOURCE) == RCC_USART2CLKSOURCE_LSE) || \
  260. ((SOURCE) == RCC_USART2CLKSOURCE_HSI))
  261. #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
  262. /* STM32F091xC || STM32F098xx */
  263. #if defined(STM32F091xC) || defined(STM32F098xx)
  264. #define IS_RCC_USART3CLKSOURCE(SOURCE) (((SOURCE) == RCC_USART3CLKSOURCE_PCLK1) || \
  265. ((SOURCE) == RCC_USART3CLKSOURCE_SYSCLK) || \
  266. ((SOURCE) == RCC_USART3CLKSOURCE_LSE) || \
  267. ((SOURCE) == RCC_USART3CLKSOURCE_HSI))
  268. #endif /* STM32F091xC || STM32F098xx */
  269. #if defined(STM32F042x6) || defined(STM32F048xx)\
  270. || defined(STM32F051x8) || defined(STM32F058xx)\
  271. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  272. || defined(STM32F091xC) || defined(STM32F098xx)
  273. #define IS_RCC_CECCLKSOURCE(SOURCE) (((SOURCE) == RCC_CECCLKSOURCE_HSI) || \
  274. ((SOURCE) == RCC_CECCLKSOURCE_LSE))
  275. #endif /* STM32F042x6 || STM32F048xx || */
  276. /* STM32F051x8 || STM32F058xx || */
  277. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  278. /* STM32F091xC || STM32F098xx */
  279. #if defined(RCC_CFGR_MCOPRE)
  280. #define IS_RCC_MCODIV(DIV) (((DIV) == RCC_MCODIV_1) || ((DIV) == RCC_MCODIV_2) || \
  281. ((DIV) == RCC_MCODIV_4) || ((DIV) == RCC_MCODIV_8) || \
  282. ((DIV) == RCC_MCODIV_16) || ((DIV) == RCC_MCODIV_32) || \
  283. ((DIV) == RCC_MCODIV_64) || ((DIV) == RCC_MCODIV_128))
  284. #else
  285. #define IS_RCC_MCODIV(DIV) (((DIV) == RCC_MCODIV_1))
  286. #endif /* RCC_CFGR_MCOPRE */
  287. #define IS_RCC_LSE_DRIVE(__DRIVE__) (((__DRIVE__) == RCC_LSEDRIVE_LOW) || \
  288. ((__DRIVE__) == RCC_LSEDRIVE_MEDIUMLOW) || \
  289. ((__DRIVE__) == RCC_LSEDRIVE_MEDIUMHIGH) || \
  290. ((__DRIVE__) == RCC_LSEDRIVE_HIGH))
  291. #if defined(CRS)
  292. #define IS_RCC_CRS_SYNC_SOURCE(_SOURCE_) (((_SOURCE_) == RCC_CRS_SYNC_SOURCE_GPIO) || \
  293. ((_SOURCE_) == RCC_CRS_SYNC_SOURCE_LSE) || \
  294. ((_SOURCE_) == RCC_CRS_SYNC_SOURCE_USB))
  295. #define IS_RCC_CRS_SYNC_DIV(_DIV_) (((_DIV_) == RCC_CRS_SYNC_DIV1) || ((_DIV_) == RCC_CRS_SYNC_DIV2) || \
  296. ((_DIV_) == RCC_CRS_SYNC_DIV4) || ((_DIV_) == RCC_CRS_SYNC_DIV8) || \
  297. ((_DIV_) == RCC_CRS_SYNC_DIV16) || ((_DIV_) == RCC_CRS_SYNC_DIV32) || \
  298. ((_DIV_) == RCC_CRS_SYNC_DIV64) || ((_DIV_) == RCC_CRS_SYNC_DIV128))
  299. #define IS_RCC_CRS_SYNC_POLARITY(_POLARITY_) (((_POLARITY_) == RCC_CRS_SYNC_POLARITY_RISING) || \
  300. ((_POLARITY_) == RCC_CRS_SYNC_POLARITY_FALLING))
  301. #define IS_RCC_CRS_RELOADVALUE(_VALUE_) (((_VALUE_) <= 0xFFFFU))
  302. #define IS_RCC_CRS_ERRORLIMIT(_VALUE_) (((_VALUE_) <= 0xFFU))
  303. #define IS_RCC_CRS_HSI48CALIBRATION(_VALUE_) (((_VALUE_) <= 0x3FU))
  304. #define IS_RCC_CRS_FREQERRORDIR(_DIR_) (((_DIR_) == RCC_CRS_FREQERRORDIR_UP) || \
  305. ((_DIR_) == RCC_CRS_FREQERRORDIR_DOWN))
  306. #endif /* CRS */
  307. /**
  308. * @}
  309. */
  310. /* Exported types ------------------------------------------------------------*/
  311. /** @defgroup RCCEx_Exported_Types RCCEx Exported Types
  312. * @{
  313. */
  314. /**
  315. * @brief RCC extended clocks structure definition
  316. */
  317. #if defined(STM32F030x6) || defined(STM32F030x8) || defined(STM32F031x6) || defined(STM32F038xx)\
  318. || defined(STM32F030xC)
  319. typedef struct
  320. {
  321. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  322. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  323. uint32_t RTCClockSelection; /*!< Specifies RTC Clock Prescalers Selection
  324. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  325. uint32_t Usart1ClockSelection; /*!< USART1 clock source
  326. This parameter can be a value of @ref RCC_USART1_Clock_Source */
  327. uint32_t I2c1ClockSelection; /*!< I2C1 clock source
  328. This parameter can be a value of @ref RCC_I2C1_Clock_Source */
  329. }RCC_PeriphCLKInitTypeDef;
  330. #endif /* STM32F030x6 || STM32F030x8 || STM32F031x6 || STM32F038xx ||
  331. STM32F030xC */
  332. #if defined(STM32F070x6) || defined(STM32F070xB)
  333. typedef struct
  334. {
  335. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  336. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  337. uint32_t RTCClockSelection; /*!< Specifies RTC Clock Prescalers Selection
  338. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  339. uint32_t Usart1ClockSelection; /*!< USART1 clock source
  340. This parameter can be a value of @ref RCC_USART1_Clock_Source */
  341. uint32_t I2c1ClockSelection; /*!< I2C1 clock source
  342. This parameter can be a value of @ref RCC_I2C1_Clock_Source */
  343. uint32_t UsbClockSelection; /*!< USB clock source
  344. This parameter can be a value of @ref RCCEx_USB_Clock_Source */
  345. }RCC_PeriphCLKInitTypeDef;
  346. #endif /* STM32F070x6 || STM32F070xB */
  347. #if defined(STM32F042x6) || defined(STM32F048xx)
  348. typedef struct
  349. {
  350. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  351. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  352. uint32_t RTCClockSelection; /*!< Specifies RTC Clock Prescalers Selection
  353. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  354. uint32_t Usart1ClockSelection; /*!< USART1 clock source
  355. This parameter can be a value of @ref RCC_USART1_Clock_Source */
  356. uint32_t I2c1ClockSelection; /*!< I2C1 clock source
  357. This parameter can be a value of @ref RCC_I2C1_Clock_Source */
  358. uint32_t CecClockSelection; /*!< HDMI CEC clock source
  359. This parameter can be a value of @ref RCCEx_CEC_Clock_Source */
  360. uint32_t UsbClockSelection; /*!< USB clock source
  361. This parameter can be a value of @ref RCCEx_USB_Clock_Source */
  362. }RCC_PeriphCLKInitTypeDef;
  363. #endif /* STM32F042x6 || STM32F048xx */
  364. #if defined(STM32F051x8) || defined(STM32F058xx)
  365. typedef struct
  366. {
  367. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  368. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  369. uint32_t RTCClockSelection; /*!< Specifies RTC Clock Prescalers Selection
  370. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  371. uint32_t Usart1ClockSelection; /*!< USART1 clock source
  372. This parameter can be a value of @ref RCC_USART1_Clock_Source */
  373. uint32_t I2c1ClockSelection; /*!< I2C1 clock source
  374. This parameter can be a value of @ref RCC_I2C1_Clock_Source */
  375. uint32_t CecClockSelection; /*!< HDMI CEC clock source
  376. This parameter can be a value of @ref RCCEx_CEC_Clock_Source */
  377. }RCC_PeriphCLKInitTypeDef;
  378. #endif /* STM32F051x8 || STM32F058xx */
  379. #if defined(STM32F071xB)
  380. typedef struct
  381. {
  382. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  383. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  384. uint32_t RTCClockSelection; /*!< Specifies RTC Clock Prescalers Selection
  385. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  386. uint32_t Usart1ClockSelection; /*!< USART1 clock source
  387. This parameter can be a value of @ref RCC_USART1_Clock_Source */
  388. uint32_t Usart2ClockSelection; /*!< USART2 clock source
  389. This parameter can be a value of @ref RCCEx_USART2_Clock_Source */
  390. uint32_t I2c1ClockSelection; /*!< I2C1 clock source
  391. This parameter can be a value of @ref RCC_I2C1_Clock_Source */
  392. uint32_t CecClockSelection; /*!< HDMI CEC clock source
  393. This parameter can be a value of @ref RCCEx_CEC_Clock_Source */
  394. }RCC_PeriphCLKInitTypeDef;
  395. #endif /* STM32F071xB */
  396. #if defined(STM32F072xB) || defined(STM32F078xx)
  397. typedef struct
  398. {
  399. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  400. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  401. uint32_t RTCClockSelection; /*!< Specifies RTC Clock Prescalers Selection
  402. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  403. uint32_t Usart1ClockSelection; /*!< USART1 clock source
  404. This parameter can be a value of @ref RCC_USART1_Clock_Source */
  405. uint32_t Usart2ClockSelection; /*!< USART2 clock source
  406. This parameter can be a value of @ref RCCEx_USART2_Clock_Source */
  407. uint32_t I2c1ClockSelection; /*!< I2C1 clock source
  408. This parameter can be a value of @ref RCC_I2C1_Clock_Source */
  409. uint32_t CecClockSelection; /*!< HDMI CEC clock source
  410. This parameter can be a value of @ref RCCEx_CEC_Clock_Source */
  411. uint32_t UsbClockSelection; /*!< USB clock source
  412. This parameter can be a value of @ref RCCEx_USB_Clock_Source */
  413. }RCC_PeriphCLKInitTypeDef;
  414. #endif /* STM32F072xB || STM32F078xx */
  415. #if defined(STM32F091xC) || defined(STM32F098xx)
  416. typedef struct
  417. {
  418. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  419. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  420. uint32_t RTCClockSelection; /*!< Specifies RTC Clock Prescalers Selection
  421. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  422. uint32_t Usart1ClockSelection; /*!< USART1 clock source
  423. This parameter can be a value of @ref RCC_USART1_Clock_Source */
  424. uint32_t Usart2ClockSelection; /*!< USART2 clock source
  425. This parameter can be a value of @ref RCCEx_USART2_Clock_Source */
  426. uint32_t Usart3ClockSelection; /*!< USART3 clock source
  427. This parameter can be a value of @ref RCCEx_USART3_Clock_Source */
  428. uint32_t I2c1ClockSelection; /*!< I2C1 clock source
  429. This parameter can be a value of @ref RCC_I2C1_Clock_Source */
  430. uint32_t CecClockSelection; /*!< HDMI CEC clock source
  431. This parameter can be a value of @ref RCCEx_CEC_Clock_Source */
  432. }RCC_PeriphCLKInitTypeDef;
  433. #endif /* STM32F091xC || STM32F098xx */
  434. #if defined(CRS)
  435. /**
  436. * @brief RCC_CRS Init structure definition
  437. */
  438. typedef struct
  439. {
  440. uint32_t Prescaler; /*!< Specifies the division factor of the SYNC signal.
  441. This parameter can be a value of @ref RCCEx_CRS_SynchroDivider */
  442. uint32_t Source; /*!< Specifies the SYNC signal source.
  443. This parameter can be a value of @ref RCCEx_CRS_SynchroSource */
  444. uint32_t Polarity; /*!< Specifies the input polarity for the SYNC signal source.
  445. This parameter can be a value of @ref RCCEx_CRS_SynchroPolarity */
  446. uint32_t ReloadValue; /*!< Specifies the value to be loaded in the frequency error counter with each SYNC event.
  447. It can be calculated in using macro @ref __HAL_RCC_CRS_RELOADVALUE_CALCULATE(__FTARGET__, __FSYNC__)
  448. This parameter must be a number between 0 and 0xFFFF or a value of @ref RCCEx_CRS_ReloadValueDefault .*/
  449. uint32_t ErrorLimitValue; /*!< Specifies the value to be used to evaluate the captured frequency error value.
  450. This parameter must be a number between 0 and 0xFF or a value of @ref RCCEx_CRS_ErrorLimitDefault */
  451. uint32_t HSI48CalibrationValue; /*!< Specifies a user-programmable trimming value to the HSI48 oscillator.
  452. This parameter must be a number between 0 and 0x3F or a value of @ref RCCEx_CRS_HSI48CalibrationDefault */
  453. }RCC_CRSInitTypeDef;
  454. /**
  455. * @brief RCC_CRS Synchronization structure definition
  456. */
  457. typedef struct
  458. {
  459. uint32_t ReloadValue; /*!< Specifies the value loaded in the Counter reload value.
  460. This parameter must be a number between 0 and 0xFFFFU */
  461. uint32_t HSI48CalibrationValue; /*!< Specifies value loaded in HSI48 oscillator smooth trimming.
  462. This parameter must be a number between 0 and 0x3FU */
  463. uint32_t FreqErrorCapture; /*!< Specifies the value loaded in the .FECAP, the frequency error counter
  464. value latched in the time of the last SYNC event.
  465. This parameter must be a number between 0 and 0xFFFFU */
  466. uint32_t FreqErrorDirection; /*!< Specifies the value loaded in the .FEDIR, the counting direction of the
  467. frequency error counter latched in the time of the last SYNC event.
  468. It shows whether the actual frequency is below or above the target.
  469. This parameter must be a value of @ref RCCEx_CRS_FreqErrorDirection*/
  470. }RCC_CRSSynchroInfoTypeDef;
  471. #endif /* CRS */
  472. /**
  473. * @}
  474. */
  475. /* Exported constants --------------------------------------------------------*/
  476. /** @defgroup RCCEx_Exported_Constants RCCEx Exported Constants
  477. * @{
  478. */
  479. /** @defgroup RCCEx_Periph_Clock_Selection RCCEx Periph Clock Selection
  480. * @{
  481. */
  482. #if defined(STM32F030x6) || defined(STM32F030x8) || defined(STM32F031x6) || defined(STM32F038xx)\
  483. || defined(STM32F030xC)
  484. #define RCC_PERIPHCLK_USART1 (0x00000001U)
  485. #define RCC_PERIPHCLK_I2C1 (0x00000020U)
  486. #define RCC_PERIPHCLK_RTC (0x00010000U)
  487. #endif /* STM32F030x6 || STM32F030x8 || STM32F031x6 || STM32F038xx ||
  488. STM32F030xC */
  489. #if defined(STM32F070x6) || defined(STM32F070xB)
  490. #define RCC_PERIPHCLK_USART1 (0x00000001U)
  491. #define RCC_PERIPHCLK_I2C1 (0x00000020U)
  492. #define RCC_PERIPHCLK_RTC (0x00010000U)
  493. #define RCC_PERIPHCLK_USB (0x00020000U)
  494. #endif /* STM32F070x6 || STM32F070xB */
  495. #if defined(STM32F042x6) || defined(STM32F048xx)
  496. #define RCC_PERIPHCLK_USART1 (0x00000001U)
  497. #define RCC_PERIPHCLK_I2C1 (0x00000020U)
  498. #define RCC_PERIPHCLK_CEC (0x00000400U)
  499. #define RCC_PERIPHCLK_RTC (0x00010000U)
  500. #define RCC_PERIPHCLK_USB (0x00020000U)
  501. #endif /* STM32F042x6 || STM32F048xx */
  502. #if defined(STM32F051x8) || defined(STM32F058xx)
  503. #define RCC_PERIPHCLK_USART1 (0x00000001U)
  504. #define RCC_PERIPHCLK_I2C1 (0x00000020U)
  505. #define RCC_PERIPHCLK_CEC (0x00000400U)
  506. #define RCC_PERIPHCLK_RTC (0x00010000U)
  507. #endif /* STM32F051x8 || STM32F058xx */
  508. #if defined(STM32F071xB)
  509. #define RCC_PERIPHCLK_USART1 (0x00000001U)
  510. #define RCC_PERIPHCLK_USART2 (0x00000002U)
  511. #define RCC_PERIPHCLK_I2C1 (0x00000020U)
  512. #define RCC_PERIPHCLK_CEC (0x00000400U)
  513. #define RCC_PERIPHCLK_RTC (0x00010000U)
  514. #endif /* STM32F071xB */
  515. #if defined(STM32F072xB) || defined(STM32F078xx)
  516. #define RCC_PERIPHCLK_USART1 (0x00000001U)
  517. #define RCC_PERIPHCLK_USART2 (0x00000002U)
  518. #define RCC_PERIPHCLK_I2C1 (0x00000020U)
  519. #define RCC_PERIPHCLK_CEC (0x00000400U)
  520. #define RCC_PERIPHCLK_RTC (0x00010000U)
  521. #define RCC_PERIPHCLK_USB (0x00020000U)
  522. #endif /* STM32F072xB || STM32F078xx */
  523. #if defined(STM32F091xC) || defined(STM32F098xx)
  524. #define RCC_PERIPHCLK_USART1 (0x00000001U)
  525. #define RCC_PERIPHCLK_USART2 (0x00000002U)
  526. #define RCC_PERIPHCLK_I2C1 (0x00000020U)
  527. #define RCC_PERIPHCLK_CEC (0x00000400U)
  528. #define RCC_PERIPHCLK_RTC (0x00010000U)
  529. #define RCC_PERIPHCLK_USART3 (0x00040000U)
  530. #endif /* STM32F091xC || STM32F098xx */
  531. /**
  532. * @}
  533. */
  534. #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx)
  535. /** @defgroup RCCEx_USB_Clock_Source RCCEx USB Clock Source
  536. * @{
  537. */
  538. #define RCC_USBCLKSOURCE_HSI48 RCC_CFGR3_USBSW_HSI48 /*!< HSI48 clock selected as USB clock source */
  539. #define RCC_USBCLKSOURCE_PLL RCC_CFGR3_USBSW_PLLCLK /*!< PLL clock (PLLCLK) selected as USB clock */
  540. /**
  541. * @}
  542. */
  543. #endif /* STM32F042x6 || STM32F048xx || STM32F072xB || STM32F078xx */
  544. #if defined(STM32F070x6) || defined(STM32F070xB)
  545. /** @defgroup RCCEx_USB_Clock_Source RCCEx USB Clock Source
  546. * @{
  547. */
  548. #define RCC_USBCLKSOURCE_NONE (0x00000000U) /*!< USB clock disabled */
  549. #define RCC_USBCLKSOURCE_PLL RCC_CFGR3_USBSW_PLLCLK /*!< PLL clock (PLLCLK) selected as USB clock */
  550. /**
  551. * @}
  552. */
  553. #endif /* STM32F070x6 || STM32F070xB */
  554. #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  555. || defined(STM32F091xC) || defined(STM32F098xx)
  556. /** @defgroup RCCEx_USART2_Clock_Source RCCEx USART2 Clock Source
  557. * @{
  558. */
  559. #define RCC_USART2CLKSOURCE_PCLK1 RCC_CFGR3_USART2SW_PCLK
  560. #define RCC_USART2CLKSOURCE_SYSCLK RCC_CFGR3_USART2SW_SYSCLK
  561. #define RCC_USART2CLKSOURCE_LSE RCC_CFGR3_USART2SW_LSE
  562. #define RCC_USART2CLKSOURCE_HSI RCC_CFGR3_USART2SW_HSI
  563. /**
  564. * @}
  565. */
  566. #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
  567. /* STM32F091xC || STM32F098xx */
  568. #if defined(STM32F091xC) || defined(STM32F098xx)
  569. /** @defgroup RCCEx_USART3_Clock_Source RCCEx USART3 Clock Source
  570. * @{
  571. */
  572. #define RCC_USART3CLKSOURCE_PCLK1 RCC_CFGR3_USART3SW_PCLK
  573. #define RCC_USART3CLKSOURCE_SYSCLK RCC_CFGR3_USART3SW_SYSCLK
  574. #define RCC_USART3CLKSOURCE_LSE RCC_CFGR3_USART3SW_LSE
  575. #define RCC_USART3CLKSOURCE_HSI RCC_CFGR3_USART3SW_HSI
  576. /**
  577. * @}
  578. */
  579. #endif /* STM32F091xC || STM32F098xx */
  580. #if defined(STM32F042x6) || defined(STM32F048xx)\
  581. || defined(STM32F051x8) || defined(STM32F058xx)\
  582. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  583. || defined(STM32F091xC) || defined(STM32F098xx)
  584. /** @defgroup RCCEx_CEC_Clock_Source RCCEx CEC Clock Source
  585. * @{
  586. */
  587. #define RCC_CECCLKSOURCE_HSI RCC_CFGR3_CECSW_HSI_DIV244
  588. #define RCC_CECCLKSOURCE_LSE RCC_CFGR3_CECSW_LSE
  589. /**
  590. * @}
  591. */
  592. #endif /* STM32F042x6 || STM32F048xx || */
  593. /* STM32F051x8 || STM32F058xx || */
  594. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  595. /* STM32F091xC || STM32F098xx */
  596. /** @defgroup RCCEx_MCOx_Clock_Prescaler RCCEx MCOx Clock Prescaler
  597. * @{
  598. */
  599. #if defined(RCC_CFGR_MCOPRE)
  600. #define RCC_MCODIV_1 (0x00000000U)
  601. #define RCC_MCODIV_2 (0x10000000U)
  602. #define RCC_MCODIV_4 (0x20000000U)
  603. #define RCC_MCODIV_8 (0x30000000U)
  604. #define RCC_MCODIV_16 (0x40000000U)
  605. #define RCC_MCODIV_32 (0x50000000U)
  606. #define RCC_MCODIV_64 (0x60000000U)
  607. #define RCC_MCODIV_128 (0x70000000U)
  608. #else
  609. #define RCC_MCODIV_1 (0x00000000U)
  610. #endif /* RCC_CFGR_MCOPRE */
  611. /**
  612. * @}
  613. */
  614. /** @defgroup RCCEx_LSEDrive_Configuration RCC LSE Drive Configuration
  615. * @{
  616. */
  617. #define RCC_LSEDRIVE_LOW (0x00000000U) /*!< Xtal mode lower driving capability */
  618. #define RCC_LSEDRIVE_MEDIUMLOW RCC_BDCR_LSEDRV_1 /*!< Xtal mode medium low driving capability */
  619. #define RCC_LSEDRIVE_MEDIUMHIGH RCC_BDCR_LSEDRV_0 /*!< Xtal mode medium high driving capability */
  620. #define RCC_LSEDRIVE_HIGH RCC_BDCR_LSEDRV /*!< Xtal mode higher driving capability */
  621. /**
  622. * @}
  623. */
  624. #if defined(CRS)
  625. /** @defgroup RCCEx_CRS_Status RCCEx CRS Status
  626. * @{
  627. */
  628. #define RCC_CRS_NONE (0x00000000U)
  629. #define RCC_CRS_TIMEOUT (0x00000001U)
  630. #define RCC_CRS_SYNCOK (0x00000002U)
  631. #define RCC_CRS_SYNCWARN (0x00000004U)
  632. #define RCC_CRS_SYNCERR (0x00000008U)
  633. #define RCC_CRS_SYNCMISS (0x00000010U)
  634. #define RCC_CRS_TRIMOVF (0x00000020U)
  635. /**
  636. * @}
  637. */
  638. /** @defgroup RCCEx_CRS_SynchroSource RCCEx CRS Synchronization Source
  639. * @{
  640. */
  641. #define RCC_CRS_SYNC_SOURCE_GPIO (0x00000000U) /*!< Synchro Signal source GPIO */
  642. #define RCC_CRS_SYNC_SOURCE_LSE CRS_CFGR_SYNCSRC_0 /*!< Synchro Signal source LSE */
  643. #define RCC_CRS_SYNC_SOURCE_USB CRS_CFGR_SYNCSRC_1 /*!< Synchro Signal source USB SOF (default)*/
  644. /**
  645. * @}
  646. */
  647. /** @defgroup RCCEx_CRS_SynchroDivider RCCEx CRS Synchronization Divider
  648. * @{
  649. */
  650. #define RCC_CRS_SYNC_DIV1 (0x00000000U) /*!< Synchro Signal not divided (default) */
  651. #define RCC_CRS_SYNC_DIV2 CRS_CFGR_SYNCDIV_0 /*!< Synchro Signal divided by 2 */
  652. #define RCC_CRS_SYNC_DIV4 CRS_CFGR_SYNCDIV_1 /*!< Synchro Signal divided by 4 */
  653. #define RCC_CRS_SYNC_DIV8 (CRS_CFGR_SYNCDIV_1 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 8 */
  654. #define RCC_CRS_SYNC_DIV16 CRS_CFGR_SYNCDIV_2 /*!< Synchro Signal divided by 16 */
  655. #define RCC_CRS_SYNC_DIV32 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 32 */
  656. #define RCC_CRS_SYNC_DIV64 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_1) /*!< Synchro Signal divided by 64 */
  657. #define RCC_CRS_SYNC_DIV128 CRS_CFGR_SYNCDIV /*!< Synchro Signal divided by 128 */
  658. /**
  659. * @}
  660. */
  661. /** @defgroup RCCEx_CRS_SynchroPolarity RCCEx CRS Synchronization Polarity
  662. * @{
  663. */
  664. #define RCC_CRS_SYNC_POLARITY_RISING (0x00000000U) /*!< Synchro Active on rising edge (default) */
  665. #define RCC_CRS_SYNC_POLARITY_FALLING CRS_CFGR_SYNCPOL /*!< Synchro Active on falling edge */
  666. /**
  667. * @}
  668. */
  669. /** @defgroup RCCEx_CRS_ReloadValueDefault RCCEx CRS Default Reload Value
  670. * @{
  671. */
  672. #define RCC_CRS_RELOADVALUE_DEFAULT (0x0000BB7FU) /*!< The reset value of the RELOAD field corresponds
  673. to a target frequency of 48 MHz and a synchronization signal frequency of 1 kHz (SOF signal from USB). */
  674. /**
  675. * @}
  676. */
  677. /** @defgroup RCCEx_CRS_ErrorLimitDefault RCCEx CRS Default Error Limit Value
  678. * @{
  679. */
  680. #define RCC_CRS_ERRORLIMIT_DEFAULT (0x00000022U) /*!< Default Frequency error limit */
  681. /**
  682. * @}
  683. */
  684. /** @defgroup RCCEx_CRS_HSI48CalibrationDefault RCCEx CRS Default HSI48 Calibration vakye
  685. * @{
  686. */
  687. #define RCC_CRS_HSI48CALIBRATION_DEFAULT (0x00000020U) /*!< The default value is 32, which corresponds to the middle of the trimming interval.
  688. The trimming step is around 67 kHz between two consecutive TRIM steps. A higher TRIM value
  689. corresponds to a higher output frequency */
  690. /**
  691. * @}
  692. */
  693. /** @defgroup RCCEx_CRS_FreqErrorDirection RCCEx CRS Frequency Error Direction
  694. * @{
  695. */
  696. #define RCC_CRS_FREQERRORDIR_UP (0x00000000U) /*!< Upcounting direction, the actual frequency is above the target */
  697. #define RCC_CRS_FREQERRORDIR_DOWN ((uint32_t)CRS_ISR_FEDIR) /*!< Downcounting direction, the actual frequency is below the target */
  698. /**
  699. * @}
  700. */
  701. /** @defgroup RCCEx_CRS_Interrupt_Sources RCCEx CRS Interrupt Sources
  702. * @{
  703. */
  704. #define RCC_CRS_IT_SYNCOK CRS_CR_SYNCOKIE /*!< SYNC event OK */
  705. #define RCC_CRS_IT_SYNCWARN CRS_CR_SYNCWARNIE /*!< SYNC warning */
  706. #define RCC_CRS_IT_ERR CRS_CR_ERRIE /*!< Error */
  707. #define RCC_CRS_IT_ESYNC CRS_CR_ESYNCIE /*!< Expected SYNC */
  708. #define RCC_CRS_IT_SYNCERR CRS_CR_ERRIE /*!< SYNC error */
  709. #define RCC_CRS_IT_SYNCMISS CRS_CR_ERRIE /*!< SYNC missed */
  710. #define RCC_CRS_IT_TRIMOVF CRS_CR_ERRIE /*!< Trimming overflow or underflow */
  711. /**
  712. * @}
  713. */
  714. /** @defgroup RCCEx_CRS_Flags RCCEx CRS Flags
  715. * @{
  716. */
  717. #define RCC_CRS_FLAG_SYNCOK CRS_ISR_SYNCOKF /*!< SYNC event OK flag */
  718. #define RCC_CRS_FLAG_SYNCWARN CRS_ISR_SYNCWARNF /*!< SYNC warning flag */
  719. #define RCC_CRS_FLAG_ERR CRS_ISR_ERRF /*!< Error flag */
  720. #define RCC_CRS_FLAG_ESYNC CRS_ISR_ESYNCF /*!< Expected SYNC flag */
  721. #define RCC_CRS_FLAG_SYNCERR CRS_ISR_SYNCERR /*!< SYNC error */
  722. #define RCC_CRS_FLAG_SYNCMISS CRS_ISR_SYNCMISS /*!< SYNC missed*/
  723. #define RCC_CRS_FLAG_TRIMOVF CRS_ISR_TRIMOVF /*!< Trimming overflow or underflow */
  724. /**
  725. * @}
  726. */
  727. #endif /* CRS */
  728. /**
  729. * @}
  730. */
  731. /* Exported macros ------------------------------------------------------------*/
  732. /** @defgroup RCCEx_Exported_Macros RCCEx Exported Macros
  733. * @{
  734. */
  735. /** @defgroup RCCEx_Peripheral_Clock_Enable_Disable RCCEx_Peripheral_Clock_Enable_Disable
  736. * @brief Enables or disables the AHB1 peripheral clock.
  737. * @note After reset, the peripheral clock (used for registers read/write access)
  738. * is disabled and the application software has to enable this clock before
  739. * using it.
  740. * @{
  741. */
  742. #if defined(GPIOD)
  743. #define __HAL_RCC_GPIOD_CLK_ENABLE() do { \
  744. __IO uint32_t tmpreg; \
  745. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIODEN);\
  746. /* Delay after an RCC peripheral clock enabling */ \
  747. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIODEN);\
  748. UNUSED(tmpreg); \
  749. } while(0U)
  750. #define __HAL_RCC_GPIOD_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIODEN))
  751. #endif /* GPIOD */
  752. #if defined(GPIOE)
  753. #define __HAL_RCC_GPIOE_CLK_ENABLE() do { \
  754. __IO uint32_t tmpreg; \
  755. SET_BIT(RCC->AHBENR, RCC_AHBENR_GPIOEEN);\
  756. /* Delay after an RCC peripheral clock enabling */ \
  757. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_GPIOEEN);\
  758. UNUSED(tmpreg); \
  759. } while(0U)
  760. #define __HAL_RCC_GPIOE_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_GPIOEEN))
  761. #endif /* GPIOE */
  762. #if defined(STM32F042x6) || defined(STM32F048xx)\
  763. || defined(STM32F051x8) || defined(STM32F058xx)\
  764. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  765. || defined(STM32F091xC) || defined(STM32F098xx)
  766. #define __HAL_RCC_TSC_CLK_ENABLE() do { \
  767. __IO uint32_t tmpreg; \
  768. SET_BIT(RCC->AHBENR, RCC_AHBENR_TSCEN);\
  769. /* Delay after an RCC peripheral clock enabling */ \
  770. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_TSCEN);\
  771. UNUSED(tmpreg); \
  772. } while(0U)
  773. #define __HAL_RCC_TSC_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_TSCEN))
  774. #endif /* STM32F042x6 || STM32F048xx || */
  775. /* STM32F051x8 || STM32F058xx || */
  776. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  777. /* STM32F091xC || STM32F098xx */
  778. #if defined(STM32F091xC) || defined(STM32F098xx)
  779. #define __HAL_RCC_DMA2_CLK_ENABLE() do { \
  780. __IO uint32_t tmpreg; \
  781. SET_BIT(RCC->AHBENR, RCC_AHBENR_DMA2EN);\
  782. /* Delay after an RCC peripheral clock enabling */ \
  783. tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_DMA2EN);\
  784. UNUSED(tmpreg); \
  785. } while(0U)
  786. #define __HAL_RCC_DMA2_CLK_DISABLE() (RCC->AHBENR &= ~(RCC_AHBENR_DMA2EN))
  787. #endif /* STM32F091xC || STM32F098xx */
  788. /** @brief Enable or disable the Low Speed APB (APB1) peripheral clock.
  789. * @note After reset, the peripheral clock (used for registers read/write access)
  790. * is disabled and the application software has to enable this clock before
  791. * using it.
  792. */
  793. #if defined(STM32F030x8)\
  794. || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6)\
  795. || defined(STM32F051x8) || defined(STM32F058xx)\
  796. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  797. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  798. #define __HAL_RCC_USART2_CLK_ENABLE() do { \
  799. __IO uint32_t tmpreg; \
  800. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  801. /* Delay after an RCC peripheral clock enabling */ \
  802. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART2EN);\
  803. UNUSED(tmpreg); \
  804. } while(0U)
  805. #define __HAL_RCC_USART2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART2EN))
  806. #endif /* STM32F030x8 || STM32F042x6 || STM32F048xx || */
  807. /* STM32F051x8 || STM32F058xx || STM32F070x6 || */
  808. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  809. /* STM32F091xC || STM32F098xx || STM32F030xC */
  810. #if defined(STM32F030x8)\
  811. || defined(STM32F042x6) || defined(STM32F048xx)\
  812. || defined(STM32F051x8) || defined(STM32F058xx)\
  813. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  814. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  815. #define __HAL_RCC_SPI2_CLK_ENABLE() do { \
  816. __IO uint32_t tmpreg; \
  817. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI2EN);\
  818. /* Delay after an RCC peripheral clock enabling */ \
  819. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI2EN);\
  820. UNUSED(tmpreg); \
  821. } while(0U)
  822. #define __HAL_RCC_SPI2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_SPI2EN))
  823. #endif /* STM32F030x8 || STM32F042x6 || STM32F048xx || */
  824. /* STM32F051x8 || STM32F058xx || */
  825. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  826. /* STM32F091xC || STM32F098xx || STM32F030xC */
  827. #if defined(STM32F031x6) || defined(STM32F038xx)\
  828. || defined(STM32F042x6) || defined(STM32F048xx)\
  829. || defined(STM32F051x8) || defined(STM32F058xx)\
  830. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  831. || defined(STM32F091xC) || defined(STM32F098xx)
  832. #define __HAL_RCC_TIM2_CLK_ENABLE() do { \
  833. __IO uint32_t tmpreg; \
  834. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  835. /* Delay after an RCC peripheral clock enabling */ \
  836. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM2EN);\
  837. UNUSED(tmpreg); \
  838. } while(0U)
  839. #define __HAL_RCC_TIM2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM2EN))
  840. #endif /* STM32F031x6 || STM32F038xx || */
  841. /* STM32F042x6 || STM32F048xx || */
  842. /* STM32F051x8 || STM32F058xx || */
  843. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  844. /* STM32F091xC || STM32F098xx */
  845. #if defined(STM32F030x8) \
  846. || defined(STM32F051x8) || defined(STM32F058xx)\
  847. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  848. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  849. #define __HAL_RCC_TIM6_CLK_ENABLE() do { \
  850. __IO uint32_t tmpreg; \
  851. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM6EN);\
  852. /* Delay after an RCC peripheral clock enabling */ \
  853. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM6EN);\
  854. UNUSED(tmpreg); \
  855. } while(0U)
  856. #define __HAL_RCC_I2C2_CLK_ENABLE() do { \
  857. __IO uint32_t tmpreg; \
  858. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C2EN);\
  859. /* Delay after an RCC peripheral clock enabling */ \
  860. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C2EN);\
  861. UNUSED(tmpreg); \
  862. } while(0U)
  863. #define __HAL_RCC_TIM6_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM6EN))
  864. #define __HAL_RCC_I2C2_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_I2C2EN))
  865. #endif /* STM32F030x8 || */
  866. /* STM32F051x8 || STM32F058xx || */
  867. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  868. /* STM32F091xC || STM32F098xx || STM32F030xC */
  869. #if defined(STM32F051x8) || defined(STM32F058xx)\
  870. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  871. || defined(STM32F091xC) || defined(STM32F098xx)
  872. #define __HAL_RCC_DAC1_CLK_ENABLE() do { \
  873. __IO uint32_t tmpreg; \
  874. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_DACEN);\
  875. /* Delay after an RCC peripheral clock enabling */ \
  876. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_DACEN);\
  877. UNUSED(tmpreg); \
  878. } while(0U)
  879. #define __HAL_RCC_DAC1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_DACEN))
  880. #endif /* STM32F051x8 || STM32F058xx || */
  881. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  882. /* STM32F091xC || STM32F098xx */
  883. #if defined(STM32F042x6) || defined(STM32F048xx)\
  884. || defined(STM32F051x8) || defined(STM32F058xx)\
  885. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  886. || defined(STM32F091xC) || defined(STM32F098xx)
  887. #define __HAL_RCC_CEC_CLK_ENABLE() do { \
  888. __IO uint32_t tmpreg; \
  889. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_CECEN);\
  890. /* Delay after an RCC peripheral clock enabling */ \
  891. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_CECEN);\
  892. UNUSED(tmpreg); \
  893. } while(0U)
  894. #define __HAL_RCC_CEC_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_CECEN))
  895. #endif /* STM32F042x6 || STM32F048xx || */
  896. /* STM32F051x8 || STM32F058xx || */
  897. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  898. /* STM32F091xC || STM32F098xx */
  899. #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  900. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  901. #define __HAL_RCC_TIM7_CLK_ENABLE() do { \
  902. __IO uint32_t tmpreg; \
  903. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM7EN);\
  904. /* Delay after an RCC peripheral clock enabling */ \
  905. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_TIM7EN);\
  906. UNUSED(tmpreg); \
  907. } while(0U)
  908. #define __HAL_RCC_USART3_CLK_ENABLE() do { \
  909. __IO uint32_t tmpreg; \
  910. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\
  911. /* Delay after an RCC peripheral clock enabling */ \
  912. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\
  913. UNUSED(tmpreg); \
  914. } while(0U)
  915. #define __HAL_RCC_USART4_CLK_ENABLE() do { \
  916. __IO uint32_t tmpreg; \
  917. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART4EN);\
  918. /* Delay after an RCC peripheral clock enabling */ \
  919. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART4EN);\
  920. UNUSED(tmpreg); \
  921. } while(0U)
  922. #define __HAL_RCC_TIM7_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM7EN))
  923. #define __HAL_RCC_USART3_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART3EN))
  924. #define __HAL_RCC_USART4_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART4EN))
  925. #endif /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  926. /* STM32F091xC || STM32F098xx || STM32F030xC */
  927. #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6)\
  928. || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)
  929. #define __HAL_RCC_USB_CLK_ENABLE() do { \
  930. __IO uint32_t tmpreg; \
  931. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USBEN);\
  932. /* Delay after an RCC peripheral clock enabling */ \
  933. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USBEN);\
  934. UNUSED(tmpreg); \
  935. } while(0U)
  936. #define __HAL_RCC_USB_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USBEN))
  937. #endif /* STM32F042x6 || STM32F048xx || STM32F070x6 || */
  938. /* STM32F072xB || STM32F078xx || STM32F070xB */
  939. #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB)\
  940. || defined(STM32F091xC) || defined(STM32F098xx)
  941. #define __HAL_RCC_CAN1_CLK_ENABLE() do { \
  942. __IO uint32_t tmpreg; \
  943. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_CANEN);\
  944. /* Delay after an RCC peripheral clock enabling */ \
  945. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_CANEN);\
  946. UNUSED(tmpreg); \
  947. } while(0U)
  948. #define __HAL_RCC_CAN1_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_CANEN))
  949. #endif /* STM32F042x6 || STM32F048xx || STM32F072xB || */
  950. /* STM32F091xC || STM32F098xx */
  951. #if defined(CRS)
  952. #define __HAL_RCC_CRS_CLK_ENABLE() do { \
  953. __IO uint32_t tmpreg; \
  954. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_CRSEN);\
  955. /* Delay after an RCC peripheral clock enabling */ \
  956. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_CRSEN);\
  957. UNUSED(tmpreg); \
  958. } while(0U)
  959. #define __HAL_RCC_CRS_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_CRSEN))
  960. #endif /* CRS */
  961. #if defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  962. #define __HAL_RCC_USART5_CLK_ENABLE() do { \
  963. __IO uint32_t tmpreg; \
  964. SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART5EN);\
  965. /* Delay after an RCC peripheral clock enabling */ \
  966. tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART5EN);\
  967. UNUSED(tmpreg); \
  968. } while(0U)
  969. #define __HAL_RCC_USART5_CLK_DISABLE() (RCC->APB1ENR &= ~(RCC_APB1ENR_USART5EN))
  970. #endif /* STM32F091xC || STM32F098xx || STM32F030xC */
  971. /** @brief Enable or disable the High Speed APB (APB2) peripheral clock.
  972. * @note After reset, the peripheral clock (used for registers read/write access)
  973. * is disabled and the application software has to enable this clock before
  974. * using it.
  975. */
  976. #if defined(STM32F030x8) || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6)\
  977. || defined(STM32F051x8) || defined(STM32F058xx)\
  978. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  979. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  980. #define __HAL_RCC_TIM15_CLK_ENABLE() do { \
  981. __IO uint32_t tmpreg; \
  982. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM15EN);\
  983. /* Delay after an RCC peripheral clock enabling */ \
  984. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM15EN);\
  985. UNUSED(tmpreg); \
  986. } while(0U)
  987. #define __HAL_RCC_TIM15_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM15EN))
  988. #endif /* STM32F030x8 || STM32F042x6 || STM32F048xx || STM32F070x6 || */
  989. /* STM32F051x8 || STM32F058xx || */
  990. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  991. /* STM32F091xC || STM32F098xx || STM32F030xC */
  992. #if defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  993. #define __HAL_RCC_USART6_CLK_ENABLE() do { \
  994. __IO uint32_t tmpreg; \
  995. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART6EN);\
  996. /* Delay after an RCC peripheral clock enabling */ \
  997. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART6EN);\
  998. UNUSED(tmpreg); \
  999. } while(0U)
  1000. #define __HAL_RCC_USART6_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART6EN))
  1001. #endif /* STM32F091xC || STM32F098xx || STM32F030xC */
  1002. #if defined(STM32F091xC) || defined(STM32F098xx)
  1003. #define __HAL_RCC_USART7_CLK_ENABLE() do { \
  1004. __IO uint32_t tmpreg; \
  1005. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART7EN);\
  1006. /* Delay after an RCC peripheral clock enabling */ \
  1007. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART7EN);\
  1008. UNUSED(tmpreg); \
  1009. } while(0U)
  1010. #define __HAL_RCC_USART8_CLK_ENABLE() do { \
  1011. __IO uint32_t tmpreg; \
  1012. SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART8EN);\
  1013. /* Delay after an RCC peripheral clock enabling */ \
  1014. tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART8EN);\
  1015. UNUSED(tmpreg); \
  1016. } while(0U)
  1017. #define __HAL_RCC_USART7_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART7EN))
  1018. #define __HAL_RCC_USART8_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART8EN))
  1019. #endif /* STM32F091xC || STM32F098xx */
  1020. /**
  1021. * @}
  1022. */
  1023. /** @defgroup RCCEx_Force_Release_Peripheral_Reset RCCEx Force Release Peripheral Reset
  1024. * @brief Forces or releases peripheral reset.
  1025. * @{
  1026. */
  1027. /** @brief Force or release AHB peripheral reset.
  1028. */
  1029. #if defined(GPIOD)
  1030. #define __HAL_RCC_GPIOD_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIODRST))
  1031. #define __HAL_RCC_GPIOD_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIODRST))
  1032. #endif /* GPIOD */
  1033. #if defined(GPIOE)
  1034. #define __HAL_RCC_GPIOE_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_GPIOERST))
  1035. #define __HAL_RCC_GPIOE_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_GPIOERST))
  1036. #endif /* GPIOE */
  1037. #if defined(STM32F042x6) || defined(STM32F048xx)\
  1038. || defined(STM32F051x8) || defined(STM32F058xx)\
  1039. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1040. || defined(STM32F091xC) || defined(STM32F098xx)
  1041. #define __HAL_RCC_TSC_FORCE_RESET() (RCC->AHBRSTR |= (RCC_AHBRSTR_TSCRST))
  1042. #define __HAL_RCC_TSC_RELEASE_RESET() (RCC->AHBRSTR &= ~(RCC_AHBRSTR_TSCRST))
  1043. #endif /* STM32F042x6 || STM32F048xx || */
  1044. /* STM32F051x8 || STM32F058xx || */
  1045. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  1046. /* STM32F091xC || STM32F098xx */
  1047. /** @brief Force or release APB1 peripheral reset.
  1048. */
  1049. #if defined(STM32F030x8) \
  1050. || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6)\
  1051. || defined(STM32F051x8) || defined(STM32F058xx)\
  1052. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  1053. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1054. #define __HAL_RCC_USART2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART2RST))
  1055. #define __HAL_RCC_SPI2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_SPI2RST))
  1056. #define __HAL_RCC_USART2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART2RST))
  1057. #define __HAL_RCC_SPI2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_SPI2RST))
  1058. #endif /* STM32F030x8 || STM32F042x6 || STM32F048xx || STM32F070x6 || */
  1059. /* STM32F051x8 || STM32F058xx || */
  1060. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  1061. /* STM32F091xC || STM32F098xx || STM32F030xC */
  1062. #if defined(STM32F031x6) || defined(STM32F038xx)\
  1063. || defined(STM32F042x6) || defined(STM32F048xx)\
  1064. || defined(STM32F051x8) || defined(STM32F058xx)\
  1065. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1066. || defined(STM32F091xC) || defined(STM32F098xx)
  1067. #define __HAL_RCC_TIM2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM2RST))
  1068. #define __HAL_RCC_TIM2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM2RST))
  1069. #endif /* STM32F031x6 || STM32F038xx || */
  1070. /* STM32F042x6 || STM32F048xx || */
  1071. /* STM32F051x8 || STM32F058xx || */
  1072. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  1073. /* STM32F091xC || STM32F098xx */
  1074. #if defined(STM32F030x8) \
  1075. || defined(STM32F051x8) || defined(STM32F058xx)\
  1076. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  1077. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1078. #define __HAL_RCC_TIM6_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM6RST))
  1079. #define __HAL_RCC_I2C2_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_I2C2RST))
  1080. #define __HAL_RCC_TIM6_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM6RST))
  1081. #define __HAL_RCC_I2C2_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_I2C2RST))
  1082. #endif /* STM32F030x8 || */
  1083. /* STM32F051x8 || STM32F058xx || */
  1084. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  1085. /* STM32F091xC || STM32F098xx || STM32F030xC */
  1086. #if defined(STM32F051x8) || defined(STM32F058xx)\
  1087. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1088. || defined(STM32F091xC) || defined(STM32F098xx)
  1089. #define __HAL_RCC_DAC1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_DACRST))
  1090. #define __HAL_RCC_DAC1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_DACRST))
  1091. #endif /* STM32F051x8 || STM32F058xx || */
  1092. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  1093. /* STM32F091xC || STM32F098xx */
  1094. #if defined(STM32F042x6) || defined(STM32F048xx)\
  1095. || defined(STM32F051x8) || defined(STM32F058xx)\
  1096. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1097. || defined(STM32F091xC) || defined(STM32F098xx)
  1098. #define __HAL_RCC_CEC_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_CECRST))
  1099. #define __HAL_RCC_CEC_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_CECRST))
  1100. #endif /* STM32F042x6 || STM32F048xx || */
  1101. /* STM32F051x8 || STM32F058xx || */
  1102. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  1103. /* STM32F091xC || STM32F098xx */
  1104. #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  1105. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1106. #define __HAL_RCC_TIM7_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_TIM7RST))
  1107. #define __HAL_RCC_USART3_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART3RST))
  1108. #define __HAL_RCC_USART4_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART4RST))
  1109. #define __HAL_RCC_TIM7_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_TIM7RST))
  1110. #define __HAL_RCC_USART3_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART3RST))
  1111. #define __HAL_RCC_USART4_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART4RST))
  1112. #endif /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  1113. /* STM32F091xC || STM32F098xx || STM32F030xC */
  1114. #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6)\
  1115. || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)
  1116. #define __HAL_RCC_USB_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USBRST))
  1117. #define __HAL_RCC_USB_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USBRST))
  1118. #endif /* STM32F042x6 || STM32F048xx || STM32F070x6 || */
  1119. /* STM32F072xB || STM32F078xx || STM32F070xB */
  1120. #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB)\
  1121. || defined(STM32F091xC) || defined(STM32F098xx)
  1122. #define __HAL_RCC_CAN1_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_CANRST))
  1123. #define __HAL_RCC_CAN1_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_CANRST))
  1124. #endif /* STM32F042x6 || STM32F048xx || STM32F072xB || */
  1125. /* STM32F091xC || STM32F098xx */
  1126. #if defined(CRS)
  1127. #define __HAL_RCC_CRS_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_CRSRST))
  1128. #define __HAL_RCC_CRS_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_CRSRST))
  1129. #endif /* CRS */
  1130. #if defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1131. #define __HAL_RCC_USART5_FORCE_RESET() (RCC->APB1RSTR |= (RCC_APB1RSTR_USART5RST))
  1132. #define __HAL_RCC_USART5_RELEASE_RESET() (RCC->APB1RSTR &= ~(RCC_APB1RSTR_USART5RST))
  1133. #endif /* STM32F091xC || STM32F098xx || STM32F030xC */
  1134. /** @brief Force or release APB2 peripheral reset.
  1135. */
  1136. #if defined(STM32F030x8) || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6)\
  1137. || defined(STM32F051x8) || defined(STM32F058xx)\
  1138. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  1139. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1140. #define __HAL_RCC_TIM15_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_TIM15RST))
  1141. #define __HAL_RCC_TIM15_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_TIM15RST))
  1142. #endif /* STM32F030x8 || STM32F042x6 || STM32F048xx || STM32F070x6 || */
  1143. /* STM32F051x8 || STM32F058xx || */
  1144. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  1145. /* STM32F091xC || STM32F098xx || STM32F030xC */
  1146. #if defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1147. #define __HAL_RCC_USART6_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART6RST))
  1148. #define __HAL_RCC_USART6_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART6RST))
  1149. #endif /* STM32F091xC || STM32F098xx || STM32F030xC */
  1150. #if defined(STM32F091xC) || defined(STM32F098xx)
  1151. #define __HAL_RCC_USART7_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART7RST))
  1152. #define __HAL_RCC_USART8_FORCE_RESET() (RCC->APB2RSTR |= (RCC_APB2RSTR_USART8RST))
  1153. #define __HAL_RCC_USART7_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART7RST))
  1154. #define __HAL_RCC_USART8_RELEASE_RESET() (RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART8RST))
  1155. #endif /* STM32F091xC || STM32F098xx */
  1156. /**
  1157. * @}
  1158. */
  1159. /** @defgroup RCCEx_Peripheral_Clock_Enable_Disable_Status Peripheral Clock Enable Disable Status
  1160. * @brief Get the enable or disable status of peripheral clock.
  1161. * @note After reset, the peripheral clock (used for registers read/write access)
  1162. * is disabled and the application software has to enable this clock before
  1163. * using it.
  1164. * @{
  1165. */
  1166. /** @brief AHB Peripheral Clock Enable Disable Status
  1167. */
  1168. #if defined(GPIOD)
  1169. #define __HAL_RCC_GPIOD_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIODEN)) != RESET)
  1170. #define __HAL_RCC_GPIOD_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIODEN)) == RESET)
  1171. #endif /* GPIOD */
  1172. #if defined(GPIOE)
  1173. #define __HAL_RCC_GPIOE_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOEEN)) != RESET)
  1174. #define __HAL_RCC_GPIOE_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_GPIOEEN)) == RESET)
  1175. #endif /* GPIOE */
  1176. #if defined(STM32F042x6) || defined(STM32F048xx)\
  1177. || defined(STM32F051x8) || defined(STM32F058xx)\
  1178. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1179. || defined(STM32F091xC) || defined(STM32F098xx)
  1180. #define __HAL_RCC_TSC_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_TSCEN)) != RESET)
  1181. #define __HAL_RCC_TSC_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_TSCEN)) == RESET)
  1182. #endif /* STM32F042x6 || STM32F048xx || */
  1183. /* STM32F051x8 || STM32F058xx || */
  1184. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  1185. /* STM32F091xC || STM32F098xx */
  1186. #if defined(STM32F091xC) || defined(STM32F098xx)
  1187. #define __HAL_RCC_DMA2_IS_CLK_ENABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA2EN)) != RESET)
  1188. #define __HAL_RCC_DMA2_IS_CLK_DISABLED() ((RCC->AHBENR & (RCC_AHBENR_DMA2EN)) == RESET)
  1189. #endif /* STM32F091xC || STM32F098xx */
  1190. /** @brief APB1 Peripheral Clock Enable Disable Status
  1191. */
  1192. #if defined(STM32F030x8)\
  1193. || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6)\
  1194. || defined(STM32F051x8) || defined(STM32F058xx)\
  1195. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  1196. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1197. #define __HAL_RCC_USART2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) != RESET)
  1198. #define __HAL_RCC_USART2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART2EN)) == RESET)
  1199. #endif /* STM32F030x8 || STM32F042x6 || STM32F048xx || */
  1200. /* STM32F051x8 || STM32F058xx || STM32F070x6 || */
  1201. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  1202. /* STM32F091xC || STM32F098xx || STM32F030xC */
  1203. #if defined(STM32F030x8)\
  1204. || defined(STM32F042x6) || defined(STM32F048xx)\
  1205. || defined(STM32F051x8) || defined(STM32F058xx)\
  1206. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  1207. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1208. #define __HAL_RCC_SPI2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_SPI2EN)) != RESET)
  1209. #define __HAL_RCC_SPI2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_SPI2EN)) == RESET)
  1210. #endif /* STM32F030x8 || STM32F042x6 || STM32F048xx || */
  1211. /* STM32F051x8 || STM32F058xx || */
  1212. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  1213. /* STM32F091xC || STM32F098xx || STM32F030xC */
  1214. #if defined(STM32F031x6) || defined(STM32F038xx)\
  1215. || defined(STM32F042x6) || defined(STM32F048xx)\
  1216. || defined(STM32F051x8) || defined(STM32F058xx)\
  1217. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1218. || defined(STM32F091xC) || defined(STM32F098xx)
  1219. #define __HAL_RCC_TIM2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) != RESET)
  1220. #define __HAL_RCC_TIM2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM2EN)) == RESET)
  1221. #endif /* STM32F031x6 || STM32F038xx || */
  1222. /* STM32F042x6 || STM32F048xx || */
  1223. /* STM32F051x8 || STM32F058xx || */
  1224. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  1225. /* STM32F091xC || STM32F098xx */
  1226. #if defined(STM32F030x8) \
  1227. || defined(STM32F051x8) || defined(STM32F058xx)\
  1228. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  1229. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1230. #define __HAL_RCC_TIM6_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM6EN)) != RESET)
  1231. #define __HAL_RCC_I2C2_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C2EN)) != RESET)
  1232. #define __HAL_RCC_TIM6_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM6EN)) == RESET)
  1233. #define __HAL_RCC_I2C2_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_I2C2EN)) == RESET)
  1234. #endif /* STM32F030x8 || */
  1235. /* STM32F051x8 || STM32F058xx || */
  1236. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  1237. /* STM32F091xC || STM32F098xx || STM32F030xC */
  1238. #if defined(STM32F051x8) || defined(STM32F058xx)\
  1239. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1240. || defined(STM32F091xC) || defined(STM32F098xx)
  1241. #define __HAL_RCC_DAC1_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_DAC1EN)) != RESET)
  1242. #define __HAL_RCC_DAC1_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_DAC1EN)) == RESET)
  1243. #endif /* STM32F051x8 || STM32F058xx || */
  1244. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  1245. /* STM32F091xC || STM32F098xx */
  1246. #if defined(STM32F042x6) || defined(STM32F048xx)\
  1247. || defined(STM32F051x8) || defined(STM32F058xx)\
  1248. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1249. || defined(STM32F091xC) || defined(STM32F098xx)
  1250. #define __HAL_RCC_CEC_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_CECEN)) != RESET)
  1251. #define __HAL_RCC_CEC_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_CECEN)) == RESET)
  1252. #endif /* STM32F042x6 || STM32F048xx || */
  1253. /* STM32F051x8 || STM32F058xx || */
  1254. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  1255. /* STM32F091xC || STM32F098xx */
  1256. #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  1257. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1258. #define __HAL_RCC_TIM7_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM7EN)) != RESET)
  1259. #define __HAL_RCC_USART3_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART3EN)) != RESET)
  1260. #define __HAL_RCC_USART4_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART4EN)) != RESET)
  1261. #define __HAL_RCC_TIM7_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_TIM7EN)) == RESET)
  1262. #define __HAL_RCC_USART3_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART3EN)) == RESET)
  1263. #define __HAL_RCC_USART4_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART4EN)) == RESET)
  1264. #endif /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  1265. /* STM32F091xC || STM32F098xx || STM32F030xC */
  1266. #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6)\
  1267. || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)
  1268. #define __HAL_RCC_USB_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USBEN)) != RESET)
  1269. #define __HAL_RCC_USB_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USBEN)) == RESET)
  1270. #endif /* STM32F042x6 || STM32F048xx || STM32F070x6 || */
  1271. /* STM32F072xB || STM32F078xx || STM32F070xB */
  1272. #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB)\
  1273. || defined(STM32F091xC) || defined(STM32F098xx)
  1274. #define __HAL_RCC_CAN1_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_CAN1EN)) != RESET)
  1275. #define __HAL_RCC_CAN1_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_CAN1EN)) == RESET)
  1276. #endif /* STM32F042x6 || STM32F048xx || STM32F072xB || */
  1277. /* STM32F091xC || STM32F098xx */
  1278. #if defined(CRS)
  1279. #define __HAL_RCC_CRS_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_CRSEN)) != RESET)
  1280. #define __HAL_RCC_CRS_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_CRSEN)) == RESET)
  1281. #endif /* CRS */
  1282. #if defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1283. #define __HAL_RCC_USART5_IS_CLK_ENABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART5EN)) != RESET)
  1284. #define __HAL_RCC_USART5_IS_CLK_DISABLED() ((RCC->APB1ENR & (RCC_APB1ENR_USART5EN)) == RESET)
  1285. #endif /* STM32F091xC || STM32F098xx || STM32F030xC */
  1286. /** @brief APB1 Peripheral Clock Enable Disable Status
  1287. */
  1288. #if defined(STM32F030x8) || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6)\
  1289. || defined(STM32F051x8) || defined(STM32F058xx)\
  1290. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)\
  1291. || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1292. #define __HAL_RCC_TIM15_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM15EN)) != RESET)
  1293. #define __HAL_RCC_TIM15_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_TIM15EN)) == RESET)
  1294. #endif /* STM32F030x8 || STM32F042x6 || STM32F048xx || STM32F070x6 || */
  1295. /* STM32F051x8 || STM32F058xx || */
  1296. /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || */
  1297. /* STM32F091xC || STM32F098xx || STM32F030xC */
  1298. #if defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
  1299. #define __HAL_RCC_USART6_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART6EN)) != RESET)
  1300. #define __HAL_RCC_USART6_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART6EN)) == RESET)
  1301. #endif /* STM32F091xC || STM32F098xx || STM32F030xC */
  1302. #if defined(STM32F091xC) || defined(STM32F098xx)
  1303. #define __HAL_RCC_USART7_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART7EN)) != RESET)
  1304. #define __HAL_RCC_USART8_IS_CLK_ENABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART8EN)) != RESET)
  1305. #define __HAL_RCC_USART7_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART7EN)) == RESET)
  1306. #define __HAL_RCC_USART8_IS_CLK_DISABLED() ((RCC->APB2ENR & (RCC_APB2ENR_USART8EN)) == RESET)
  1307. #endif /* STM32F091xC || STM32F098xx */
  1308. /**
  1309. * @}
  1310. */
  1311. /** @defgroup RCCEx_HSI48_Enable_Disable RCCEx HSI48 Enable Disable
  1312. * @brief Macros to enable or disable the Internal 48Mhz High Speed oscillator (HSI48).
  1313. * @note The HSI48 is stopped by hardware when entering STOP and STANDBY modes.
  1314. * @note HSI48 can not be stopped if it is used as system clock source. In this case,
  1315. * you have to select another source of the system clock then stop the HSI14.
  1316. * @note After enabling the HSI48 with __HAL_RCC_HSI48_ENABLE(), the application software
  1317. * should wait on HSI48RDY flag to be set indicating that HSI48 clock is stable and can be
  1318. * used as system clock source. This is not necessary if HAL_RCC_OscConfig() is used.
  1319. * @note When the HSI48 is stopped, HSI48RDY flag goes low after 6 HSI48 oscillator
  1320. * clock cycles.
  1321. * @{
  1322. */
  1323. #if defined(RCC_HSI48_SUPPORT)
  1324. #define __HAL_RCC_HSI48_ENABLE() SET_BIT(RCC->CR2, RCC_CR2_HSI48ON)
  1325. #define __HAL_RCC_HSI48_DISABLE() CLEAR_BIT(RCC->CR2, RCC_CR2_HSI48ON)
  1326. /** @brief Macro to get the Internal 48Mhz High Speed oscillator (HSI48) state.
  1327. * @retval The clock source can be one of the following values:
  1328. * @arg @ref RCC_HSI48_ON HSI48 enabled
  1329. * @arg @ref RCC_HSI48_OFF HSI48 disabled
  1330. */
  1331. #define __HAL_RCC_GET_HSI48_STATE() \
  1332. (((uint32_t)(READ_BIT(RCC->CR2, RCC_CR2_HSI48ON)) != RESET) ? RCC_HSI48_ON : RCC_HSI48_OFF)
  1333. #endif /* RCC_HSI48_SUPPORT */
  1334. /**
  1335. * @}
  1336. */
  1337. /** @defgroup RCCEx_Peripheral_Clock_Source_Config RCCEx Peripheral Clock Source Config
  1338. * @{
  1339. */
  1340. #if defined(STM32F042x6) || defined(STM32F048xx)\
  1341. || defined(STM32F072xB) || defined(STM32F078xx)\
  1342. || defined(STM32F070x6) || defined(STM32F070xB)
  1343. /** @brief Macro to configure the USB clock (USBCLK).
  1344. * @param __USBCLKSOURCE__ specifies the USB clock source.
  1345. * This parameter can be one of the following values:
  1346. @if STM32F070xB
  1347. @elseif STM32F070x6
  1348. @else
  1349. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 selected as USB clock
  1350. @endif
  1351. * @arg @ref RCC_USBCLKSOURCE_PLL PLL Clock selected as USB clock
  1352. */
  1353. #define __HAL_RCC_USB_CONFIG(__USBCLKSOURCE__) \
  1354. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_USBSW, (uint32_t)(__USBCLKSOURCE__))
  1355. /** @brief Macro to get the USB clock source.
  1356. * @retval The clock source can be one of the following values:
  1357. @if STM32F070xB
  1358. @elseif STM32F070x6
  1359. @else
  1360. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 selected as USB clock
  1361. @endif
  1362. * @arg @ref RCC_USBCLKSOURCE_PLL PLL Clock selected as USB clock
  1363. */
  1364. #define __HAL_RCC_GET_USB_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_USBSW)))
  1365. #endif /* STM32F042x6 || STM32F048xx || */
  1366. /* STM32F072xB || STM32F078xx || */
  1367. /* STM32F070x6 || STM32F070xB */
  1368. #if defined(STM32F042x6) || defined(STM32F048xx)\
  1369. || defined(STM32F051x8) || defined(STM32F058xx)\
  1370. || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1371. || defined(STM32F091xC) || defined(STM32F098xx)
  1372. /** @brief Macro to configure the CEC clock.
  1373. * @param __CECCLKSOURCE__ specifies the CEC clock source.
  1374. * This parameter can be one of the following values:
  1375. * @arg @ref RCC_CECCLKSOURCE_HSI HSI selected as CEC clock
  1376. * @arg @ref RCC_CECCLKSOURCE_LSE LSE selected as CEC clock
  1377. */
  1378. #define __HAL_RCC_CEC_CONFIG(__CECCLKSOURCE__) \
  1379. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_CECSW, (uint32_t)(__CECCLKSOURCE__))
  1380. /** @brief Macro to get the HDMI CEC clock source.
  1381. * @retval The clock source can be one of the following values:
  1382. * @arg @ref RCC_CECCLKSOURCE_HSI HSI selected as CEC clock
  1383. * @arg @ref RCC_CECCLKSOURCE_LSE LSE selected as CEC clock
  1384. */
  1385. #define __HAL_RCC_GET_CEC_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_CECSW)))
  1386. #endif /* STM32F042x6 || STM32F048xx || */
  1387. /* STM32F051x8 || STM32F058xx || */
  1388. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  1389. /* STM32F091xC || defined(STM32F098xx) */
  1390. #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)\
  1391. || defined(STM32F091xC) || defined(STM32F098xx)
  1392. /** @brief Macro to configure the USART2 clock (USART2CLK).
  1393. * @param __USART2CLKSOURCE__ specifies the USART2 clock source.
  1394. * This parameter can be one of the following values:
  1395. * @arg @ref RCC_USART2CLKSOURCE_PCLK1 PCLK1 selected as USART2 clock
  1396. * @arg @ref RCC_USART2CLKSOURCE_HSI HSI selected as USART2 clock
  1397. * @arg @ref RCC_USART2CLKSOURCE_SYSCLK System Clock selected as USART2 clock
  1398. * @arg @ref RCC_USART2CLKSOURCE_LSE LSE selected as USART2 clock
  1399. */
  1400. #define __HAL_RCC_USART2_CONFIG(__USART2CLKSOURCE__) \
  1401. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_USART2SW, (uint32_t)(__USART2CLKSOURCE__))
  1402. /** @brief Macro to get the USART2 clock source.
  1403. * @retval The clock source can be one of the following values:
  1404. * @arg @ref RCC_USART2CLKSOURCE_PCLK1 PCLK1 selected as USART2 clock
  1405. * @arg @ref RCC_USART2CLKSOURCE_HSI HSI selected as USART2 clock
  1406. * @arg @ref RCC_USART2CLKSOURCE_SYSCLK System Clock selected as USART2 clock
  1407. * @arg @ref RCC_USART2CLKSOURCE_LSE LSE selected as USART2 clock
  1408. */
  1409. #define __HAL_RCC_GET_USART2_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_USART2SW)))
  1410. #endif /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F091xC || STM32F098xx*/
  1411. #if defined(STM32F091xC) || defined(STM32F098xx)
  1412. /** @brief Macro to configure the USART3 clock (USART3CLK).
  1413. * @param __USART3CLKSOURCE__ specifies the USART3 clock source.
  1414. * This parameter can be one of the following values:
  1415. * @arg @ref RCC_USART3CLKSOURCE_PCLK1 PCLK1 selected as USART3 clock
  1416. * @arg @ref RCC_USART3CLKSOURCE_HSI HSI selected as USART3 clock
  1417. * @arg @ref RCC_USART3CLKSOURCE_SYSCLK System Clock selected as USART3 clock
  1418. * @arg @ref RCC_USART3CLKSOURCE_LSE LSE selected as USART3 clock
  1419. */
  1420. #define __HAL_RCC_USART3_CONFIG(__USART3CLKSOURCE__) \
  1421. MODIFY_REG(RCC->CFGR3, RCC_CFGR3_USART3SW, (uint32_t)(__USART3CLKSOURCE__))
  1422. /** @brief Macro to get the USART3 clock source.
  1423. * @retval The clock source can be one of the following values:
  1424. * @arg @ref RCC_USART3CLKSOURCE_PCLK1 PCLK1 selected as USART3 clock
  1425. * @arg @ref RCC_USART3CLKSOURCE_HSI HSI selected as USART3 clock
  1426. * @arg @ref RCC_USART3CLKSOURCE_SYSCLK System Clock selected as USART3 clock
  1427. * @arg @ref RCC_USART3CLKSOURCE_LSE LSE selected as USART3 clock
  1428. */
  1429. #define __HAL_RCC_GET_USART3_SOURCE() ((uint32_t)(READ_BIT(RCC->CFGR3, RCC_CFGR3_USART3SW)))
  1430. #endif /* STM32F091xC || STM32F098xx */
  1431. /**
  1432. * @}
  1433. */
  1434. /** @defgroup RCCEx_LSE_Configuration LSE Drive Configuration
  1435. * @{
  1436. */
  1437. /**
  1438. * @brief Macro to configure the External Low Speed oscillator (LSE) drive capability.
  1439. * @param __RCC_LSEDRIVE__ specifies the new state of the LSE drive capability.
  1440. * This parameter can be one of the following values:
  1441. * @arg @ref RCC_LSEDRIVE_LOW LSE oscillator low drive capability.
  1442. * @arg @ref RCC_LSEDRIVE_MEDIUMLOW LSE oscillator medium low drive capability.
  1443. * @arg @ref RCC_LSEDRIVE_MEDIUMHIGH LSE oscillator medium high drive capability.
  1444. * @arg @ref RCC_LSEDRIVE_HIGH LSE oscillator high drive capability.
  1445. * @retval None
  1446. */
  1447. #define __HAL_RCC_LSEDRIVE_CONFIG(__RCC_LSEDRIVE__) (MODIFY_REG(RCC->BDCR,\
  1448. RCC_BDCR_LSEDRV, (uint32_t)(__RCC_LSEDRIVE__) ))
  1449. /**
  1450. * @}
  1451. */
  1452. #if defined(CRS)
  1453. /** @defgroup RCCEx_IT_And_Flag RCCEx IT and Flag
  1454. * @{
  1455. */
  1456. /* Interrupt & Flag management */
  1457. /**
  1458. * @brief Enable the specified CRS interrupts.
  1459. * @param __INTERRUPT__ specifies the CRS interrupt sources to be enabled.
  1460. * This parameter can be any combination of the following values:
  1461. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  1462. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  1463. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  1464. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  1465. * @retval None
  1466. */
  1467. #define __HAL_RCC_CRS_ENABLE_IT(__INTERRUPT__) SET_BIT(CRS->CR, (__INTERRUPT__))
  1468. /**
  1469. * @brief Disable the specified CRS interrupts.
  1470. * @param __INTERRUPT__ specifies the CRS interrupt sources to be disabled.
  1471. * This parameter can be any combination of the following values:
  1472. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  1473. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  1474. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  1475. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  1476. * @retval None
  1477. */
  1478. #define __HAL_RCC_CRS_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(CRS->CR, (__INTERRUPT__))
  1479. /** @brief Check whether the CRS interrupt has occurred or not.
  1480. * @param __INTERRUPT__ specifies the CRS interrupt source to check.
  1481. * This parameter can be one of the following values:
  1482. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  1483. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  1484. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  1485. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  1486. * @retval The new state of __INTERRUPT__ (SET or RESET).
  1487. */
  1488. #define __HAL_RCC_CRS_GET_IT_SOURCE(__INTERRUPT__) ((READ_BIT(CRS->CR, (__INTERRUPT__)) != RESET) ? SET : RESET)
  1489. /** @brief Clear the CRS interrupt pending bits
  1490. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1491. * This parameter can be any combination of the following values:
  1492. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  1493. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  1494. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  1495. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  1496. * @arg @ref RCC_CRS_IT_TRIMOVF Trimming overflow or underflow interrupt
  1497. * @arg @ref RCC_CRS_IT_SYNCERR SYNC error interrupt
  1498. * @arg @ref RCC_CRS_IT_SYNCMISS SYNC missed interrupt
  1499. */
  1500. #define __HAL_RCC_CRS_CLEAR_IT(__INTERRUPT__) do { \
  1501. if(((__INTERRUPT__) & RCC_CRS_IT_ERROR_MASK) != RESET) \
  1502. { \
  1503. WRITE_REG(CRS->ICR, CRS_ICR_ERRC | ((__INTERRUPT__) & ~RCC_CRS_IT_ERROR_MASK)); \
  1504. } \
  1505. else \
  1506. { \
  1507. WRITE_REG(CRS->ICR, (__INTERRUPT__)); \
  1508. } \
  1509. } while(0U)
  1510. /**
  1511. * @brief Check whether the specified CRS flag is set or not.
  1512. * @param __FLAG__ specifies the flag to check.
  1513. * This parameter can be one of the following values:
  1514. * @arg @ref RCC_CRS_FLAG_SYNCOK SYNC event OK
  1515. * @arg @ref RCC_CRS_FLAG_SYNCWARN SYNC warning
  1516. * @arg @ref RCC_CRS_FLAG_ERR Error
  1517. * @arg @ref RCC_CRS_FLAG_ESYNC Expected SYNC
  1518. * @arg @ref RCC_CRS_FLAG_TRIMOVF Trimming overflow or underflow
  1519. * @arg @ref RCC_CRS_FLAG_SYNCERR SYNC error
  1520. * @arg @ref RCC_CRS_FLAG_SYNCMISS SYNC missed
  1521. * @retval The new state of _FLAG_ (TRUE or FALSE).
  1522. */
  1523. #define __HAL_RCC_CRS_GET_FLAG(__FLAG__) (READ_BIT(CRS->ISR, (__FLAG__)) == (__FLAG__))
  1524. /**
  1525. * @brief Clear the CRS specified FLAG.
  1526. * @param __FLAG__ specifies the flag to clear.
  1527. * This parameter can be one of the following values:
  1528. * @arg @ref RCC_CRS_FLAG_SYNCOK SYNC event OK
  1529. * @arg @ref RCC_CRS_FLAG_SYNCWARN SYNC warning
  1530. * @arg @ref RCC_CRS_FLAG_ERR Error
  1531. * @arg @ref RCC_CRS_FLAG_ESYNC Expected SYNC
  1532. * @arg @ref RCC_CRS_FLAG_TRIMOVF Trimming overflow or underflow
  1533. * @arg @ref RCC_CRS_FLAG_SYNCERR SYNC error
  1534. * @arg @ref RCC_CRS_FLAG_SYNCMISS SYNC missed
  1535. * @note RCC_CRS_FLAG_ERR clears RCC_CRS_FLAG_TRIMOVF, RCC_CRS_FLAG_SYNCERR, RCC_CRS_FLAG_SYNCMISS and consequently RCC_CRS_FLAG_ERR
  1536. * @retval None
  1537. */
  1538. #define __HAL_RCC_CRS_CLEAR_FLAG(__FLAG__) do { \
  1539. if(((__FLAG__) & RCC_CRS_FLAG_ERROR_MASK) != RESET) \
  1540. { \
  1541. WRITE_REG(CRS->ICR, CRS_ICR_ERRC | ((__FLAG__) & ~RCC_CRS_FLAG_ERROR_MASK)); \
  1542. } \
  1543. else \
  1544. { \
  1545. WRITE_REG(CRS->ICR, (__FLAG__)); \
  1546. } \
  1547. } while(0U)
  1548. /**
  1549. * @}
  1550. */
  1551. /** @defgroup RCCEx_CRS_Extended_Features RCCEx CRS Extended Features
  1552. * @{
  1553. */
  1554. /**
  1555. * @brief Enable the oscillator clock for frequency error counter.
  1556. * @note when the CEN bit is set the CRS_CFGR register becomes write-protected.
  1557. * @retval None
  1558. */
  1559. #define __HAL_RCC_CRS_FREQ_ERROR_COUNTER_ENABLE() SET_BIT(CRS->CR, CRS_CR_CEN)
  1560. /**
  1561. * @brief Disable the oscillator clock for frequency error counter.
  1562. * @retval None
  1563. */
  1564. #define __HAL_RCC_CRS_FREQ_ERROR_COUNTER_DISABLE() CLEAR_BIT(CRS->CR, CRS_CR_CEN)
  1565. /**
  1566. * @brief Enable the automatic hardware adjustement of TRIM bits.
  1567. * @note When the AUTOTRIMEN bit is set the CRS_CFGR register becomes write-protected.
  1568. * @retval None
  1569. */
  1570. #define __HAL_RCC_CRS_AUTOMATIC_CALIB_ENABLE() SET_BIT(CRS->CR, CRS_CR_AUTOTRIMEN)
  1571. /**
  1572. * @brief Disable the automatic hardware adjustement of TRIM bits.
  1573. * @retval None
  1574. */
  1575. #define __HAL_RCC_CRS_AUTOMATIC_CALIB_DISABLE() CLEAR_BIT(CRS->CR, CRS_CR_AUTOTRIMEN)
  1576. /**
  1577. * @brief Macro to calculate reload value to be set in CRS register according to target and sync frequencies
  1578. * @note The RELOAD value should be selected according to the ratio between the target frequency and the frequency
  1579. * of the synchronization source after prescaling. It is then decreased by one in order to
  1580. * reach the expected synchronization on the zero value. The formula is the following:
  1581. * RELOAD = (fTARGET / fSYNC) -1
  1582. * @param __FTARGET__ Target frequency (value in Hz)
  1583. * @param __FSYNC__ Synchronization signal frequency (value in Hz)
  1584. * @retval None
  1585. */
  1586. #define __HAL_RCC_CRS_RELOADVALUE_CALCULATE(__FTARGET__, __FSYNC__) (((__FTARGET__) / (__FSYNC__)) - 1U)
  1587. /**
  1588. * @}
  1589. */
  1590. #endif /* CRS */
  1591. /**
  1592. * @}
  1593. */
  1594. /* Exported functions --------------------------------------------------------*/
  1595. /** @addtogroup RCCEx_Exported_Functions
  1596. * @{
  1597. */
  1598. /** @addtogroup RCCEx_Exported_Functions_Group1
  1599. * @{
  1600. */
  1601. HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit);
  1602. void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit);
  1603. uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk);
  1604. /**
  1605. * @}
  1606. */
  1607. #if defined(CRS)
  1608. /** @addtogroup RCCEx_Exported_Functions_Group3
  1609. * @{
  1610. */
  1611. void HAL_RCCEx_CRSConfig(RCC_CRSInitTypeDef *pInit);
  1612. void HAL_RCCEx_CRSSoftwareSynchronizationGenerate(void);
  1613. void HAL_RCCEx_CRSGetSynchronizationInfo(RCC_CRSSynchroInfoTypeDef *pSynchroInfo);
  1614. uint32_t HAL_RCCEx_CRSWaitSynchronization(uint32_t Timeout);
  1615. void HAL_RCCEx_CRS_IRQHandler(void);
  1616. void HAL_RCCEx_CRS_SyncOkCallback(void);
  1617. void HAL_RCCEx_CRS_SyncWarnCallback(void);
  1618. void HAL_RCCEx_CRS_ExpectedSyncCallback(void);
  1619. void HAL_RCCEx_CRS_ErrorCallback(uint32_t Error);
  1620. /**
  1621. * @}
  1622. */
  1623. #endif /* CRS */
  1624. /**
  1625. * @}
  1626. */
  1627. /**
  1628. * @}
  1629. */
  1630. /**
  1631. * @}
  1632. */
  1633. /**
  1634. * @}
  1635. */
  1636. #ifdef __cplusplus
  1637. }
  1638. #endif
  1639. #endif /* __STM32F0xx_HAL_RCC_EX_H */
  1640. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/