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.
 
 
 

2486 lines
110 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_rcc_ex.h
  4. * @author MCD Application Team
  5. * @version V1.7.2
  6. * @date 16-June-2017
  7. * @brief Header file of RCC HAL Extended module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32L4xx_HAL_RCC_EX_H
  39. #define __STM32L4xx_HAL_RCC_EX_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l4xx_hal_def.h"
  45. /** @addtogroup STM32L4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup RCCEx
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup RCCEx_Exported_Types RCCEx Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief PLLSAI1 Clock structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t PLLSAI1Source; /*!< PLLSAI1Source: PLLSAI1 entry clock source.
  61. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  62. uint32_t PLLSAI1M; /*!< PLLSAI1M: specifies the division factor for PLLSAI1 input clock.
  63. This parameter must be a number between Min_Data = 1 and Max_Data = 8 */
  64. uint32_t PLLSAI1N; /*!< PLLSAI1N: specifies the multiplication factor for PLLSAI1 VCO output clock.
  65. This parameter must be a number between 8 and 86 or 127 depending on devices. */
  66. uint32_t PLLSAI1P; /*!< PLLSAI1P: specifies the division factor for SAI clock.
  67. This parameter must be a value of @ref RCC_PLLP_Clock_Divider */
  68. uint32_t PLLSAI1Q; /*!< PLLSAI1Q: specifies the division factor for USB/RNG/SDMMC1 clock.
  69. This parameter must be a value of @ref RCC_PLLQ_Clock_Divider */
  70. uint32_t PLLSAI1R; /*!< PLLSAI1R: specifies the division factor for ADC clock.
  71. This parameter must be a value of @ref RCC_PLLR_Clock_Divider */
  72. uint32_t PLLSAI1ClockOut; /*!< PLLSAIClockOut: specifies PLLSAI1 output clock to be enabled.
  73. This parameter must be a value of @ref RCC_PLLSAI1_Clock_Output */
  74. }RCC_PLLSAI1InitTypeDef;
  75. #if defined(RCC_PLLSAI2_SUPPORT)
  76. /**
  77. * @brief PLLSAI2 Clock structure definition
  78. */
  79. typedef struct
  80. {
  81. uint32_t PLLSAI2Source; /*!< PLLSAI2Source: PLLSAI2 entry clock source.
  82. This parameter must be a value of @ref RCC_PLL_Clock_Source */
  83. uint32_t PLLSAI2M; /*!< PLLSAI2M: specifies the division factor for PLLSAI2 input clock.
  84. This parameter must be a number between Min_Data = 1 and Max_Data = 8 */
  85. uint32_t PLLSAI2N; /*!< PLLSAI2N: specifies the multiplication factor for PLLSAI2 VCO output clock.
  86. This parameter must be a number between 8 and 86 or 127 depending on devices. */
  87. uint32_t PLLSAI2P; /*!< PLLSAI2P: specifies the division factor for SAI clock.
  88. This parameter must be a value of @ref RCC_PLLP_Clock_Divider */
  89. uint32_t PLLSAI2R; /*!< PLLSAI2R: specifies the division factor for ADC clock.
  90. This parameter must be a value of @ref RCC_PLLR_Clock_Divider */
  91. uint32_t PLLSAI2ClockOut; /*!< PLLSAIClockOut: specifies PLLSAI2 output clock to be enabled.
  92. This parameter must be a value of @ref RCC_PLLSAI2_Clock_Output */
  93. }RCC_PLLSAI2InitTypeDef;
  94. #endif /* RCC_PLLSAI2_SUPPORT */
  95. /**
  96. * @brief RCC extended clocks structure definition
  97. */
  98. typedef struct
  99. {
  100. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  101. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  102. RCC_PLLSAI1InitTypeDef PLLSAI1; /*!< PLLSAI1 structure parameters.
  103. This parameter will be used only when PLLSAI1 is selected as Clock Source for SAI1, USB/RNG/SDMMC1 or ADC */
  104. #if defined(RCC_PLLSAI2_SUPPORT)
  105. RCC_PLLSAI2InitTypeDef PLLSAI2; /*!< PLLSAI2 structure parameters.
  106. This parameter will be used only when PLLSAI2 is selected as Clock Source for SAI2 or ADC */
  107. #endif /* RCC_PLLSAI2_SUPPORT */
  108. uint32_t Usart1ClockSelection; /*!< Specifies USART1 clock source.
  109. This parameter can be a value of @ref RCCEx_USART1_Clock_Source */
  110. uint32_t Usart2ClockSelection; /*!< Specifies USART2 clock source.
  111. This parameter can be a value of @ref RCCEx_USART2_Clock_Source */
  112. #if defined(USART3)
  113. uint32_t Usart3ClockSelection; /*!< Specifies USART3 clock source.
  114. This parameter can be a value of @ref RCCEx_USART3_Clock_Source */
  115. #endif /* USART3 */
  116. #if defined(UART4)
  117. uint32_t Uart4ClockSelection; /*!< Specifies UART4 clock source.
  118. This parameter can be a value of @ref RCCEx_UART4_Clock_Source */
  119. #endif /* UART4 */
  120. #if defined(UART5)
  121. uint32_t Uart5ClockSelection; /*!< Specifies UART5 clock source.
  122. This parameter can be a value of @ref RCCEx_UART5_Clock_Source */
  123. #endif /* UART5 */
  124. uint32_t Lpuart1ClockSelection; /*!< Specifies LPUART1 clock source.
  125. This parameter can be a value of @ref RCCEx_LPUART1_Clock_Source */
  126. uint32_t I2c1ClockSelection; /*!< Specifies I2C1 clock source.
  127. This parameter can be a value of @ref RCCEx_I2C1_Clock_Source */
  128. #if defined(I2C2)
  129. uint32_t I2c2ClockSelection; /*!< Specifies I2C2 clock source.
  130. This parameter can be a value of @ref RCCEx_I2C2_Clock_Source */
  131. #endif /* I2C2 */
  132. uint32_t I2c3ClockSelection; /*!< Specifies I2C3 clock source.
  133. This parameter can be a value of @ref RCCEx_I2C3_Clock_Source */
  134. #if defined(I2C4)
  135. uint32_t I2c4ClockSelection; /*!< Specifies I2C4 clock source.
  136. This parameter can be a value of @ref RCCEx_I2C4_Clock_Source */
  137. #endif /* I2C4 */
  138. uint32_t Lptim1ClockSelection; /*!< Specifies LPTIM1 clock source.
  139. This parameter can be a value of @ref RCCEx_LPTIM1_Clock_Source */
  140. uint32_t Lptim2ClockSelection; /*!< Specifies LPTIM2 clock source.
  141. This parameter can be a value of @ref RCCEx_LPTIM2_Clock_Source */
  142. uint32_t Sai1ClockSelection; /*!< Specifies SAI1 clock source.
  143. This parameter can be a value of @ref RCCEx_SAI1_Clock_Source */
  144. #if defined(SAI2)
  145. uint32_t Sai2ClockSelection; /*!< Specifies SAI2 clock source.
  146. This parameter can be a value of @ref RCCEx_SAI2_Clock_Source */
  147. #endif /* SAI2 */
  148. #if defined(USB_OTG_FS) || defined(USB)
  149. uint32_t UsbClockSelection; /*!< Specifies USB clock source (warning: same source for SDMMC1 and RNG).
  150. This parameter can be a value of @ref RCCEx_USB_Clock_Source */
  151. #endif /* USB_OTG_FS || USB */
  152. #if defined(SDMMC1)
  153. uint32_t Sdmmc1ClockSelection; /*!< Specifies SDMMC1 clock source (warning: same source for USB and RNG).
  154. This parameter can be a value of @ref RCCEx_SDMMC1_Clock_Source */
  155. #endif /* SDMMC1 */
  156. uint32_t RngClockSelection; /*!< Specifies RNG clock source (warning: same source for USB and SDMMC1).
  157. This parameter can be a value of @ref RCCEx_RNG_Clock_Source */
  158. uint32_t AdcClockSelection; /*!< Specifies ADC interface clock source.
  159. This parameter can be a value of @ref RCCEx_ADC_Clock_Source */
  160. #if defined(SWPMI1)
  161. uint32_t Swpmi1ClockSelection; /*!< Specifies SWPMI1 clock source.
  162. This parameter can be a value of @ref RCCEx_SWPMI1_Clock_Source */
  163. #endif /* SWPMI1 */
  164. #if defined(DFSDM1_Filter0)
  165. uint32_t Dfsdm1ClockSelection; /*!< Specifies DFSDM1 clock source.
  166. This parameter can be a value of @ref RCCEx_DFSDM1_Clock_Source */
  167. #endif /* DFSDM1_Filter0 */
  168. uint32_t RTCClockSelection; /*!< Specifies RTC clock source.
  169. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  170. }RCC_PeriphCLKInitTypeDef;
  171. #if defined(CRS)
  172. /**
  173. * @brief RCC_CRS Init structure definition
  174. */
  175. typedef struct
  176. {
  177. uint32_t Prescaler; /*!< Specifies the division factor of the SYNC signal.
  178. This parameter can be a value of @ref RCCEx_CRS_SynchroDivider */
  179. uint32_t Source; /*!< Specifies the SYNC signal source.
  180. This parameter can be a value of @ref RCCEx_CRS_SynchroSource */
  181. uint32_t Polarity; /*!< Specifies the input polarity for the SYNC signal source.
  182. This parameter can be a value of @ref RCCEx_CRS_SynchroPolarity */
  183. uint32_t ReloadValue; /*!< Specifies the value to be loaded in the frequency error counter with each SYNC event.
  184. It can be calculated in using macro __HAL_RCC_CRS_RELOADVALUE_CALCULATE(__FTARGET__, __FSYNC__)
  185. This parameter must be a number between 0 and 0xFFFF or a value of @ref RCCEx_CRS_ReloadValueDefault .*/
  186. uint32_t ErrorLimitValue; /*!< Specifies the value to be used to evaluate the captured frequency error value.
  187. This parameter must be a number between 0 and 0xFF or a value of @ref RCCEx_CRS_ErrorLimitDefault */
  188. uint32_t HSI48CalibrationValue; /*!< Specifies a user-programmable trimming value to the HSI48 oscillator.
  189. This parameter must be a number between 0 and 0x3F or a value of @ref RCCEx_CRS_HSI48CalibrationDefault */
  190. }RCC_CRSInitTypeDef;
  191. /**
  192. * @brief RCC_CRS Synchronization structure definition
  193. */
  194. typedef struct
  195. {
  196. uint32_t ReloadValue; /*!< Specifies the value loaded in the Counter reload value.
  197. This parameter must be a number between 0 and 0xFFFF */
  198. uint32_t HSI48CalibrationValue; /*!< Specifies value loaded in HSI48 oscillator smooth trimming.
  199. This parameter must be a number between 0 and 0x3F */
  200. uint32_t FreqErrorCapture; /*!< Specifies the value loaded in the .FECAP, the frequency error counter
  201. value latched in the time of the last SYNC event.
  202. This parameter must be a number between 0 and 0xFFFF */
  203. uint32_t FreqErrorDirection; /*!< Specifies the value loaded in the .FEDIR, the counting direction of the
  204. frequency error counter latched in the time of the last SYNC event.
  205. It shows whether the actual frequency is below or above the target.
  206. This parameter must be a value of @ref RCCEx_CRS_FreqErrorDirection*/
  207. }RCC_CRSSynchroInfoTypeDef;
  208. #endif /* CRS */
  209. /**
  210. * @}
  211. */
  212. /* Exported constants --------------------------------------------------------*/
  213. /** @defgroup RCCEx_Exported_Constants RCCEx Exported Constants
  214. * @{
  215. */
  216. /** @defgroup RCCEx_LSCO_Clock_Source Low Speed Clock Source
  217. * @{
  218. */
  219. #define RCC_LSCOSOURCE_LSI (uint32_t)0x00000000U /*!< LSI selection for low speed clock output */
  220. #define RCC_LSCOSOURCE_LSE RCC_BDCR_LSCOSEL /*!< LSE selection for low speed clock output */
  221. /**
  222. * @}
  223. */
  224. /** @defgroup RCCEx_Periph_Clock_Selection Periph Clock Selection
  225. * @{
  226. */
  227. #define RCC_PERIPHCLK_USART1 ((uint32_t)0x00000001U)
  228. #define RCC_PERIPHCLK_USART2 ((uint32_t)0x00000002U)
  229. #if defined(USART3)
  230. #define RCC_PERIPHCLK_USART3 ((uint32_t)0x00000004U)
  231. #endif
  232. #if defined(UART4)
  233. #define RCC_PERIPHCLK_UART4 ((uint32_t)0x00000008U)
  234. #endif
  235. #if defined(UART5)
  236. #define RCC_PERIPHCLK_UART5 ((uint32_t)0x00000010U)
  237. #endif
  238. #define RCC_PERIPHCLK_LPUART1 ((uint32_t)0x00000020U)
  239. #define RCC_PERIPHCLK_I2C1 ((uint32_t)0x00000040U)
  240. #if defined(I2C2)
  241. #define RCC_PERIPHCLK_I2C2 ((uint32_t)0x00000080U)
  242. #endif
  243. #define RCC_PERIPHCLK_I2C3 ((uint32_t)0x00000100U)
  244. #define RCC_PERIPHCLK_LPTIM1 ((uint32_t)0x00000200U)
  245. #define RCC_PERIPHCLK_LPTIM2 ((uint32_t)0x00000400U)
  246. #define RCC_PERIPHCLK_SAI1 ((uint32_t)0x00000800U)
  247. #if defined(SAI2)
  248. #define RCC_PERIPHCLK_SAI2 ((uint32_t)0x00001000U)
  249. #endif
  250. #if defined(USB_OTG_FS) || defined(USB)
  251. #define RCC_PERIPHCLK_USB ((uint32_t)0x00002000U)
  252. #endif
  253. #define RCC_PERIPHCLK_ADC ((uint32_t)0x00004000U)
  254. #if defined(SWPMI1)
  255. #define RCC_PERIPHCLK_SWPMI1 ((uint32_t)0x00008000U)
  256. #endif
  257. #if defined(DFSDM1_Filter0)
  258. #define RCC_PERIPHCLK_DFSDM1 ((uint32_t)0x00010000U)
  259. #endif
  260. #define RCC_PERIPHCLK_RTC ((uint32_t)0x00020000U)
  261. #define RCC_PERIPHCLK_RNG ((uint32_t)0x00040000U)
  262. #if defined(SDMMC1)
  263. #define RCC_PERIPHCLK_SDMMC1 ((uint32_t)0x00080000U)
  264. #endif
  265. #if defined(I2C4)
  266. #define RCC_PERIPHCLK_I2C4 ((uint32_t)0x00100000U)
  267. #endif
  268. /**
  269. * @}
  270. */
  271. /** @defgroup RCCEx_USART1_Clock_Source USART1 Clock Source
  272. * @{
  273. */
  274. #define RCC_USART1CLKSOURCE_PCLK2 ((uint32_t)0x00000000U)
  275. #define RCC_USART1CLKSOURCE_SYSCLK RCC_CCIPR_USART1SEL_0
  276. #define RCC_USART1CLKSOURCE_HSI RCC_CCIPR_USART1SEL_1
  277. #define RCC_USART1CLKSOURCE_LSE (RCC_CCIPR_USART1SEL_0 | RCC_CCIPR_USART1SEL_1)
  278. /**
  279. * @}
  280. */
  281. /** @defgroup RCCEx_USART2_Clock_Source USART2 Clock Source
  282. * @{
  283. */
  284. #define RCC_USART2CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  285. #define RCC_USART2CLKSOURCE_SYSCLK RCC_CCIPR_USART2SEL_0
  286. #define RCC_USART2CLKSOURCE_HSI RCC_CCIPR_USART2SEL_1
  287. #define RCC_USART2CLKSOURCE_LSE (RCC_CCIPR_USART2SEL_0 | RCC_CCIPR_USART2SEL_1)
  288. /**
  289. * @}
  290. */
  291. #if defined(USART3)
  292. /** @defgroup RCCEx_USART3_Clock_Source USART3 Clock Source
  293. * @{
  294. */
  295. #define RCC_USART3CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  296. #define RCC_USART3CLKSOURCE_SYSCLK RCC_CCIPR_USART3SEL_0
  297. #define RCC_USART3CLKSOURCE_HSI RCC_CCIPR_USART3SEL_1
  298. #define RCC_USART3CLKSOURCE_LSE (RCC_CCIPR_USART3SEL_0 | RCC_CCIPR_USART3SEL_1)
  299. /**
  300. * @}
  301. */
  302. #endif /* USART3 */
  303. #if defined(UART4)
  304. /** @defgroup RCCEx_UART4_Clock_Source UART4 Clock Source
  305. * @{
  306. */
  307. #define RCC_UART4CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  308. #define RCC_UART4CLKSOURCE_SYSCLK RCC_CCIPR_UART4SEL_0
  309. #define RCC_UART4CLKSOURCE_HSI RCC_CCIPR_UART4SEL_1
  310. #define RCC_UART4CLKSOURCE_LSE (RCC_CCIPR_UART4SEL_0 | RCC_CCIPR_UART4SEL_1)
  311. /**
  312. * @}
  313. */
  314. #endif /* UART4 */
  315. #if defined(UART5)
  316. /** @defgroup RCCEx_UART5_Clock_Source UART5 Clock Source
  317. * @{
  318. */
  319. #define RCC_UART5CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  320. #define RCC_UART5CLKSOURCE_SYSCLK RCC_CCIPR_UART5SEL_0
  321. #define RCC_UART5CLKSOURCE_HSI RCC_CCIPR_UART5SEL_1
  322. #define RCC_UART5CLKSOURCE_LSE (RCC_CCIPR_UART5SEL_0 | RCC_CCIPR_UART5SEL_1)
  323. /**
  324. * @}
  325. */
  326. #endif /* UART5 */
  327. /** @defgroup RCCEx_LPUART1_Clock_Source LPUART1 Clock Source
  328. * @{
  329. */
  330. #define RCC_LPUART1CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  331. #define RCC_LPUART1CLKSOURCE_SYSCLK RCC_CCIPR_LPUART1SEL_0
  332. #define RCC_LPUART1CLKSOURCE_HSI RCC_CCIPR_LPUART1SEL_1
  333. #define RCC_LPUART1CLKSOURCE_LSE (RCC_CCIPR_LPUART1SEL_0 | RCC_CCIPR_LPUART1SEL_1)
  334. /**
  335. * @}
  336. */
  337. /** @defgroup RCCEx_I2C1_Clock_Source I2C1 Clock Source
  338. * @{
  339. */
  340. #define RCC_I2C1CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  341. #define RCC_I2C1CLKSOURCE_SYSCLK RCC_CCIPR_I2C1SEL_0
  342. #define RCC_I2C1CLKSOURCE_HSI RCC_CCIPR_I2C1SEL_1
  343. /**
  344. * @}
  345. */
  346. #if defined(I2C2)
  347. /** @defgroup RCCEx_I2C2_Clock_Source I2C2 Clock Source
  348. * @{
  349. */
  350. #define RCC_I2C2CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  351. #define RCC_I2C2CLKSOURCE_SYSCLK RCC_CCIPR_I2C2SEL_0
  352. #define RCC_I2C2CLKSOURCE_HSI RCC_CCIPR_I2C2SEL_1
  353. /**
  354. * @}
  355. */
  356. #endif /* I2C2 */
  357. /** @defgroup RCCEx_I2C3_Clock_Source I2C3 Clock Source
  358. * @{
  359. */
  360. #define RCC_I2C3CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  361. #define RCC_I2C3CLKSOURCE_SYSCLK RCC_CCIPR_I2C3SEL_0
  362. #define RCC_I2C3CLKSOURCE_HSI RCC_CCIPR_I2C3SEL_1
  363. /**
  364. * @}
  365. */
  366. #if defined(I2C4)
  367. /** @defgroup RCCEx_I2C4_Clock_Source I2C4 Clock Source
  368. * @{
  369. */
  370. #define RCC_I2C4CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  371. #define RCC_I2C4CLKSOURCE_SYSCLK RCC_CCIPR2_I2C4SEL_0
  372. #define RCC_I2C4CLKSOURCE_HSI RCC_CCIPR2_I2C4SEL_1
  373. /**
  374. * @}
  375. */
  376. #endif /* I2C4 */
  377. /** @defgroup RCCEx_SAI1_Clock_Source SAI1 Clock Source
  378. * @{
  379. */
  380. #define RCC_SAI1CLKSOURCE_PLLSAI1 ((uint32_t)0x00000000U)
  381. #if defined(RCC_PLLSAI2_SUPPORT)
  382. #define RCC_SAI1CLKSOURCE_PLLSAI2 RCC_CCIPR_SAI1SEL_0
  383. #endif /* RCC_PLLSAI2_SUPPORT */
  384. #define RCC_SAI1CLKSOURCE_PLL RCC_CCIPR_SAI1SEL_1
  385. #define RCC_SAI1CLKSOURCE_PIN RCC_CCIPR_SAI1SEL
  386. /**
  387. * @}
  388. */
  389. #if defined(SAI2)
  390. /** @defgroup RCCEx_SAI2_Clock_Source SAI2 Clock Source
  391. * @{
  392. */
  393. #define RCC_SAI2CLKSOURCE_PLLSAI1 ((uint32_t)0x00000000U)
  394. #define RCC_SAI2CLKSOURCE_PLLSAI2 RCC_CCIPR_SAI2SEL_0
  395. #define RCC_SAI2CLKSOURCE_PLL RCC_CCIPR_SAI2SEL_1
  396. #define RCC_SAI2CLKSOURCE_PIN RCC_CCIPR_SAI2SEL
  397. /**
  398. * @}
  399. */
  400. #endif /* SAI2 */
  401. /** @defgroup RCCEx_LPTIM1_Clock_Source LPTIM1 Clock Source
  402. * @{
  403. */
  404. #define RCC_LPTIM1CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  405. #define RCC_LPTIM1CLKSOURCE_LSI RCC_CCIPR_LPTIM1SEL_0
  406. #define RCC_LPTIM1CLKSOURCE_HSI RCC_CCIPR_LPTIM1SEL_1
  407. #define RCC_LPTIM1CLKSOURCE_LSE RCC_CCIPR_LPTIM1SEL
  408. /**
  409. * @}
  410. */
  411. /** @defgroup RCCEx_LPTIM2_Clock_Source LPTIM2 Clock Source
  412. * @{
  413. */
  414. #define RCC_LPTIM2CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  415. #define RCC_LPTIM2CLKSOURCE_LSI RCC_CCIPR_LPTIM2SEL_0
  416. #define RCC_LPTIM2CLKSOURCE_HSI RCC_CCIPR_LPTIM2SEL_1
  417. #define RCC_LPTIM2CLKSOURCE_LSE RCC_CCIPR_LPTIM2SEL
  418. /**
  419. * @}
  420. */
  421. #if defined(SDMMC1)
  422. /** @defgroup RCCEx_SDMMC1_Clock_Source SDMMC1 Clock Source
  423. * @{
  424. */
  425. #if defined(RCC_HSI48_SUPPORT)
  426. #define RCC_SDMMC1CLKSOURCE_HSI48 ((uint32_t)0x00000000U)
  427. #else
  428. #define RCC_SDMMC1CLKSOURCE_NONE ((uint32_t)0x00000000U)
  429. #endif /* RCC_HSI48_SUPPORT */
  430. #define RCC_SDMMC1CLKSOURCE_PLLSAI1 RCC_CCIPR_CLK48SEL_0
  431. #define RCC_SDMMC1CLKSOURCE_PLL RCC_CCIPR_CLK48SEL_1
  432. #define RCC_SDMMC1CLKSOURCE_MSI RCC_CCIPR_CLK48SEL
  433. /**
  434. * @}
  435. */
  436. #endif /* SDMMC1 */
  437. /** @defgroup RCCEx_RNG_Clock_Source RNG Clock Source
  438. * @{
  439. */
  440. #if defined(RCC_HSI48_SUPPORT)
  441. #define RCC_RNGCLKSOURCE_HSI48 ((uint32_t)0x00000000U)
  442. #else
  443. #define RCC_RNGCLKSOURCE_NONE ((uint32_t)0x00000000U)
  444. #endif /* RCC_HSI48_SUPPORT */
  445. #define RCC_RNGCLKSOURCE_PLLSAI1 RCC_CCIPR_CLK48SEL_0
  446. #define RCC_RNGCLKSOURCE_PLL RCC_CCIPR_CLK48SEL_1
  447. #define RCC_RNGCLKSOURCE_MSI RCC_CCIPR_CLK48SEL
  448. /**
  449. * @}
  450. */
  451. #if defined(USB_OTG_FS) || defined(USB)
  452. /** @defgroup RCCEx_USB_Clock_Source USB Clock Source
  453. * @{
  454. */
  455. #if defined(RCC_HSI48_SUPPORT)
  456. #define RCC_USBCLKSOURCE_HSI48 ((uint32_t)0x00000000U)
  457. #else
  458. #define RCC_USBCLKSOURCE_NONE ((uint32_t)0x00000000U)
  459. #endif /* RCC_HSI48_SUPPORT */
  460. #define RCC_USBCLKSOURCE_PLLSAI1 RCC_CCIPR_CLK48SEL_0
  461. #define RCC_USBCLKSOURCE_PLL RCC_CCIPR_CLK48SEL_1
  462. #define RCC_USBCLKSOURCE_MSI RCC_CCIPR_CLK48SEL
  463. /**
  464. * @}
  465. */
  466. #endif /* USB_OTG_FS || USB */
  467. /** @defgroup RCCEx_ADC_Clock_Source ADC Clock Source
  468. * @{
  469. */
  470. #define RCC_ADCCLKSOURCE_NONE ((uint32_t)0x00000000U)
  471. #define RCC_ADCCLKSOURCE_PLLSAI1 RCC_CCIPR_ADCSEL_0
  472. #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || defined(STM32L496xx) || defined(STM32L4A6xx)
  473. #define RCC_ADCCLKSOURCE_PLLSAI2 RCC_CCIPR_ADCSEL_1
  474. #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || STM32L496xx || STM32L4A6xx */
  475. #define RCC_ADCCLKSOURCE_SYSCLK RCC_CCIPR_ADCSEL
  476. /**
  477. * @}
  478. */
  479. #if defined(SWPMI1)
  480. /** @defgroup RCCEx_SWPMI1_Clock_Source SWPMI1 Clock Source
  481. * @{
  482. */
  483. #define RCC_SWPMI1CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
  484. #define RCC_SWPMI1CLKSOURCE_HSI RCC_CCIPR_SWPMI1SEL
  485. /**
  486. * @}
  487. */
  488. #endif /* SWPMI1 */
  489. #if defined(DFSDM1_Filter0)
  490. /** @defgroup RCCEx_DFSDM1_Clock_Source DFSDM1 Clock Source
  491. * @{
  492. */
  493. #define RCC_DFSDM1CLKSOURCE_PCLK2 ((uint32_t)0x00000000U)
  494. #define RCC_DFSDM1CLKSOURCE_SYSCLK RCC_CCIPR_DFSDM1SEL
  495. /**
  496. * @}
  497. */
  498. #endif /* DFSDM1_Filter0 */
  499. /** @defgroup RCCEx_EXTI_LINE_LSECSS RCC LSE CSS external interrupt line
  500. * @{
  501. */
  502. #define RCC_EXTI_LINE_LSECSS EXTI_IMR1_IM19 /*!< External interrupt line 19 connected to the LSE CSS EXTI Line */
  503. /**
  504. * @}
  505. */
  506. #if defined(CRS)
  507. /** @defgroup RCCEx_CRS_Status RCCEx CRS Status
  508. * @{
  509. */
  510. #define RCC_CRS_NONE ((uint32_t)0x00000000U)
  511. #define RCC_CRS_TIMEOUT ((uint32_t)0x00000001U)
  512. #define RCC_CRS_SYNCOK ((uint32_t)0x00000002U)
  513. #define RCC_CRS_SYNCWARN ((uint32_t)0x00000004U)
  514. #define RCC_CRS_SYNCERR ((uint32_t)0x00000008U)
  515. #define RCC_CRS_SYNCMISS ((uint32_t)0x00000010U)
  516. #define RCC_CRS_TRIMOVF ((uint32_t)0x00000020U)
  517. /**
  518. * @}
  519. */
  520. /** @defgroup RCCEx_CRS_SynchroSource RCCEx CRS SynchroSource
  521. * @{
  522. */
  523. #define RCC_CRS_SYNC_SOURCE_GPIO ((uint32_t)0x00000000U) /*!< Synchro Signal source GPIO */
  524. #define RCC_CRS_SYNC_SOURCE_LSE CRS_CFGR_SYNCSRC_0 /*!< Synchro Signal source LSE */
  525. #define RCC_CRS_SYNC_SOURCE_USB CRS_CFGR_SYNCSRC_1 /*!< Synchro Signal source USB SOF (default)*/
  526. /**
  527. * @}
  528. */
  529. /** @defgroup RCCEx_CRS_SynchroDivider RCCEx CRS SynchroDivider
  530. * @{
  531. */
  532. #define RCC_CRS_SYNC_DIV1 ((uint32_t)0x00000000U) /*!< Synchro Signal not divided (default) */
  533. #define RCC_CRS_SYNC_DIV2 CRS_CFGR_SYNCDIV_0 /*!< Synchro Signal divided by 2 */
  534. #define RCC_CRS_SYNC_DIV4 CRS_CFGR_SYNCDIV_1 /*!< Synchro Signal divided by 4 */
  535. #define RCC_CRS_SYNC_DIV8 (CRS_CFGR_SYNCDIV_1 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 8 */
  536. #define RCC_CRS_SYNC_DIV16 CRS_CFGR_SYNCDIV_2 /*!< Synchro Signal divided by 16 */
  537. #define RCC_CRS_SYNC_DIV32 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 32 */
  538. #define RCC_CRS_SYNC_DIV64 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_1) /*!< Synchro Signal divided by 64 */
  539. #define RCC_CRS_SYNC_DIV128 CRS_CFGR_SYNCDIV /*!< Synchro Signal divided by 128 */
  540. /**
  541. * @}
  542. */
  543. /** @defgroup RCCEx_CRS_SynchroPolarity RCCEx CRS SynchroPolarity
  544. * @{
  545. */
  546. #define RCC_CRS_SYNC_POLARITY_RISING ((uint32_t)0x00000000U) /*!< Synchro Active on rising edge (default) */
  547. #define RCC_CRS_SYNC_POLARITY_FALLING CRS_CFGR_SYNCPOL /*!< Synchro Active on falling edge */
  548. /**
  549. * @}
  550. */
  551. /** @defgroup RCCEx_CRS_ReloadValueDefault RCCEx CRS ReloadValueDefault
  552. * @{
  553. */
  554. #define RCC_CRS_RELOADVALUE_DEFAULT ((uint32_t)0x0000BB7FU) /*!< The reset value of the RELOAD field corresponds
  555. to a target frequency of 48 MHz and a synchronization signal frequency of 1 kHz (SOF signal from USB). */
  556. /**
  557. * @}
  558. */
  559. /** @defgroup RCCEx_CRS_ErrorLimitDefault RCCEx CRS ErrorLimitDefault
  560. * @{
  561. */
  562. #define RCC_CRS_ERRORLIMIT_DEFAULT ((uint32_t)0x00000022U) /*!< Default Frequency error limit */
  563. /**
  564. * @}
  565. */
  566. /** @defgroup RCCEx_CRS_HSI48CalibrationDefault RCCEx CRS HSI48CalibrationDefault
  567. * @{
  568. */
  569. #define RCC_CRS_HSI48CALIBRATION_DEFAULT ((uint32_t)0x00000020U) /*!< The default value is 32, which corresponds to the middle of the trimming interval.
  570. The trimming step is around 67 kHz between two consecutive TRIM steps. A higher TRIM value
  571. corresponds to a higher output frequency */
  572. /**
  573. * @}
  574. */
  575. /** @defgroup RCCEx_CRS_FreqErrorDirection RCCEx CRS FreqErrorDirection
  576. * @{
  577. */
  578. #define RCC_CRS_FREQERRORDIR_UP ((uint32_t)0x00000000U) /*!< Upcounting direction, the actual frequency is above the target */
  579. #define RCC_CRS_FREQERRORDIR_DOWN ((uint32_t)CRS_ISR_FEDIR) /*!< Downcounting direction, the actual frequency is below the target */
  580. /**
  581. * @}
  582. */
  583. /** @defgroup RCCEx_CRS_Interrupt_Sources RCCEx CRS Interrupt Sources
  584. * @{
  585. */
  586. #define RCC_CRS_IT_SYNCOK CRS_CR_SYNCOKIE /*!< SYNC event OK */
  587. #define RCC_CRS_IT_SYNCWARN CRS_CR_SYNCWARNIE /*!< SYNC warning */
  588. #define RCC_CRS_IT_ERR CRS_CR_ERRIE /*!< Error */
  589. #define RCC_CRS_IT_ESYNC CRS_CR_ESYNCIE /*!< Expected SYNC */
  590. #define RCC_CRS_IT_SYNCERR CRS_CR_ERRIE /*!< SYNC error */
  591. #define RCC_CRS_IT_SYNCMISS CRS_CR_ERRIE /*!< SYNC missed */
  592. #define RCC_CRS_IT_TRIMOVF CRS_CR_ERRIE /*!< Trimming overflow or underflow */
  593. /**
  594. * @}
  595. */
  596. /** @defgroup RCCEx_CRS_Flags RCCEx CRS Flags
  597. * @{
  598. */
  599. #define RCC_CRS_FLAG_SYNCOK CRS_ISR_SYNCOKF /*!< SYNC event OK flag */
  600. #define RCC_CRS_FLAG_SYNCWARN CRS_ISR_SYNCWARNF /*!< SYNC warning flag */
  601. #define RCC_CRS_FLAG_ERR CRS_ISR_ERRF /*!< Error flag */
  602. #define RCC_CRS_FLAG_ESYNC CRS_ISR_ESYNCF /*!< Expected SYNC flag */
  603. #define RCC_CRS_FLAG_SYNCERR CRS_ISR_SYNCERR /*!< SYNC error */
  604. #define RCC_CRS_FLAG_SYNCMISS CRS_ISR_SYNCMISS /*!< SYNC missed*/
  605. #define RCC_CRS_FLAG_TRIMOVF CRS_ISR_TRIMOVF /*!< Trimming overflow or underflow */
  606. /**
  607. * @}
  608. */
  609. #endif /* CRS */
  610. /**
  611. * @}
  612. */
  613. /* Exported macros -----------------------------------------------------------*/
  614. /** @defgroup RCCEx_Exported_Macros RCCEx Exported Macros
  615. * @{
  616. */
  617. /**
  618. * @brief Macro to configure the PLLSAI1 clock multiplication and division factors.
  619. *
  620. * @note This function must be used only when the PLLSAI1 is disabled.
  621. * @note PLLSAI1 clock source is common with the main PLL (configured through
  622. * __HAL_RCC_PLL_CONFIG() macro)
  623. *
  624. * @param __PLLSAI1N__ specifies the multiplication factor for PLLSAI1 VCO output clock.
  625. * This parameter must be a number between 8 and 86.
  626. * @note You have to set the PLLSAI1N parameter correctly to ensure that the VCO
  627. * output frequency is between 64 and 344 MHz.
  628. * PLLSAI1 clock frequency = f(PLLSAI1) multiplied by PLLSAI1N
  629. *
  630. * @param __PLLSAI1P__ specifies the division factor for SAI clock.
  631. * This parameter must be a number in the range (7 or 17) for STM32L47xxx/L48xxx
  632. * else (2 to 31).
  633. * SAI1 clock frequency = f(PLLSAI1) / PLLSAI1P
  634. *
  635. * @param __PLLSAI1Q__ specifies the division factor for USB/RNG/SDMMC1 clock.
  636. * This parameter must be in the range (2, 4, 6 or 8).
  637. * USB/RNG/SDMMC1 clock frequency = f(PLLSAI1) / PLLSAI1Q
  638. *
  639. * @param __PLLSAI1R__ specifies the division factor for SAR ADC clock.
  640. * This parameter must be in the range (2, 4, 6 or 8).
  641. * ADC clock frequency = f(PLLSAI1) / PLLSAI1R
  642. *
  643. * @retval None
  644. */
  645. #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
  646. #define __HAL_RCC_PLLSAI1_CONFIG(__PLLSAI1N__, __PLLSAI1P__, __PLLSAI1Q__, __PLLSAI1R__) \
  647. WRITE_REG(RCC->PLLSAI1CFGR, ((__PLLSAI1N__) << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) | \
  648. ((((__PLLSAI1Q__) >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1Q_Pos) | \
  649. ((((__PLLSAI1R__) >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1R_Pos) | \
  650. ((__PLLSAI1P__) << RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos))
  651. #else
  652. #define __HAL_RCC_PLLSAI1_CONFIG(__PLLSAI1N__, __PLLSAI1P__, __PLLSAI1Q__, __PLLSAI1R__) \
  653. WRITE_REG(RCC->PLLSAI1CFGR, ((__PLLSAI1N__) << RCC_PLLSAI1CFGR_PLLSAI1N_Pos) | \
  654. (((__PLLSAI1P__) >> 4U) << RCC_PLLSAI1CFGR_PLLSAI1P_Pos) | \
  655. ((((__PLLSAI1Q__) >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1Q_Pos) | \
  656. ((((__PLLSAI1R__) >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1R_Pos))
  657. #endif /* RCC_PLLSAI1P_DIV_2_31_SUPPORT */
  658. /**
  659. * @brief Macro to configure the PLLSAI1 clock multiplication factor N.
  660. *
  661. * @note This function must be used only when the PLLSAI1 is disabled.
  662. * @note PLLSAI1 clock source is common with the main PLL (configured through
  663. * __HAL_RCC_PLL_CONFIG() macro)
  664. *
  665. * @param __PLLSAI1N__ specifies the multiplication factor for PLLSAI1 VCO output clock.
  666. * This parameter must be a number between 8 and 86.
  667. * @note You have to set the PLLSAI1N parameter correctly to ensure that the VCO
  668. * output frequency is between 64 and 344 MHz.
  669. * Use to set PLLSAI1 clock frequency = f(PLLSAI1) multiplied by PLLSAI1N
  670. *
  671. * @retval None
  672. */
  673. #define __HAL_RCC_PLLSAI1_MULN_CONFIG(__PLLSAI1N__) \
  674. MODIFY_REG(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1N, (__PLLSAI1N__) << RCC_PLLSAI1CFGR_PLLSAI1N_Pos)
  675. /** @brief Macro to configure the PLLSAI1 clock division factor P.
  676. *
  677. * @note This function must be used only when the PLLSAI1 is disabled.
  678. * @note PLLSAI1 clock source is common with the main PLL (configured through
  679. * __HAL_RCC_PLL_CONFIG() macro)
  680. *
  681. * @param __PLLSAI1P__ specifies the division factor for SAI clock.
  682. * This parameter must be a number in the range (7 or 17) for STM32L47xxx/L48xxx
  683. * else (2 to 31).
  684. * Use to set SAI1 clock frequency = f(PLLSAI1) / PLLSAI1P
  685. *
  686. * @retval None
  687. */
  688. #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
  689. #define __HAL_RCC_PLLSAI1_DIVP_CONFIG(__PLLSAI1P__) \
  690. MODIFY_REG(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1PDIV, (__PLLSAI1P__) << RCC_PLLSAI1CFGR_PLLSAI1PDIV_Pos)
  691. #else
  692. #define __HAL_RCC_PLLSAI1_DIVP_CONFIG(__PLLSAI1P__) \
  693. MODIFY_REG(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1P, ((__PLLSAI1P__) >> 4U) << RCC_PLLSAI1CFGR_PLLSAI1P_Pos)
  694. #endif /* RCC_PLLSAI1P_DIV_2_31_SUPPORT */
  695. /** @brief Macro to configure the PLLSAI1 clock division factor Q.
  696. *
  697. * @note This function must be used only when the PLLSAI1 is disabled.
  698. * @note PLLSAI1 clock source is common with the main PLL (configured through
  699. * __HAL_RCC_PLL_CONFIG() macro)
  700. *
  701. * @param __PLLSAI1Q__ specifies the division factor for USB/RNG/SDMMC1 clock.
  702. * This parameter must be in the range (2, 4, 6 or 8).
  703. * Use to set USB/RNG/SDMMC1 clock frequency = f(PLLSAI1) / PLLSAI1Q
  704. *
  705. * @retval None
  706. */
  707. #define __HAL_RCC_PLLSAI1_DIVQ_CONFIG(__PLLSAI1Q__) \
  708. MODIFY_REG(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1Q, (((__PLLSAI1Q__) >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1Q_Pos)
  709. /** @brief Macro to configure the PLLSAI1 clock division factor R.
  710. *
  711. * @note This function must be used only when the PLLSAI1 is disabled.
  712. * @note PLLSAI1 clock source is common with the main PLL (configured through
  713. * __HAL_RCC_PLL_CONFIG() macro)
  714. *
  715. * @param __PLLSAI1R__ specifies the division factor for ADC clock.
  716. * This parameter must be in the range (2, 4, 6 or 8)
  717. * Use to set ADC clock frequency = f(PLLSAI1) / PLLSAI1R
  718. *
  719. * @retval None
  720. */
  721. #define __HAL_RCC_PLLSAI1_DIVR_CONFIG(__PLLSAI1R__) \
  722. MODIFY_REG(RCC->PLLSAI1CFGR, RCC_PLLSAI1CFGR_PLLSAI1R, (((__PLLSAI1R__) >> 1U) - 1U) << RCC_PLLSAI1CFGR_PLLSAI1R_Pos)
  723. /**
  724. * @brief Macros to enable or disable the PLLSAI1.
  725. * @note The PLLSAI1 is disabled by hardware when entering STOP and STANDBY modes.
  726. * @retval None
  727. */
  728. #define __HAL_RCC_PLLSAI1_ENABLE() SET_BIT(RCC->CR, RCC_CR_PLLSAI1ON)
  729. #define __HAL_RCC_PLLSAI1_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_PLLSAI1ON)
  730. /**
  731. * @brief Macros to enable or disable each clock output (PLLSAI1_SAI1, PLLSAI1_USB2 and PLLSAI1_ADC1).
  732. * @note Enabling and disabling those clocks can be done without the need to stop the PLL.
  733. * This is mainly used to save Power.
  734. * @param __PLLSAI1_CLOCKOUT__ specifies the PLLSAI1 clock to be output.
  735. * This parameter can be one or a combination of the following values:
  736. * @arg @ref RCC_PLLSAI1_SAI1CLK This clock is used to generate an accurate clock to achieve
  737. * high-quality audio performance on SAI interface in case.
  738. * @arg @ref RCC_PLLSAI1_48M2CLK This clock is used to generate the clock for the USB OTG FS (48 MHz),
  739. * the random number generator (<=48 MHz) and the SDIO (<= 48 MHz).
  740. * @arg @ref RCC_PLLSAI1_ADC1CLK Clock used to clock ADC peripheral.
  741. * @retval None
  742. */
  743. #define __HAL_RCC_PLLSAI1CLKOUT_ENABLE(__PLLSAI1_CLOCKOUT__) SET_BIT(RCC->PLLSAI1CFGR, (__PLLSAI1_CLOCKOUT__))
  744. #define __HAL_RCC_PLLSAI1CLKOUT_DISABLE(__PLLSAI1_CLOCKOUT__) CLEAR_BIT(RCC->PLLSAI1CFGR, (__PLLSAI1_CLOCKOUT__))
  745. /**
  746. * @brief Macro to get clock output enable status (PLLSAI1_SAI1, PLLSAI1_USB2 and PLLSAI1_ADC1).
  747. * @param __PLLSAI1_CLOCKOUT__ specifies the PLLSAI1 clock to be output.
  748. * This parameter can be one of the following values:
  749. * @arg @ref RCC_PLLSAI1_SAI1CLK This clock is used to generate an accurate clock to achieve
  750. * high-quality audio performance on SAI interface in case.
  751. * @arg @ref RCC_PLLSAI1_48M2CLK This clock is used to generate the clock for the USB OTG FS (48 MHz),
  752. * the random number generator (<=48 MHz) and the SDIO (<= 48 MHz).
  753. * @arg @ref RCC_PLLSAI1_ADC1CLK Clock used to clock ADC peripheral.
  754. * @retval SET / RESET
  755. */
  756. #define __HAL_RCC_GET_PLLSAI1CLKOUT_CONFIG(__PLLSAI1_CLOCKOUT__) READ_BIT(RCC->PLLSAI1CFGR, (__PLLSAI1_CLOCKOUT__))
  757. #if defined(RCC_PLLSAI2_SUPPORT)
  758. /**
  759. * @brief Macro to configure the PLLSAI2 clock multiplication and division factors.
  760. *
  761. * @note This function must be used only when the PLLSAI2 is disabled.
  762. * @note PLLSAI2 clock source is common with the main PLL (configured through
  763. * __HAL_RCC_PLL_CONFIG() macro)
  764. *
  765. * @param __PLLSAI2N__ specifies the multiplication factor for PLLSAI2 VCO output clock.
  766. * This parameter must be a number between 8 and 86.
  767. * @note You have to set the PLLSAI2N parameter correctly to ensure that the VCO
  768. * output frequency is between 64 and 344 MHz.
  769. *
  770. * @param __PLLSAI2P__ specifies the division factor for SAI clock.
  771. * This parameter must be a number in the range (7 or 17) for STM32L47xxx/L48xxx
  772. * else (2 to 31).
  773. * SAI2 clock frequency = f(PLLSAI2) / PLLSAI2P
  774. *
  775. * @param __PLLSAI2R__ specifies the division factor for SAR ADC clock.
  776. * This parameter must be in the range (2, 4, 6 or 8).
  777. *
  778. * @retval None
  779. */
  780. #if defined(RCC_PLLSAI2P_DIV_2_31_SUPPORT)
  781. #define __HAL_RCC_PLLSAI2_CONFIG(__PLLSAI2N__, __PLLSAI2P__, __PLLSAI2R__) \
  782. WRITE_REG(RCC->PLLSAI2CFGR, ((__PLLSAI2N__) << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) | \
  783. ((((__PLLSAI2R__) >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2R_Pos) | \
  784. ((__PLLSAI2P__) << RCC_PLLSAI2CFGR_PLLSAI2PDIV_Pos))
  785. #else
  786. #define __HAL_RCC_PLLSAI2_CONFIG(__PLLSAI2N__, __PLLSAI2P__, __PLLSAI2R__) \
  787. WRITE_REG(RCC->PLLSAI2CFGR, ((__PLLSAI2N__) << RCC_PLLSAI2CFGR_PLLSAI2N_Pos) | \
  788. (((__PLLSAI2P__) >> 4U) << RCC_PLLSAI2CFGR_PLLSAI2P_Pos) | \
  789. ((((__PLLSAI2R__) >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2R_Pos))
  790. #endif /* RCC_PLLSAI2P_DIV_2_31_SUPPORT */
  791. /**
  792. * @brief Macro to configure the PLLSAI2 clock multiplication factor N.
  793. *
  794. * @note This function must be used only when the PLLSAI2 is disabled.
  795. * @note PLLSAI2 clock source is common with the main PLL (configured through
  796. * __HAL_RCC_PLL_CONFIG() macro)
  797. *
  798. * @param __PLLSAI2N__ specifies the multiplication factor for PLLSAI2 VCO output clock.
  799. * This parameter must be a number between 8 and 86.
  800. * @note You have to set the PLLSAI2N parameter correctly to ensure that the VCO
  801. * output frequency is between 64 and 344 MHz.
  802. * PLLSAI1 clock frequency = f(PLLSAI1) multiplied by PLLSAI2N
  803. *
  804. * @retval None
  805. */
  806. #define __HAL_RCC_PLLSAI2_MULN_CONFIG(__PLLSAI2N__) \
  807. MODIFY_REG(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2N, (__PLLSAI2N__) << RCC_PLLSAI2CFGR_PLLSAI2N_Pos)
  808. /** @brief Macro to configure the PLLSAI2 clock division factor P.
  809. *
  810. * @note This function must be used only when the PLLSAI2 is disabled.
  811. * @note PLLSAI2 clock source is common with the main PLL (configured through
  812. * __HAL_RCC_PLL_CONFIG() macro)
  813. *
  814. * @param __PLLSAI2P__ specifies the division factor.
  815. * This parameter must be a number in the range (7 or 17).
  816. * Use to set SAI2 clock frequency = f(PLLSAI2) / __PLLSAI2P__
  817. *
  818. * @retval None
  819. */
  820. #define __HAL_RCC_PLLSAI2_DIVP_CONFIG(__PLLSAI2P__) \
  821. MODIFY_REG(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2P, ((__PLLSAI2P__) >> 4U) << RCC_PLLSAI2CFGR_PLLSAI2P_Pos)
  822. /** @brief Macro to configure the PLLSAI2 clock division factor R.
  823. *
  824. * @note This function must be used only when the PLLSAI2 is disabled.
  825. * @note PLLSAI2 clock source is common with the main PLL (configured through
  826. * __HAL_RCC_PLL_CONFIG() macro)
  827. *
  828. * @param __PLLSAI2R__ specifies the division factor.
  829. * This parameter must be in the range (2, 4, 6 or 8).
  830. * Use to set ADC clock frequency = f(PLLSAI2) / __PLLSAI2R__
  831. *
  832. * @retval None
  833. */
  834. #define __HAL_RCC_PLLSAI2_DIVR_CONFIG(__PLLSAI2R__) \
  835. MODIFY_REG(RCC->PLLSAI2CFGR, RCC_PLLSAI2CFGR_PLLSAI2R, (((__PLLSAI2R__) >> 1U) - 1U) << RCC_PLLSAI2CFGR_PLLSAI2R_Pos)
  836. /**
  837. * @brief Macros to enable or disable the PLLSAI2.
  838. * @note The PLLSAI2 is disabled by hardware when entering STOP and STANDBY modes.
  839. * @retval None
  840. */
  841. #define __HAL_RCC_PLLSAI2_ENABLE() SET_BIT(RCC->CR, RCC_CR_PLLSAI2ON)
  842. #define __HAL_RCC_PLLSAI2_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_PLLSAI2ON)
  843. /**
  844. * @brief Macros to enable or disable each clock output (PLLSAI2_SAI2 and PLLSAI2_ADC2).
  845. * @note Enabling and disabling those clocks can be done without the need to stop the PLL.
  846. * This is mainly used to save Power.
  847. * @param __PLLSAI2_CLOCKOUT__ specifies the PLLSAI2 clock to be output.
  848. * This parameter can be one or a combination of the following values:
  849. * @arg @ref RCC_PLLSAI2_SAI2CLK This clock is used to generate an accurate clock to achieve
  850. * high-quality audio performance on SAI interface in case.
  851. * @arg @ref RCC_PLLSAI2_ADC2CLK Clock used to clock ADC peripheral.
  852. * @retval None
  853. */
  854. #define __HAL_RCC_PLLSAI2CLKOUT_ENABLE(__PLLSAI2_CLOCKOUT__) SET_BIT(RCC->PLLSAI2CFGR, (__PLLSAI2_CLOCKOUT__))
  855. #define __HAL_RCC_PLLSAI2CLKOUT_DISABLE(__PLLSAI2_CLOCKOUT__) CLEAR_BIT(RCC->PLLSAI2CFGR, (__PLLSAI2_CLOCKOUT__))
  856. /**
  857. * @brief Macro to get clock output enable status (PLLSAI2_SAI2 and PLLSAI2_ADC2).
  858. * @param __PLLSAI2_CLOCKOUT__ specifies the PLLSAI2 clock to be output.
  859. * This parameter can be one of the following values:
  860. * @arg @ref RCC_PLLSAI2_SAI2CLK This clock is used to generate an accurate clock to achieve
  861. * high-quality audio performance on SAI interface in case.
  862. * @arg @ref RCC_PLLSAI2_ADC2CLK Clock used to clock ADC peripheral.
  863. * @retval SET / RESET
  864. */
  865. #define __HAL_RCC_GET_PLLSAI2CLKOUT_CONFIG(__PLLSAI2_CLOCKOUT__) READ_BIT(RCC->PLLSAI2CFGR, (__PLLSAI2_CLOCKOUT__))
  866. #endif /* RCC_PLLSAI2_SUPPORT */
  867. /**
  868. * @brief Macro to configure the SAI1 clock source.
  869. * @param __SAI1_CLKSOURCE__ defines the SAI1 clock source. This clock is derived
  870. * from the PLLSAI1, system PLL or external clock (through a dedicated pin).
  871. * This parameter can be one of the following values:
  872. * @arg @ref RCC_SAI1CLKSOURCE_PLLSAI1 SAI1 clock = PLLSAI1 "P" clock (PLLSAI1CLK)
  873. @if STM32L486xx
  874. * @arg @ref RCC_SAI1CLKSOURCE_PLLSAI2 SAI1 clock = PLLSAI2 "P" clock (PLLSAI2CLK) for devices with PLLSAI2
  875. @endif
  876. @if STM32L4A6xx
  877. * @arg @ref RCC_SAI1CLKSOURCE_PLLSAI2 SAI1 clock = PLLSAI2 "P" clock (PLLSAI2CLK) for devices with PLLSAI2
  878. @endif
  879. * @arg @ref RCC_SAI1CLKSOURCE_PLL SAI1 clock = PLL "P" clock (PLLSAI3CLK if PLLSAI2 exists, else PLLSAI2CLK)
  880. * @arg @ref RCC_SAI1CLKSOURCE_PIN SAI1 clock = External Clock (SAI1_EXTCLK)
  881. *
  882. @if STM32L443xx
  883. * @note HSI16 is automatically set as SAI1 clock source when PLL are disabled for devices without PLLSAI2.
  884. @endif
  885. @if STM32L462xx
  886. * @note HSI16 is automatically set as SAI1 clock source when PLL are disabled for devices without PLLSAI2.
  887. @endif
  888. *
  889. * @retval None
  890. */
  891. #define __HAL_RCC_SAI1_CONFIG(__SAI1_CLKSOURCE__)\
  892. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_SAI1SEL, (uint32_t)(__SAI1_CLKSOURCE__))
  893. /** @brief Macro to get the SAI1 clock source.
  894. * @retval The clock source can be one of the following values:
  895. * @arg @ref RCC_SAI1CLKSOURCE_PLLSAI1 SAI1 clock = PLLSAI1 "P" clock (PLLSAI1CLK)
  896. @if STM32L486xx
  897. * @arg @ref RCC_SAI1CLKSOURCE_PLLSAI2 SAI1 clock = PLLSAI2 "P" clock (PLLSAI2CLK) for devices with PLLSAI2
  898. @endif
  899. @if STM32L4A6xx
  900. * @arg @ref RCC_SAI1CLKSOURCE_PLLSAI2 SAI1 clock = PLLSAI2 "P" clock (PLLSAI2CLK) for devices with PLLSAI2
  901. @endif
  902. * @arg @ref RCC_SAI1CLKSOURCE_PLL SAI1 clock = PLL "P" clock (PLLSAI3CLK if PLLSAI2 exists, else PLLSAI2CLK)
  903. * @arg @ref RCC_SAI1CLKSOURCE_PIN SAI1 clock = External Clock (SAI1_EXTCLK)
  904. *
  905. * @note Despite returned values RCC_SAI1CLKSOURCE_PLLSAI1 or RCC_SAI1CLKSOURCE_PLL, HSI16 is automatically set as SAI1
  906. * clock source when PLLs are disabled for devices without PLLSAI2.
  907. *
  908. */
  909. #define __HAL_RCC_GET_SAI1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_SAI1SEL)))
  910. #if defined(SAI2)
  911. /**
  912. * @brief Macro to configure the SAI2 clock source.
  913. * @param __SAI2_CLKSOURCE__ defines the SAI2 clock source. This clock is derived
  914. * from the PLLSAI2, system PLL or external clock (through a dedicated pin).
  915. * This parameter can be one of the following values:
  916. * @arg @ref RCC_SAI2CLKSOURCE_PLLSAI1 SAI2 clock = PLLSAI1 "P" clock (PLLSAI1CLK)
  917. * @arg @ref RCC_SAI2CLKSOURCE_PLLSAI2 SAI2 clock = PLLSAI2 "P" clock (PLLSAI2CLK)
  918. * @arg @ref RCC_SAI2CLKSOURCE_PLL SAI2 clock = PLL "P" clock (PLLSAI3CLK)
  919. * @arg @ref RCC_SAI2CLKSOURCE_PIN SAI2 clock = External Clock (SAI2_EXTCLK)
  920. *
  921. * @retval None
  922. */
  923. #define __HAL_RCC_SAI2_CONFIG(__SAI2_CLKSOURCE__ )\
  924. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_SAI2SEL, (uint32_t)(__SAI2_CLKSOURCE__))
  925. /** @brief Macro to get the SAI2 clock source.
  926. * @retval The clock source can be one of the following values:
  927. * @arg @ref RCC_SAI2CLKSOURCE_PLLSAI1 SAI2 clock = PLLSAI1 "P" clock (PLLSAI1CLK)
  928. * @arg @ref RCC_SAI2CLKSOURCE_PLLSAI2 SAI2 clock = PLLSAI2 "P" clock (PLLSAI2CLK)
  929. * @arg @ref RCC_SAI2CLKSOURCE_PLL SAI2 clock = PLL "P" clock (PLLSAI3CLK)
  930. * @arg @ref RCC_SAI2CLKSOURCE_PIN SAI2 clock = External Clock (SAI2_EXTCLK)
  931. */
  932. #define __HAL_RCC_GET_SAI2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_SAI2SEL)))
  933. #endif /* SAI2 */
  934. /** @brief Macro to configure the I2C1 clock (I2C1CLK).
  935. *
  936. * @param __I2C1_CLKSOURCE__ specifies the I2C1 clock source.
  937. * This parameter can be one of the following values:
  938. * @arg @ref RCC_I2C1CLKSOURCE_PCLK1 PCLK1 selected as I2C1 clock
  939. * @arg @ref RCC_I2C1CLKSOURCE_HSI HSI selected as I2C1 clock
  940. * @arg @ref RCC_I2C1CLKSOURCE_SYSCLK System Clock selected as I2C1 clock
  941. * @retval None
  942. */
  943. #define __HAL_RCC_I2C1_CONFIG(__I2C1_CLKSOURCE__) \
  944. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_I2C1SEL, (uint32_t)(__I2C1_CLKSOURCE__))
  945. /** @brief Macro to get the I2C1 clock source.
  946. * @retval The clock source can be one of the following values:
  947. * @arg @ref RCC_I2C1CLKSOURCE_PCLK1 PCLK1 selected as I2C1 clock
  948. * @arg @ref RCC_I2C1CLKSOURCE_HSI HSI selected as I2C1 clock
  949. * @arg @ref RCC_I2C1CLKSOURCE_SYSCLK System Clock selected as I2C1 clock
  950. */
  951. #define __HAL_RCC_GET_I2C1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_I2C1SEL)))
  952. #if defined(I2C2)
  953. /** @brief Macro to configure the I2C2 clock (I2C2CLK).
  954. *
  955. * @param __I2C2_CLKSOURCE__ specifies the I2C2 clock source.
  956. * This parameter can be one of the following values:
  957. * @arg @ref RCC_I2C2CLKSOURCE_PCLK1 PCLK1 selected as I2C2 clock
  958. * @arg @ref RCC_I2C2CLKSOURCE_HSI HSI selected as I2C2 clock
  959. * @arg @ref RCC_I2C2CLKSOURCE_SYSCLK System Clock selected as I2C2 clock
  960. * @retval None
  961. */
  962. #define __HAL_RCC_I2C2_CONFIG(__I2C2_CLKSOURCE__) \
  963. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_I2C2SEL, (uint32_t)(__I2C2_CLKSOURCE__))
  964. /** @brief Macro to get the I2C2 clock source.
  965. * @retval The clock source can be one of the following values:
  966. * @arg @ref RCC_I2C2CLKSOURCE_PCLK1 PCLK1 selected as I2C2 clock
  967. * @arg @ref RCC_I2C2CLKSOURCE_HSI HSI selected as I2C2 clock
  968. * @arg @ref RCC_I2C2CLKSOURCE_SYSCLK System Clock selected as I2C2 clock
  969. */
  970. #define __HAL_RCC_GET_I2C2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_I2C2SEL)))
  971. #endif /* I2C2 */
  972. /** @brief Macro to configure the I2C3 clock (I2C3CLK).
  973. *
  974. * @param __I2C3_CLKSOURCE__ specifies the I2C3 clock source.
  975. * This parameter can be one of the following values:
  976. * @arg @ref RCC_I2C3CLKSOURCE_PCLK1 PCLK1 selected as I2C3 clock
  977. * @arg @ref RCC_I2C3CLKSOURCE_HSI HSI selected as I2C3 clock
  978. * @arg @ref RCC_I2C3CLKSOURCE_SYSCLK System Clock selected as I2C3 clock
  979. * @retval None
  980. */
  981. #define __HAL_RCC_I2C3_CONFIG(__I2C3_CLKSOURCE__) \
  982. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_I2C3SEL, (uint32_t)(__I2C3_CLKSOURCE__))
  983. /** @brief Macro to get the I2C3 clock source.
  984. * @retval The clock source can be one of the following values:
  985. * @arg @ref RCC_I2C3CLKSOURCE_PCLK1 PCLK1 selected as I2C3 clock
  986. * @arg @ref RCC_I2C3CLKSOURCE_HSI HSI selected as I2C3 clock
  987. * @arg @ref RCC_I2C3CLKSOURCE_SYSCLK System Clock selected as I2C3 clock
  988. */
  989. #define __HAL_RCC_GET_I2C3_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_I2C3SEL)))
  990. #if defined(I2C4)
  991. /** @brief Macro to configure the I2C4 clock (I2C4CLK).
  992. *
  993. * @param __I2C4_CLKSOURCE__ specifies the I2C4 clock source.
  994. * This parameter can be one of the following values:
  995. * @arg @ref RCC_I2C4CLKSOURCE_PCLK1 PCLK1 selected as I2C4 clock
  996. * @arg @ref RCC_I2C4CLKSOURCE_HSI HSI selected as I2C4 clock
  997. * @arg @ref RCC_I2C4CLKSOURCE_SYSCLK System Clock selected as I2C4 clock
  998. * @retval None
  999. */
  1000. #define __HAL_RCC_I2C4_CONFIG(__I2C4_CLKSOURCE__) \
  1001. MODIFY_REG(RCC->CCIPR2, RCC_CCIPR2_I2C4SEL, (uint32_t)(__I2C4_CLKSOURCE__))
  1002. /** @brief Macro to get the I2C4 clock source.
  1003. * @retval The clock source can be one of the following values:
  1004. * @arg @ref RCC_I2C4CLKSOURCE_PCLK1 PCLK1 selected as I2C4 clock
  1005. * @arg @ref RCC_I2C4CLKSOURCE_HSI HSI selected as I2C4 clock
  1006. * @arg @ref RCC_I2C4CLKSOURCE_SYSCLK System Clock selected as I2C4 clock
  1007. */
  1008. #define __HAL_RCC_GET_I2C4_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR2, RCC_CCIPR2_I2C4SEL)))
  1009. #endif /* I2C4 */
  1010. /** @brief Macro to configure the USART1 clock (USART1CLK).
  1011. *
  1012. * @param __USART1_CLKSOURCE__ specifies the USART1 clock source.
  1013. * This parameter can be one of the following values:
  1014. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1015. * @arg @ref RCC_USART1CLKSOURCE_HSI HSI selected as USART1 clock
  1016. * @arg @ref RCC_USART1CLKSOURCE_SYSCLK System Clock selected as USART1 clock
  1017. * @arg @ref RCC_USART1CLKSOURCE_LSE SE selected as USART1 clock
  1018. * @retval None
  1019. */
  1020. #define __HAL_RCC_USART1_CONFIG(__USART1_CLKSOURCE__) \
  1021. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_USART1SEL, (uint32_t)(__USART1_CLKSOURCE__))
  1022. /** @brief Macro to get the USART1 clock source.
  1023. * @retval The clock source can be one of the following values:
  1024. * @arg @ref RCC_USART1CLKSOURCE_PCLK2 PCLK2 selected as USART1 clock
  1025. * @arg @ref RCC_USART1CLKSOURCE_HSI HSI selected as USART1 clock
  1026. * @arg @ref RCC_USART1CLKSOURCE_SYSCLK System Clock selected as USART1 clock
  1027. * @arg @ref RCC_USART1CLKSOURCE_LSE LSE selected as USART1 clock
  1028. */
  1029. #define __HAL_RCC_GET_USART1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_USART1SEL)))
  1030. /** @brief Macro to configure the USART2 clock (USART2CLK).
  1031. *
  1032. * @param __USART2_CLKSOURCE__ specifies the USART2 clock source.
  1033. * This parameter can be one of the following values:
  1034. * @arg @ref RCC_USART2CLKSOURCE_PCLK1 PCLK1 selected as USART2 clock
  1035. * @arg @ref RCC_USART2CLKSOURCE_HSI HSI selected as USART2 clock
  1036. * @arg @ref RCC_USART2CLKSOURCE_SYSCLK System Clock selected as USART2 clock
  1037. * @arg @ref RCC_USART2CLKSOURCE_LSE LSE selected as USART2 clock
  1038. * @retval None
  1039. */
  1040. #define __HAL_RCC_USART2_CONFIG(__USART2_CLKSOURCE__) \
  1041. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_USART2SEL, (uint32_t)(__USART2_CLKSOURCE__))
  1042. /** @brief Macro to get the USART2 clock source.
  1043. * @retval The clock source can be one of the following values:
  1044. * @arg @ref RCC_USART2CLKSOURCE_PCLK1 PCLK1 selected as USART2 clock
  1045. * @arg @ref RCC_USART2CLKSOURCE_HSI HSI selected as USART2 clock
  1046. * @arg @ref RCC_USART2CLKSOURCE_SYSCLK System Clock selected as USART2 clock
  1047. * @arg @ref RCC_USART2CLKSOURCE_LSE LSE selected as USART2 clock
  1048. */
  1049. #define __HAL_RCC_GET_USART2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_USART2SEL)))
  1050. #if defined(USART3)
  1051. /** @brief Macro to configure the USART3 clock (USART3CLK).
  1052. *
  1053. * @param __USART3_CLKSOURCE__ specifies the USART3 clock source.
  1054. * This parameter can be one of the following values:
  1055. * @arg @ref RCC_USART3CLKSOURCE_PCLK1 PCLK1 selected as USART3 clock
  1056. * @arg @ref RCC_USART3CLKSOURCE_HSI HSI selected as USART3 clock
  1057. * @arg @ref RCC_USART3CLKSOURCE_SYSCLK System Clock selected as USART3 clock
  1058. * @arg @ref RCC_USART3CLKSOURCE_LSE LSE selected as USART3 clock
  1059. * @retval None
  1060. */
  1061. #define __HAL_RCC_USART3_CONFIG(__USART3_CLKSOURCE__) \
  1062. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_USART3SEL, (uint32_t)(__USART3_CLKSOURCE__))
  1063. /** @brief Macro to get the USART3 clock source.
  1064. * @retval The clock source can be one of the following values:
  1065. * @arg @ref RCC_USART3CLKSOURCE_PCLK1 PCLK1 selected as USART3 clock
  1066. * @arg @ref RCC_USART3CLKSOURCE_HSI HSI selected as USART3 clock
  1067. * @arg @ref RCC_USART3CLKSOURCE_SYSCLK System Clock selected as USART3 clock
  1068. * @arg @ref RCC_USART3CLKSOURCE_LSE LSE selected as USART3 clock
  1069. */
  1070. #define __HAL_RCC_GET_USART3_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_USART3SEL)))
  1071. #endif /* USART3 */
  1072. #if defined(UART4)
  1073. /** @brief Macro to configure the UART4 clock (UART4CLK).
  1074. *
  1075. * @param __UART4_CLKSOURCE__ specifies the UART4 clock source.
  1076. * This parameter can be one of the following values:
  1077. * @arg @ref RCC_UART4CLKSOURCE_PCLK1 PCLK1 selected as UART4 clock
  1078. * @arg @ref RCC_UART4CLKSOURCE_HSI HSI selected as UART4 clock
  1079. * @arg @ref RCC_UART4CLKSOURCE_SYSCLK System Clock selected as UART4 clock
  1080. * @arg @ref RCC_UART4CLKSOURCE_LSE LSE selected as UART4 clock
  1081. * @retval None
  1082. */
  1083. #define __HAL_RCC_UART4_CONFIG(__UART4_CLKSOURCE__) \
  1084. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_UART4SEL, (uint32_t)(__UART4_CLKSOURCE__))
  1085. /** @brief Macro to get the UART4 clock source.
  1086. * @retval The clock source can be one of the following values:
  1087. * @arg @ref RCC_UART4CLKSOURCE_PCLK1 PCLK1 selected as UART4 clock
  1088. * @arg @ref RCC_UART4CLKSOURCE_HSI HSI selected as UART4 clock
  1089. * @arg @ref RCC_UART4CLKSOURCE_SYSCLK System Clock selected as UART4 clock
  1090. * @arg @ref RCC_UART4CLKSOURCE_LSE LSE selected as UART4 clock
  1091. */
  1092. #define __HAL_RCC_GET_UART4_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_UART4SEL)))
  1093. #endif /* UART4 */
  1094. #if defined(UART5)
  1095. /** @brief Macro to configure the UART5 clock (UART5CLK).
  1096. *
  1097. * @param __UART5_CLKSOURCE__ specifies the UART5 clock source.
  1098. * This parameter can be one of the following values:
  1099. * @arg @ref RCC_UART5CLKSOURCE_PCLK1 PCLK1 selected as UART5 clock
  1100. * @arg @ref RCC_UART5CLKSOURCE_HSI HSI selected as UART5 clock
  1101. * @arg @ref RCC_UART5CLKSOURCE_SYSCLK System Clock selected as UART5 clock
  1102. * @arg @ref RCC_UART5CLKSOURCE_LSE LSE selected as UART5 clock
  1103. * @retval None
  1104. */
  1105. #define __HAL_RCC_UART5_CONFIG(__UART5_CLKSOURCE__) \
  1106. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_UART5SEL, (uint32_t)(__UART5_CLKSOURCE__))
  1107. /** @brief Macro to get the UART5 clock source.
  1108. * @retval The clock source can be one of the following values:
  1109. * @arg @ref RCC_UART5CLKSOURCE_PCLK1 PCLK1 selected as UART5 clock
  1110. * @arg @ref RCC_UART5CLKSOURCE_HSI HSI selected as UART5 clock
  1111. * @arg @ref RCC_UART5CLKSOURCE_SYSCLK System Clock selected as UART5 clock
  1112. * @arg @ref RCC_UART5CLKSOURCE_LSE LSE selected as UART5 clock
  1113. */
  1114. #define __HAL_RCC_GET_UART5_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_UART5SEL)))
  1115. #endif /* UART5 */
  1116. /** @brief Macro to configure the LPUART1 clock (LPUART1CLK).
  1117. *
  1118. * @param __LPUART1_CLKSOURCE__ specifies the LPUART1 clock source.
  1119. * This parameter can be one of the following values:
  1120. * @arg @ref RCC_LPUART1CLKSOURCE_PCLK1 PCLK1 selected as LPUART1 clock
  1121. * @arg @ref RCC_LPUART1CLKSOURCE_HSI HSI selected as LPUART1 clock
  1122. * @arg @ref RCC_LPUART1CLKSOURCE_SYSCLK System Clock selected as LPUART1 clock
  1123. * @arg @ref RCC_LPUART1CLKSOURCE_LSE LSE selected as LPUART1 clock
  1124. * @retval None
  1125. */
  1126. #define __HAL_RCC_LPUART1_CONFIG(__LPUART1_CLKSOURCE__) \
  1127. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_LPUART1SEL, (uint32_t)(__LPUART1_CLKSOURCE__))
  1128. /** @brief Macro to get the LPUART1 clock source.
  1129. * @retval The clock source can be one of the following values:
  1130. * @arg @ref RCC_LPUART1CLKSOURCE_PCLK1 PCLK1 selected as LPUART1 clock
  1131. * @arg @ref RCC_LPUART1CLKSOURCE_HSI HSI selected as LPUART1 clock
  1132. * @arg @ref RCC_LPUART1CLKSOURCE_SYSCLK System Clock selected as LPUART1 clock
  1133. * @arg @ref RCC_LPUART1CLKSOURCE_LSE LSE selected as LPUART1 clock
  1134. */
  1135. #define __HAL_RCC_GET_LPUART1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_LPUART1SEL)))
  1136. /** @brief Macro to configure the LPTIM1 clock (LPTIM1CLK).
  1137. *
  1138. * @param __LPTIM1_CLKSOURCE__ specifies the LPTIM1 clock source.
  1139. * This parameter can be one of the following values:
  1140. * @arg @ref RCC_LPTIM1CLKSOURCE_PCLK1 PCLK1 selected as LPTIM1 clock
  1141. * @arg @ref RCC_LPTIM1CLKSOURCE_LSI HSI selected as LPTIM1 clock
  1142. * @arg @ref RCC_LPTIM1CLKSOURCE_HSI LSI selected as LPTIM1 clock
  1143. * @arg @ref RCC_LPTIM1CLKSOURCE_LSE LSE selected as LPTIM1 clock
  1144. * @retval None
  1145. */
  1146. #define __HAL_RCC_LPTIM1_CONFIG(__LPTIM1_CLKSOURCE__) \
  1147. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_LPTIM1SEL, (uint32_t)(__LPTIM1_CLKSOURCE__))
  1148. /** @brief Macro to get the LPTIM1 clock source.
  1149. * @retval The clock source can be one of the following values:
  1150. * @arg @ref RCC_LPTIM1CLKSOURCE_PCLK1 PCLK1 selected as LPUART1 clock
  1151. * @arg @ref RCC_LPTIM1CLKSOURCE_LSI HSI selected as LPUART1 clock
  1152. * @arg @ref RCC_LPTIM1CLKSOURCE_HSI System Clock selected as LPUART1 clock
  1153. * @arg @ref RCC_LPTIM1CLKSOURCE_LSE LSE selected as LPUART1 clock
  1154. */
  1155. #define __HAL_RCC_GET_LPTIM1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_LPTIM1SEL)))
  1156. /** @brief Macro to configure the LPTIM2 clock (LPTIM2CLK).
  1157. *
  1158. * @param __LPTIM2_CLKSOURCE__ specifies the LPTIM2 clock source.
  1159. * This parameter can be one of the following values:
  1160. * @arg @ref RCC_LPTIM2CLKSOURCE_PCLK1 PCLK1 selected as LPTIM2 clock
  1161. * @arg @ref RCC_LPTIM2CLKSOURCE_LSI HSI selected as LPTIM2 clock
  1162. * @arg @ref RCC_LPTIM2CLKSOURCE_HSI LSI selected as LPTIM2 clock
  1163. * @arg @ref RCC_LPTIM2CLKSOURCE_LSE LSE selected as LPTIM2 clock
  1164. * @retval None
  1165. */
  1166. #define __HAL_RCC_LPTIM2_CONFIG(__LPTIM2_CLKSOURCE__) \
  1167. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_LPTIM2SEL, (uint32_t)(__LPTIM2_CLKSOURCE__))
  1168. /** @brief Macro to get the LPTIM2 clock source.
  1169. * @retval The clock source can be one of the following values:
  1170. * @arg @ref RCC_LPTIM2CLKSOURCE_PCLK1 PCLK1 selected as LPUART1 clock
  1171. * @arg @ref RCC_LPTIM2CLKSOURCE_LSI HSI selected as LPUART1 clock
  1172. * @arg @ref RCC_LPTIM2CLKSOURCE_HSI System Clock selected as LPUART1 clock
  1173. * @arg @ref RCC_LPTIM2CLKSOURCE_LSE LSE selected as LPUART1 clock
  1174. */
  1175. #define __HAL_RCC_GET_LPTIM2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_LPTIM2SEL)))
  1176. #if defined(SDMMC1)
  1177. /** @brief Macro to configure the SDMMC1 clock.
  1178. *
  1179. @if STM32L443xx
  1180. * @note USB, RNG and SDMMC1 peripherals share the same 48MHz clock source.
  1181. @endif
  1182. @if STM32L462xx
  1183. * @note USB, RNG and SDMMC1 peripherals share the same 48MHz clock source.
  1184. @endif
  1185. @if STM32L486xx
  1186. * @note USB, RNG and SDMMC1 peripherals share the same 48MHz clock source.
  1187. @endif
  1188. @if STM32L4A6xx
  1189. * @note USB, RNG and SDMMC1 peripherals share the same 48MHz clock source.
  1190. @endif
  1191. *
  1192. * @param __SDMMC1_CLKSOURCE__ specifies the SDMMC1 clock source.
  1193. * This parameter can be one of the following values:
  1194. @if STM32L443xx
  1195. * @arg @ref RCC_SDMMC1CLKSOURCE_HSI48 HSI48 selected as SDMMC1 clock for devices with HSI48
  1196. * @arg @ref RCC_SDMMC1CLKSOURCE_MSI MSI selected as SDMMC1 clock
  1197. * @arg @ref RCC_SDMMC1CLKSOURCE_PLLSAI1 PLLSAI1 Clock selected as SDMMC1 clock
  1198. * @arg @ref RCC_SDMMC1CLKSOURCE_PLL PLL Clock selected as SDMMC1 clock
  1199. @endif
  1200. @if STM32L462xx
  1201. * @arg @ref RCC_SDMMC1CLKSOURCE_HSI48 HSI48 selected as SDMMC1 clock for devices with HSI48
  1202. * @arg @ref RCC_SDMMC1CLKSOURCE_MSI MSI selected as SDMMC1 clock
  1203. * @arg @ref RCC_SDMMC1CLKSOURCE_PLLSAI1 PLLSAI1 Clock selected as SDMMC1 clock
  1204. * @arg @ref RCC_SDMMC1CLKSOURCE_PLL PLL Clock selected as SDMMC1 clock
  1205. @endif
  1206. @if STM32L486xx
  1207. * @arg @ref RCC_SDMMC1CLKSOURCE_NONE No clock selected as SDMMC1 clock for devices without HSI48
  1208. * @arg @ref RCC_SDMMC1CLKSOURCE_MSI MSI selected as SDMMC1 clock
  1209. * @arg @ref RCC_SDMMC1CLKSOURCE_PLLSAI1 PLLSAI1 Clock selected as SDMMC1 clock
  1210. * @arg @ref RCC_SDMMC1CLKSOURCE_PLL PLL Clock selected as SDMMC1 clock
  1211. @endif
  1212. @if STM32L4A6xx
  1213. * @arg @ref RCC_SDMMC1CLKSOURCE_HSI48 HSI48 selected as SDMMC1 clock for devices with HSI48
  1214. * @arg @ref RCC_SDMMC1CLKSOURCE_MSI MSI selected as SDMMC1 clock
  1215. * @arg @ref RCC_SDMMC1CLKSOURCE_PLLSAI1 PLLSAI1 Clock selected as SDMMC1 clock
  1216. * @arg @ref RCC_SDMMC1CLKSOURCE_PLL PLL Clock selected as SDMMC1 clock
  1217. @endif
  1218. * @retval None
  1219. */
  1220. #define __HAL_RCC_SDMMC1_CONFIG(__SDMMC1_CLKSOURCE__) \
  1221. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_CLK48SEL, (uint32_t)(__SDMMC1_CLKSOURCE__))
  1222. /** @brief Macro to get the SDMMC1 clock.
  1223. * @retval The clock source can be one of the following values:
  1224. @if STM32L443xx
  1225. * @arg @ref RCC_SDMMC1CLKSOURCE_HSI48 HSI48 selected as SDMMC1 clock for devices with HSI48
  1226. * @arg @ref RCC_SDMMC1CLKSOURCE_MSI MSI selected as SDMMC1 clock
  1227. * @arg @ref RCC_SDMMC1CLKSOURCE_PLLSAI1 PLLSAI1 "Q" clock (PLL48M2CLK) selected as SDMMC1 clock
  1228. * @arg @ref RCC_SDMMC1CLKSOURCE_PLL PLL "Q" clock (PLL48M1CLK) selected as SDMMC1 clock
  1229. @endif
  1230. @if STM32L462xx
  1231. * @arg @ref RCC_SDMMC1CLKSOURCE_HSI48 HSI48 selected as SDMMC1 clock for devices with HSI48
  1232. * @arg @ref RCC_SDMMC1CLKSOURCE_MSI MSI selected as SDMMC1 clock
  1233. * @arg @ref RCC_SDMMC1CLKSOURCE_PLLSAI1 PLLSAI1 "Q" clock (PLL48M2CLK) selected as SDMMC1 clock
  1234. * @arg @ref RCC_SDMMC1CLKSOURCE_PLL PLL "Q" clock (PLL48M1CLK) selected as SDMMC1 clock
  1235. @endif
  1236. @if STM32L486xx
  1237. * @arg @ref RCC_SDMMC1CLKSOURCE_NONE No clock selected as SDMMC1 clock for devices without HSI48
  1238. * @arg @ref RCC_SDMMC1CLKSOURCE_MSI MSI selected as SDMMC1 clock
  1239. * @arg @ref RCC_SDMMC1CLKSOURCE_PLLSAI1 PLLSAI1 "Q" clock (PLL48M2CLK) selected as SDMMC1 clock
  1240. * @arg @ref RCC_SDMMC1CLKSOURCE_PLL PLL "Q" clock (PLL48M1CLK) selected as SDMMC1 clock
  1241. @endif
  1242. @if STM32L4A6xx
  1243. * @arg @ref RCC_SDMMC1CLKSOURCE_HSI48 HSI48 selected as SDMMC1 clock for devices with HSI48
  1244. * @arg @ref RCC_SDMMC1CLKSOURCE_MSI MSI selected as SDMMC1 clock
  1245. * @arg @ref RCC_SDMMC1CLKSOURCE_PLLSAI1 PLLSAI1 "Q" clock (PLL48M2CLK) selected as SDMMC1 clock
  1246. * @arg @ref RCC_SDMMC1CLKSOURCE_PLL PLL "Q" clock (PLL48M1CLK) selected as SDMMC1 clock
  1247. @endif
  1248. */
  1249. #define __HAL_RCC_GET_SDMMC1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_CLK48SEL)))
  1250. #endif /* SDMMC1 */
  1251. /** @brief Macro to configure the RNG clock.
  1252. *
  1253. * @note USB, RNG and SDMMC1 peripherals share the same 48MHz clock source.
  1254. *
  1255. * @param __RNG_CLKSOURCE__ specifies the RNG clock source.
  1256. * This parameter can be one of the following values:
  1257. @if STM32L443xx
  1258. * @arg @ref RCC_RNGCLKSOURCE_HSI48 HSI48 selected as RNG clock clock for devices with HSI48
  1259. @endif
  1260. @if STM32L462xx
  1261. * @arg @ref RCC_RNGCLKSOURCE_HSI48 HSI48 selected as RNG clock clock for devices with HSI48
  1262. @endif
  1263. @if STM32L486xx
  1264. * @arg @ref RCC_RNGCLKSOURCE_NONE No clock selected as RNG clock for devices without HSI48
  1265. @endif
  1266. @if STM32L4A6xx
  1267. * @arg @ref RCC_RNGCLKSOURCE_HSI48 HSI48 selected as RNG clock clock for devices with HSI48
  1268. @endif
  1269. * @arg @ref RCC_RNGCLKSOURCE_MSI MSI selected as RNG clock
  1270. * @arg @ref RCC_RNGCLKSOURCE_PLLSAI1 PLLSAI1 Clock selected as RNG clock
  1271. * @arg @ref RCC_RNGCLKSOURCE_PLL PLL Clock selected as RNG clock
  1272. * @retval None
  1273. */
  1274. #define __HAL_RCC_RNG_CONFIG(__RNG_CLKSOURCE__) \
  1275. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_CLK48SEL, (uint32_t)(__RNG_CLKSOURCE__))
  1276. /** @brief Macro to get the RNG clock.
  1277. * @retval The clock source can be one of the following values:
  1278. @if STM32L443xx
  1279. * @arg @ref RCC_RNGCLKSOURCE_HSI48 HSI48 selected as RNG clock clock for devices with HSI48
  1280. @endif
  1281. @if STM32L462xx
  1282. * @arg @ref RCC_RNGCLKSOURCE_HSI48 HSI48 selected as RNG clock clock for devices with HSI48
  1283. @endif
  1284. @if STM32L486xx
  1285. * @arg @ref RCC_RNGCLKSOURCE_NONE No clock selected as RNG clock for devices without HSI48
  1286. @endif
  1287. @if STM32L4A6xx
  1288. * @arg @ref RCC_RNGCLKSOURCE_HSI48 HSI48 selected as RNG clock clock for devices with HSI48
  1289. @endif
  1290. * @arg @ref RCC_RNGCLKSOURCE_MSI MSI selected as RNG clock
  1291. * @arg @ref RCC_RNGCLKSOURCE_PLLSAI1 PLLSAI1 "Q" clock (PLL48M2CLK) selected as RNG clock
  1292. * @arg @ref RCC_RNGCLKSOURCE_PLL PLL "Q" clock (PLL48M1CLK) selected as RNG clock
  1293. */
  1294. #define __HAL_RCC_GET_RNG_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_CLK48SEL)))
  1295. #if defined(USB_OTG_FS) || defined(USB)
  1296. /** @brief Macro to configure the USB clock (USBCLK).
  1297. *
  1298. * @note USB, RNG and SDMMC1 peripherals share the same 48MHz clock source.
  1299. *
  1300. * @param __USB_CLKSOURCE__ specifies the USB clock source.
  1301. * This parameter can be one of the following values:
  1302. @if STM32L443xx
  1303. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 selected as 48MHz clock for devices with HSI48
  1304. @endif
  1305. @if STM32L462xx
  1306. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 selected as 48MHz clock for devices with HSI48
  1307. @endif
  1308. @if STM32L486xx
  1309. * @arg @ref RCC_USBCLKSOURCE_NONE No clock selected as 48MHz clock for devices without HSI48
  1310. @endif
  1311. @if STM32L4A6xx
  1312. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 selected as 48MHz clock for devices with HSI48
  1313. @endif
  1314. * @arg @ref RCC_USBCLKSOURCE_MSI MSI selected as USB clock
  1315. * @arg @ref RCC_USBCLKSOURCE_PLLSAI1 PLLSAI1 "Q" clock (PLL48M2CLK) selected as USB clock
  1316. * @arg @ref RCC_USBCLKSOURCE_PLL PLL "Q" clock (PLL48M1CLK) selected as USB clock
  1317. * @retval None
  1318. */
  1319. #define __HAL_RCC_USB_CONFIG(__USB_CLKSOURCE__) \
  1320. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_CLK48SEL, (uint32_t)(__USB_CLKSOURCE__))
  1321. /** @brief Macro to get the USB clock source.
  1322. * @retval The clock source can be one of the following values:
  1323. @if STM32L443xx
  1324. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 selected as 48MHz clock for devices with HSI48
  1325. @endif
  1326. @if STM32L462xx
  1327. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 selected as 48MHz clock for devices with HSI48
  1328. @endif
  1329. @if STM32L486xx
  1330. * @arg @ref RCC_USBCLKSOURCE_NONE No clock selected as 48MHz clock for devices without HSI48
  1331. @endif
  1332. @if STM32L4A6xx
  1333. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 selected as 48MHz clock for devices with HSI48
  1334. @endif
  1335. * @arg @ref RCC_USBCLKSOURCE_MSI MSI selected as USB clock
  1336. * @arg @ref RCC_USBCLKSOURCE_PLLSAI1 PLLSAI1 "Q" clock (PLL48M2CLK) selected as USB clock
  1337. * @arg @ref RCC_USBCLKSOURCE_PLL PLL "Q" clock (PLL48M1CLK) selected as USB clock
  1338. */
  1339. #define __HAL_RCC_GET_USB_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_CLK48SEL)))
  1340. #endif /* USB_OTG_FS || USB */
  1341. /** @brief Macro to configure the ADC interface clock.
  1342. * @param __ADC_CLKSOURCE__ specifies the ADC digital interface clock source.
  1343. * This parameter can be one of the following values:
  1344. * @arg @ref RCC_ADCCLKSOURCE_NONE No clock selected as ADC clock
  1345. * @arg @ref RCC_ADCCLKSOURCE_PLLSAI1 PLLSAI1 Clock selected as ADC clock
  1346. @if STM32L486xx
  1347. * @arg @ref RCC_ADCCLKSOURCE_PLLSAI2 PLLSAI2 Clock selected as ADC clock for STM32L47x/STM32L48x/STM32L49x/STM32L4Ax devices
  1348. @endif
  1349. @if STM32L4A6xx
  1350. * @arg @ref RCC_ADCCLKSOURCE_PLLSAI2 PLLSAI2 Clock selected as ADC clock for STM32L47x/STM32L48x/STM32L49x/STM32L4Ax devices
  1351. @endif
  1352. * @arg @ref RCC_ADCCLKSOURCE_SYSCLK System Clock selected as ADC clock
  1353. * @retval None
  1354. */
  1355. #define __HAL_RCC_ADC_CONFIG(__ADC_CLKSOURCE__) \
  1356. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_ADCSEL, (uint32_t)(__ADC_CLKSOURCE__))
  1357. /** @brief Macro to get the ADC clock source.
  1358. * @retval The clock source can be one of the following values:
  1359. * @arg @ref RCC_ADCCLKSOURCE_NONE No clock selected as ADC clock
  1360. * @arg @ref RCC_ADCCLKSOURCE_PLLSAI1 PLLSAI1 Clock selected as ADC clock
  1361. @if STM32L486xx
  1362. * @arg @ref RCC_ADCCLKSOURCE_PLLSAI2 PLLSAI2 Clock selected as ADC clock for STM32L47x/STM32L48x/STM32L49x/STM32L4Ax devices
  1363. @endif
  1364. @if STM32L4A6xx
  1365. * @arg @ref RCC_ADCCLKSOURCE_PLLSAI2 PLLSAI2 Clock selected as ADC clock for STM32L47x/STM32L48x/STM32L49x/STM32L4Ax devices
  1366. @endif
  1367. * @arg @ref RCC_ADCCLKSOURCE_SYSCLK System Clock selected as ADC clock
  1368. */
  1369. #define __HAL_RCC_GET_ADC_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_ADCSEL)))
  1370. #if defined(SWPMI1)
  1371. /** @brief Macro to configure the SWPMI1 clock.
  1372. * @param __SWPMI1_CLKSOURCE__ specifies the SWPMI1 clock source.
  1373. * This parameter can be one of the following values:
  1374. * @arg @ref RCC_SWPMI1CLKSOURCE_PCLK1 PCLK1 Clock selected as SWPMI1 clock
  1375. * @arg @ref RCC_SWPMI1CLKSOURCE_HSI HSI Clock selected as SWPMI1 clock
  1376. * @retval None
  1377. */
  1378. #define __HAL_RCC_SWPMI1_CONFIG(__SWPMI1_CLKSOURCE__) \
  1379. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_SWPMI1SEL, (uint32_t)(__SWPMI1_CLKSOURCE__))
  1380. /** @brief Macro to get the SWPMI1 clock source.
  1381. * @retval The clock source can be one of the following values:
  1382. * @arg @ref RCC_SWPMI1CLKSOURCE_PCLK1 PCLK1 Clock selected as SWPMI1 clock
  1383. * @arg @ref RCC_SWPMI1CLKSOURCE_HSI HSI Clock selected as SWPMI1 clock
  1384. */
  1385. #define __HAL_RCC_GET_SWPMI1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_SWPMI1SEL)))
  1386. #endif /* SWPMI1 */
  1387. #if defined(DFSDM1_Filter0)
  1388. /** @brief Macro to configure the DFSDM1 clock.
  1389. * @param __DFSDM1_CLKSOURCE__ specifies the DFSDM1 clock source.
  1390. * This parameter can be one of the following values:
  1391. * @arg @ref RCC_DFSDM1CLKSOURCE_PCLK2 PCLK2 Clock selected as DFSDM1 clock
  1392. * @arg @ref RCC_DFSDM1CLKSOURCE_SYSCLK System Clock selected as DFSDM1 clock
  1393. * @retval None
  1394. */
  1395. #define __HAL_RCC_DFSDM1_CONFIG(__DFSDM1_CLKSOURCE__) \
  1396. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_DFSDM1SEL, (uint32_t)(__DFSDM1_CLKSOURCE__))
  1397. /** @brief Macro to get the DFSDM1 clock source.
  1398. * @retval The clock source can be one of the following values:
  1399. * @arg @ref RCC_DFSDM1CLKSOURCE_PCLK2 PCLK2 Clock selected as DFSDM1 clock
  1400. * @arg @ref RCC_DFSDM1CLKSOURCE_SYSCLK System Clock selected as DFSDM1 clock
  1401. */
  1402. #define __HAL_RCC_GET_DFSDM1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_DFSDM1SEL)))
  1403. #endif /* DFSDM1_Filter0 */
  1404. /** @defgroup RCCEx_Flags_Interrupts_Management Flags Interrupts Management
  1405. * @brief macros to manage the specified RCC Flags and interrupts.
  1406. * @{
  1407. */
  1408. /** @brief Enable PLLSAI1RDY interrupt.
  1409. * @retval None
  1410. */
  1411. #define __HAL_RCC_PLLSAI1_ENABLE_IT() SET_BIT(RCC->CIER, RCC_CIER_PLLSAI1RDYIE)
  1412. /** @brief Disable PLLSAI1RDY interrupt.
  1413. * @retval None
  1414. */
  1415. #define __HAL_RCC_PLLSAI1_DISABLE_IT() CLEAR_BIT(RCC->CIER, RCC_CIER_PLLSAI1RDYIE)
  1416. /** @brief Clear the PLLSAI1RDY interrupt pending bit.
  1417. * @retval None
  1418. */
  1419. #define __HAL_RCC_PLLSAI1_CLEAR_IT() WRITE_REG(RCC->CICR, RCC_CICR_PLLSAI1RDYC)
  1420. /** @brief Check whether PLLSAI1RDY interrupt has occurred or not.
  1421. * @retval TRUE or FALSE.
  1422. */
  1423. #define __HAL_RCC_PLLSAI1_GET_IT_SOURCE() (READ_BIT(RCC->CIFR, RCC_CIFR_PLLSAI1RDYF) == RCC_CIFR_PLLSAI1RDYF)
  1424. /** @brief Check whether the PLLSAI1RDY flag is set or not.
  1425. * @retval TRUE or FALSE.
  1426. */
  1427. #define __HAL_RCC_PLLSAI1_GET_FLAG() (READ_BIT(RCC->CR, RCC_CR_PLLSAI1RDY) == (RCC_CR_PLLSAI1RDY))
  1428. #if defined(RCC_PLLSAI2_SUPPORT)
  1429. /** @brief Enable PLLSAI2RDY interrupt.
  1430. * @retval None
  1431. */
  1432. #define __HAL_RCC_PLLSAI2_ENABLE_IT() SET_BIT(RCC->CIER, RCC_CIER_PLLSAI2RDYIE)
  1433. /** @brief Disable PLLSAI2RDY interrupt.
  1434. * @retval None
  1435. */
  1436. #define __HAL_RCC_PLLSAI2_DISABLE_IT() CLEAR_BIT(RCC->CIER, RCC_CIER_PLLSAI2RDYIE)
  1437. /** @brief Clear the PLLSAI2RDY interrupt pending bit.
  1438. * @retval None
  1439. */
  1440. #define __HAL_RCC_PLLSAI2_CLEAR_IT() WRITE_REG(RCC->CICR, RCC_CICR_PLLSAI2RDYC)
  1441. /** @brief Check whether the PLLSAI2RDY interrupt has occurred or not.
  1442. * @retval TRUE or FALSE.
  1443. */
  1444. #define __HAL_RCC_PLLSAI2_GET_IT_SOURCE() (READ_BIT(RCC->CIFR, RCC_CIFR_PLLSAI2RDYF) == RCC_CIFR_PLLSAI2RDYF)
  1445. /** @brief Check whether the PLLSAI2RDY flag is set or not.
  1446. * @retval TRUE or FALSE.
  1447. */
  1448. #define __HAL_RCC_PLLSAI2_GET_FLAG() (READ_BIT(RCC->CR, RCC_CR_PLLSAI2RDY) == (RCC_CR_PLLSAI2RDY))
  1449. #endif /* RCC_PLLSAI2_SUPPORT */
  1450. /**
  1451. * @brief Enable the RCC LSE CSS Extended Interrupt Line.
  1452. * @retval None
  1453. */
  1454. #define __HAL_RCC_LSECSS_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, RCC_EXTI_LINE_LSECSS)
  1455. /**
  1456. * @brief Disable the RCC LSE CSS Extended Interrupt Line.
  1457. * @retval None
  1458. */
  1459. #define __HAL_RCC_LSECSS_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, RCC_EXTI_LINE_LSECSS)
  1460. /**
  1461. * @brief Enable the RCC LSE CSS Event Line.
  1462. * @retval None.
  1463. */
  1464. #define __HAL_RCC_LSECSS_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, RCC_EXTI_LINE_LSECSS)
  1465. /**
  1466. * @brief Disable the RCC LSE CSS Event Line.
  1467. * @retval None.
  1468. */
  1469. #define __HAL_RCC_LSECSS_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, RCC_EXTI_LINE_LSECSS)
  1470. /**
  1471. * @brief Enable the RCC LSE CSS Extended Interrupt Falling Trigger.
  1472. * @retval None.
  1473. */
  1474. #define __HAL_RCC_LSECSS_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, RCC_EXTI_LINE_LSECSS)
  1475. /**
  1476. * @brief Disable the RCC LSE CSS Extended Interrupt Falling Trigger.
  1477. * @retval None.
  1478. */
  1479. #define __HAL_RCC_LSECSS_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, RCC_EXTI_LINE_LSECSS)
  1480. /**
  1481. * @brief Enable the RCC LSE CSS Extended Interrupt Rising Trigger.
  1482. * @retval None.
  1483. */
  1484. #define __HAL_RCC_LSECSS_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, RCC_EXTI_LINE_LSECSS)
  1485. /**
  1486. * @brief Disable the RCC LSE CSS Extended Interrupt Rising Trigger.
  1487. * @retval None.
  1488. */
  1489. #define __HAL_RCC_LSECSS_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, RCC_EXTI_LINE_LSECSS)
  1490. /**
  1491. * @brief Enable the RCC LSE CSS Extended Interrupt Rising & Falling Trigger.
  1492. * @retval None.
  1493. */
  1494. #define __HAL_RCC_LSECSS_EXTI_ENABLE_RISING_FALLING_EDGE() \
  1495. do { \
  1496. __HAL_RCC_LSECSS_EXTI_ENABLE_RISING_EDGE(); \
  1497. __HAL_RCC_LSECSS_EXTI_ENABLE_FALLING_EDGE(); \
  1498. } while(0)
  1499. /**
  1500. * @brief Disable the RCC LSE CSS Extended Interrupt Rising & Falling Trigger.
  1501. * @retval None.
  1502. */
  1503. #define __HAL_RCC_LSECSS_EXTI_DISABLE_RISING_FALLING_EDGE() \
  1504. do { \
  1505. __HAL_RCC_LSECSS_EXTI_DISABLE_RISING_EDGE(); \
  1506. __HAL_RCC_LSECSS_EXTI_DISABLE_FALLING_EDGE(); \
  1507. } while(0)
  1508. /**
  1509. * @brief Check whether the specified RCC LSE CSS EXTI interrupt flag is set or not.
  1510. * @retval EXTI RCC LSE CSS Line Status.
  1511. */
  1512. #define __HAL_RCC_LSECSS_EXTI_GET_FLAG() (READ_BIT(EXTI->PR1, RCC_EXTI_LINE_LSECSS) == RCC_EXTI_LINE_LSECSS)
  1513. /**
  1514. * @brief Clear the RCC LSE CSS EXTI flag.
  1515. * @retval None.
  1516. */
  1517. #define __HAL_RCC_LSECSS_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR1, RCC_EXTI_LINE_LSECSS)
  1518. /**
  1519. * @brief Generate a Software interrupt on the RCC LSE CSS EXTI line.
  1520. * @retval None.
  1521. */
  1522. #define __HAL_RCC_LSECSS_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, RCC_EXTI_LINE_LSECSS)
  1523. #if defined(CRS)
  1524. /**
  1525. * @brief Enable the specified CRS interrupts.
  1526. * @param __INTERRUPT__ specifies the CRS interrupt sources to be enabled.
  1527. * This parameter can be any combination of the following values:
  1528. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  1529. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  1530. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  1531. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  1532. * @retval None
  1533. */
  1534. #define __HAL_RCC_CRS_ENABLE_IT(__INTERRUPT__) SET_BIT(CRS->CR, (__INTERRUPT__))
  1535. /**
  1536. * @brief Disable the specified CRS interrupts.
  1537. * @param __INTERRUPT__ specifies the CRS interrupt sources to be disabled.
  1538. * This parameter can be any combination of the following values:
  1539. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  1540. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  1541. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  1542. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  1543. * @retval None
  1544. */
  1545. #define __HAL_RCC_CRS_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(CRS->CR, (__INTERRUPT__))
  1546. /** @brief Check whether the CRS interrupt has occurred or not.
  1547. * @param __INTERRUPT__ specifies the CRS interrupt source to check.
  1548. * This parameter can be one of the following values:
  1549. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  1550. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  1551. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  1552. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  1553. * @retval The new state of __INTERRUPT__ (SET or RESET).
  1554. */
  1555. #define __HAL_RCC_CRS_GET_IT_SOURCE(__INTERRUPT__) ((READ_BIT(CRS->CR, (__INTERRUPT__)) != RESET) ? SET : RESET)
  1556. /** @brief Clear the CRS interrupt pending bits
  1557. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1558. * This parameter can be any combination of the following values:
  1559. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  1560. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  1561. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  1562. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  1563. * @arg @ref RCC_CRS_IT_TRIMOVF Trimming overflow or underflow interrupt
  1564. * @arg @ref RCC_CRS_IT_SYNCERR SYNC error interrupt
  1565. * @arg @ref RCC_CRS_IT_SYNCMISS SYNC missed interrupt
  1566. */
  1567. /* CRS IT Error Mask */
  1568. #define RCC_CRS_IT_ERROR_MASK ((uint32_t)(RCC_CRS_IT_TRIMOVF | RCC_CRS_IT_SYNCERR | RCC_CRS_IT_SYNCMISS))
  1569. #define __HAL_RCC_CRS_CLEAR_IT(__INTERRUPT__) do { \
  1570. if(((__INTERRUPT__) & RCC_CRS_IT_ERROR_MASK) != RESET) \
  1571. { \
  1572. WRITE_REG(CRS->ICR, CRS_ICR_ERRC | ((__INTERRUPT__) & ~RCC_CRS_IT_ERROR_MASK)); \
  1573. } \
  1574. else \
  1575. { \
  1576. WRITE_REG(CRS->ICR, (__INTERRUPT__)); \
  1577. } \
  1578. } while(0)
  1579. /**
  1580. * @brief Check whether the specified CRS flag is set or not.
  1581. * @param __FLAG__ specifies the flag to check.
  1582. * This parameter can be one of the following values:
  1583. * @arg @ref RCC_CRS_FLAG_SYNCOK SYNC event OK
  1584. * @arg @ref RCC_CRS_FLAG_SYNCWARN SYNC warning
  1585. * @arg @ref RCC_CRS_FLAG_ERR Error
  1586. * @arg @ref RCC_CRS_FLAG_ESYNC Expected SYNC
  1587. * @arg @ref RCC_CRS_FLAG_TRIMOVF Trimming overflow or underflow
  1588. * @arg @ref RCC_CRS_FLAG_SYNCERR SYNC error
  1589. * @arg @ref RCC_CRS_FLAG_SYNCMISS SYNC missed
  1590. * @retval The new state of _FLAG_ (TRUE or FALSE).
  1591. */
  1592. #define __HAL_RCC_CRS_GET_FLAG(__FLAG__) (READ_BIT(CRS->ISR, (__FLAG__)) == (__FLAG__))
  1593. /**
  1594. * @brief Clear the CRS specified FLAG.
  1595. * @param __FLAG__ specifies the flag to clear.
  1596. * This parameter can be one of the following values:
  1597. * @arg @ref RCC_CRS_FLAG_SYNCOK SYNC event OK
  1598. * @arg @ref RCC_CRS_FLAG_SYNCWARN SYNC warning
  1599. * @arg @ref RCC_CRS_FLAG_ERR Error
  1600. * @arg @ref RCC_CRS_FLAG_ESYNC Expected SYNC
  1601. * @arg @ref RCC_CRS_FLAG_TRIMOVF Trimming overflow or underflow
  1602. * @arg @ref RCC_CRS_FLAG_SYNCERR SYNC error
  1603. * @arg @ref RCC_CRS_FLAG_SYNCMISS SYNC missed
  1604. * @note RCC_CRS_FLAG_ERR clears RCC_CRS_FLAG_TRIMOVF, RCC_CRS_FLAG_SYNCERR, RCC_CRS_FLAG_SYNCMISS and consequently RCC_CRS_FLAG_ERR
  1605. * @retval None
  1606. */
  1607. /* CRS Flag Error Mask */
  1608. #define RCC_CRS_FLAG_ERROR_MASK ((uint32_t)(RCC_CRS_FLAG_TRIMOVF | RCC_CRS_FLAG_SYNCERR | RCC_CRS_FLAG_SYNCMISS))
  1609. #define __HAL_RCC_CRS_CLEAR_FLAG(__FLAG__) do { \
  1610. if(((__FLAG__) & RCC_CRS_FLAG_ERROR_MASK) != RESET) \
  1611. { \
  1612. WRITE_REG(CRS->ICR, CRS_ICR_ERRC | ((__FLAG__) & ~RCC_CRS_FLAG_ERROR_MASK)); \
  1613. } \
  1614. else \
  1615. { \
  1616. WRITE_REG(CRS->ICR, (__FLAG__)); \
  1617. } \
  1618. } while(0)
  1619. #endif /* CRS */
  1620. /**
  1621. * @}
  1622. */
  1623. #if defined(CRS)
  1624. /** @defgroup RCCEx_CRS_Extended_Features RCCEx CRS Extended Features
  1625. * @{
  1626. */
  1627. /**
  1628. * @brief Enable the oscillator clock for frequency error counter.
  1629. * @note when the CEN bit is set the CRS_CFGR register becomes write-protected.
  1630. * @retval None
  1631. */
  1632. #define __HAL_RCC_CRS_FREQ_ERROR_COUNTER_ENABLE() SET_BIT(CRS->CR, CRS_CR_CEN)
  1633. /**
  1634. * @brief Disable the oscillator clock for frequency error counter.
  1635. * @retval None
  1636. */
  1637. #define __HAL_RCC_CRS_FREQ_ERROR_COUNTER_DISABLE() CLEAR_BIT(CRS->CR, CRS_CR_CEN)
  1638. /**
  1639. * @brief Enable the automatic hardware adjustement of TRIM bits.
  1640. * @note When the AUTOTRIMEN bit is set the CRS_CFGR register becomes write-protected.
  1641. * @retval None
  1642. */
  1643. #define __HAL_RCC_CRS_AUTOMATIC_CALIB_ENABLE() SET_BIT(CRS->CR, CRS_CR_AUTOTRIMEN)
  1644. /**
  1645. * @brief Enable or disable the automatic hardware adjustement of TRIM bits.
  1646. * @retval None
  1647. */
  1648. #define __HAL_RCC_CRS_AUTOMATIC_CALIB_DISABLE() CLEAR_BIT(CRS->CR, CRS_CR_AUTOTRIMEN)
  1649. /**
  1650. * @brief Macro to calculate reload value to be set in CRS register according to target and sync frequencies
  1651. * @note The RELOAD value should be selected according to the ratio between the target frequency and the frequency
  1652. * of the synchronization source after prescaling. It is then decreased by one in order to
  1653. * reach the expected synchronization on the zero value. The formula is the following:
  1654. * RELOAD = (fTARGET / fSYNC) -1
  1655. * @param __FTARGET__ Target frequency (value in Hz)
  1656. * @param __FSYNC__ Synchronization signal frequency (value in Hz)
  1657. * @retval None
  1658. */
  1659. #define __HAL_RCC_CRS_RELOADVALUE_CALCULATE(__FTARGET__, __FSYNC__) (((__FTARGET__) / (__FSYNC__)) - 1U)
  1660. /**
  1661. * @}
  1662. */
  1663. #endif /* CRS */
  1664. /**
  1665. * @}
  1666. */
  1667. /* Exported functions --------------------------------------------------------*/
  1668. /** @addtogroup RCCEx_Exported_Functions
  1669. * @{
  1670. */
  1671. /** @addtogroup RCCEx_Exported_Functions_Group1
  1672. * @{
  1673. */
  1674. HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit);
  1675. void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit);
  1676. uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk);
  1677. /**
  1678. * @}
  1679. */
  1680. /** @addtogroup RCCEx_Exported_Functions_Group2
  1681. * @{
  1682. */
  1683. HAL_StatusTypeDef HAL_RCCEx_EnablePLLSAI1(RCC_PLLSAI1InitTypeDef *PLLSAI1Init);
  1684. HAL_StatusTypeDef HAL_RCCEx_DisablePLLSAI1(void);
  1685. #if defined(RCC_PLLSAI2_SUPPORT)
  1686. HAL_StatusTypeDef HAL_RCCEx_EnablePLLSAI2(RCC_PLLSAI2InitTypeDef *PLLSAI2Init);
  1687. HAL_StatusTypeDef HAL_RCCEx_DisablePLLSAI2(void);
  1688. #endif /* RCC_PLLSAI2_SUPPORT */
  1689. void HAL_RCCEx_WakeUpStopCLKConfig(uint32_t WakeUpClk);
  1690. void HAL_RCCEx_StandbyMSIRangeConfig(uint32_t MSIRange);
  1691. void HAL_RCCEx_EnableLSECSS(void);
  1692. void HAL_RCCEx_DisableLSECSS(void);
  1693. void HAL_RCCEx_EnableLSECSS_IT(void);
  1694. void HAL_RCCEx_LSECSS_IRQHandler(void);
  1695. void HAL_RCCEx_LSECSS_Callback(void);
  1696. void HAL_RCCEx_EnableLSCO(uint32_t LSCOSource);
  1697. void HAL_RCCEx_DisableLSCO(void);
  1698. void HAL_RCCEx_EnableMSIPLLMode(void);
  1699. void HAL_RCCEx_DisableMSIPLLMode(void);
  1700. /**
  1701. * @}
  1702. */
  1703. #if defined(CRS)
  1704. /** @addtogroup RCCEx_Exported_Functions_Group3
  1705. * @{
  1706. */
  1707. void HAL_RCCEx_CRSConfig(RCC_CRSInitTypeDef *pInit);
  1708. void HAL_RCCEx_CRSSoftwareSynchronizationGenerate(void);
  1709. void HAL_RCCEx_CRSGetSynchronizationInfo(RCC_CRSSynchroInfoTypeDef *pSynchroInfo);
  1710. uint32_t HAL_RCCEx_CRSWaitSynchronization(uint32_t Timeout);
  1711. void HAL_RCCEx_CRS_IRQHandler(void);
  1712. void HAL_RCCEx_CRS_SyncOkCallback(void);
  1713. void HAL_RCCEx_CRS_SyncWarnCallback(void);
  1714. void HAL_RCCEx_CRS_ExpectedSyncCallback(void);
  1715. void HAL_RCCEx_CRS_ErrorCallback(uint32_t Error);
  1716. /**
  1717. * @}
  1718. */
  1719. #endif /* CRS */
  1720. /**
  1721. * @}
  1722. */
  1723. /* Private macros ------------------------------------------------------------*/
  1724. /** @addtogroup RCCEx_Private_Macros
  1725. * @{
  1726. */
  1727. #define IS_RCC_LSCOSOURCE(__SOURCE__) (((__SOURCE__) == RCC_LSCOSOURCE_LSI) || \
  1728. ((__SOURCE__) == RCC_LSCOSOURCE_LSE))
  1729. #if defined(STM32L431xx)
  1730. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1731. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1732. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1733. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1734. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1735. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1736. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1737. (((__SELECTION__) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) || \
  1738. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1739. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1740. (((__SELECTION__) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) || \
  1741. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1742. (((__SELECTION__) & RCC_PERIPHCLK_SWPMI1) == RCC_PERIPHCLK_SWPMI1) || \
  1743. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1744. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1745. (((__SELECTION__) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1))
  1746. #elif defined(STM32L432xx) || defined(STM32L442xx)
  1747. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1748. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1749. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1750. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1751. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1752. (((__SELECTION__) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) || \
  1753. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1754. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1755. (((__SELECTION__) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) || \
  1756. (((__SELECTION__) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) || \
  1757. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1758. (((__SELECTION__) & RCC_PERIPHCLK_SWPMI1) == RCC_PERIPHCLK_SWPMI1) || \
  1759. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1760. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG))
  1761. #elif defined(STM32L433xx) || defined(STM32L443xx)
  1762. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1763. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1764. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1765. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1766. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1767. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1768. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1769. (((__SELECTION__) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) || \
  1770. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1771. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1772. (((__SELECTION__) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) || \
  1773. (((__SELECTION__) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) || \
  1774. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1775. (((__SELECTION__) & RCC_PERIPHCLK_SWPMI1) == RCC_PERIPHCLK_SWPMI1) || \
  1776. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1777. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1778. (((__SELECTION__) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1))
  1779. #elif defined(STM32L451xx)
  1780. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1781. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1782. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1783. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1784. (((__SELECTION__) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4) || \
  1785. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1786. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1787. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1788. (((__SELECTION__) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) || \
  1789. (((__SELECTION__) & RCC_PERIPHCLK_I2C4) == RCC_PERIPHCLK_I2C4) || \
  1790. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1791. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1792. (((__SELECTION__) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) || \
  1793. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1794. (((__SELECTION__) & RCC_PERIPHCLK_DFSDM1) == RCC_PERIPHCLK_DFSDM1) || \
  1795. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1796. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1797. (((__SELECTION__) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1))
  1798. #elif defined(STM32L452xx) || defined(STM32L462xx)
  1799. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1800. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1801. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1802. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1803. (((__SELECTION__) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4) || \
  1804. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1805. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1806. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1807. (((__SELECTION__) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) || \
  1808. (((__SELECTION__) & RCC_PERIPHCLK_I2C4) == RCC_PERIPHCLK_I2C4) || \
  1809. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1810. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1811. (((__SELECTION__) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) || \
  1812. (((__SELECTION__) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) || \
  1813. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1814. (((__SELECTION__) & RCC_PERIPHCLK_DFSDM1) == RCC_PERIPHCLK_DFSDM1) || \
  1815. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1816. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1817. (((__SELECTION__) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1))
  1818. #elif defined(STM32L471xx)
  1819. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1820. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1821. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1822. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1823. (((__SELECTION__) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4) || \
  1824. (((__SELECTION__) & RCC_PERIPHCLK_UART5) == RCC_PERIPHCLK_UART5) || \
  1825. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1826. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1827. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1828. (((__SELECTION__) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) || \
  1829. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1830. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1831. (((__SELECTION__) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) || \
  1832. (((__SELECTION__) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) || \
  1833. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1834. (((__SELECTION__) & RCC_PERIPHCLK_SWPMI1) == RCC_PERIPHCLK_SWPMI1) || \
  1835. (((__SELECTION__) & RCC_PERIPHCLK_DFSDM1) == RCC_PERIPHCLK_DFSDM1) || \
  1836. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1837. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1838. (((__SELECTION__) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1))
  1839. #elif defined(STM32L496xx) || defined(STM32L4A6xx)
  1840. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1841. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1842. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1843. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1844. (((__SELECTION__) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4) || \
  1845. (((__SELECTION__) & RCC_PERIPHCLK_UART5) == RCC_PERIPHCLK_UART5) || \
  1846. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1847. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1848. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1849. (((__SELECTION__) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) || \
  1850. (((__SELECTION__) & RCC_PERIPHCLK_I2C4) == RCC_PERIPHCLK_I2C4) || \
  1851. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1852. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1853. (((__SELECTION__) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) || \
  1854. (((__SELECTION__) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) || \
  1855. (((__SELECTION__) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) || \
  1856. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1857. (((__SELECTION__) & RCC_PERIPHCLK_SWPMI1) == RCC_PERIPHCLK_SWPMI1) || \
  1858. (((__SELECTION__) & RCC_PERIPHCLK_DFSDM1) == RCC_PERIPHCLK_DFSDM1) || \
  1859. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1860. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1861. (((__SELECTION__) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1))
  1862. #else
  1863. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1864. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1865. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1866. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1867. (((__SELECTION__) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4) || \
  1868. (((__SELECTION__) & RCC_PERIPHCLK_UART5) == RCC_PERIPHCLK_UART5) || \
  1869. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1870. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1871. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1872. (((__SELECTION__) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3) || \
  1873. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1874. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1875. (((__SELECTION__) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) || \
  1876. (((__SELECTION__) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) || \
  1877. (((__SELECTION__) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) || \
  1878. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1879. (((__SELECTION__) & RCC_PERIPHCLK_SWPMI1) == RCC_PERIPHCLK_SWPMI1) || \
  1880. (((__SELECTION__) & RCC_PERIPHCLK_DFSDM1) == RCC_PERIPHCLK_DFSDM1) || \
  1881. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1882. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1883. (((__SELECTION__) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1))
  1884. #endif /* STM32L431xx */
  1885. #define IS_RCC_USART1CLKSOURCE(__SOURCE__) \
  1886. (((__SOURCE__) == RCC_USART1CLKSOURCE_PCLK2) || \
  1887. ((__SOURCE__) == RCC_USART1CLKSOURCE_SYSCLK) || \
  1888. ((__SOURCE__) == RCC_USART1CLKSOURCE_LSE) || \
  1889. ((__SOURCE__) == RCC_USART1CLKSOURCE_HSI))
  1890. #define IS_RCC_USART2CLKSOURCE(__SOURCE__) \
  1891. (((__SOURCE__) == RCC_USART2CLKSOURCE_PCLK1) || \
  1892. ((__SOURCE__) == RCC_USART2CLKSOURCE_SYSCLK) || \
  1893. ((__SOURCE__) == RCC_USART2CLKSOURCE_LSE) || \
  1894. ((__SOURCE__) == RCC_USART2CLKSOURCE_HSI))
  1895. #if defined(USART3)
  1896. #define IS_RCC_USART3CLKSOURCE(__SOURCE__) \
  1897. (((__SOURCE__) == RCC_USART3CLKSOURCE_PCLK1) || \
  1898. ((__SOURCE__) == RCC_USART3CLKSOURCE_SYSCLK) || \
  1899. ((__SOURCE__) == RCC_USART3CLKSOURCE_LSE) || \
  1900. ((__SOURCE__) == RCC_USART3CLKSOURCE_HSI))
  1901. #endif /* USART3 */
  1902. #if defined(UART4)
  1903. #define IS_RCC_UART4CLKSOURCE(__SOURCE__) \
  1904. (((__SOURCE__) == RCC_UART4CLKSOURCE_PCLK1) || \
  1905. ((__SOURCE__) == RCC_UART4CLKSOURCE_SYSCLK) || \
  1906. ((__SOURCE__) == RCC_UART4CLKSOURCE_LSE) || \
  1907. ((__SOURCE__) == RCC_UART4CLKSOURCE_HSI))
  1908. #endif /* UART4 */
  1909. #if defined(UART5)
  1910. #define IS_RCC_UART5CLKSOURCE(__SOURCE__) \
  1911. (((__SOURCE__) == RCC_UART5CLKSOURCE_PCLK1) || \
  1912. ((__SOURCE__) == RCC_UART5CLKSOURCE_SYSCLK) || \
  1913. ((__SOURCE__) == RCC_UART5CLKSOURCE_LSE) || \
  1914. ((__SOURCE__) == RCC_UART5CLKSOURCE_HSI))
  1915. #endif /* UART5 */
  1916. #define IS_RCC_LPUART1CLKSOURCE(__SOURCE__) \
  1917. (((__SOURCE__) == RCC_LPUART1CLKSOURCE_PCLK1) || \
  1918. ((__SOURCE__) == RCC_LPUART1CLKSOURCE_SYSCLK) || \
  1919. ((__SOURCE__) == RCC_LPUART1CLKSOURCE_LSE) || \
  1920. ((__SOURCE__) == RCC_LPUART1CLKSOURCE_HSI))
  1921. #define IS_RCC_I2C1CLKSOURCE(__SOURCE__) \
  1922. (((__SOURCE__) == RCC_I2C1CLKSOURCE_PCLK1) || \
  1923. ((__SOURCE__) == RCC_I2C1CLKSOURCE_SYSCLK)|| \
  1924. ((__SOURCE__) == RCC_I2C1CLKSOURCE_HSI))
  1925. #if defined(I2C2)
  1926. #define IS_RCC_I2C2CLKSOURCE(__SOURCE__) \
  1927. (((__SOURCE__) == RCC_I2C2CLKSOURCE_PCLK1) || \
  1928. ((__SOURCE__) == RCC_I2C2CLKSOURCE_SYSCLK)|| \
  1929. ((__SOURCE__) == RCC_I2C2CLKSOURCE_HSI))
  1930. #endif /* I2C2 */
  1931. #define IS_RCC_I2C3CLKSOURCE(__SOURCE__) \
  1932. (((__SOURCE__) == RCC_I2C3CLKSOURCE_PCLK1) || \
  1933. ((__SOURCE__) == RCC_I2C3CLKSOURCE_SYSCLK)|| \
  1934. ((__SOURCE__) == RCC_I2C3CLKSOURCE_HSI))
  1935. #if defined(I2C4)
  1936. #define IS_RCC_I2C4CLKSOURCE(__SOURCE__) \
  1937. (((__SOURCE__) == RCC_I2C4CLKSOURCE_PCLK1) || \
  1938. ((__SOURCE__) == RCC_I2C4CLKSOURCE_SYSCLK)|| \
  1939. ((__SOURCE__) == RCC_I2C4CLKSOURCE_HSI))
  1940. #endif /* I2C4 */
  1941. #if defined(RCC_PLLSAI2_SUPPORT)
  1942. #define IS_RCC_SAI1CLK(__SOURCE__) \
  1943. (((__SOURCE__) == RCC_SAI1CLKSOURCE_PLLSAI1) || \
  1944. ((__SOURCE__) == RCC_SAI1CLKSOURCE_PLLSAI2) || \
  1945. ((__SOURCE__) == RCC_SAI1CLKSOURCE_PLL) || \
  1946. ((__SOURCE__) == RCC_SAI1CLKSOURCE_PIN))
  1947. #else
  1948. #define IS_RCC_SAI1CLK(__SOURCE__) \
  1949. (((__SOURCE__) == RCC_SAI1CLKSOURCE_PLLSAI1) || \
  1950. ((__SOURCE__) == RCC_SAI1CLKSOURCE_PLL) || \
  1951. ((__SOURCE__) == RCC_SAI1CLKSOURCE_PIN))
  1952. #endif /* RCC_PLLSAI2_SUPPORT */
  1953. #if defined(RCC_PLLSAI2_SUPPORT)
  1954. #define IS_RCC_SAI2CLK(__SOURCE__) \
  1955. (((__SOURCE__) == RCC_SAI2CLKSOURCE_PLLSAI1) || \
  1956. ((__SOURCE__) == RCC_SAI2CLKSOURCE_PLLSAI2) || \
  1957. ((__SOURCE__) == RCC_SAI2CLKSOURCE_PLL) || \
  1958. ((__SOURCE__) == RCC_SAI2CLKSOURCE_PIN))
  1959. #endif /* RCC_PLLSAI2_SUPPORT */
  1960. #define IS_RCC_LPTIM1CLK(__SOURCE__) \
  1961. (((__SOURCE__) == RCC_LPTIM1CLKSOURCE_PCLK1) || \
  1962. ((__SOURCE__) == RCC_LPTIM1CLKSOURCE_LSI) || \
  1963. ((__SOURCE__) == RCC_LPTIM1CLKSOURCE_HSI) || \
  1964. ((__SOURCE__) == RCC_LPTIM1CLKSOURCE_LSE))
  1965. #define IS_RCC_LPTIM2CLK(__SOURCE__) \
  1966. (((__SOURCE__) == RCC_LPTIM2CLKSOURCE_PCLK1) || \
  1967. ((__SOURCE__) == RCC_LPTIM2CLKSOURCE_LSI) || \
  1968. ((__SOURCE__) == RCC_LPTIM2CLKSOURCE_HSI) || \
  1969. ((__SOURCE__) == RCC_LPTIM2CLKSOURCE_LSE))
  1970. #if defined(SDMMC1)
  1971. #if defined(RCC_HSI48_SUPPORT)
  1972. #define IS_RCC_SDMMC1CLKSOURCE(__SOURCE__) \
  1973. (((__SOURCE__) == RCC_SDMMC1CLKSOURCE_HSI48) || \
  1974. ((__SOURCE__) == RCC_SDMMC1CLKSOURCE_PLLSAI1) || \
  1975. ((__SOURCE__) == RCC_SDMMC1CLKSOURCE_PLL) || \
  1976. ((__SOURCE__) == RCC_SDMMC1CLKSOURCE_MSI))
  1977. #else
  1978. #define IS_RCC_SDMMC1CLKSOURCE(__SOURCE__) \
  1979. (((__SOURCE__) == RCC_SDMMC1CLKSOURCE_NONE) || \
  1980. ((__SOURCE__) == RCC_SDMMC1CLKSOURCE_PLLSAI1) || \
  1981. ((__SOURCE__) == RCC_SDMMC1CLKSOURCE_PLL) || \
  1982. ((__SOURCE__) == RCC_SDMMC1CLKSOURCE_MSI))
  1983. #endif /* RCC_HSI48_SUPPORT */
  1984. #endif /* SDMMC1 */
  1985. #if defined(RCC_HSI48_SUPPORT)
  1986. #define IS_RCC_RNGCLKSOURCE(__SOURCE__) \
  1987. (((__SOURCE__) == RCC_RNGCLKSOURCE_HSI48) || \
  1988. ((__SOURCE__) == RCC_RNGCLKSOURCE_PLLSAI1) || \
  1989. ((__SOURCE__) == RCC_RNGCLKSOURCE_PLL) || \
  1990. ((__SOURCE__) == RCC_RNGCLKSOURCE_MSI))
  1991. #else
  1992. #define IS_RCC_RNGCLKSOURCE(__SOURCE__) \
  1993. (((__SOURCE__) == RCC_RNGCLKSOURCE_NONE) || \
  1994. ((__SOURCE__) == RCC_RNGCLKSOURCE_PLLSAI1) || \
  1995. ((__SOURCE__) == RCC_RNGCLKSOURCE_PLL) || \
  1996. ((__SOURCE__) == RCC_RNGCLKSOURCE_MSI))
  1997. #endif /* RCC_HSI48_SUPPORT */
  1998. #if defined(USB_OTG_FS) || defined(USB)
  1999. #if defined(RCC_HSI48_SUPPORT)
  2000. #define IS_RCC_USBCLKSOURCE(__SOURCE__) \
  2001. (((__SOURCE__) == RCC_USBCLKSOURCE_HSI48) || \
  2002. ((__SOURCE__) == RCC_USBCLKSOURCE_PLLSAI1) || \
  2003. ((__SOURCE__) == RCC_USBCLKSOURCE_PLL) || \
  2004. ((__SOURCE__) == RCC_USBCLKSOURCE_MSI))
  2005. #else
  2006. #define IS_RCC_USBCLKSOURCE(__SOURCE__) \
  2007. (((__SOURCE__) == RCC_USBCLKSOURCE_NONE) || \
  2008. ((__SOURCE__) == RCC_USBCLKSOURCE_PLLSAI1) || \
  2009. ((__SOURCE__) == RCC_USBCLKSOURCE_PLL) || \
  2010. ((__SOURCE__) == RCC_USBCLKSOURCE_MSI))
  2011. #endif /* RCC_HSI48_SUPPORT */
  2012. #endif /* USB_OTG_FS || USB */
  2013. #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || defined(STM32L496xx) || defined(STM32L4A6xx)
  2014. #define IS_RCC_ADCCLKSOURCE(__SOURCE__) \
  2015. (((__SOURCE__) == RCC_ADCCLKSOURCE_NONE) || \
  2016. ((__SOURCE__) == RCC_ADCCLKSOURCE_PLLSAI1) || \
  2017. ((__SOURCE__) == RCC_ADCCLKSOURCE_PLLSAI2) || \
  2018. ((__SOURCE__) == RCC_ADCCLKSOURCE_SYSCLK))
  2019. #else
  2020. #define IS_RCC_ADCCLKSOURCE(__SOURCE__) \
  2021. (((__SOURCE__) == RCC_ADCCLKSOURCE_NONE) || \
  2022. ((__SOURCE__) == RCC_ADCCLKSOURCE_PLLSAI1) || \
  2023. ((__SOURCE__) == RCC_ADCCLKSOURCE_SYSCLK))
  2024. #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || STM32L496xx || STM32L4A6xx */
  2025. #if defined(SWPMI1)
  2026. #define IS_RCC_SWPMI1CLKSOURCE(__SOURCE__) \
  2027. (((__SOURCE__) == RCC_SWPMI1CLKSOURCE_PCLK1) || \
  2028. ((__SOURCE__) == RCC_SWPMI1CLKSOURCE_HSI))
  2029. #endif /* SWPMI1 */
  2030. #if defined(DFSDM1_Filter0)
  2031. #define IS_RCC_DFSDM1CLKSOURCE(__SOURCE__) \
  2032. (((__SOURCE__) == RCC_DFSDM1CLKSOURCE_PCLK2) || \
  2033. ((__SOURCE__) == RCC_DFSDM1CLKSOURCE_SYSCLK))
  2034. #endif /* DFSDM1_Filter0 */
  2035. #define IS_RCC_PLLSAI1SOURCE(__VALUE__) IS_RCC_PLLSOURCE(__VALUE__)
  2036. #define IS_RCC_PLLSAI1M_VALUE(__VALUE__) ((1U <= (__VALUE__)) && ((__VALUE__) <= 8U))
  2037. #define IS_RCC_PLLSAI1N_VALUE(__VALUE__) ((8U <= (__VALUE__)) && ((__VALUE__) <= 86U))
  2038. #if defined(RCC_PLLSAI1P_DIV_2_31_SUPPORT)
  2039. #define IS_RCC_PLLSAI1P_VALUE(__VALUE__) (((__VALUE__) >= 2U) && ((__VALUE__) <= 31U))
  2040. #else
  2041. #define IS_RCC_PLLSAI1P_VALUE(__VALUE__) (((__VALUE__) == 7U) || ((__VALUE__) == 17U))
  2042. #endif /* RCC_PLLSAI1P_DIV_2_31_SUPPORT */
  2043. #define IS_RCC_PLLSAI1Q_VALUE(__VALUE__) (((__VALUE__) == 2U) || ((__VALUE__) == 4U) || \
  2044. ((__VALUE__) == 6U) || ((__VALUE__) == 8U))
  2045. #define IS_RCC_PLLSAI1R_VALUE(__VALUE__) (((__VALUE__) == 2U) || ((__VALUE__) == 4U) || \
  2046. ((__VALUE__) == 6U) || ((__VALUE__) == 8U))
  2047. #if defined(RCC_PLLSAI2_SUPPORT)
  2048. #define IS_RCC_PLLSAI2SOURCE(__VALUE__) IS_RCC_PLLSOURCE(__VALUE__)
  2049. #define IS_RCC_PLLSAI2M_VALUE(__VALUE__) ((1U <= (__VALUE__)) && ((__VALUE__) <= 8U))
  2050. #define IS_RCC_PLLSAI2N_VALUE(__VALUE__) ((8U <= (__VALUE__)) && ((__VALUE__) <= 86U))
  2051. #if defined(RCC_PLLSAI2P_DIV_2_31_SUPPORT)
  2052. #define IS_RCC_PLLSAI2P_VALUE(__VALUE__) (((__VALUE__) >= 2U) && ((__VALUE__) <= 31U))
  2053. #else
  2054. #define IS_RCC_PLLSAI2P_VALUE(__VALUE__) (((__VALUE__) == 7U) || ((__VALUE__) == 17U))
  2055. #endif /* RCC_PLLSAI2P_DIV_2_31_SUPPORT */
  2056. #define IS_RCC_PLLSAI2R_VALUE(__VALUE__) (((__VALUE__) == 2U) || ((__VALUE__) == 4U) || \
  2057. ((__VALUE__) == 6U) || ((__VALUE__) == 8U))
  2058. #endif /* RCC_PLLSAI2_SUPPORT */
  2059. #if defined(CRS)
  2060. #define IS_RCC_CRS_SYNC_SOURCE(__SOURCE__) (((__SOURCE__) == RCC_CRS_SYNC_SOURCE_GPIO) || \
  2061. ((__SOURCE__) == RCC_CRS_SYNC_SOURCE_LSE) || \
  2062. ((__SOURCE__) == RCC_CRS_SYNC_SOURCE_USB))
  2063. #define IS_RCC_CRS_SYNC_DIV(__DIV__) (((__DIV__) == RCC_CRS_SYNC_DIV1) || ((__DIV__) == RCC_CRS_SYNC_DIV2) || \
  2064. ((__DIV__) == RCC_CRS_SYNC_DIV4) || ((__DIV__) == RCC_CRS_SYNC_DIV8) || \
  2065. ((__DIV__) == RCC_CRS_SYNC_DIV16) || ((__DIV__) == RCC_CRS_SYNC_DIV32) || \
  2066. ((__DIV__) == RCC_CRS_SYNC_DIV64) || ((__DIV__) == RCC_CRS_SYNC_DIV128))
  2067. #define IS_RCC_CRS_SYNC_POLARITY(__POLARITY__) (((__POLARITY__) == RCC_CRS_SYNC_POLARITY_RISING) || \
  2068. ((__POLARITY__) == RCC_CRS_SYNC_POLARITY_FALLING))
  2069. #define IS_RCC_CRS_RELOADVALUE(__VALUE__) (((__VALUE__) <= 0xFFFFU))
  2070. #define IS_RCC_CRS_ERRORLIMIT(__VALUE__) (((__VALUE__) <= 0xFFU))
  2071. #define IS_RCC_CRS_HSI48CALIBRATION(__VALUE__) (((__VALUE__) <= 0x3FU))
  2072. #define IS_RCC_CRS_FREQERRORDIR(__DIR__) (((__DIR__) == RCC_CRS_FREQERRORDIR_UP) || \
  2073. ((__DIR__) == RCC_CRS_FREQERRORDIR_DOWN))
  2074. #endif /* CRS */
  2075. /**
  2076. * @}
  2077. */
  2078. /**
  2079. * @}
  2080. */
  2081. /**
  2082. * @}
  2083. */
  2084. #ifdef __cplusplus
  2085. }
  2086. #endif
  2087. #endif /* __STM32L4xx_HAL_RCC_EX_H */
  2088. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/