stm32l4xx_hal_rcc_ex.h 140 KB

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