stm32g0xx_hal_rcc_ex.h 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_hal_rcc_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of RCC HAL Extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2018 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file in
  13. * the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. ******************************************************************************
  16. */
  17. /* Define to prevent recursive inclusion -------------------------------------*/
  18. #ifndef STM32G0xx_HAL_RCC_EX_H
  19. #define STM32G0xx_HAL_RCC_EX_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32g0xx_hal_def.h"
  25. /** @addtogroup STM32G0xx_HAL_Driver
  26. * @{
  27. */
  28. /** @addtogroup RCCEx
  29. * @{
  30. */
  31. /* Exported types ------------------------------------------------------------*/
  32. /** @defgroup RCCEx_Exported_Types RCCEx Exported Types
  33. * @{
  34. */
  35. /**
  36. * @brief RCC extended clocks structure definition
  37. */
  38. typedef struct
  39. {
  40. uint32_t PeriphClockSelection; /*!< The Extended Clock to be configured.
  41. This parameter can be a value of @ref RCCEx_Periph_Clock_Selection */
  42. uint32_t Usart1ClockSelection; /*!< Specifies USART1 clock source.
  43. This parameter can be a value of @ref RCCEx_USART1_Clock_Source */
  44. #if defined(RCC_CCIPR_USART2SEL)
  45. uint32_t Usart2ClockSelection; /*!< Specifies USART2 clock source.
  46. This parameter can be a value of @ref RCCEx_USART2_Clock_Source */
  47. #endif /* RCC_CCIPR_USART2SEL */
  48. #if defined(RCC_CCIPR_USART3SEL)
  49. uint32_t Usart3ClockSelection; /*!< Specifies USART3 clock source.
  50. This parameter can be a value of @ref RCCEx_USART3_Clock_Source */
  51. #endif /* RCC_CCIPR_USART3SEL */
  52. #if defined(LPUART1)
  53. uint32_t Lpuart1ClockSelection; /*!< Specifies LPUART1 clock source
  54. This parameter can be a value of @ref RCCEx_LPUART1_Clock_Source */
  55. #endif /* LPUART1 */
  56. #if defined(LPUART2)
  57. uint32_t Lpuart2ClockSelection; /*!< Specifies LPUART2 clock source
  58. This parameter can be a value of @ref RCCEx_LPUART2_Clock_Source */
  59. #endif /* LPUART2 */
  60. uint32_t I2c1ClockSelection; /*!< Specifies I2C1 clock source
  61. This parameter can be a value of @ref RCCEx_I2C1_Clock_Source */
  62. #if defined(RCC_CCIPR_I2C2SEL)
  63. uint32_t I2c2ClockSelection; /*!< Specifies I2C2 clock source
  64. This parameter can be a value of @ref RCCEx_I2C2_Clock_Source */
  65. #endif /* RCC_CCIPR_I2C2SEL */
  66. uint32_t I2s1ClockSelection; /*!< Specifies I2S1 clock source
  67. This parameter can be a value of @ref RCCEx_I2S1_Clock_Source */
  68. #if defined(RCC_CCIPR2_I2S2SEL)
  69. uint32_t I2s2ClockSelection; /*!< Specifies I2S2 clock source
  70. This parameter can be a value of @ref RCCEx_I2S2_Clock_Source */
  71. #endif /* RCC_CCIPR2_I2S2SEL */
  72. #if defined(RCC_CCIPR_LPTIM1SEL)
  73. uint32_t Lptim1ClockSelection; /*!< Specifies LPTIM1 clock source
  74. This parameter can be a value of @ref RCCEx_LPTIM1_Clock_Source */
  75. #endif /* RCC_CCIPR_LPTIM1SEL */
  76. #if defined(RCC_CCIPR_LPTIM2SEL)
  77. uint32_t Lptim2ClockSelection; /*!< Specifies LPTIM2 clock source
  78. This parameter can be a value of @ref RCCEx_LPTIM2_Clock_Source */
  79. #endif /* RCC_CCIPR_LPTIM2SEL */
  80. #if defined(RNG)
  81. uint32_t RngClockSelection; /*!< Specifies RNG clock source
  82. This parameter can be a value of @ref RCCEx_RNG_Clock_Source */
  83. #endif /* RNG */
  84. uint32_t AdcClockSelection; /*!< Specifies ADC interface clock source
  85. This parameter can be a value of @ref RCCEx_ADC_Clock_Source */
  86. #if defined(CEC)
  87. uint32_t CecClockSelection; /*!< Specifies CEC Clock clock source
  88. This parameter can be a value of @ref RCCEx_CEC_Clock_Source */
  89. #endif /* CEC */
  90. #if defined(RCC_CCIPR_TIM1SEL)
  91. uint32_t Tim1ClockSelection; /*!< Specifies TIM1 Clock clock source
  92. This parameter can be a value of @ref RCCEx_TIM1_Clock_Source */
  93. #endif /* RCC_CCIPR_TIM1SEL */
  94. #if defined(RCC_CCIPR_TIM15SEL)
  95. uint32_t Tim15ClockSelection; /*!< Specifies TIM15 Clock clock source
  96. This parameter can be a value of @ref RCCEx_TIM15_Clock_Source */
  97. #endif /* RCC_CCIPR_TIM15SEL */
  98. uint32_t RTCClockSelection; /*!< Specifies RTC clock source.
  99. This parameter can be a value of @ref RCC_RTC_Clock_Source */
  100. #if defined(RCC_CCIPR2_USBSEL)
  101. uint32_t UsbClockSelection; /*!< Specifies USB Clock clock source
  102. This parameter can be a value of @ref RCCEx_USB_Clock_Source */
  103. #endif /* RCC_CCIPR2_USBSEL */
  104. #if defined(FDCAN1) || defined(FDCAN2)
  105. uint32_t FdcanClockSelection; /*!< Specifies FDCAN Clock clock source
  106. This parameter can be a value of @ref RCCEx_FDCAN_Clock_Source */
  107. #endif /* FDCAN1 || FDCAN2 */
  108. } RCC_PeriphCLKInitTypeDef;
  109. #if defined(CRS)
  110. /**
  111. * @brief RCC_CRS Init structure definition
  112. */
  113. typedef struct
  114. {
  115. uint32_t Prescaler; /*!< Specifies the division factor of the SYNC signal.
  116. This parameter can be a value of @ref RCCEx_CRS_SynchroDivider */
  117. uint32_t Source; /*!< Specifies the SYNC signal source.
  118. This parameter can be a value of @ref RCCEx_CRS_SynchroSource */
  119. uint32_t Polarity; /*!< Specifies the input polarity for the SYNC signal source.
  120. This parameter can be a value of @ref RCCEx_CRS_SynchroPolarity */
  121. uint32_t ReloadValue; /*!< Specifies the value to be loaded in the frequency error counter with each SYNC event.
  122. It can be calculated in using macro __HAL_RCC_CRS_RELOADVALUE_CALCULATE(__FTARGET__, __FSYNC__)
  123. This parameter must be a number between 0 and 0xFFFF or a value of @ref RCCEx_CRS_ReloadValueDefault .*/
  124. uint32_t ErrorLimitValue; /*!< Specifies the value to be used to evaluate the captured frequency error value.
  125. This parameter must be a number between 0 and 0xFF or a value of @ref RCCEx_CRS_ErrorLimitDefault */
  126. uint32_t HSI48CalibrationValue; /*!< Specifies a user-programmable trimming value to the HSI48 oscillator.
  127. This parameter must be a number between 0 and 0x7F or a value of @ref RCCEx_CRS_HSI48CalibrationDefault */
  128. } RCC_CRSInitTypeDef;
  129. /**
  130. * @brief RCC_CRS Synchronization structure definition
  131. */
  132. typedef struct
  133. {
  134. uint32_t ReloadValue; /*!< Specifies the value loaded in the Counter reload value.
  135. This parameter must be a number between 0 and 0xFFFF */
  136. uint32_t HSI48CalibrationValue; /*!< Specifies value loaded in HSI48 oscillator smooth trimming.
  137. This parameter must be a number between 0 and 0x7F */
  138. uint32_t FreqErrorCapture; /*!< Specifies the value loaded in the .FECAP, the frequency error counter
  139. value latched in the time of the last SYNC event.
  140. This parameter must be a number between 0 and 0xFFFF */
  141. uint32_t FreqErrorDirection; /*!< Specifies the value loaded in the .FEDIR, the counting direction of the
  142. frequency error counter latched in the time of the last SYNC event.
  143. It shows whether the actual frequency is below or above the target.
  144. This parameter must be a value of @ref RCCEx_CRS_FreqErrorDirection*/
  145. } RCC_CRSSynchroInfoTypeDef;
  146. #endif /* CRS */
  147. /**
  148. * @}
  149. */
  150. /* Exported constants --------------------------------------------------------*/
  151. /** @defgroup RCCEx_Exported_Constants RCCEx Exported Constants
  152. * @{
  153. */
  154. /** @defgroup RCCEx_LSCO_Clock_Source Low Speed Clock Source
  155. * @{
  156. */
  157. #define RCC_LSCOSOURCE_LSI 0x00000000U /*!< LSI selection for low speed clock output */
  158. #define RCC_LSCOSOURCE_LSE RCC_BDCR_LSCOSEL /*!< LSE selection for low speed clock output */
  159. /**
  160. * @}
  161. */
  162. /** @defgroup RCCEx_Periph_Clock_Selection Periph Clock Selection
  163. * @{
  164. */
  165. #define RCC_PERIPHCLK_USART1 0x00000001U
  166. #if defined(RCC_CCIPR_USART2SEL)
  167. #define RCC_PERIPHCLK_USART2 0x00000002U
  168. #endif /* RCC_CCIPR_USART2SEL */
  169. #if defined(RCC_CCIPR_USART3SEL)
  170. #define RCC_PERIPHCLK_USART3 0x00000004U
  171. #endif /* RCC_CCIPR_USART3SEL */
  172. #if defined(LPUART1)
  173. #define RCC_PERIPHCLK_LPUART1 0x00000010U
  174. #endif /* LPUART1 */
  175. #define RCC_PERIPHCLK_I2C1 0x00000020U
  176. #if defined(RCC_CCIPR_I2C2SEL)
  177. #define RCC_PERIPHCLK_I2C2 0x00000040U
  178. #endif /* RCC_CCIPR_I2C2SEL */
  179. #if defined(RCC_CCIPR_LPTIM1SEL)
  180. #define RCC_PERIPHCLK_LPTIM1 0x00000200U
  181. #endif /* RCC_CCIPR_LPTIM1SEL */
  182. #if defined(RCC_CCIPR_LPTIM2SEL)
  183. #define RCC_PERIPHCLK_LPTIM2 0x00000400U
  184. #endif /* RCC_CCIPR_LPTIM2SEL */
  185. #define RCC_PERIPHCLK_I2S1 0x00000800U
  186. #if defined(LPUART2)
  187. #define RCC_PERIPHCLK_LPUART2 0x00001000U
  188. #endif /* LPUART2 */
  189. #if defined(RCC_CCIPR2_I2S2SEL)
  190. #define RCC_PERIPHCLK_I2S2 0x00002000U
  191. #endif /* RCC_CCIPR2_I2S2SEL */
  192. #define RCC_PERIPHCLK_ADC 0x00004000U
  193. #define RCC_PERIPHCLK_RTC 0x00020000U
  194. #if defined(RCC_CCIPR_RNGSEL)
  195. #define RCC_PERIPHCLK_RNG 0x00040000U
  196. #endif /* RCC_CCIPR_RNGSEL */
  197. #if defined(RCC_CCIPR_CECSEL)
  198. #define RCC_PERIPHCLK_CEC 0x00080000U
  199. #endif /* RCC_CCIPR_CECSEL */
  200. #if defined(RCC_CCIPR_TIM1SEL)
  201. #define RCC_PERIPHCLK_TIM1 0x00200000U
  202. #endif /* RCC_CCIPR_TIM1SEL */
  203. #if defined(RCC_CCIPR_TIM15SEL)
  204. #define RCC_PERIPHCLK_TIM15 0x00400000U
  205. #endif /* RCC_CCIPR_TIM15SEL */
  206. #if defined(RCC_CCIPR2_USBSEL)
  207. #define RCC_PERIPHCLK_USB 0x01000000U
  208. #endif /* RCC_CCIPR2_USBSEL */
  209. #if defined(FDCAN1) || defined(FDCAN2)
  210. #define RCC_PERIPHCLK_FDCAN 0x02000000U
  211. #endif /* FDCAN1 || FDCAN2 */
  212. /**
  213. * @}
  214. */
  215. /** @defgroup RCCEx_USART1_Clock_Source RCC USART1 Clock Source
  216. * @{
  217. */
  218. #define RCC_USART1CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as USART1 clock */
  219. #define RCC_USART1CLKSOURCE_SYSCLK RCC_CCIPR_USART1SEL_0 /*!< SYSCLK clock selected as USART1 clock */
  220. #define RCC_USART1CLKSOURCE_HSI RCC_CCIPR_USART1SEL_1 /*!< HSI clock selected as USART1 clock */
  221. #define RCC_USART1CLKSOURCE_LSE (RCC_CCIPR_USART1SEL_0 | RCC_CCIPR_USART1SEL_1) /*!< LSE clock selected as USART1 clock */
  222. /**
  223. * @}
  224. */
  225. #if defined(RCC_CCIPR_USART2SEL)
  226. /** @defgroup RCCEx_USART2_Clock_Source RCC USART2 Clock Source
  227. * @{
  228. */
  229. #define RCC_USART2CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as USART2 clock */
  230. #define RCC_USART2CLKSOURCE_SYSCLK RCC_CCIPR_USART2SEL_0 /*!< SYSCLK clock selected as USART2 clock */
  231. #define RCC_USART2CLKSOURCE_HSI RCC_CCIPR_USART2SEL_1 /*!< HSI clock selected as USART2 clock */
  232. #define RCC_USART2CLKSOURCE_LSE (RCC_CCIPR_USART2SEL_0 | RCC_CCIPR_USART2SEL_1) /*!< LSE clock selected as USART2 clock */
  233. /**
  234. * @}
  235. */
  236. #endif /* RCC_CCIPR_USART2SEL */
  237. #if defined(RCC_CCIPR_USART3SEL)
  238. /** @defgroup RCCEx_USART3_Clock_Source RCC USART3 Clock Source
  239. * @{
  240. */
  241. #define RCC_USART3CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as USART3 clock */
  242. #define RCC_USART3CLKSOURCE_SYSCLK RCC_CCIPR_USART3SEL_0 /*!< SYSCLK clock selected as USART3 clock */
  243. #define RCC_USART3CLKSOURCE_HSI RCC_CCIPR_USART3SEL_1 /*!< HSI clock selected as USART3 clock */
  244. #define RCC_USART3CLKSOURCE_LSE (RCC_CCIPR_USART3SEL_0 | RCC_CCIPR_USART3SEL_1) /*!< LSE clock selected as USART3 clock */
  245. /**
  246. * @}
  247. */
  248. #endif /* RCC_CCIPR_USART3SEL */
  249. #if defined(LPUART1)
  250. /** @defgroup RCCEx_LPUART1_Clock_Source RCC LPUART1 Clock Source
  251. * @{
  252. */
  253. #define RCC_LPUART1CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as LPUART1 clock */
  254. #define RCC_LPUART1CLKSOURCE_SYSCLK RCC_CCIPR_LPUART1SEL_0 /*!< SYSCLK clock selected as LPUART1 clock */
  255. #define RCC_LPUART1CLKSOURCE_HSI RCC_CCIPR_LPUART1SEL_1 /*!< HSI clock selected as LPUART1 clock */
  256. #define RCC_LPUART1CLKSOURCE_LSE (RCC_CCIPR_LPUART1SEL_0 | RCC_CCIPR_LPUART1SEL_1) /*!< LSE clock selected as LPUART1 clock */
  257. /**
  258. * @}
  259. */
  260. #endif /* LPUART1 */
  261. #if defined(LPUART2)
  262. /** @defgroup RCCEx_LPUART2_Clock_Source RCC LPUART2 Clock Source
  263. * @{
  264. */
  265. #define RCC_LPUART2CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as LPUART2 clock */
  266. #define RCC_LPUART2CLKSOURCE_SYSCLK RCC_CCIPR_LPUART2SEL_0 /*!< SYSCLK clock selected as LPUART2 clock */
  267. #define RCC_LPUART2CLKSOURCE_HSI RCC_CCIPR_LPUART2SEL_1 /*!< HSI clock selected as LPUART2 clock */
  268. #define RCC_LPUART2CLKSOURCE_LSE (RCC_CCIPR_LPUART2SEL_0 | RCC_CCIPR_LPUART2SEL_1) /*!< LSE clock selected as LPUART2 clock */
  269. /**
  270. * @}
  271. */
  272. #endif /* LPUART2 */
  273. /** @defgroup RCCEx_I2C1_Clock_Source RCC I2C1 Clock Source
  274. * @{
  275. */
  276. #define RCC_I2C1CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as I2C1 clock */
  277. #define RCC_I2C1CLKSOURCE_SYSCLK RCC_CCIPR_I2C1SEL_0 /*!< SYSCLK clock selected as I2C1 clock */
  278. #define RCC_I2C1CLKSOURCE_HSI RCC_CCIPR_I2C1SEL_1 /*!< HSI clock selected as I2C1 clock */
  279. /**
  280. * @}
  281. */
  282. #if defined(RCC_CCIPR_I2C2SEL)
  283. /** @defgroup RCCEx_I2C2_Clock_Source RCC I2C2 Clock Source
  284. * @{
  285. */
  286. #define RCC_I2C2CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as I2C2 clock */
  287. #define RCC_I2C2CLKSOURCE_SYSCLK RCC_CCIPR_I2C2SEL_0 /*!< SYSCLK clock selected as I2C2 clock */
  288. #define RCC_I2C2CLKSOURCE_HSI RCC_CCIPR_I2C2SEL_1 /*!< HSI clock selected as I2C2 clock */
  289. /**
  290. * @}
  291. */
  292. #endif /* RCC_CCIPR_I2C2SEL */
  293. /** @defgroup RCCEx_I2S1_Clock_Source RCC I2S1 Clock Source
  294. * @{
  295. */
  296. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  297. #define RCC_I2S1CLKSOURCE_SYSCLK 0x00000000U /*!< SYSCLK clock selected as I2S1 clock */
  298. #define RCC_I2S1CLKSOURCE_PLL RCC_CCIPR2_I2S1SEL_0 /*!< PLL "P" selected as I2S1 clock */
  299. #define RCC_I2S1CLKSOURCE_HSI RCC_CCIPR2_I2S1SEL_1 /*!< HSI clock selected as I2S1 clock */
  300. #define RCC_I2S1CLKSOURCE_EXT RCC_CCIPR2_I2S1SEL /*!< External I2S clock source selected as I2S1 clock */
  301. #else
  302. #define RCC_I2S1CLKSOURCE_SYSCLK 0x00000000U /*!< SYSCLK clock selected as I2S1 clock */
  303. #define RCC_I2S1CLKSOURCE_PLL RCC_CCIPR_I2S1SEL_0 /*!< PLL "P" selected as I2S1 clock */
  304. #define RCC_I2S1CLKSOURCE_HSI RCC_CCIPR_I2S1SEL_1 /*!< HSI clock selected as I2S1 clock */
  305. #define RCC_I2S1CLKSOURCE_EXT RCC_CCIPR_I2S1SEL /*!< External I2S clock source selected as I2S1 clock */
  306. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
  307. /**
  308. * @}
  309. */
  310. #if defined(RCC_CCIPR2_I2S2SEL)
  311. /** @defgroup RCCEx_I2S2_Clock_Source RCC I2S2 Clock Source
  312. * @{
  313. */
  314. #define RCC_I2S2CLKSOURCE_SYSCLK 0x00000000U /*!< SYSCLK clock selected as I2S2 clock */
  315. #define RCC_I2S2CLKSOURCE_PLL RCC_CCIPR2_I2S2SEL_0 /*!< PLL "P" selected as I2S2 clock */
  316. #define RCC_I2S2CLKSOURCE_HSI RCC_CCIPR2_I2S2SEL_1 /*!< HSI clock selected as I2S2 clock */
  317. #define RCC_I2S2CLKSOURCE_EXT RCC_CCIPR2_I2S2SEL /*!< External I2S clock source selected as I2S2 clock */
  318. /**
  319. * @}
  320. */
  321. #endif /* RCC_CCIPR2_I2S2SEL */
  322. #if defined(RCC_CCIPR_LPTIM1SEL)
  323. /** @defgroup RCCEx_LPTIM1_Clock_Source RCC LPTIM1 Clock Source
  324. * @{
  325. */
  326. #define RCC_LPTIM1CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as LPTimer 1 clock */
  327. #define RCC_LPTIM1CLKSOURCE_LSI RCC_CCIPR_LPTIM1SEL_0 /*!< LSI clock selected as LPTimer 1 clock */
  328. #define RCC_LPTIM1CLKSOURCE_HSI RCC_CCIPR_LPTIM1SEL_1 /*!< HSI clock selected as LPTimer 1 clock */
  329. #define RCC_LPTIM1CLKSOURCE_LSE RCC_CCIPR_LPTIM1SEL /*!< LSE clock selected as LPTimer 1 clock */
  330. /**
  331. * @}
  332. */
  333. #endif /* RCC_CCIPR_LPTIM1SEL */
  334. #if defined(RCC_CCIPR_LPTIM2SEL)
  335. /** @defgroup RCCEx_LPTIM2_Clock_Source RCC LPTIM2 Clock Source
  336. * @{
  337. */
  338. #define RCC_LPTIM2CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as LPTimer 2 clock */
  339. #define RCC_LPTIM2CLKSOURCE_LSI RCC_CCIPR_LPTIM2SEL_0 /*!< LSI clock selected as LPTimer 2 clock */
  340. #define RCC_LPTIM2CLKSOURCE_HSI RCC_CCIPR_LPTIM2SEL_1 /*!< HSI clock selected as LPTimer 2 clock */
  341. #define RCC_LPTIM2CLKSOURCE_LSE RCC_CCIPR_LPTIM2SEL /*!< LSE clock selected as LPTimer 2 clock */
  342. /**
  343. * @}
  344. */
  345. #endif /* RCC_CCIPR_LPTIM2SEL */
  346. #if defined(RNG)
  347. /** @defgroup RCCEx_RNG_Clock_Source RCC RNG Clock Source
  348. * @{
  349. */
  350. #define RCC_RNGCLKSOURCE_NONE 0x00000000U /*!< No clock selected */
  351. #define RCC_RNGCLKSOURCE_HSI_DIV8 RCC_CCIPR_RNGSEL_0 /*!< HSI oscillator divided by 8 clock selected as RNG clock */
  352. #define RCC_RNGCLKSOURCE_SYSCLK RCC_CCIPR_RNGSEL_1 /*!< SYSCLK selected as RNG clock */
  353. #define RCC_RNGCLKSOURCE_PLL (RCC_CCIPR_RNGSEL_0|RCC_CCIPR_RNGSEL_1) /*!< PLL "Q" selected as RNG clock */
  354. /**
  355. * @}
  356. */
  357. /** @defgroup RCCEx_RNG_Division_factor RCC RNG Division factor
  358. * @{
  359. */
  360. #define RCC_RNGCLK_DIV1 0x00000000U /*!< RNG clock not divided */
  361. #define RCC_RNGCLK_DIV2 RCC_CCIPR_RNGDIV_0 /*!< RNG clock divided by 2 */
  362. #define RCC_RNGCLK_DIV4 RCC_CCIPR_RNGDIV_1 /*!< RNG clock divided by 4 */
  363. #define RCC_RNGCLK_DIV8 (RCC_CCIPR_RNGDIV_0|RCC_CCIPR_RNGDIV_1) /*!< RNG clock divided by 8 */
  364. /**
  365. * @}
  366. */
  367. #endif /* RNG */
  368. #if defined(FDCAN1) || defined(FDCAN2)
  369. /** @defgroup RCCEx_FDCAN_Clock_Source RCC FDCAN Clock Source
  370. * @{
  371. */
  372. #define RCC_FDCANCLKSOURCE_PCLK1 0x00000000U /*!< PCLK1 selected as FDCAN clock */
  373. #define RCC_FDCANCLKSOURCE_PLL RCC_CCIPR2_FDCANSEL_0 /*!< PLL "Q" selected as FDCAN clock */
  374. #define RCC_FDCANCLKSOURCE_HSE RCC_CCIPR2_FDCANSEL_1 /*!< HSE oscillator clock selected as FDCAN clock */
  375. /**
  376. * @}
  377. */
  378. #endif /* FDCAN1 || FDCAN2 */
  379. #if defined(RCC_CCIPR2_USBSEL)
  380. /** @defgroup RCCEx_USB_Clock_Source USB Clock Source
  381. * @{
  382. */
  383. #if defined(RCC_HSI48_SUPPORT)
  384. #define RCC_USBCLKSOURCE_HSI48 0x00000000U /*!< HSI48 oscillator clock selected as USB clock */
  385. #endif /* RCC_HSI48_SUPPORT */
  386. #define RCC_USBCLKSOURCE_HSE RCC_CCIPR2_USBSEL_0 /*!< HSE oscillator clock selected as USB clock */
  387. #define RCC_USBCLKSOURCE_PLL RCC_CCIPR2_USBSEL_1 /*!< PLL "Q" selected as USB clock */
  388. /**
  389. * @}
  390. */
  391. #endif /* RCC_CCIPR2_USBSEL */
  392. /** @defgroup RCCEx_ADC_Clock_Source RCC ADC Clock Source
  393. * @{
  394. */
  395. #define RCC_ADCCLKSOURCE_SYSCLK 0x00000000U /*!< SYSCLK used as ADC clock */
  396. #define RCC_ADCCLKSOURCE_PLLADC RCC_CCIPR_ADCSEL_0 /*!< PLL "P" (PLLADC) used as ADC clock */
  397. #define RCC_ADCCLKSOURCE_HSI RCC_CCIPR_ADCSEL_1 /*!< HSI used as ADC clock */
  398. /**
  399. * @}
  400. */
  401. #if defined(CEC)
  402. /** @defgroup RCCEx_CEC_Clock_Source RCC CEC Clock Source
  403. * @{
  404. */
  405. #define RCC_CECCLKSOURCE_HSI_DIV488 0x00000000U /*!< HSI oscillator clock divided by 488 used as default CEC clock */
  406. #define RCC_CECCLKSOURCE_LSE RCC_CCIPR_CECSEL /*!< LSE oscillator clock used as CEC clock */
  407. /**
  408. * @}
  409. */
  410. #endif /* CEC */
  411. #if defined(RCC_CCIPR_TIM1SEL)
  412. /** @defgroup RCCEx_TIM1_Clock_Source RCC TIM1 Clock Source
  413. * @{
  414. */
  415. #define RCC_TIM1CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as Timer 1 clock */
  416. #define RCC_TIM1CLKSOURCE_PLL RCC_CCIPR_TIM1SEL /*!< PLL "Q" clock selected as Timer 1 clock */
  417. /**
  418. * @}
  419. */
  420. #endif /* RCC_CCIPR_TIM1SEL */
  421. #if defined(RCC_CCIPR_TIM15SEL)
  422. /** @defgroup RCCEx_TIM15_Clock_Source RCC TIM15 Clock Source
  423. * @{
  424. */
  425. #define RCC_TIM15CLKSOURCE_PCLK1 0x00000000U /*!< APB clock selected as Timer 15 clock */
  426. #define RCC_TIM15CLKSOURCE_PLL RCC_CCIPR_TIM15SEL /*!< PLL "Q" clock selected as Timer 15 clock */
  427. /**
  428. * @}
  429. */
  430. #endif /* RCC_CCIPR_TIM15SEL */
  431. #if defined(CRS)
  432. /** @defgroup RCCEx_CRS_Status RCCEx CRS Status
  433. * @{
  434. */
  435. #define RCC_CRS_NONE 0x00000000U
  436. #define RCC_CRS_TIMEOUT 0x00000001U
  437. #define RCC_CRS_SYNCOK 0x00000002U
  438. #define RCC_CRS_SYNCWARN 0x00000004U
  439. #define RCC_CRS_SYNCERR 0x00000008U
  440. #define RCC_CRS_SYNCMISS 0x00000010U
  441. #define RCC_CRS_TRIMOVF 0x00000020U
  442. /**
  443. * @}
  444. */
  445. /** @defgroup RCCEx_CRS_SynchroSource RCCEx CRS SynchroSource
  446. * @{
  447. */
  448. #define RCC_CRS_SYNC_SOURCE_GPIO 0x00000000U /*!< Synchro Signal source GPIO */
  449. #define RCC_CRS_SYNC_SOURCE_LSE CRS_CFGR_SYNCSRC_0 /*!< Synchro Signal source LSE */
  450. #define RCC_CRS_SYNC_SOURCE_USB CRS_CFGR_SYNCSRC_1 /*!< Synchro Signal source USB SOF (default)*/
  451. /**
  452. * @}
  453. */
  454. /** @defgroup RCCEx_CRS_SynchroDivider RCCEx CRS SynchroDivider
  455. * @{
  456. */
  457. #define RCC_CRS_SYNC_DIV1 0x00000000U /*!< Synchro Signal not divided (default) */
  458. #define RCC_CRS_SYNC_DIV2 CRS_CFGR_SYNCDIV_0 /*!< Synchro Signal divided by 2 */
  459. #define RCC_CRS_SYNC_DIV4 CRS_CFGR_SYNCDIV_1 /*!< Synchro Signal divided by 4 */
  460. #define RCC_CRS_SYNC_DIV8 (CRS_CFGR_SYNCDIV_1 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 8 */
  461. #define RCC_CRS_SYNC_DIV16 CRS_CFGR_SYNCDIV_2 /*!< Synchro Signal divided by 16 */
  462. #define RCC_CRS_SYNC_DIV32 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 32 */
  463. #define RCC_CRS_SYNC_DIV64 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_1) /*!< Synchro Signal divided by 64 */
  464. #define RCC_CRS_SYNC_DIV128 CRS_CFGR_SYNCDIV /*!< Synchro Signal divided by 128 */
  465. /**
  466. * @}
  467. */
  468. /** @defgroup RCCEx_CRS_SynchroPolarity RCCEx CRS SynchroPolarity
  469. * @{
  470. */
  471. #define RCC_CRS_SYNC_POLARITY_RISING 0x00000000U /*!< Synchro Active on rising edge (default) */
  472. #define RCC_CRS_SYNC_POLARITY_FALLING CRS_CFGR_SYNCPOL /*!< Synchro Active on falling edge */
  473. /**
  474. * @}
  475. */
  476. /** @defgroup RCCEx_CRS_ReloadValueDefault RCCEx CRS ReloadValueDefault
  477. * @{
  478. */
  479. #define RCC_CRS_RELOADVALUE_DEFAULT 0x0000BB7FU /*!< The reset value of the RELOAD field corresponds
  480. to a target frequency of 48 MHz and a synchronization signal frequency of 1 kHz (SOF signal from USB). */
  481. /**
  482. * @}
  483. */
  484. /** @defgroup RCCEx_CRS_ErrorLimitDefault RCCEx CRS ErrorLimitDefault
  485. * @{
  486. */
  487. #define RCC_CRS_ERRORLIMIT_DEFAULT 0x00000022U /*!< Default Frequency error limit */
  488. /**
  489. * @}
  490. */
  491. /** @defgroup RCCEx_CRS_HSI48CalibrationDefault RCCEx CRS HSI48CalibrationDefault
  492. * @{
  493. */
  494. #define RCC_CRS_HSI48CALIBRATION_DEFAULT 0x00000040U /*!< The default value is 64, which corresponds to the middle of the trimming interval.
  495. The trimming step is specified in the product datasheet. A higher TRIM value
  496. corresponds to a higher output frequency */
  497. /**
  498. * @}
  499. */
  500. /** @defgroup RCCEx_CRS_FreqErrorDirection RCCEx CRS FreqErrorDirection
  501. * @{
  502. */
  503. #define RCC_CRS_FREQERRORDIR_UP 0x00000000U /*!< Upcounting direction, the actual frequency is above the target */
  504. #define RCC_CRS_FREQERRORDIR_DOWN CRS_ISR_FEDIR /*!< Downcounting direction, the actual frequency is below the target */
  505. /**
  506. * @}
  507. */
  508. /** @defgroup RCCEx_CRS_Interrupt_Sources RCCEx CRS Interrupt Sources
  509. * @{
  510. */
  511. #define RCC_CRS_IT_SYNCOK CRS_CR_SYNCOKIE /*!< SYNC event OK */
  512. #define RCC_CRS_IT_SYNCWARN CRS_CR_SYNCWARNIE /*!< SYNC warning */
  513. #define RCC_CRS_IT_ERR CRS_CR_ERRIE /*!< Error */
  514. #define RCC_CRS_IT_ESYNC CRS_CR_ESYNCIE /*!< Expected SYNC */
  515. #define RCC_CRS_IT_SYNCERR CRS_CR_ERRIE /*!< SYNC error */
  516. #define RCC_CRS_IT_SYNCMISS CRS_CR_ERRIE /*!< SYNC missed */
  517. #define RCC_CRS_IT_TRIMOVF CRS_CR_ERRIE /*!< Trimming overflow or underflow */
  518. /**
  519. * @}
  520. */
  521. /** @defgroup RCCEx_CRS_Flags RCCEx CRS Flags
  522. * @{
  523. */
  524. #define RCC_CRS_FLAG_SYNCOK CRS_ISR_SYNCOKF /*!< SYNC event OK flag */
  525. #define RCC_CRS_FLAG_SYNCWARN CRS_ISR_SYNCWARNF /*!< SYNC warning flag */
  526. #define RCC_CRS_FLAG_ERR CRS_ISR_ERRF /*!< Error flag */
  527. #define RCC_CRS_FLAG_ESYNC CRS_ISR_ESYNCF /*!< Expected SYNC flag */
  528. #define RCC_CRS_FLAG_SYNCERR CRS_ISR_SYNCERR /*!< SYNC error */
  529. #define RCC_CRS_FLAG_SYNCMISS CRS_ISR_SYNCMISS /*!< SYNC missed*/
  530. #define RCC_CRS_FLAG_TRIMOVF CRS_ISR_TRIMOVF /*!< Trimming overflow or underflow */
  531. /**
  532. * @}
  533. */
  534. #endif /* CRS */
  535. /**
  536. * @}
  537. */
  538. /* Exported macros -----------------------------------------------------------*/
  539. /** @defgroup RCCEx_Exported_Macros RCCEx Exported Macros
  540. * @{
  541. */
  542. /** @brief Macro to configure the I2C1 clock (I2C1CLK).
  543. *
  544. * @param __I2C1_CLKSOURCE__ specifies the I2C1 clock source.
  545. * This parameter can be one of the following values:
  546. * @arg @ref RCC_I2C1CLKSOURCE_HSI HSI selected as I2C1 clock
  547. * @arg @ref RCC_I2C1CLKSOURCE_SYSCLK System Clock selected as I2C1 clock
  548. */
  549. #define __HAL_RCC_I2C1_CONFIG(__I2C1_CLKSOURCE__) \
  550. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_I2C1SEL, (uint32_t)(__I2C1_CLKSOURCE__))
  551. /** @brief Macro to get the I2C1 clock source.
  552. * @retval The clock source can be one of the following values:
  553. * @arg @ref RCC_I2C1CLKSOURCE_HSI HSI selected as I2C1 clock
  554. * @arg @ref RCC_I2C1CLKSOURCE_SYSCLK System Clock selected as I2C1 clock
  555. */
  556. #define __HAL_RCC_GET_I2C1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_I2C1SEL)))
  557. #if defined(RCC_CCIPR_I2C2SEL)
  558. /** @brief Macro to configure the I2C2 clock (I2C2CLK).
  559. *
  560. * @param __I2C2_CLKSOURCE__ specifies the I2C2 clock source.
  561. * This parameter can be one of the following values:
  562. * @arg @ref RCC_I2C2CLKSOURCE_HSI HSI selected as I2C2 clock
  563. * @arg @ref RCC_I2C2CLKSOURCE_SYSCLK System Clock selected as I2C2 clock
  564. */
  565. #define __HAL_RCC_I2C2_CONFIG(__I2C2_CLKSOURCE__) \
  566. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_I2C2SEL, (uint32_t)(__I2C2_CLKSOURCE__))
  567. /** @brief Macro to get the I2C2 clock source.
  568. * @retval The clock source can be one of the following values:
  569. * @arg @ref RCC_I2C2CLKSOURCE_HSI HSI selected as I2C2 clock
  570. * @arg @ref RCC_I2C2CLKSOURCE_SYSCLK System Clock selected as I2C2 clock
  571. */
  572. #define __HAL_RCC_GET_I2C2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_I2C2SEL)))
  573. #endif /* RCC_CCIPR_I2C2SEL */
  574. /** @brief Macro to configure the I2S1 clock (I2S1CLK).
  575. *
  576. * @param __I2S1_CLKSOURCE__ specifies the I2S1 clock source.
  577. * This parameter can be one of the following values:
  578. * @arg @ref RCC_I2S1CLKSOURCE_SYSCLK System Clock selected as I2S1 clock
  579. * @arg @ref RCC_I2S1CLKSOURCE_PLL PLLP Clock selected as I2S1 clock
  580. * @arg @ref RCC_I2S1CLKSOURCE_HSI HSI Clock selected as I2S1 clock
  581. * @arg @ref RCC_I2S1CLKSOURCE_EXT External clock selected as I2S1 clock
  582. */
  583. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  584. #define __HAL_RCC_I2S1_CONFIG(__I2S1_CLKSOURCE__) \
  585. MODIFY_REG(RCC->CCIPR2, RCC_CCIPR2_I2S1SEL, (uint32_t)(__I2S1_CLKSOURCE__))
  586. #else
  587. #define __HAL_RCC_I2S1_CONFIG(__I2S1_CLKSOURCE__) \
  588. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_I2S1SEL, (uint32_t)(__I2S1_CLKSOURCE__))
  589. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
  590. /** @brief Macro to get the I2S1 clock source.
  591. * @retval The clock source can be one of the following values:
  592. * @arg @ref RCC_I2S1CLKSOURCE_SYSCLK System Clock selected as I2S1 clock
  593. * @arg @ref RCC_I2S1CLKSOURCE_PLL PLLP Clock selected as I2S1 clock
  594. * @arg @ref RCC_I2S1CLKSOURCE_HSI HSI Clock selected as I2S1 clock
  595. * @arg @ref RCC_I2S1CLKSOURCE_EXT External clock selected as I2S1 clock
  596. */
  597. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  598. #define __HAL_RCC_GET_I2S1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR2, RCC_CCIPR2_I2S1SEL)))
  599. #else
  600. #define __HAL_RCC_GET_I2S1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_I2S1SEL)))
  601. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
  602. #if defined(RCC_CCIPR2_I2S2SEL)
  603. /** @brief Macro to configure the I2S2 clock (I2S2CLK).
  604. *
  605. * @param __I2S2_CLKSOURCE__ specifies the I2S2 clock source.
  606. * This parameter can be one of the following values:
  607. * @arg @ref RCC_I2S2CLKSOURCE_SYSCLK System Clock selected as I2S2 clock
  608. * @arg @ref RCC_I2S2CLKSOURCE_PLL PLLP Clock selected as I2S2 clock
  609. * @arg @ref RCC_I2S2CLKSOURCE_HSI HSI Clock selected as I2S2 clock
  610. * @arg @ref RCC_I2S2CLKSOURCE_EXT External clock selected as I2S2 clock
  611. */
  612. #define __HAL_RCC_I2S2_CONFIG(__I2S2_CLKSOURCE__) \
  613. MODIFY_REG(RCC->CCIPR2, RCC_CCIPR2_I2S2SEL, (uint32_t)(__I2S2_CLKSOURCE__))
  614. /** @brief Macro to get the I2S2 clock source.
  615. * @retval The clock source can be one of the following values:
  616. * @arg @ref RCC_I2S2CLKSOURCE_SYSCLK System Clock selected as I2S2 clock
  617. * @arg @ref RCC_I2S2CLKSOURCE_PLL PLLP Clock selected as I2S2 clock
  618. * @arg @ref RCC_I2S2CLKSOURCE_HSI HSI Clock selected as I2S2 clock
  619. * @arg @ref RCC_I2S2CLKSOURCE_EXT External clock selected as I2S2 clock
  620. */
  621. #define __HAL_RCC_GET_I2S2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR2, RCC_CCIPR2_I2S2SEL)))
  622. #endif /* RCC_CCIPR2_I2S2SEL */
  623. /** @brief Macro to configure the USART1 clock (USART1CLK).
  624. *
  625. * @param __USART1_CLKSOURCE__ specifies the USART1 clock source.
  626. * This parameter can be one of the following values:
  627. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  628. * @arg @ref RCC_USART1CLKSOURCE_HSI HSI selected as USART1 clock
  629. * @arg @ref RCC_USART1CLKSOURCE_SYSCLK System Clock selected as USART1 clock
  630. * @arg @ref RCC_USART1CLKSOURCE_LSE LSE selected as USART1 clock
  631. */
  632. #define __HAL_RCC_USART1_CONFIG(__USART1_CLKSOURCE__) \
  633. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_USART1SEL, (uint32_t)(__USART1_CLKSOURCE__))
  634. /** @brief Macro to get the USART1 clock source.
  635. * @retval The clock source can be one of the following values:
  636. * @arg @ref RCC_USART1CLKSOURCE_PCLK1 PCLK1 selected as USART1 clock
  637. * @arg @ref RCC_USART1CLKSOURCE_HSI HSI selected as USART1 clock
  638. * @arg @ref RCC_USART1CLKSOURCE_SYSCLK System Clock selected as USART1 clock
  639. * @arg @ref RCC_USART1CLKSOURCE_LSE LSE selected as USART1 clock
  640. */
  641. #define __HAL_RCC_GET_USART1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_USART1SEL)))
  642. #if defined(RCC_CCIPR_USART2SEL)
  643. /** @brief Macro to configure the USART2 clock (USART2CLK).
  644. *
  645. * @param __USART2_CLKSOURCE__ specifies the USART2 clock source.
  646. * This parameter can be one of the following values:
  647. * @arg @ref RCC_USART2CLKSOURCE_PCLK1 PCLK1 selected as USART2 clock
  648. * @arg @ref RCC_USART2CLKSOURCE_HSI HSI selected as USART2 clock
  649. * @arg @ref RCC_USART2CLKSOURCE_SYSCLK System Clock selected as USART2 clock
  650. * @arg @ref RCC_USART2CLKSOURCE_LSE LSE selected as USART2 clock
  651. */
  652. #define __HAL_RCC_USART2_CONFIG(__USART2_CLKSOURCE__) \
  653. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_USART2SEL, (uint32_t)(__USART2_CLKSOURCE__))
  654. /** @brief Macro to get the USART2 clock source.
  655. * @retval The clock source can be one of the following values:
  656. * @arg @ref RCC_USART2CLKSOURCE_PCLK1 PCLK1 selected as USART2 clock
  657. * @arg @ref RCC_USART2CLKSOURCE_HSI HSI selected as USART2 clock
  658. * @arg @ref RCC_USART2CLKSOURCE_SYSCLK System Clock selected as USART2 clock
  659. * @arg @ref RCC_USART2CLKSOURCE_LSE LSE selected as USART2 clock
  660. */
  661. #define __HAL_RCC_GET_USART2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_USART2SEL)))
  662. #endif /* RCC_CCIPR_USART2SEL */
  663. #if defined(RCC_CCIPR_USART3SEL)
  664. /** @brief Macro to configure the USART3 clock (USART3CLK).
  665. *
  666. * @param __USART3_CLKSOURCE__ specifies the USART3 clock source.
  667. * This parameter can be one of the following values:
  668. * @arg @ref RCC_USART3CLKSOURCE_PCLK1 PCLK1 selected as USART3 clock
  669. * @arg @ref RCC_USART3CLKSOURCE_HSI HSI selected as USART3 clock
  670. * @arg @ref RCC_USART3CLKSOURCE_SYSCLK System Clock selected as USART3 clock
  671. * @arg @ref RCC_USART3CLKSOURCE_LSE LSE selected as USART3 clock
  672. */
  673. #define __HAL_RCC_USART3_CONFIG(__USART3_CLKSOURCE__) \
  674. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_USART3SEL, (uint32_t)(__USART3_CLKSOURCE__))
  675. /** @brief Macro to get the USART3 clock source.
  676. * @retval The clock source can be one of the following values:
  677. * @arg @ref RCC_USART3CLKSOURCE_PCLK1 PCLK1 selected as USART3 clock
  678. * @arg @ref RCC_USART3CLKSOURCE_HSI HSI selected as USART3 clock
  679. * @arg @ref RCC_USART3CLKSOURCE_SYSCLK System Clock selected as USART3 clock
  680. * @arg @ref RCC_USART3CLKSOURCE_LSE LSE selected as USART3 clock
  681. */
  682. #define __HAL_RCC_GET_USART3_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_USART3SEL)))
  683. #endif /* RCC_CCIPR_USART3SEL */
  684. #if defined(RCC_CCIPR_LPUART1SEL)
  685. /** @brief Macro to configure the LPUART1 clock (LPUART1CLK).
  686. *
  687. * @param __LPUART1_CLKSOURCE__ specifies the LPUART1 clock source.
  688. * This parameter can be one of the following values:
  689. * @arg @ref RCC_LPUART1CLKSOURCE_PCLK1 PCLK1 selected as LPUART1 clock
  690. * @arg @ref RCC_LPUART1CLKSOURCE_HSI HSI selected as LPUART1 clock
  691. * @arg @ref RCC_LPUART1CLKSOURCE_SYSCLK System Clock selected as LPUART1 clock
  692. * @arg @ref RCC_LPUART1CLKSOURCE_LSE LSE selected as LPUART1 clock
  693. */
  694. #define __HAL_RCC_LPUART1_CONFIG(__LPUART1_CLKSOURCE__) \
  695. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_LPUART1SEL, (uint32_t)(__LPUART1_CLKSOURCE__))
  696. /** @brief Macro to get the LPUART1 clock source.
  697. * @retval The clock source can be one of the following values:
  698. * @arg @ref RCC_LPUART1CLKSOURCE_PCLK1 PCLK1 selected as LPUART1 clock
  699. * @arg @ref RCC_LPUART1CLKSOURCE_HSI HSI selected as LPUART1 clock
  700. * @arg @ref RCC_LPUART1CLKSOURCE_SYSCLK System Clock selected as LPUART1 clock
  701. * @arg @ref RCC_LPUART1CLKSOURCE_LSE LSE selected as LPUART1 clock
  702. */
  703. #define __HAL_RCC_GET_LPUART1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_LPUART1SEL)))
  704. #endif /* RCC_CCIPR_LPUART1SEL */
  705. #if defined(RCC_CCIPR_LPUART2SEL)
  706. /** @brief Macro to configure the LPUART2 clock (LPUART2CLK).
  707. *
  708. * @param __LPUART2_CLKSOURCE__ specifies the LPUART2 clock source.
  709. * This parameter can be one of the following values:
  710. * @arg @ref RCC_LPUART2CLKSOURCE_PCLK1 PCLK1 selected as LPUART2 clock
  711. * @arg @ref RCC_LPUART2CLKSOURCE_HSI HSI selected as LPUART2 clock
  712. * @arg @ref RCC_LPUART2CLKSOURCE_SYSCLK System Clock selected as LPUART2 clock
  713. * @arg @ref RCC_LPUART2CLKSOURCE_LSE LSE selected as LPUART2 clock
  714. */
  715. #define __HAL_RCC_LPUART2_CONFIG(__LPUART2_CLKSOURCE__) \
  716. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_LPUART2SEL, (uint32_t)(__LPUART2_CLKSOURCE__))
  717. /** @brief Macro to get the LPUART2 clock source.
  718. * @retval The clock source can be one of the following values:
  719. * @arg @ref RCC_LPUART2CLKSOURCE_PCLK1 PCLK1 selected as LPUART2 clock
  720. * @arg @ref RCC_LPUART2CLKSOURCE_HSI HSI selected as LPUART2 clock
  721. * @arg @ref RCC_LPUART2CLKSOURCE_SYSCLK System Clock selected as LPUART2 clock
  722. * @arg @ref RCC_LPUART2CLKSOURCE_LSE LSE selected as LPUART2 clock
  723. */
  724. #define __HAL_RCC_GET_LPUART2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_LPUART2SEL)))
  725. #endif /* RCC_CCIPR_LPUART2SEL */
  726. #if defined(RCC_CCIPR_LPTIM1SEL)
  727. /** @brief Macro to configure the LPTIM1 clock (LPTIM1CLK).
  728. *
  729. * @param __LPTIM1_CLKSOURCE__ specifies the LPTIM1 clock source.
  730. * This parameter can be one of the following values:
  731. * @arg @ref RCC_LPTIM1CLKSOURCE_PCLK1 PCLK1 selected as LPTIM1 clock
  732. * @arg @ref RCC_LPTIM1CLKSOURCE_LSI HSI selected as LPTIM1 clock
  733. * @arg @ref RCC_LPTIM1CLKSOURCE_HSI LSI selected as LPTIM1 clock
  734. * @arg @ref RCC_LPTIM1CLKSOURCE_LSE LSE selected as LPTIM1 clock
  735. */
  736. #define __HAL_RCC_LPTIM1_CONFIG(__LPTIM1_CLKSOURCE__) \
  737. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_LPTIM1SEL, (uint32_t)(__LPTIM1_CLKSOURCE__))
  738. /** @brief Macro to get the LPTIM1 clock source.
  739. * @retval The clock source can be one of the following values:
  740. * @arg @ref RCC_LPTIM1CLKSOURCE_PCLK1 PCLK1 selected as LPUART1 clock
  741. * @arg @ref RCC_LPTIM1CLKSOURCE_LSI HSI selected as LPUART1 clock
  742. * @arg @ref RCC_LPTIM1CLKSOURCE_HSI System Clock selected as LPUART1 clock
  743. * @arg @ref RCC_LPTIM1CLKSOURCE_LSE LSE selected as LPUART1 clock
  744. */
  745. #define __HAL_RCC_GET_LPTIM1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_LPTIM1SEL)))
  746. #endif /* RCC_CCIPR_LPTIM1SEL */
  747. #if defined(RCC_CCIPR_LPTIM2SEL)
  748. /** @brief Macro to configure the LPTIM2 clock (LPTIM2CLK).
  749. *
  750. * @param __LPTIM2_CLKSOURCE__ specifies the LPTIM2 clock source.
  751. * This parameter can be one of the following values:
  752. * @arg @ref RCC_LPTIM2CLKSOURCE_PCLK1 PCLK1 selected as LPTIM2 clock
  753. * @arg @ref RCC_LPTIM2CLKSOURCE_LSI HSI selected as LPTIM2 clock
  754. * @arg @ref RCC_LPTIM2CLKSOURCE_HSI LSI selected as LPTIM2 clock
  755. * @arg @ref RCC_LPTIM2CLKSOURCE_LSE LSE selected as LPTIM2 clock
  756. */
  757. #define __HAL_RCC_LPTIM2_CONFIG(__LPTIM2_CLKSOURCE__) \
  758. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_LPTIM2SEL, (uint32_t)(__LPTIM2_CLKSOURCE__))
  759. /** @brief Macro to get the LPTIM2 clock source.
  760. * @retval The clock source can be one of the following values:
  761. * @arg @ref RCC_LPTIM2CLKSOURCE_PCLK1 PCLK1 selected as LPTIM2 clock
  762. * @arg @ref RCC_LPTIM2CLKSOURCE_LSI HSI selected as LPTIM2 clock
  763. * @arg @ref RCC_LPTIM2CLKSOURCE_HSI System Clock selected as LPTIM2 clock
  764. * @arg @ref RCC_LPTIM2CLKSOURCE_LSE LSE selected as LPTIM2 clock
  765. */
  766. #define __HAL_RCC_GET_LPTIM2_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_LPTIM2SEL)))
  767. #endif /* RCC_CCIPR_LPTIM2SEL */
  768. #if defined(CEC)
  769. /** @brief Macro to configure the CEC clock (CECCLK).
  770. *
  771. * @param __CEC_CLKSOURCE__ specifies the CEC clock source.
  772. * This parameter can be one of the following values:
  773. * @arg @ref RCC_CECCLKSOURCE_HSI_DIV488 HSI_DIV_488 selected as CEC clock
  774. * @arg @ref RCC_CECCLKSOURCE_LSE LSE selected as CEC clock
  775. */
  776. #define __HAL_RCC_CEC_CONFIG(__CEC_CLKSOURCE__) \
  777. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_CECSEL, (uint32_t)(__CEC_CLKSOURCE__))
  778. /** @brief Macro to get the CEC clock source.
  779. * @retval The clock source can be one of the following values:
  780. * @arg @ref RCC_CECCLKSOURCE_HSI_DIV488 HSI_DIV_488 Clock selected as CEC clock
  781. * @arg @ref RCC_CECCLKSOURCE_LSE LSE selected as CEC clock
  782. */
  783. #define __HAL_RCC_GET_CEC_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_CECSEL)))
  784. #endif /* CEC */
  785. #if defined(RNG)
  786. /** @brief Macro to configure the RNG clock.
  787. *
  788. *
  789. * @param __RNG_CLKSOURCE__ specifies the RNG clock source.
  790. * This parameter can be one of the following values:
  791. * @arg @ref RCC_RNGCLKSOURCE_NONE No clock selected as RNG clock
  792. * @arg @ref RCC_RNGCLKSOURCE_HSI_DIV8 HSI Clock divided by 8 selected as RNG clock
  793. * @arg @ref RCC_RNGCLKSOURCE_SYSCLK System Clock selected as RNG clock
  794. * @arg @ref RCC_RNGCLKSOURCE_PLL PLLQ Output Clock selected as RNG clock
  795. */
  796. #define __HAL_RCC_RNG_CONFIG(__RNG_CLKSOURCE__) \
  797. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_RNGSEL, (uint32_t)(__RNG_CLKSOURCE__))
  798. /** @brief Macro to get the RNG clock.
  799. * @retval The clock source can be one of the following values:
  800. * @arg @ref RCC_RNGCLKSOURCE_NONE No clock selected as RNG clock
  801. * @arg @ref RCC_RNGCLKSOURCE_HSI_DIV8 HSI Clock divide by 8 selected as RNG clock
  802. * @arg @ref RCC_RNGCLKSOURCE_SYSCLK System clock selected as RNG clock
  803. * @arg @ref RCC_RNGCLKSOURCE_PLL PLLQ Output Clock selected as RNG clock
  804. */
  805. #define __HAL_RCC_GET_RNG_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_RNGSEL)))
  806. /** @brief Macro to configure the RNG clock.
  807. *
  808. *
  809. * @param __RNG_CLKDIV__ specifies the RNG clock division factor.
  810. * This parameter can be one of the following values:
  811. * @arg @ref RCC_RNGCLK_DIV1 RNG Clock not divided
  812. * @arg @ref RCC_RNGCLK_DIV2 RNG Clock divided by 2
  813. * @arg @ref RCC_RNGCLK_DIV4 RNG Clock divided by 4
  814. * @arg @ref RCC_RNGCLK_DIV8 RNG Clock divided by 8
  815. */
  816. #define __HAL_RCC_RNGDIV_CONFIG(__RNG_CLKDIV__) \
  817. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_RNGDIV, (uint32_t)(__RNG_CLKDIV__))
  818. /** @brief Macro to get the RNG clock division factor.
  819. * @retval The division factor can be one of the following values:
  820. * @arg @ref RCC_RNGCLK_DIV1 RNG Clock not divided
  821. * @arg @ref RCC_RNGCLK_DIV2 RNG Clock divided by 2
  822. * @arg @ref RCC_RNGCLK_DIV4 RNG Clock divided by 4
  823. * @arg @ref RCC_RNGCLK_DIV8 RNG Clock divided by 8
  824. */
  825. #define __HAL_RCC_GET_RNG_DIV() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_RNGDIV)))
  826. #endif /* RNG */
  827. /** @brief Macro to configure the ADC interface clock
  828. * @param __ADC_CLKSOURCE__ specifies the ADC digital interface clock source.
  829. * This parameter can be one of the following values:
  830. * @arg @ref RCC_ADCCLKSOURCE_PLLADC PLL "P" (PLLADC) Clock selected as ADC clock
  831. * @arg @ref RCC_ADCCLKSOURCE_SYSCLK System Clock selected as ADC clock
  832. * @arg @ref RCC_ADCCLKSOURCE_HSI HSI Clock selected as ADC clock
  833. */
  834. #define __HAL_RCC_ADC_CONFIG(__ADC_CLKSOURCE__) \
  835. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_ADCSEL, (uint32_t)(__ADC_CLKSOURCE__))
  836. /** @brief Macro to get the ADC clock source.
  837. * @retval The clock source can be one of the following values:
  838. * @arg @ref RCC_ADCCLKSOURCE_PLLADC PLL "P" (PLLADC) Clock selected as ADC clock
  839. * @arg @ref RCC_ADCCLKSOURCE_SYSCLK System Clock selected as ADC clock
  840. * @arg @ref RCC_ADCCLKSOURCE_HSI HSI Clock selected as ADC clock
  841. */
  842. #define __HAL_RCC_GET_ADC_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_ADCSEL)))
  843. #if defined(RCC_CCIPR_TIM1SEL)
  844. /** @brief Macro to configure the TIM1 interface clock
  845. * @param __TIM1_CLKSOURCE__ specifies the TIM1 digital interface clock source.
  846. * This parameter can be one of the following values:
  847. * @arg @ref RCC_TIM1CLKSOURCE_PLL PLLQ Output Clock selected as TIM1 clock
  848. * @arg @ref RCC_TIM1CLKSOURCE_PCLK1 System Clock selected as TIM1 clock
  849. */
  850. #define __HAL_RCC_TIM1_CONFIG(__TIM1_CLKSOURCE__) \
  851. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_TIM1SEL, (uint32_t)(__TIM1_CLKSOURCE__))
  852. /** @brief Macro to get the TIM1 clock source.
  853. * @retval The clock source can be one of the following values:
  854. * @arg @ref RCC_TIM1CLKSOURCE_PLL PLLQ Output Clock selected as TIM1 clock
  855. * @arg @ref RCC_TIM1CLKSOURCE_PCLK1 System Clock selected as TIM1 clock
  856. */
  857. #define __HAL_RCC_GET_TIM1_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_TIM1SEL)))
  858. #endif /* RCC_CCIPR_TIM1SEL */
  859. #if defined(RCC_CCIPR_TIM15SEL)
  860. /** @brief Macro to configure the TIM15 interface clock
  861. * @param __TIM15_CLKSOURCE__ specifies the TIM15 digital interface clock source.
  862. * This parameter can be one of the following values:
  863. * @arg RCC_TIM15CLKSOURCE_PLL PLLQ Output Clock selected as TIM15 clock
  864. * @arg RCC_TIM15CLKSOURCE_PCLK1 System Clock selected as TIM15 clock
  865. */
  866. #define __HAL_RCC_TIM15_CONFIG(__TIM15_CLKSOURCE__) \
  867. MODIFY_REG(RCC->CCIPR, RCC_CCIPR_TIM15SEL, (uint32_t)(__TIM15_CLKSOURCE__))
  868. /** @brief Macro to get the TIM15 clock source.
  869. * @retval The clock source can be one of the following values:
  870. * @arg @ref RCC_TIM15CLKSOURCE_PLL PLLQ Output Clock selected as TIM15 clock
  871. * @arg @ref RCC_TIM15CLKSOURCE_PCLK1 System Clock selected as TIM15 clock
  872. */
  873. #define __HAL_RCC_GET_TIM15_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR, RCC_CCIPR_TIM15SEL)))
  874. #endif /* RCC_CCIPR_TIM15SEL */
  875. #if defined(RCC_CCIPR2_USBSEL)
  876. /** @brief Macro to configure the USB interface clock
  877. * @param __USB_CLKSOURCE__ specifies the USB digital interface clock source.
  878. * This parameter can be one of the following values:
  879. * @arg @ref RCC_USBCLKSOURCE_PLL PLLQ Output Clock selected as USB clock (*)
  880. * @arg @ref RCC_USBCLKSOURCE_HSE HSE Output Clock selected as USB clock
  881. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 Clock selected as USB clock (*)
  882. * (*) Feature not available on all devices
  883. */
  884. #define __HAL_RCC_USB_CONFIG(__USB_CLKSOURCE__) \
  885. MODIFY_REG(RCC->CCIPR2, RCC_CCIPR2_USBSEL, (uint32_t)(__USB_CLKSOURCE__))
  886. /** @brief Macro to get the USB clock source.
  887. * @retval The clock source can be one of the following values:
  888. * @arg @ref RCC_USBCLKSOURCE_HSI48 HSI48 Clock selected as USB clock
  889. * @arg @ref RCC_USBCLKSOURCE_HSE HSE Output Clock selected as USB clock
  890. * @arg @ref RCC_USBCLKSOURCE_PLL PLLQ Output Clock selected as USB clock
  891. */
  892. #define __HAL_RCC_GET_USB_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR2, RCC_CCIPR2_USBSEL)))
  893. #endif /* RCC_CCIPR2_USBSEL */
  894. #if defined(FDCAN1) || defined(FDCAN2)
  895. /** @brief Macro to configure the FDCAN interface clock
  896. * @param __FDCAN_CLKSOURCE__ specifies the FDCAN digital interface clock source.
  897. * This parameter can be one of the following values:
  898. * @arg RCC_FDCANCLKSOURCE_PLL PLLQ Output Clock selected as FDCAN clock
  899. * @arg RCC_FDCANCLKSOURCE_PCLK1 System Clock selected as FDCAN clock
  900. * @arg RCC_FDCANCLKSOURCE_HSE HSE Clock selected as FDCAN clock
  901. */
  902. #define __HAL_RCC_FDCAN_CONFIG(__FDCAN_CLKSOURCE__) \
  903. MODIFY_REG(RCC->CCIPR2, RCC_CCIPR2_FDCANSEL, (uint32_t)(__FDCAN_CLKSOURCE__))
  904. /** @brief Macro to get the FDCAN clock source.
  905. * @retval The clock source can be one of the following values:
  906. * @arg @ref RCC_FDCANCLKSOURCE_PLL PLLQ Output Clock selected as FDCAN clock
  907. * @arg @ref RCC_FDCANCLKSOURCE_PCLK1 System Clock selected as FDCAN clock
  908. * @arg @ref RCC_FDCANCLKSOURCE_HSE HSE Clock selected as FDCAN clock
  909. */
  910. #define __HAL_RCC_GET_FDCAN_SOURCE() ((uint32_t)(READ_BIT(RCC->CCIPR2, RCC_CCIPR2_FDCANSEL)))
  911. #endif /* FDCAN1 || FDCAN2 */
  912. #if defined(CRS)
  913. /**
  914. * @brief Enable the specified CRS interrupts.
  915. * @param __INTERRUPT__ specifies the CRS interrupt sources to be enabled.
  916. * This parameter can be any combination of the following values:
  917. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  918. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  919. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  920. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  921. * @retval None
  922. */
  923. #define __HAL_RCC_CRS_ENABLE_IT(__INTERRUPT__) SET_BIT(CRS->CR, (__INTERRUPT__))
  924. /**
  925. * @brief Disable the specified CRS interrupts.
  926. * @param __INTERRUPT__ specifies the CRS interrupt sources to be disabled.
  927. * This parameter can be any combination of the following values:
  928. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  929. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  930. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  931. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  932. * @retval None
  933. */
  934. #define __HAL_RCC_CRS_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(CRS->CR, (__INTERRUPT__))
  935. /** @brief Check whether the CRS interrupt has occurred or not.
  936. * @param __INTERRUPT__ specifies the CRS interrupt source to check.
  937. * This parameter can be one of the following values:
  938. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  939. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  940. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  941. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  942. * @retval The new state of __INTERRUPT__ (SET or RESET).
  943. */
  944. #define __HAL_RCC_CRS_GET_IT_SOURCE(__INTERRUPT__) ((READ_BIT(CRS->CR, (__INTERRUPT__)) != 0U) ? SET : RESET)
  945. /** @brief Clear the CRS interrupt pending bits
  946. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  947. * This parameter can be any combination of the following values:
  948. * @arg @ref RCC_CRS_IT_SYNCOK SYNC event OK interrupt
  949. * @arg @ref RCC_CRS_IT_SYNCWARN SYNC warning interrupt
  950. * @arg @ref RCC_CRS_IT_ERR Synchronization or trimming error interrupt
  951. * @arg @ref RCC_CRS_IT_ESYNC Expected SYNC interrupt
  952. * @arg @ref RCC_CRS_IT_TRIMOVF Trimming overflow or underflow interrupt
  953. * @arg @ref RCC_CRS_IT_SYNCERR SYNC error interrupt
  954. * @arg @ref RCC_CRS_IT_SYNCMISS SYNC missed interrupt
  955. */
  956. /* CRS IT Error Mask */
  957. #define RCC_CRS_IT_ERROR_MASK (RCC_CRS_IT_TRIMOVF | RCC_CRS_IT_SYNCERR | RCC_CRS_IT_SYNCMISS)
  958. #define __HAL_RCC_CRS_CLEAR_IT(__INTERRUPT__) do { \
  959. if(((__INTERRUPT__) & RCC_CRS_IT_ERROR_MASK) != 0U) \
  960. { \
  961. WRITE_REG(CRS->ICR, CRS_ICR_ERRC | ((__INTERRUPT__) & ~RCC_CRS_IT_ERROR_MASK)); \
  962. } \
  963. else \
  964. { \
  965. WRITE_REG(CRS->ICR, (__INTERRUPT__)); \
  966. } \
  967. } while(0)
  968. /**
  969. * @brief Check whether the specified CRS flag is set or not.
  970. * @param __FLAG__ specifies the flag to check.
  971. * This parameter can be one of the following values:
  972. * @arg @ref RCC_CRS_FLAG_SYNCOK SYNC event OK
  973. * @arg @ref RCC_CRS_FLAG_SYNCWARN SYNC warning
  974. * @arg @ref RCC_CRS_FLAG_ERR Error
  975. * @arg @ref RCC_CRS_FLAG_ESYNC Expected SYNC
  976. * @arg @ref RCC_CRS_FLAG_TRIMOVF Trimming overflow or underflow
  977. * @arg @ref RCC_CRS_FLAG_SYNCERR SYNC error
  978. * @arg @ref RCC_CRS_FLAG_SYNCMISS SYNC missed
  979. * @retval The new state of _FLAG_ (TRUE or FALSE).
  980. */
  981. #define __HAL_RCC_CRS_GET_FLAG(__FLAG__) (READ_BIT(CRS->ISR, (__FLAG__)) == (__FLAG__))
  982. /**
  983. * @brief Clear the CRS specified FLAG.
  984. * @param __FLAG__ specifies the flag to clear.
  985. * This parameter can be one of the following values:
  986. * @arg @ref RCC_CRS_FLAG_SYNCOK SYNC event OK
  987. * @arg @ref RCC_CRS_FLAG_SYNCWARN SYNC warning
  988. * @arg @ref RCC_CRS_FLAG_ERR Error
  989. * @arg @ref RCC_CRS_FLAG_ESYNC Expected SYNC
  990. * @arg @ref RCC_CRS_FLAG_TRIMOVF Trimming overflow or underflow
  991. * @arg @ref RCC_CRS_FLAG_SYNCERR SYNC error
  992. * @arg @ref RCC_CRS_FLAG_SYNCMISS SYNC missed
  993. * @note RCC_CRS_FLAG_ERR clears RCC_CRS_FLAG_TRIMOVF, RCC_CRS_FLAG_SYNCERR, RCC_CRS_FLAG_SYNCMISS and consequently RCC_CRS_FLAG_ERR
  994. * @retval None
  995. */
  996. /* CRS Flag Error Mask */
  997. #define RCC_CRS_FLAG_ERROR_MASK (RCC_CRS_FLAG_TRIMOVF | RCC_CRS_FLAG_SYNCERR | RCC_CRS_FLAG_SYNCMISS)
  998. #define __HAL_RCC_CRS_CLEAR_FLAG(__FLAG__) do { \
  999. if(((__FLAG__) & RCC_CRS_FLAG_ERROR_MASK) != 0U) \
  1000. { \
  1001. WRITE_REG(CRS->ICR, CRS_ICR_ERRC | ((__FLAG__) & ~RCC_CRS_FLAG_ERROR_MASK)); \
  1002. } \
  1003. else \
  1004. { \
  1005. WRITE_REG(CRS->ICR, (__FLAG__)); \
  1006. } \
  1007. } while(0)
  1008. #endif /* CRS */
  1009. /**
  1010. * @}
  1011. */
  1012. #if defined(CRS)
  1013. /** @defgroup RCCEx_CRS_Extended_Features RCCEx CRS Extended Features
  1014. * @{
  1015. */
  1016. /**
  1017. * @brief Enable the oscillator clock for frequency error counter.
  1018. * @note when the CEN bit is set the CRS_CFGR register becomes write-protected.
  1019. * @retval None
  1020. */
  1021. #define __HAL_RCC_CRS_FREQ_ERROR_COUNTER_ENABLE() SET_BIT(CRS->CR, CRS_CR_CEN)
  1022. /**
  1023. * @brief Disable the oscillator clock for frequency error counter.
  1024. * @retval None
  1025. */
  1026. #define __HAL_RCC_CRS_FREQ_ERROR_COUNTER_DISABLE() CLEAR_BIT(CRS->CR, CRS_CR_CEN)
  1027. /**
  1028. * @brief Enable the automatic hardware adjustment of TRIM bits.
  1029. * @note When the AUTOTRIMEN bit is set the CRS_CFGR register becomes write-protected.
  1030. * @retval None
  1031. */
  1032. #define __HAL_RCC_CRS_AUTOMATIC_CALIB_ENABLE() SET_BIT(CRS->CR, CRS_CR_AUTOTRIMEN)
  1033. /**
  1034. * @brief Enable or disable the automatic hardware adjustment of TRIM bits.
  1035. * @retval None
  1036. */
  1037. #define __HAL_RCC_CRS_AUTOMATIC_CALIB_DISABLE() CLEAR_BIT(CRS->CR, CRS_CR_AUTOTRIMEN)
  1038. /**
  1039. * @brief Macro to calculate reload value to be set in CRS register according to target and sync frequencies
  1040. * @note The RELOAD value should be selected according to the ratio between the target frequency and the frequency
  1041. * of the synchronization source after prescaling. It is then decreased by one in order to
  1042. * reach the expected synchronization on the zero value. The formula is the following:
  1043. * RELOAD = (fTARGET / fSYNC) -1
  1044. * @param __FTARGET__ Target frequency (value in Hz)
  1045. * @param __FSYNC__ Synchronization signal frequency (value in Hz)
  1046. * @retval None
  1047. */
  1048. #define __HAL_RCC_CRS_RELOADVALUE_CALCULATE(__FTARGET__, __FSYNC__) (((__FTARGET__) / (__FSYNC__)) - 1U)
  1049. /**
  1050. * @}
  1051. */
  1052. #endif /* CRS */
  1053. /* Exported functions --------------------------------------------------------*/
  1054. /** @addtogroup RCCEx_Exported_Functions
  1055. * @{
  1056. */
  1057. /** @addtogroup RCCEx_Exported_Functions_Group1
  1058. * @{
  1059. */
  1060. HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit);
  1061. void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit);
  1062. uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk);
  1063. /**
  1064. * @}
  1065. */
  1066. /** @addtogroup RCCEx_Exported_Functions_Group2
  1067. * @{
  1068. */
  1069. void HAL_RCCEx_EnableLSCO(uint32_t LSCOSource);
  1070. void HAL_RCCEx_DisableLSCO(void);
  1071. /**
  1072. * @}
  1073. */
  1074. #if defined(CRS)
  1075. /** @addtogroup RCCEx_Exported_Functions_Group3
  1076. * @{
  1077. */
  1078. void HAL_RCCEx_CRSConfig(RCC_CRSInitTypeDef *pInit);
  1079. void HAL_RCCEx_CRSSoftwareSynchronizationGenerate(void);
  1080. void HAL_RCCEx_CRSGetSynchronizationInfo(RCC_CRSSynchroInfoTypeDef *pSynchroInfo);
  1081. uint32_t HAL_RCCEx_CRSWaitSynchronization(uint32_t Timeout);
  1082. void HAL_RCCEx_CRS_IRQHandler(void);
  1083. void HAL_RCCEx_CRS_SyncOkCallback(void);
  1084. void HAL_RCCEx_CRS_SyncWarnCallback(void);
  1085. void HAL_RCCEx_CRS_ExpectedSyncCallback(void);
  1086. void HAL_RCCEx_CRS_ErrorCallback(uint32_t Error);
  1087. /**
  1088. * @}
  1089. */
  1090. #endif /* CRS */
  1091. /**
  1092. * @}
  1093. */
  1094. /* Private macros ------------------------------------------------------------*/
  1095. /** @defgroup RCCEx_Private_Macros RCCEx Private Macros
  1096. * @{
  1097. */
  1098. #define IS_RCC_LSCOSOURCE(__SOURCE__) (((__SOURCE__) == RCC_LSCOSOURCE_LSI) || \
  1099. ((__SOURCE__) == RCC_LSCOSOURCE_LSE))
  1100. #if defined(STM32G0C1xx)
  1101. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1102. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1103. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1104. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1105. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1106. (((__SELECTION__) & RCC_PERIPHCLK_LPUART2) == RCC_PERIPHCLK_LPUART2) || \
  1107. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1108. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1109. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1110. (((__SELECTION__) & RCC_PERIPHCLK_I2S2) == RCC_PERIPHCLK_I2S2) || \
  1111. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1112. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1113. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1114. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1115. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1116. (((__SELECTION__) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC) || \
  1117. (((__SELECTION__) & RCC_PERIPHCLK_FDCAN) == RCC_PERIPHCLK_FDCAN) || \
  1118. (((__SELECTION__) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) || \
  1119. (((__SELECTION__) & RCC_PERIPHCLK_TIM1) == RCC_PERIPHCLK_TIM1) || \
  1120. (((__SELECTION__) & RCC_PERIPHCLK_TIM15) == RCC_PERIPHCLK_TIM15))
  1121. #elif defined(STM32G0B1xx)
  1122. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1123. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1124. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1125. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1126. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1127. (((__SELECTION__) & RCC_PERIPHCLK_LPUART2) == RCC_PERIPHCLK_LPUART2) || \
  1128. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1129. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1130. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1131. (((__SELECTION__) & RCC_PERIPHCLK_I2S2) == RCC_PERIPHCLK_I2S2) || \
  1132. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1133. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1134. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1135. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1136. (((__SELECTION__) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC) || \
  1137. (((__SELECTION__) & RCC_PERIPHCLK_FDCAN) == RCC_PERIPHCLK_FDCAN) || \
  1138. (((__SELECTION__) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) || \
  1139. (((__SELECTION__) & RCC_PERIPHCLK_TIM1) == RCC_PERIPHCLK_TIM1) || \
  1140. (((__SELECTION__) & RCC_PERIPHCLK_TIM15) == RCC_PERIPHCLK_TIM15))
  1141. #elif defined(STM32G0B0xx)
  1142. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1143. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1144. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1145. (((__SELECTION__) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3) || \
  1146. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1147. (((__SELECTION__) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2) || \
  1148. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1149. (((__SELECTION__) & RCC_PERIPHCLK_I2S2) == RCC_PERIPHCLK_I2S2) || \
  1150. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1151. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1152. (((__SELECTION__) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB))
  1153. #elif defined(STM32G081xx)
  1154. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1155. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1156. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1157. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1158. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1159. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1160. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1161. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1162. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1163. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1164. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1165. (((__SELECTION__) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC) || \
  1166. (((__SELECTION__) & RCC_PERIPHCLK_TIM1) == RCC_PERIPHCLK_TIM1) || \
  1167. (((__SELECTION__) & RCC_PERIPHCLK_TIM15) == RCC_PERIPHCLK_TIM15))
  1168. #elif defined(STM32G071xx)
  1169. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1170. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1171. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1172. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1173. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1174. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1175. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1176. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1177. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1178. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1179. (((__SELECTION__) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC) || \
  1180. (((__SELECTION__) & RCC_PERIPHCLK_TIM1) == RCC_PERIPHCLK_TIM1) || \
  1181. (((__SELECTION__) & RCC_PERIPHCLK_TIM15) == RCC_PERIPHCLK_TIM15))
  1182. #elif defined(STM32G070xx)
  1183. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1184. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1185. (((__SELECTION__) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2) || \
  1186. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1187. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1188. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1189. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
  1190. #elif defined(STM32G061xx)
  1191. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1192. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1193. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1194. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1195. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1196. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1197. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1198. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1199. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1200. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1201. (((__SELECTION__) & RCC_PERIPHCLK_TIM1) == RCC_PERIPHCLK_TIM1) || \
  1202. (((__SELECTION__) & RCC_PERIPHCLK_TIM15) == RCC_PERIPHCLK_TIM15))
  1203. #elif defined(STM32G051xx)
  1204. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1205. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1206. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1207. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1208. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1209. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1210. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1211. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1212. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1213. (((__SELECTION__) & RCC_PERIPHCLK_TIM1) == RCC_PERIPHCLK_TIM1) || \
  1214. (((__SELECTION__) & RCC_PERIPHCLK_TIM15) == RCC_PERIPHCLK_TIM15))
  1215. #elif defined(STM32G041xx)
  1216. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1217. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1218. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1219. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1220. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1221. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1222. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1223. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1224. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1225. (((__SELECTION__) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG) || \
  1226. (((__SELECTION__) & RCC_PERIPHCLK_TIM1) == RCC_PERIPHCLK_TIM1))
  1227. #elif defined(STM32G031xx)
  1228. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1229. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1230. (((__SELECTION__) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1) || \
  1231. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1232. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1233. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1) || \
  1234. (((__SELECTION__) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2) || \
  1235. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1236. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) || \
  1237. (((__SELECTION__) & RCC_PERIPHCLK_TIM1) == RCC_PERIPHCLK_TIM1))
  1238. #elif defined(STM32G030xx) || defined(STM32G050xx)
  1239. #define IS_RCC_PERIPHCLOCK(__SELECTION__) \
  1240. ((((__SELECTION__) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1) || \
  1241. (((__SELECTION__) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1) || \
  1242. (((__SELECTION__) & RCC_PERIPHCLK_I2S1) == RCC_PERIPHCLK_I2S1) || \
  1243. (((__SELECTION__) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) || \
  1244. (((__SELECTION__) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
  1245. #endif /* STM32G0C1xx */
  1246. #define IS_RCC_USART1CLKSOURCE(__SOURCE__) \
  1247. (((__SOURCE__) == RCC_USART1CLKSOURCE_PCLK1) || \
  1248. ((__SOURCE__) == RCC_USART1CLKSOURCE_SYSCLK) || \
  1249. ((__SOURCE__) == RCC_USART1CLKSOURCE_LSE) || \
  1250. ((__SOURCE__) == RCC_USART1CLKSOURCE_HSI))
  1251. #if defined(RCC_CCIPR_USART2SEL)
  1252. #define IS_RCC_USART2CLKSOURCE(__SOURCE__) \
  1253. (((__SOURCE__) == RCC_USART2CLKSOURCE_PCLK1) || \
  1254. ((__SOURCE__) == RCC_USART2CLKSOURCE_SYSCLK) || \
  1255. ((__SOURCE__) == RCC_USART2CLKSOURCE_LSE) || \
  1256. ((__SOURCE__) == RCC_USART2CLKSOURCE_HSI))
  1257. #endif /* RCC_CCIPR_USART2SEL */
  1258. #if defined(RCC_CCIPR_USART3SEL)
  1259. #define IS_RCC_USART3CLKSOURCE(__SOURCE__) \
  1260. (((__SOURCE__) == RCC_USART3CLKSOURCE_PCLK1) || \
  1261. ((__SOURCE__) == RCC_USART3CLKSOURCE_SYSCLK) || \
  1262. ((__SOURCE__) == RCC_USART3CLKSOURCE_LSE) || \
  1263. ((__SOURCE__) == RCC_USART3CLKSOURCE_HSI))
  1264. #endif /* RCC_CCIPR_USART3SEL */
  1265. #if defined(LPUART1)
  1266. #define IS_RCC_LPUART1CLKSOURCE(__SOURCE__) \
  1267. (((__SOURCE__) == RCC_LPUART1CLKSOURCE_PCLK1) || \
  1268. ((__SOURCE__) == RCC_LPUART1CLKSOURCE_SYSCLK) || \
  1269. ((__SOURCE__) == RCC_LPUART1CLKSOURCE_LSE) || \
  1270. ((__SOURCE__) == RCC_LPUART1CLKSOURCE_HSI))
  1271. #endif /* LPUART1 */
  1272. #if defined(LPUART2)
  1273. #define IS_RCC_LPUART2CLKSOURCE(__SOURCE__) \
  1274. (((__SOURCE__) == RCC_LPUART2CLKSOURCE_PCLK1) || \
  1275. ((__SOURCE__) == RCC_LPUART2CLKSOURCE_SYSCLK) || \
  1276. ((__SOURCE__) == RCC_LPUART2CLKSOURCE_LSE) || \
  1277. ((__SOURCE__) == RCC_LPUART2CLKSOURCE_HSI))
  1278. #endif /* LPUART2 */
  1279. #define IS_RCC_I2C1CLKSOURCE(__SOURCE__) \
  1280. (((__SOURCE__) == RCC_I2C1CLKSOURCE_PCLK1) || \
  1281. ((__SOURCE__) == RCC_I2C1CLKSOURCE_SYSCLK) || \
  1282. ((__SOURCE__) == RCC_I2C1CLKSOURCE_HSI))
  1283. #if defined(RCC_CCIPR_I2C2SEL)
  1284. #define IS_RCC_I2C2CLKSOURCE(__SOURCE__) \
  1285. (((__SOURCE__) == RCC_I2C2CLKSOURCE_PCLK1) || \
  1286. ((__SOURCE__) == RCC_I2C2CLKSOURCE_SYSCLK) || \
  1287. ((__SOURCE__) == RCC_I2C2CLKSOURCE_HSI))
  1288. #endif /* RCC_CCIPR_I2C2SEL */
  1289. #define IS_RCC_I2S1CLKSOURCE(__SOURCE__) \
  1290. (((__SOURCE__) == RCC_I2S1CLKSOURCE_SYSCLK)|| \
  1291. ((__SOURCE__) == RCC_I2S1CLKSOURCE_PLL) || \
  1292. ((__SOURCE__) == RCC_I2S1CLKSOURCE_HSI) || \
  1293. ((__SOURCE__) == RCC_I2S1CLKSOURCE_EXT))
  1294. #if defined(RCC_CCIPR2_I2S2SEL)
  1295. #define IS_RCC_I2S2CLKSOURCE(__SOURCE__) \
  1296. (((__SOURCE__) == RCC_I2S2CLKSOURCE_SYSCLK)|| \
  1297. ((__SOURCE__) == RCC_I2S2CLKSOURCE_PLL) || \
  1298. ((__SOURCE__) == RCC_I2S2CLKSOURCE_HSI) || \
  1299. ((__SOURCE__) == RCC_I2S2CLKSOURCE_EXT))
  1300. #endif /* RCC_CCIPR2_I2S2SEL */
  1301. #if defined(RCC_CCIPR_LPTIM1SEL)
  1302. #define IS_RCC_LPTIM1CLKSOURCE(__SOURCE__) \
  1303. (((__SOURCE__) == RCC_LPTIM1CLKSOURCE_PCLK1)|| \
  1304. ((__SOURCE__) == RCC_LPTIM1CLKSOURCE_LSI) || \
  1305. ((__SOURCE__) == RCC_LPTIM1CLKSOURCE_HSI) || \
  1306. ((__SOURCE__) == RCC_LPTIM1CLKSOURCE_LSE))
  1307. #endif /* RCC_CCIPR_LPTIM1SEL */
  1308. #if defined(RCC_CCIPR_LPTIM2SEL)
  1309. #define IS_RCC_LPTIM2CLKSOURCE(__SOURCE__) \
  1310. (((__SOURCE__) == RCC_LPTIM2CLKSOURCE_PCLK1)|| \
  1311. ((__SOURCE__) == RCC_LPTIM2CLKSOURCE_LSI) || \
  1312. ((__SOURCE__) == RCC_LPTIM2CLKSOURCE_HSI) || \
  1313. ((__SOURCE__) == RCC_LPTIM2CLKSOURCE_LSE))
  1314. #endif /* RCC_CCIPR_LPTIM2SEL */
  1315. #define IS_RCC_ADCCLKSOURCE(__SOURCE__) \
  1316. (((__SOURCE__) == RCC_ADCCLKSOURCE_PLLADC) || \
  1317. ((__SOURCE__) == RCC_ADCCLKSOURCE_SYSCLK) || \
  1318. ((__SOURCE__) == RCC_ADCCLKSOURCE_HSI))
  1319. #if defined(RNG)
  1320. #define IS_RCC_RNGCLKSOURCE(__SOURCE__) \
  1321. (((__SOURCE__) == RCC_RNGCLKSOURCE_NONE) || \
  1322. ((__SOURCE__) == RCC_RNGCLKSOURCE_HSI_DIV8) || \
  1323. ((__SOURCE__) == RCC_RNGCLKSOURCE_SYSCLK) || \
  1324. ((__SOURCE__) == RCC_RNGCLKSOURCE_PLL))
  1325. #define IS_RCC_RNGDIV(__DIV__) \
  1326. (((__DIV__) == RCC_RNGCLK_DIV1) || \
  1327. ((__DIV__) == RCC_RNGCLK_DIV2) || \
  1328. ((__DIV__) == RCC_RNGCLK_DIV4) || \
  1329. ((__DIV__) == RCC_RNGCLK_DIV8))
  1330. #endif /* RNG */
  1331. #if defined(CEC)
  1332. #define IS_RCC_CECCLKSOURCE(__SOURCE__) \
  1333. (((__SOURCE__) == RCC_CECCLKSOURCE_HSI_DIV488)|| \
  1334. ((__SOURCE__) == RCC_CECCLKSOURCE_LSE))
  1335. #endif /* CEC */
  1336. #if defined(FDCAN1) || defined(FDCAN2)
  1337. #define IS_RCC_FDCANCLKSOURCE(__SOURCE__) \
  1338. (((__SOURCE__) == RCC_FDCANCLKSOURCE_HSE)|| \
  1339. ((__SOURCE__) == RCC_FDCANCLKSOURCE_PLL)|| \
  1340. ((__SOURCE__) == RCC_FDCANCLKSOURCE_PCLK1))
  1341. #endif /* FDCAN1 */
  1342. #if defined(RCC_HSI48_SUPPORT)
  1343. #define IS_RCC_USBCLKSOURCE(__SOURCE__) \
  1344. (((__SOURCE__) == RCC_USBCLKSOURCE_HSI48)|| \
  1345. ((__SOURCE__) == RCC_USBCLKSOURCE_HSE) || \
  1346. ((__SOURCE__) == RCC_USBCLKSOURCE_PLL))
  1347. #else
  1348. #define IS_RCC_USBCLKSOURCE(__SOURCE__) \
  1349. (((__SOURCE__) == RCC_USBCLKSOURCE_HSE)|| \
  1350. ((__SOURCE__) == RCC_USBCLKSOURCE_PLL))
  1351. #endif /* RCC_HSI48_SUPPORT */
  1352. #if defined(RCC_CCIPR_TIM1SEL)
  1353. #define IS_RCC_TIM1CLKSOURCE(__SOURCE__) \
  1354. (((__SOURCE__) == RCC_TIM1CLKSOURCE_PLL) || \
  1355. ((__SOURCE__) == RCC_TIM1CLKSOURCE_PCLK1))
  1356. #endif /* RCC_CCIPR_TIM1SEL */
  1357. #if defined(RCC_CCIPR_TIM15SEL)
  1358. #define IS_RCC_TIM15CLKSOURCE(__SOURCE__) \
  1359. (((__SOURCE__) == RCC_TIM15CLKSOURCE_PLL) || \
  1360. ((__SOURCE__) == RCC_TIM15CLKSOURCE_PCLK1))
  1361. #endif /* RCC_CCIPR_TIM15SEL */
  1362. #if defined(CRS)
  1363. #define IS_RCC_CRS_SYNC_SOURCE(__SOURCE__) (((__SOURCE__) == RCC_CRS_SYNC_SOURCE_GPIO) || \
  1364. ((__SOURCE__) == RCC_CRS_SYNC_SOURCE_LSE) || \
  1365. ((__SOURCE__) == RCC_CRS_SYNC_SOURCE_USB))
  1366. #define IS_RCC_CRS_SYNC_DIV(__DIV__) (((__DIV__) == RCC_CRS_SYNC_DIV1) || ((__DIV__) == RCC_CRS_SYNC_DIV2) || \
  1367. ((__DIV__) == RCC_CRS_SYNC_DIV4) || ((__DIV__) == RCC_CRS_SYNC_DIV8) || \
  1368. ((__DIV__) == RCC_CRS_SYNC_DIV16) || ((__DIV__) == RCC_CRS_SYNC_DIV32) || \
  1369. ((__DIV__) == RCC_CRS_SYNC_DIV64) || ((__DIV__) == RCC_CRS_SYNC_DIV128))
  1370. #define IS_RCC_CRS_SYNC_POLARITY(__POLARITY__) (((__POLARITY__) == RCC_CRS_SYNC_POLARITY_RISING) || \
  1371. ((__POLARITY__) == RCC_CRS_SYNC_POLARITY_FALLING))
  1372. #define IS_RCC_CRS_RELOADVALUE(__VALUE__) (((__VALUE__) <= 0xFFFFU))
  1373. #define IS_RCC_CRS_ERRORLIMIT(__VALUE__) (((__VALUE__) <= 0xFFU))
  1374. #define IS_RCC_CRS_HSI48CALIBRATION(__VALUE__) (((__VALUE__) <= 0x7FU))
  1375. #define IS_RCC_CRS_FREQERRORDIR(__DIR__) (((__DIR__) == RCC_CRS_FREQERRORDIR_UP) || \
  1376. ((__DIR__) == RCC_CRS_FREQERRORDIR_DOWN))
  1377. #endif /* CRS */
  1378. /**
  1379. * @}
  1380. */
  1381. /**
  1382. * @}
  1383. */
  1384. /**
  1385. * @}
  1386. */
  1387. #ifdef __cplusplus
  1388. }
  1389. #endif
  1390. #endif /* STM32G0xx_HAL_RCC_EX_H */