stm32h7xx_hal_rcc_ex.c 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_rcc_ex.c
  4. * @author MCD Application Team
  5. * @brief Extended RCC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities RCC extension peripheral:
  8. * + Extended Peripheral Control functions
  9. *
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * Copyright (c) 2017 STMicroelectronics.
  14. * All rights reserved.
  15. *
  16. * This software is licensed under terms that can be found in the LICENSE file in
  17. * the root directory of this software component.
  18. * If no LICENSE file comes with this software, it is provided AS-IS.
  19. ******************************************************************************
  20. */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32h7xx_hal.h"
  23. /** @addtogroup STM32H7xx_HAL_Driver
  24. * @{
  25. */
  26. /** @defgroup RCCEx RCCEx
  27. * @brief RCC HAL module driver
  28. * @{
  29. */
  30. #ifdef HAL_RCC_MODULE_ENABLED
  31. /* Private typedef -----------------------------------------------------------*/
  32. /* Private defines -----------------------------------------------------------*/
  33. /** @defgroup RCCEx_Private_defines RCCEx Private Defines
  34. * @{
  35. */
  36. #define PLL2_TIMEOUT_VALUE PLL_TIMEOUT_VALUE /* 2 ms */
  37. #define PLL3_TIMEOUT_VALUE PLL_TIMEOUT_VALUE /* 2 ms */
  38. #define DIVIDER_P_UPDATE 0U
  39. #define DIVIDER_Q_UPDATE 1U
  40. #define DIVIDER_R_UPDATE 2U
  41. /**
  42. * @}
  43. */
  44. /* Private macros ------------------------------------------------------------*/
  45. /** @defgroup RCCEx_Private_Macros RCCEx Private Macros
  46. * @{
  47. */
  48. /**
  49. * @}
  50. */
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private function prototypes -----------------------------------------------*/
  53. static HAL_StatusTypeDef RCCEx_PLL2_Config(RCC_PLL2InitTypeDef *pll2, uint32_t Divider);
  54. static HAL_StatusTypeDef RCCEx_PLL3_Config(RCC_PLL3InitTypeDef *pll3, uint32_t Divider);
  55. /* Exported functions --------------------------------------------------------*/
  56. /** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
  57. * @{
  58. */
  59. /** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions
  60. * @brief Extended Peripheral Control functions
  61. *
  62. @verbatim
  63. ===============================================================================
  64. ##### Extended Peripheral Control functions #####
  65. ===============================================================================
  66. [..]
  67. This subsection provides a set of functions allowing to control the RCC Clocks
  68. frequencies.
  69. [..]
  70. (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to
  71. select the RTC clock source; in this case the Backup domain will be reset in
  72. order to modify the RTC Clock source, as consequence RTC registers (including
  73. the backup registers) and RCC_BDCR register are set to their reset values.
  74. @endverbatim
  75. * @{
  76. */
  77. /**
  78. * @brief Initializes the RCC extended peripherals clocks according to the specified
  79. * parameters in the RCC_PeriphCLKInitTypeDef.
  80. * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
  81. * contains the configuration information for the Extended Peripherals
  82. * clocks (SDMMC, CKPER, FMC, QSPI*, OSPI*, DSI, SPI45, SPDIF, DFSDM1, DFSDM2*, FDCAN, SWPMI, SAI23*,SAI2A*, SAI2B*, SAI1, SPI123,
  83. * USART234578, USART16 (USART16910*), RNG, HRTIM1*, I2C123 (I2C1235*), USB, CEC, LPTIM1, LPUART1, I2C4, LPTIM2, LPTIM345, ADC,
  84. * SAI4A*, SAI4B*, SPI6, RTC).
  85. * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
  86. * the RTC clock source; in this case the Backup domain will be reset in
  87. * order to modify the RTC Clock source, as consequence RTC registers (including
  88. * the backup registers) are set to their reset values.
  89. *
  90. * (*) : Available on some STM32H7 lines only.
  91. *
  92. * @retval HAL status
  93. */
  94. HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  95. {
  96. uint32_t tmpreg;
  97. uint32_t tickstart;
  98. HAL_StatusTypeDef ret = HAL_OK; /* Intermediate status */
  99. HAL_StatusTypeDef status = HAL_OK; /* Final status */
  100. /*---------------------------- SPDIFRX configuration -------------------------------*/
  101. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPDIFRX) == RCC_PERIPHCLK_SPDIFRX)
  102. {
  103. switch(PeriphClkInit->SpdifrxClockSelection)
  104. {
  105. case RCC_SPDIFRXCLKSOURCE_PLL: /* PLL is used as clock source for SPDIFRX*/
  106. /* Enable PLL1Q Clock output generated form System PLL . */
  107. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  108. /* SPDIFRX clock source configuration done later after clock selection check */
  109. break;
  110. case RCC_SPDIFRXCLKSOURCE_PLL2: /* PLL2 is used as clock source for SPDIFRX*/
  111. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_R_UPDATE);
  112. /* SPDIFRX clock source configuration done later after clock selection check */
  113. break;
  114. case RCC_SPDIFRXCLKSOURCE_PLL3: /* PLL3 is used as clock source for SPDIFRX*/
  115. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_R_UPDATE);
  116. /* SPDIFRX clock source configuration done later after clock selection check */
  117. break;
  118. case RCC_SPDIFRXCLKSOURCE_HSI:
  119. /* Internal OSC clock is used as source of SPDIFRX clock*/
  120. /* SPDIFRX clock source configuration done later after clock selection check */
  121. break;
  122. default:
  123. ret = HAL_ERROR;
  124. break;
  125. }
  126. if(ret == HAL_OK)
  127. {
  128. /* Set the source of SPDIFRX clock*/
  129. __HAL_RCC_SPDIFRX_CONFIG(PeriphClkInit->SpdifrxClockSelection);
  130. }
  131. else
  132. {
  133. /* set overall return value */
  134. status = ret;
  135. }
  136. }
  137. /*---------------------------- SAI1 configuration -------------------------------*/
  138. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1)
  139. {
  140. switch(PeriphClkInit->Sai1ClockSelection)
  141. {
  142. case RCC_SAI1CLKSOURCE_PLL: /* PLL is used as clock source for SAI1*/
  143. /* Enable SAI Clock output generated form System PLL . */
  144. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  145. /* SAI1 clock source configuration done later after clock selection check */
  146. break;
  147. case RCC_SAI1CLKSOURCE_PLL2: /* PLL2 is used as clock source for SAI1*/
  148. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  149. /* SAI1 clock source configuration done later after clock selection check */
  150. break;
  151. case RCC_SAI1CLKSOURCE_PLL3: /* PLL3 is used as clock source for SAI1*/
  152. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_P_UPDATE);
  153. /* SAI1 clock source configuration done later after clock selection check */
  154. break;
  155. case RCC_SAI1CLKSOURCE_PIN:
  156. /* External clock is used as source of SAI1 clock*/
  157. /* SAI1 clock source configuration done later after clock selection check */
  158. break;
  159. case RCC_SAI1CLKSOURCE_CLKP:
  160. /* HSI, HSE, or CSI oscillator is used as source of SAI1 clock */
  161. /* SAI1 clock source configuration done later after clock selection check */
  162. break;
  163. default:
  164. ret = HAL_ERROR;
  165. break;
  166. }
  167. if(ret == HAL_OK)
  168. {
  169. /* Set the source of SAI1 clock*/
  170. __HAL_RCC_SAI1_CONFIG(PeriphClkInit->Sai1ClockSelection);
  171. }
  172. else
  173. {
  174. /* set overall return value */
  175. status = ret;
  176. }
  177. }
  178. #if defined(SAI3)
  179. /*---------------------------- SAI2/3 configuration -------------------------------*/
  180. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI23) == RCC_PERIPHCLK_SAI23)
  181. {
  182. switch(PeriphClkInit->Sai23ClockSelection)
  183. {
  184. case RCC_SAI23CLKSOURCE_PLL: /* PLL is used as clock source for SAI2/3 */
  185. /* Enable SAI Clock output generated form System PLL . */
  186. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  187. /* SAI2/3 clock source configuration done later after clock selection check */
  188. break;
  189. case RCC_SAI23CLKSOURCE_PLL2: /* PLL2 is used as clock source for SAI2/3 */
  190. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  191. /* SAI2/3 clock source configuration done later after clock selection check */
  192. break;
  193. case RCC_SAI23CLKSOURCE_PLL3: /* PLL3 is used as clock source for SAI2/3 */
  194. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_P_UPDATE);
  195. /* SAI2/3 clock source configuration done later after clock selection check */
  196. break;
  197. case RCC_SAI23CLKSOURCE_PIN:
  198. /* External clock is used as source of SAI2/3 clock*/
  199. /* SAI2/3 clock source configuration done later after clock selection check */
  200. break;
  201. case RCC_SAI23CLKSOURCE_CLKP:
  202. /* HSI, HSE, or CSI oscillator is used as source of SAI2/3 clock */
  203. /* SAI2/3 clock source configuration done later after clock selection check */
  204. break;
  205. default:
  206. ret = HAL_ERROR;
  207. break;
  208. }
  209. if(ret == HAL_OK)
  210. {
  211. /* Set the source of SAI2/3 clock*/
  212. __HAL_RCC_SAI23_CONFIG(PeriphClkInit->Sai23ClockSelection);
  213. }
  214. else
  215. {
  216. /* set overall return value */
  217. status = ret;
  218. }
  219. }
  220. #endif /* SAI3 */
  221. #if defined(RCC_CDCCIP1R_SAI2ASEL)
  222. /*---------------------------- SAI2A configuration -------------------------------*/
  223. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2A) == RCC_PERIPHCLK_SAI2A)
  224. {
  225. switch(PeriphClkInit->Sai2AClockSelection)
  226. {
  227. case RCC_SAI2ACLKSOURCE_PLL: /* PLL is used as clock source for SAI2A */
  228. /* Enable SAI2A Clock output generated form System PLL . */
  229. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  230. /* SAI2A clock source configuration done later after clock selection check */
  231. break;
  232. case RCC_SAI2ACLKSOURCE_PLL2: /* PLL2 is used as clock source for SAI2A */
  233. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  234. /* SAI2A clock source configuration done later after clock selection check */
  235. break;
  236. case RCC_SAI2ACLKSOURCE_PLL3: /* PLL3 is used as clock source for SAI2A */
  237. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_P_UPDATE);
  238. /* SAI2A clock source configuration done later after clock selection check */
  239. break;
  240. case RCC_SAI2ACLKSOURCE_PIN:
  241. /* External clock is used as source of SAI2A clock*/
  242. /* SAI2A clock source configuration done later after clock selection check */
  243. break;
  244. case RCC_SAI2ACLKSOURCE_CLKP:
  245. /* HSI, HSE, or CSI oscillator is used as source of SAI2A clock */
  246. /* SAI2A clock source configuration done later after clock selection check */
  247. break;
  248. case RCC_SAI2ACLKSOURCE_SPDIF:
  249. /* SPDIF clock is used as source of SAI2A clock */
  250. /* SAI2A clock source configuration done later after clock selection check */
  251. break;
  252. default:
  253. ret = HAL_ERROR;
  254. break;
  255. }
  256. if(ret == HAL_OK)
  257. {
  258. /* Set the source of SAI2A clock*/
  259. __HAL_RCC_SAI2A_CONFIG(PeriphClkInit->Sai2AClockSelection);
  260. }
  261. else
  262. {
  263. /* set overall return value */
  264. status = ret;
  265. }
  266. }
  267. #endif /*SAI2A*/
  268. #if defined(RCC_CDCCIP1R_SAI2BSEL)
  269. /*---------------------------- SAI2B configuration -------------------------------*/
  270. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2B) == RCC_PERIPHCLK_SAI2B)
  271. {
  272. switch(PeriphClkInit->Sai2BClockSelection)
  273. {
  274. case RCC_SAI2BCLKSOURCE_PLL: /* PLL is used as clock source for SAI2B */
  275. /* Enable SAI Clock output generated form System PLL . */
  276. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  277. /* SAI2B clock source configuration done later after clock selection check */
  278. break;
  279. case RCC_SAI2BCLKSOURCE_PLL2: /* PLL2 is used as clock source for SAI2B */
  280. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  281. /* SAI2B clock source configuration done later after clock selection check */
  282. break;
  283. case RCC_SAI2BCLKSOURCE_PLL3: /* PLL3 is used as clock source for SAI2B */
  284. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_P_UPDATE);
  285. /* SAI2B clock source configuration done later after clock selection check */
  286. break;
  287. case RCC_SAI2BCLKSOURCE_PIN:
  288. /* External clock is used as source of SAI2B clock*/
  289. /* SAI2B clock source configuration done later after clock selection check */
  290. break;
  291. case RCC_SAI2BCLKSOURCE_CLKP:
  292. /* HSI, HSE, or CSI oscillator is used as source of SAI2B clock */
  293. /* SAI2B clock source configuration done later after clock selection check */
  294. break;
  295. case RCC_SAI2BCLKSOURCE_SPDIF:
  296. /* SPDIF clock is used as source of SAI2B clock */
  297. /* SAI2B clock source configuration done later after clock selection check */
  298. break;
  299. default:
  300. ret = HAL_ERROR;
  301. break;
  302. }
  303. if(ret == HAL_OK)
  304. {
  305. /* Set the source of SAI2B clock*/
  306. __HAL_RCC_SAI2B_CONFIG(PeriphClkInit->Sai2BClockSelection);
  307. }
  308. else
  309. {
  310. /* set overall return value */
  311. status = ret;
  312. }
  313. }
  314. #endif /*SAI2B*/
  315. #if defined(SAI4)
  316. /*---------------------------- SAI4A configuration -------------------------------*/
  317. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI4A) == RCC_PERIPHCLK_SAI4A)
  318. {
  319. switch(PeriphClkInit->Sai4AClockSelection)
  320. {
  321. case RCC_SAI4ACLKSOURCE_PLL: /* PLL is used as clock source for SAI2*/
  322. /* Enable SAI Clock output generated form System PLL . */
  323. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  324. /* SAI1 clock source configuration done later after clock selection check */
  325. break;
  326. case RCC_SAI4ACLKSOURCE_PLL2: /* PLL2 is used as clock source for SAI2*/
  327. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  328. /* SAI2 clock source configuration done later after clock selection check */
  329. break;
  330. case RCC_SAI4ACLKSOURCE_PLL3: /* PLL3 is used as clock source for SAI2*/
  331. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_P_UPDATE);
  332. /* SAI1 clock source configuration done later after clock selection check */
  333. break;
  334. case RCC_SAI4ACLKSOURCE_PIN:
  335. /* External clock is used as source of SAI2 clock*/
  336. /* SAI2 clock source configuration done later after clock selection check */
  337. break;
  338. case RCC_SAI4ACLKSOURCE_CLKP:
  339. /* HSI, HSE, or CSI oscillator is used as source of SAI2 clock */
  340. /* SAI1 clock source configuration done later after clock selection check */
  341. break;
  342. #if defined(RCC_VER_3_0)
  343. case RCC_SAI4ACLKSOURCE_SPDIF:
  344. /* SPDIF clock is used as source of SAI4A clock */
  345. /* SAI4A clock source configuration done later after clock selection check */
  346. break;
  347. #endif /* RCC_VER_3_0 */
  348. default:
  349. ret = HAL_ERROR;
  350. break;
  351. }
  352. if(ret == HAL_OK)
  353. {
  354. /* Set the source of SAI4A clock*/
  355. __HAL_RCC_SAI4A_CONFIG(PeriphClkInit->Sai4AClockSelection);
  356. }
  357. else
  358. {
  359. /* set overall return value */
  360. status = ret;
  361. }
  362. }
  363. /*---------------------------- SAI4B configuration -------------------------------*/
  364. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI4B) == RCC_PERIPHCLK_SAI4B)
  365. {
  366. switch(PeriphClkInit->Sai4BClockSelection)
  367. {
  368. case RCC_SAI4BCLKSOURCE_PLL: /* PLL is used as clock source for SAI2*/
  369. /* Enable SAI Clock output generated form System PLL . */
  370. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  371. /* SAI1 clock source configuration done later after clock selection check */
  372. break;
  373. case RCC_SAI4BCLKSOURCE_PLL2: /* PLL2 is used as clock source for SAI2*/
  374. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  375. /* SAI2 clock source configuration done later after clock selection check */
  376. break;
  377. case RCC_SAI4BCLKSOURCE_PLL3: /* PLL3 is used as clock source for SAI2*/
  378. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3), DIVIDER_P_UPDATE);
  379. /* SAI1 clock source configuration done later after clock selection check */
  380. break;
  381. case RCC_SAI4BCLKSOURCE_PIN:
  382. /* External clock is used as source of SAI2 clock*/
  383. /* SAI2 clock source configuration done later after clock selection check */
  384. break;
  385. case RCC_SAI4BCLKSOURCE_CLKP:
  386. /* HSI, HSE, or CSI oscillator is used as source of SAI2 clock */
  387. /* SAI1 clock source configuration done later after clock selection check */
  388. break;
  389. #if defined(RCC_VER_3_0)
  390. case RCC_SAI4BCLKSOURCE_SPDIF:
  391. /* SPDIF clock is used as source of SAI4B clock */
  392. /* SAI4B clock source configuration done later after clock selection check */
  393. break;
  394. #endif /* RCC_VER_3_0 */
  395. default:
  396. ret = HAL_ERROR;
  397. break;
  398. }
  399. if(ret == HAL_OK)
  400. {
  401. /* Set the source of SAI4B clock*/
  402. __HAL_RCC_SAI4B_CONFIG(PeriphClkInit->Sai4BClockSelection);
  403. }
  404. else
  405. {
  406. /* set overall return value */
  407. status = ret;
  408. }
  409. }
  410. #endif /*SAI4*/
  411. #if defined(QUADSPI)
  412. /*---------------------------- QSPI configuration -------------------------------*/
  413. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_QSPI) == RCC_PERIPHCLK_QSPI)
  414. {
  415. switch(PeriphClkInit->QspiClockSelection)
  416. {
  417. case RCC_QSPICLKSOURCE_PLL: /* PLL is used as clock source for QSPI*/
  418. /* Enable QSPI Clock output generated form System PLL . */
  419. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  420. /* QSPI clock source configuration done later after clock selection check */
  421. break;
  422. case RCC_QSPICLKSOURCE_PLL2: /* PLL2 is used as clock source for QSPI*/
  423. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_R_UPDATE);
  424. /* QSPI clock source configuration done later after clock selection check */
  425. break;
  426. case RCC_QSPICLKSOURCE_CLKP:
  427. /* HSI, HSE, or CSI oscillator is used as source of QSPI clock */
  428. /* QSPI clock source configuration done later after clock selection check */
  429. break;
  430. case RCC_QSPICLKSOURCE_D1HCLK:
  431. /* Domain1 HCLK clock selected as QSPI kernel peripheral clock */
  432. break;
  433. default:
  434. ret = HAL_ERROR;
  435. break;
  436. }
  437. if(ret == HAL_OK)
  438. {
  439. /* Set the source of QSPI clock*/
  440. __HAL_RCC_QSPI_CONFIG(PeriphClkInit->QspiClockSelection);
  441. }
  442. else
  443. {
  444. /* set overall return value */
  445. status = ret;
  446. }
  447. }
  448. #endif /*QUADSPI*/
  449. #if defined(OCTOSPI1) || defined(OCTOSPI2)
  450. /*---------------------------- OCTOSPI configuration -------------------------------*/
  451. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_OSPI) == RCC_PERIPHCLK_OSPI)
  452. {
  453. switch(PeriphClkInit->OspiClockSelection)
  454. {
  455. case RCC_OSPICLKSOURCE_PLL: /* PLL is used as clock source for OSPI*/
  456. /* Enable OSPI Clock output generated form System PLL . */
  457. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  458. /* OSPI clock source configuration done later after clock selection check */
  459. break;
  460. case RCC_OSPICLKSOURCE_PLL2: /* PLL2 is used as clock source for OSPI*/
  461. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_R_UPDATE);
  462. /* OSPI clock source configuration done later after clock selection check */
  463. break;
  464. case RCC_OSPICLKSOURCE_CLKP:
  465. /* HSI, HSE, or CSI oscillator is used as source of OSPI clock */
  466. /* OSPI clock source configuration done later after clock selection check */
  467. break;
  468. case RCC_OSPICLKSOURCE_HCLK:
  469. /* HCLK clock selected as OSPI kernel peripheral clock */
  470. break;
  471. default:
  472. ret = HAL_ERROR;
  473. break;
  474. }
  475. if(ret == HAL_OK)
  476. {
  477. /* Set the source of OSPI clock*/
  478. __HAL_RCC_OSPI_CONFIG(PeriphClkInit->OspiClockSelection);
  479. }
  480. else
  481. {
  482. /* set overall return value */
  483. status = ret;
  484. }
  485. }
  486. #endif /*OCTOSPI*/
  487. /*---------------------------- SPI1/2/3 configuration -------------------------------*/
  488. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPI123) == RCC_PERIPHCLK_SPI123)
  489. {
  490. switch(PeriphClkInit->Spi123ClockSelection)
  491. {
  492. case RCC_SPI123CLKSOURCE_PLL: /* PLL is used as clock source for SPI1/2/3 */
  493. /* Enable SPI Clock output generated form System PLL . */
  494. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  495. /* SPI1/2/3 clock source configuration done later after clock selection check */
  496. break;
  497. case RCC_SPI123CLKSOURCE_PLL2: /* PLL2 is used as clock source for SPI1/2/3 */
  498. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  499. /* SPI1/2/3 clock source configuration done later after clock selection check */
  500. break;
  501. case RCC_SPI123CLKSOURCE_PLL3: /* PLL3 is used as clock source for SPI1/2/3 */
  502. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_P_UPDATE);
  503. /* SPI1/2/3 clock source configuration done later after clock selection check */
  504. break;
  505. case RCC_SPI123CLKSOURCE_PIN:
  506. /* External clock is used as source of SPI1/2/3 clock*/
  507. /* SPI1/2/3 clock source configuration done later after clock selection check */
  508. break;
  509. case RCC_SPI123CLKSOURCE_CLKP:
  510. /* HSI, HSE, or CSI oscillator is used as source of SPI1/2/3 clock */
  511. /* SPI1/2/3 clock source configuration done later after clock selection check */
  512. break;
  513. default:
  514. ret = HAL_ERROR;
  515. break;
  516. }
  517. if(ret == HAL_OK)
  518. {
  519. /* Set the source of SPI1/2/3 clock*/
  520. __HAL_RCC_SPI123_CONFIG(PeriphClkInit->Spi123ClockSelection);
  521. }
  522. else
  523. {
  524. /* set overall return value */
  525. status = ret;
  526. }
  527. }
  528. /*---------------------------- SPI4/5 configuration -------------------------------*/
  529. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPI45) == RCC_PERIPHCLK_SPI45)
  530. {
  531. switch(PeriphClkInit->Spi45ClockSelection)
  532. {
  533. case RCC_SPI45CLKSOURCE_PCLK1: /* CD/D2 PCLK1 as clock source for SPI4/5 */
  534. /* SPI4/5 clock source configuration done later after clock selection check */
  535. break;
  536. case RCC_SPI45CLKSOURCE_PLL2: /* PLL2 is used as clock source for SPI4/5 */
  537. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_Q_UPDATE);
  538. /* SPI4/5 clock source configuration done later after clock selection check */
  539. break;
  540. case RCC_SPI45CLKSOURCE_PLL3: /* PLL3 is used as clock source for SPI4/5 */
  541. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_Q_UPDATE);
  542. /* SPI4/5 clock source configuration done later after clock selection check */
  543. break;
  544. case RCC_SPI45CLKSOURCE_HSI:
  545. /* HSI oscillator clock is used as source of SPI4/5 clock*/
  546. /* SPI4/5 clock source configuration done later after clock selection check */
  547. break;
  548. case RCC_SPI45CLKSOURCE_CSI:
  549. /* CSI oscillator clock is used as source of SPI4/5 clock */
  550. /* SPI4/5 clock source configuration done later after clock selection check */
  551. break;
  552. case RCC_SPI45CLKSOURCE_HSE:
  553. /* HSE, oscillator is used as source of SPI4/5 clock */
  554. /* SPI4/5 clock source configuration done later after clock selection check */
  555. break;
  556. default:
  557. ret = HAL_ERROR;
  558. break;
  559. }
  560. if(ret == HAL_OK)
  561. {
  562. /* Set the source of SPI4/5 clock*/
  563. __HAL_RCC_SPI45_CONFIG(PeriphClkInit->Spi45ClockSelection);
  564. }
  565. else
  566. {
  567. /* set overall return value */
  568. status = ret;
  569. }
  570. }
  571. /*---------------------------- SPI6 configuration -------------------------------*/
  572. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPI6) == RCC_PERIPHCLK_SPI6)
  573. {
  574. switch(PeriphClkInit->Spi6ClockSelection)
  575. {
  576. case RCC_SPI6CLKSOURCE_PCLK4: /* SRD/D3 PCLK1 (PCLK4) as clock source for SPI6*/
  577. /* SPI6 clock source configuration done later after clock selection check */
  578. break;
  579. case RCC_SPI6CLKSOURCE_PLL2: /* PLL2 is used as clock source for SPI6*/
  580. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_Q_UPDATE);
  581. /* SPI6 clock source configuration done later after clock selection check */
  582. break;
  583. case RCC_SPI6CLKSOURCE_PLL3: /* PLL3 is used as clock source for SPI6*/
  584. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_Q_UPDATE);
  585. /* SPI6 clock source configuration done later after clock selection check */
  586. break;
  587. case RCC_SPI6CLKSOURCE_HSI:
  588. /* HSI oscillator clock is used as source of SPI6 clock*/
  589. /* SPI6 clock source configuration done later after clock selection check */
  590. break;
  591. case RCC_SPI6CLKSOURCE_CSI:
  592. /* CSI oscillator clock is used as source of SPI6 clock */
  593. /* SPI6 clock source configuration done later after clock selection check */
  594. break;
  595. case RCC_SPI6CLKSOURCE_HSE:
  596. /* HSE, oscillator is used as source of SPI6 clock */
  597. /* SPI6 clock source configuration done later after clock selection check */
  598. break;
  599. #if defined(RCC_SPI6CLKSOURCE_PIN)
  600. case RCC_SPI6CLKSOURCE_PIN:
  601. /* 2S_CKIN is used as source of SPI6 clock */
  602. /* SPI6 clock source configuration done later after clock selection check */
  603. break;
  604. #endif
  605. default:
  606. ret = HAL_ERROR;
  607. break;
  608. }
  609. if(ret == HAL_OK)
  610. {
  611. /* Set the source of SPI6 clock*/
  612. __HAL_RCC_SPI6_CONFIG(PeriphClkInit->Spi6ClockSelection);
  613. }
  614. else
  615. {
  616. /* set overall return value */
  617. status = ret;
  618. }
  619. }
  620. #if defined(DSI)
  621. /*---------------------------- DSI configuration -------------------------------*/
  622. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_DSI) == RCC_PERIPHCLK_DSI)
  623. {
  624. switch(PeriphClkInit->DsiClockSelection)
  625. {
  626. case RCC_DSICLKSOURCE_PLL2: /* PLL2 is used as clock source for DSI*/
  627. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_Q_UPDATE);
  628. /* DSI clock source configuration done later after clock selection check */
  629. break;
  630. case RCC_DSICLKSOURCE_PHY:
  631. /* PHY is used as clock source for DSI*/
  632. /* DSI clock source configuration done later after clock selection check */
  633. break;
  634. default:
  635. ret = HAL_ERROR;
  636. break;
  637. }
  638. if(ret == HAL_OK)
  639. {
  640. /* Set the source of DSI clock*/
  641. __HAL_RCC_DSI_CONFIG(PeriphClkInit->DsiClockSelection);
  642. }
  643. else
  644. {
  645. /* set overall return value */
  646. status = ret;
  647. }
  648. }
  649. #endif /*DSI*/
  650. #if defined(FDCAN1) || defined(FDCAN2)
  651. /*---------------------------- FDCAN configuration -------------------------------*/
  652. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_FDCAN) == RCC_PERIPHCLK_FDCAN)
  653. {
  654. switch(PeriphClkInit->FdcanClockSelection)
  655. {
  656. case RCC_FDCANCLKSOURCE_PLL: /* PLL is used as clock source for FDCAN*/
  657. /* Enable FDCAN Clock output generated form System PLL . */
  658. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  659. /* FDCAN clock source configuration done later after clock selection check */
  660. break;
  661. case RCC_FDCANCLKSOURCE_PLL2: /* PLL2 is used as clock source for FDCAN*/
  662. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_Q_UPDATE);
  663. /* FDCAN clock source configuration done later after clock selection check */
  664. break;
  665. case RCC_FDCANCLKSOURCE_HSE:
  666. /* HSE is used as clock source for FDCAN*/
  667. /* FDCAN clock source configuration done later after clock selection check */
  668. break;
  669. default:
  670. ret = HAL_ERROR;
  671. break;
  672. }
  673. if(ret == HAL_OK)
  674. {
  675. /* Set the source of FDCAN clock*/
  676. __HAL_RCC_FDCAN_CONFIG(PeriphClkInit->FdcanClockSelection);
  677. }
  678. else
  679. {
  680. /* set overall return value */
  681. status = ret;
  682. }
  683. }
  684. #endif /*FDCAN1 || FDCAN2*/
  685. /*---------------------------- FMC configuration -------------------------------*/
  686. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_FMC) == RCC_PERIPHCLK_FMC)
  687. {
  688. switch(PeriphClkInit->FmcClockSelection)
  689. {
  690. case RCC_FMCCLKSOURCE_PLL: /* PLL is used as clock source for FMC*/
  691. /* Enable FMC Clock output generated form System PLL . */
  692. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  693. /* FMC clock source configuration done later after clock selection check */
  694. break;
  695. case RCC_FMCCLKSOURCE_PLL2: /* PLL2 is used as clock source for FMC*/
  696. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_R_UPDATE);
  697. /* FMC clock source configuration done later after clock selection check */
  698. break;
  699. case RCC_FMCCLKSOURCE_CLKP:
  700. /* HSI, HSE, or CSI oscillator is used as source of FMC clock */
  701. /* FMC clock source configuration done later after clock selection check */
  702. break;
  703. case RCC_FMCCLKSOURCE_HCLK:
  704. /* D1/CD HCLK clock selected as FMC kernel peripheral clock */
  705. break;
  706. default:
  707. ret = HAL_ERROR;
  708. break;
  709. }
  710. if(ret == HAL_OK)
  711. {
  712. /* Set the source of FMC clock*/
  713. __HAL_RCC_FMC_CONFIG(PeriphClkInit->FmcClockSelection);
  714. }
  715. else
  716. {
  717. /* set overall return value */
  718. status = ret;
  719. }
  720. }
  721. /*---------------------------- RTC configuration -------------------------------*/
  722. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)
  723. {
  724. /* check for RTC Parameters used to output RTCCLK */
  725. assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
  726. /* Enable write access to Backup domain */
  727. SET_BIT(PWR->CR1, PWR_CR1_DBP);
  728. /* Wait for Backup domain Write protection disable */
  729. tickstart = HAL_GetTick();
  730. while((PWR->CR1 & PWR_CR1_DBP) == 0U)
  731. {
  732. if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
  733. {
  734. ret = HAL_TIMEOUT;
  735. break;
  736. }
  737. }
  738. if(ret == HAL_OK)
  739. {
  740. /* Reset the Backup domain only if the RTC Clock source selection is modified */
  741. if((RCC->BDCR & RCC_BDCR_RTCSEL) != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL))
  742. {
  743. /* Store the content of BDCR register before the reset of Backup Domain */
  744. tmpreg = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
  745. /* RTC Clock selection can be changed only if the Backup Domain is reset */
  746. __HAL_RCC_BACKUPRESET_FORCE();
  747. __HAL_RCC_BACKUPRESET_RELEASE();
  748. /* Restore the Content of BDCR register */
  749. RCC->BDCR = tmpreg;
  750. }
  751. /* If LSE is selected as RTC clock source (and enabled prior to Backup Domain reset), wait for LSE reactivation */
  752. if(PeriphClkInit->RTCClockSelection == RCC_RTCCLKSOURCE_LSE)
  753. {
  754. /* Get Start Tick*/
  755. tickstart = HAL_GetTick();
  756. /* Wait till LSE is ready */
  757. while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == 0U)
  758. {
  759. if((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
  760. {
  761. ret = HAL_TIMEOUT;
  762. break;
  763. }
  764. }
  765. }
  766. if(ret == HAL_OK)
  767. {
  768. __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
  769. }
  770. else
  771. {
  772. /* set overall return value */
  773. status = ret;
  774. }
  775. }
  776. else
  777. {
  778. /* set overall return value */
  779. status = ret;
  780. }
  781. }
  782. /*-------------------------- USART1/6 configuration --------------------------*/
  783. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART16) == RCC_PERIPHCLK_USART16)
  784. {
  785. switch(PeriphClkInit->Usart16ClockSelection)
  786. {
  787. case RCC_USART16CLKSOURCE_PCLK2: /* CD/D2 PCLK2 as clock source for USART1/6 */
  788. /* USART1/6 clock source configuration done later after clock selection check */
  789. break;
  790. case RCC_USART16CLKSOURCE_PLL2: /* PLL2 is used as clock source for USART1/6 */
  791. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_Q_UPDATE);
  792. /* USART1/6 clock source configuration done later after clock selection check */
  793. break;
  794. case RCC_USART16CLKSOURCE_PLL3: /* PLL3 is used as clock source for USART1/6 */
  795. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_Q_UPDATE);
  796. /* USART1/6 clock source configuration done later after clock selection check */
  797. break;
  798. case RCC_USART16CLKSOURCE_HSI:
  799. /* HSI oscillator clock is used as source of USART1/6 clock */
  800. /* USART1/6 clock source configuration done later after clock selection check */
  801. break;
  802. case RCC_USART16CLKSOURCE_CSI:
  803. /* CSI oscillator clock is used as source of USART1/6 clock */
  804. /* USART1/6 clock source configuration done later after clock selection check */
  805. break;
  806. case RCC_USART16CLKSOURCE_LSE:
  807. /* LSE, oscillator is used as source of USART1/6 clock */
  808. /* USART1/6 clock source configuration done later after clock selection check */
  809. break;
  810. default:
  811. ret = HAL_ERROR;
  812. break;
  813. }
  814. if(ret == HAL_OK)
  815. {
  816. /* Set the source of USART1/6 clock */
  817. __HAL_RCC_USART16_CONFIG(PeriphClkInit->Usart16ClockSelection);
  818. }
  819. else
  820. {
  821. /* set overall return value */
  822. status = ret;
  823. }
  824. }
  825. /*-------------------------- USART2/3/4/5/7/8 Configuration --------------------------*/
  826. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART234578) == RCC_PERIPHCLK_USART234578)
  827. {
  828. switch(PeriphClkInit->Usart234578ClockSelection)
  829. {
  830. case RCC_USART234578CLKSOURCE_PCLK1: /* CD/D2 PCLK1 as clock source for USART2/3/4/5/7/8 */
  831. /* USART2/3/4/5/7/8 clock source configuration done later after clock selection check */
  832. break;
  833. case RCC_USART234578CLKSOURCE_PLL2: /* PLL2 is used as clock source for USART2/3/4/5/7/8 */
  834. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_Q_UPDATE);
  835. /* USART2/3/4/5/7/8 clock source configuration done later after clock selection check */
  836. break;
  837. case RCC_USART234578CLKSOURCE_PLL3: /* PLL3 is used as clock source for USART2/3/4/5/7/8 */
  838. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_Q_UPDATE);
  839. /* USART2/3/4/5/7/8 clock source configuration done later after clock selection check */
  840. break;
  841. case RCC_USART234578CLKSOURCE_HSI:
  842. /* HSI oscillator clock is used as source of USART2/3/4/5/7/8 clock */
  843. /* USART2/3/4/5/7/8 clock source configuration done later after clock selection check */
  844. break;
  845. case RCC_USART234578CLKSOURCE_CSI:
  846. /* CSI oscillator clock is used as source of USART2/3/4/5/7/8 clock */
  847. /* USART2/3/4/5/7/8 clock source configuration done later after clock selection check */
  848. break;
  849. case RCC_USART234578CLKSOURCE_LSE:
  850. /* LSE, oscillator is used as source of USART2/3/4/5/7/8 clock */
  851. /* USART2/3/4/5/7/8 clock source configuration done later after clock selection check */
  852. break;
  853. default:
  854. ret = HAL_ERROR;
  855. break;
  856. }
  857. if(ret == HAL_OK)
  858. {
  859. /* Set the source of USART2/3/4/5/7/8 clock */
  860. __HAL_RCC_USART234578_CONFIG(PeriphClkInit->Usart234578ClockSelection);
  861. }
  862. else
  863. {
  864. /* set overall return value */
  865. status = ret;
  866. }
  867. }
  868. /*-------------------------- LPUART1 Configuration -------------------------*/
  869. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPUART1) == RCC_PERIPHCLK_LPUART1)
  870. {
  871. switch(PeriphClkInit->Lpuart1ClockSelection)
  872. {
  873. case RCC_LPUART1CLKSOURCE_PCLK4: /* SRD/D3 PCLK1 (PCLK4) as clock source for LPUART1 */
  874. /* LPUART1 clock source configuration done later after clock selection check */
  875. break;
  876. case RCC_LPUART1CLKSOURCE_PLL2: /* PLL2 is used as clock source for LPUART1 */
  877. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_Q_UPDATE);
  878. /* LPUART1 clock source configuration done later after clock selection check */
  879. break;
  880. case RCC_LPUART1CLKSOURCE_PLL3: /* PLL3 is used as clock source for LPUART1 */
  881. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_Q_UPDATE);
  882. /* LPUART1 clock source configuration done later after clock selection check */
  883. break;
  884. case RCC_LPUART1CLKSOURCE_HSI:
  885. /* HSI oscillator clock is used as source of LPUART1 clock */
  886. /* LPUART1 clock source configuration done later after clock selection check */
  887. break;
  888. case RCC_LPUART1CLKSOURCE_CSI:
  889. /* CSI oscillator clock is used as source of LPUART1 clock */
  890. /* LPUART1 clock source configuration done later after clock selection check */
  891. break;
  892. case RCC_LPUART1CLKSOURCE_LSE:
  893. /* LSE, oscillator is used as source of LPUART1 clock */
  894. /* LPUART1 clock source configuration done later after clock selection check */
  895. break;
  896. default:
  897. ret = HAL_ERROR;
  898. break;
  899. }
  900. if(ret == HAL_OK)
  901. {
  902. /* Set the source of LPUART1 clock */
  903. __HAL_RCC_LPUART1_CONFIG(PeriphClkInit->Lpuart1ClockSelection);
  904. }
  905. else
  906. {
  907. /* set overall return value */
  908. status = ret;
  909. }
  910. }
  911. /*---------------------------- LPTIM1 configuration -------------------------------*/
  912. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1)
  913. {
  914. switch(PeriphClkInit->Lptim1ClockSelection)
  915. {
  916. case RCC_LPTIM1CLKSOURCE_PCLK1: /* CD/D2 PCLK1 as clock source for LPTIM1*/
  917. /* LPTIM1 clock source configuration done later after clock selection check */
  918. break;
  919. case RCC_LPTIM1CLKSOURCE_PLL2: /* PLL2 is used as clock source for LPTIM1*/
  920. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  921. /* LPTIM1 clock source configuration done later after clock selection check */
  922. break;
  923. case RCC_LPTIM1CLKSOURCE_PLL3: /* PLL3 is used as clock source for LPTIM1*/
  924. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_R_UPDATE);
  925. /* LPTIM1 clock source configuration done later after clock selection check */
  926. break;
  927. case RCC_LPTIM1CLKSOURCE_LSE:
  928. /* External low speed OSC clock is used as source of LPTIM1 clock*/
  929. /* LPTIM1 clock source configuration done later after clock selection check */
  930. break;
  931. case RCC_LPTIM1CLKSOURCE_LSI:
  932. /* Internal low speed OSC clock is used as source of LPTIM1 clock*/
  933. /* LPTIM1 clock source configuration done later after clock selection check */
  934. break;
  935. case RCC_LPTIM1CLKSOURCE_CLKP:
  936. /* HSI, HSE, or CSI oscillator is used as source of LPTIM1 clock */
  937. /* LPTIM1 clock source configuration done later after clock selection check */
  938. break;
  939. default:
  940. ret = HAL_ERROR;
  941. break;
  942. }
  943. if(ret == HAL_OK)
  944. {
  945. /* Set the source of LPTIM1 clock*/
  946. __HAL_RCC_LPTIM1_CONFIG(PeriphClkInit->Lptim1ClockSelection);
  947. }
  948. else
  949. {
  950. /* set overall return value */
  951. status = ret;
  952. }
  953. }
  954. /*---------------------------- LPTIM2 configuration -------------------------------*/
  955. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM2) == RCC_PERIPHCLK_LPTIM2)
  956. {
  957. switch(PeriphClkInit->Lptim2ClockSelection)
  958. {
  959. case RCC_LPTIM2CLKSOURCE_PCLK4: /* SRD/D3 PCLK1 (PCLK4) as clock source for LPTIM2*/
  960. /* LPTIM2 clock source configuration done later after clock selection check */
  961. break;
  962. case RCC_LPTIM2CLKSOURCE_PLL2: /* PLL2 is used as clock source for LPTIM2*/
  963. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  964. /* LPTIM2 clock source configuration done later after clock selection check */
  965. break;
  966. case RCC_LPTIM2CLKSOURCE_PLL3: /* PLL3 is used as clock source for LPTIM2*/
  967. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_R_UPDATE);
  968. /* LPTIM2 clock source configuration done later after clock selection check */
  969. break;
  970. case RCC_LPTIM2CLKSOURCE_LSE:
  971. /* External low speed OSC clock is used as source of LPTIM2 clock*/
  972. /* LPTIM2 clock source configuration done later after clock selection check */
  973. break;
  974. case RCC_LPTIM2CLKSOURCE_LSI:
  975. /* Internal low speed OSC clock is used as source of LPTIM2 clock*/
  976. /* LPTIM2 clock source configuration done later after clock selection check */
  977. break;
  978. case RCC_LPTIM2CLKSOURCE_CLKP:
  979. /* HSI, HSE, or CSI oscillator is used as source of LPTIM2 clock */
  980. /* LPTIM2 clock source configuration done later after clock selection check */
  981. break;
  982. default:
  983. ret = HAL_ERROR;
  984. break;
  985. }
  986. if(ret == HAL_OK)
  987. {
  988. /* Set the source of LPTIM2 clock*/
  989. __HAL_RCC_LPTIM2_CONFIG(PeriphClkInit->Lptim2ClockSelection);
  990. }
  991. else
  992. {
  993. /* set overall return value */
  994. status = ret;
  995. }
  996. }
  997. /*---------------------------- LPTIM345 configuration -------------------------------*/
  998. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM345) == RCC_PERIPHCLK_LPTIM345)
  999. {
  1000. switch(PeriphClkInit->Lptim345ClockSelection)
  1001. {
  1002. case RCC_LPTIM345CLKSOURCE_PCLK4: /* SRD/D3 PCLK1 (PCLK4) as clock source for LPTIM3/4/5 */
  1003. /* LPTIM3/4/5 clock source configuration done later after clock selection check */
  1004. break;
  1005. case RCC_LPTIM345CLKSOURCE_PLL2: /* PLL2 is used as clock source for LPTIM3/4/5 */
  1006. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  1007. /* LPTIM3/4/5 clock source configuration done later after clock selection check */
  1008. break;
  1009. case RCC_LPTIM345CLKSOURCE_PLL3: /* PLL3 is used as clock source for LPTIM3/4/5 */
  1010. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_R_UPDATE);
  1011. /* LPTIM3/4/5 clock source configuration done later after clock selection check */
  1012. break;
  1013. case RCC_LPTIM345CLKSOURCE_LSE:
  1014. /* External low speed OSC clock is used as source of LPTIM3/4/5 clock */
  1015. /* LPTIM3/4/5 clock source configuration done later after clock selection check */
  1016. break;
  1017. case RCC_LPTIM345CLKSOURCE_LSI:
  1018. /* Internal low speed OSC clock is used as source of LPTIM3/4/5 clock */
  1019. /* LPTIM3/4/5 clock source configuration done later after clock selection check */
  1020. break;
  1021. case RCC_LPTIM345CLKSOURCE_CLKP:
  1022. /* HSI, HSE, or CSI oscillator is used as source of LPTIM3/4/5 clock */
  1023. /* LPTIM3/4/5 clock source configuration done later after clock selection check */
  1024. break;
  1025. default:
  1026. ret = HAL_ERROR;
  1027. break;
  1028. }
  1029. if(ret == HAL_OK)
  1030. {
  1031. /* Set the source of LPTIM3/4/5 clock */
  1032. __HAL_RCC_LPTIM345_CONFIG(PeriphClkInit->Lptim345ClockSelection);
  1033. }
  1034. else
  1035. {
  1036. /* set overall return value */
  1037. status = ret;
  1038. }
  1039. }
  1040. /*------------------------------ I2C1/2/3/5* Configuration ------------------------*/
  1041. #if defined(I2C5)
  1042. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C1235) == RCC_PERIPHCLK_I2C1235)
  1043. {
  1044. /* Check the parameters */
  1045. assert_param(IS_RCC_I2C1235CLKSOURCE(PeriphClkInit->I2c1235ClockSelection));
  1046. if ((PeriphClkInit->I2c1235ClockSelection )== RCC_I2C1235CLKSOURCE_PLL3 )
  1047. {
  1048. if(RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_R_UPDATE)!= HAL_OK)
  1049. {
  1050. status = HAL_ERROR;
  1051. }
  1052. }
  1053. __HAL_RCC_I2C1235_CONFIG(PeriphClkInit->I2c1235ClockSelection);
  1054. }
  1055. #else
  1056. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C123) == RCC_PERIPHCLK_I2C123)
  1057. {
  1058. /* Check the parameters */
  1059. assert_param(IS_RCC_I2C123CLKSOURCE(PeriphClkInit->I2c123ClockSelection));
  1060. if ((PeriphClkInit->I2c123ClockSelection )== RCC_I2C123CLKSOURCE_PLL3 )
  1061. {
  1062. if(RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_R_UPDATE)!= HAL_OK)
  1063. {
  1064. status = HAL_ERROR;
  1065. }
  1066. }
  1067. __HAL_RCC_I2C123_CONFIG(PeriphClkInit->I2c123ClockSelection);
  1068. }
  1069. #endif /* I2C5 */
  1070. /*------------------------------ I2C4 Configuration ------------------------*/
  1071. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C4) == RCC_PERIPHCLK_I2C4)
  1072. {
  1073. /* Check the parameters */
  1074. assert_param(IS_RCC_I2C4CLKSOURCE(PeriphClkInit->I2c4ClockSelection));
  1075. if ((PeriphClkInit->I2c4ClockSelection) == RCC_I2C4CLKSOURCE_PLL3 )
  1076. {
  1077. if(RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_R_UPDATE)!= HAL_OK)
  1078. {
  1079. status = HAL_ERROR;
  1080. }
  1081. }
  1082. __HAL_RCC_I2C4_CONFIG(PeriphClkInit->I2c4ClockSelection);
  1083. }
  1084. /*---------------------------- ADC configuration -------------------------------*/
  1085. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC)
  1086. {
  1087. switch(PeriphClkInit->AdcClockSelection)
  1088. {
  1089. case RCC_ADCCLKSOURCE_PLL2: /* PLL2 is used as clock source for ADC*/
  1090. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_P_UPDATE);
  1091. /* ADC clock source configuration done later after clock selection check */
  1092. break;
  1093. case RCC_ADCCLKSOURCE_PLL3: /* PLL3 is used as clock source for ADC*/
  1094. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_R_UPDATE);
  1095. /* ADC clock source configuration done later after clock selection check */
  1096. break;
  1097. case RCC_ADCCLKSOURCE_CLKP:
  1098. /* HSI, HSE, or CSI oscillator is used as source of ADC clock */
  1099. /* ADC clock source configuration done later after clock selection check */
  1100. break;
  1101. default:
  1102. ret = HAL_ERROR;
  1103. break;
  1104. }
  1105. if(ret == HAL_OK)
  1106. {
  1107. /* Set the source of ADC clock*/
  1108. __HAL_RCC_ADC_CONFIG(PeriphClkInit->AdcClockSelection);
  1109. }
  1110. else
  1111. {
  1112. /* set overall return value */
  1113. status = ret;
  1114. }
  1115. }
  1116. /*------------------------------ USB Configuration -------------------------*/
  1117. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB)
  1118. {
  1119. switch(PeriphClkInit->UsbClockSelection)
  1120. {
  1121. case RCC_USBCLKSOURCE_PLL: /* PLL is used as clock source for USB*/
  1122. /* Enable USB Clock output generated form System USB . */
  1123. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  1124. /* USB clock source configuration done later after clock selection check */
  1125. break;
  1126. case RCC_USBCLKSOURCE_PLL3: /* PLL3 is used as clock source for USB*/
  1127. ret = RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_Q_UPDATE);
  1128. /* USB clock source configuration done later after clock selection check */
  1129. break;
  1130. case RCC_USBCLKSOURCE_HSI48:
  1131. /* HSI48 oscillator is used as source of USB clock */
  1132. /* USB clock source configuration done later after clock selection check */
  1133. break;
  1134. default:
  1135. ret = HAL_ERROR;
  1136. break;
  1137. }
  1138. if(ret == HAL_OK)
  1139. {
  1140. /* Set the source of USB clock*/
  1141. __HAL_RCC_USB_CONFIG(PeriphClkInit->UsbClockSelection);
  1142. }
  1143. else
  1144. {
  1145. /* set overall return value */
  1146. status = ret;
  1147. }
  1148. }
  1149. /*------------------------------------- SDMMC Configuration ------------------------------------*/
  1150. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDMMC) == RCC_PERIPHCLK_SDMMC)
  1151. {
  1152. /* Check the parameters */
  1153. assert_param(IS_RCC_SDMMC(PeriphClkInit->SdmmcClockSelection));
  1154. switch(PeriphClkInit->SdmmcClockSelection)
  1155. {
  1156. case RCC_SDMMCCLKSOURCE_PLL: /* PLL is used as clock source for SDMMC*/
  1157. /* Enable SDMMC Clock output generated form System PLL . */
  1158. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  1159. /* SDMMC clock source configuration done later after clock selection check */
  1160. break;
  1161. case RCC_SDMMCCLKSOURCE_PLL2: /* PLL2 is used as clock source for SDMMC*/
  1162. ret = RCCEx_PLL2_Config(&(PeriphClkInit->PLL2),DIVIDER_R_UPDATE);
  1163. /* SDMMC clock source configuration done later after clock selection check */
  1164. break;
  1165. default:
  1166. ret = HAL_ERROR;
  1167. break;
  1168. }
  1169. if(ret == HAL_OK)
  1170. {
  1171. /* Set the source of SDMMC clock*/
  1172. __HAL_RCC_SDMMC_CONFIG(PeriphClkInit->SdmmcClockSelection);
  1173. }
  1174. else
  1175. {
  1176. /* set overall return value */
  1177. status = ret;
  1178. }
  1179. }
  1180. #if defined(LTDC)
  1181. /*-------------------------------------- LTDC Configuration -----------------------------------*/
  1182. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == RCC_PERIPHCLK_LTDC)
  1183. {
  1184. if(RCCEx_PLL3_Config(&(PeriphClkInit->PLL3),DIVIDER_R_UPDATE)!=HAL_OK)
  1185. {
  1186. status=HAL_ERROR;
  1187. }
  1188. }
  1189. #endif /* LTDC */
  1190. /*------------------------------ RNG Configuration -------------------------*/
  1191. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RNG) == RCC_PERIPHCLK_RNG)
  1192. {
  1193. switch(PeriphClkInit->RngClockSelection)
  1194. {
  1195. case RCC_RNGCLKSOURCE_PLL: /* PLL is used as clock source for RNG*/
  1196. /* Enable RNG Clock output generated form System RNG . */
  1197. __HAL_RCC_PLLCLKOUT_ENABLE(RCC_PLL1_DIVQ);
  1198. /* RNG clock source configuration done later after clock selection check */
  1199. break;
  1200. case RCC_RNGCLKSOURCE_LSE: /* LSE is used as clock source for RNG*/
  1201. /* RNG clock source configuration done later after clock selection check */
  1202. break;
  1203. case RCC_RNGCLKSOURCE_LSI: /* LSI is used as clock source for RNG*/
  1204. /* RNG clock source configuration done later after clock selection check */
  1205. break;
  1206. case RCC_RNGCLKSOURCE_HSI48:
  1207. /* HSI48 oscillator is used as source of RNG clock */
  1208. /* RNG clock source configuration done later after clock selection check */
  1209. break;
  1210. default:
  1211. ret = HAL_ERROR;
  1212. break;
  1213. }
  1214. if(ret == HAL_OK)
  1215. {
  1216. /* Set the source of RNG clock*/
  1217. __HAL_RCC_RNG_CONFIG(PeriphClkInit->RngClockSelection);
  1218. }
  1219. else
  1220. {
  1221. /* set overall return value */
  1222. status = ret;
  1223. }
  1224. }
  1225. /*------------------------------ SWPMI1 Configuration ------------------------*/
  1226. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SWPMI1) == RCC_PERIPHCLK_SWPMI1)
  1227. {
  1228. /* Check the parameters */
  1229. assert_param(IS_RCC_SWPMI1CLKSOURCE(PeriphClkInit->Swpmi1ClockSelection));
  1230. /* Configure the SWPMI1 interface clock source */
  1231. __HAL_RCC_SWPMI1_CONFIG(PeriphClkInit->Swpmi1ClockSelection);
  1232. }
  1233. #if defined(HRTIM1)
  1234. /*------------------------------ HRTIM1 clock Configuration ----------------*/
  1235. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_HRTIM1) == RCC_PERIPHCLK_HRTIM1)
  1236. {
  1237. /* Check the parameters */
  1238. assert_param(IS_RCC_HRTIM1CLKSOURCE(PeriphClkInit->Hrtim1ClockSelection));
  1239. /* Configure the HRTIM1 clock source */
  1240. __HAL_RCC_HRTIM1_CONFIG(PeriphClkInit->Hrtim1ClockSelection);
  1241. }
  1242. #endif /*HRTIM1*/
  1243. /*------------------------------ DFSDM1 Configuration ------------------------*/
  1244. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_DFSDM1) == RCC_PERIPHCLK_DFSDM1)
  1245. {
  1246. /* Check the parameters */
  1247. assert_param(IS_RCC_DFSDM1CLKSOURCE(PeriphClkInit->Dfsdm1ClockSelection));
  1248. /* Configure the DFSDM1 interface clock source */
  1249. __HAL_RCC_DFSDM1_CONFIG(PeriphClkInit->Dfsdm1ClockSelection);
  1250. }
  1251. #if defined(DFSDM2_BASE)
  1252. /*------------------------------ DFSDM2 Configuration ------------------------*/
  1253. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_DFSDM2) == RCC_PERIPHCLK_DFSDM2)
  1254. {
  1255. /* Check the parameters */
  1256. assert_param(IS_RCC_DFSDM2CLKSOURCE(PeriphClkInit->Dfsdm2ClockSelection));
  1257. /* Configure the DFSDM2 interface clock source */
  1258. __HAL_RCC_DFSDM2_CONFIG(PeriphClkInit->Dfsdm2ClockSelection);
  1259. }
  1260. #endif /* DFSDM2 */
  1261. /*------------------------------------ TIM configuration --------------------------------------*/
  1262. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM) == RCC_PERIPHCLK_TIM)
  1263. {
  1264. /* Check the parameters */
  1265. assert_param(IS_RCC_TIMPRES(PeriphClkInit->TIMPresSelection));
  1266. /* Configure Timer Prescaler */
  1267. __HAL_RCC_TIMCLKPRESCALER(PeriphClkInit->TIMPresSelection);
  1268. }
  1269. /*------------------------------------ CKPER configuration --------------------------------------*/
  1270. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CKPER) == RCC_PERIPHCLK_CKPER)
  1271. {
  1272. /* Check the parameters */
  1273. assert_param(IS_RCC_CLKPSOURCE(PeriphClkInit->CkperClockSelection));
  1274. /* Configure the CKPER clock source */
  1275. __HAL_RCC_CLKP_CONFIG(PeriphClkInit->CkperClockSelection);
  1276. }
  1277. /*------------------------------ CEC Configuration ------------------------*/
  1278. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC)
  1279. {
  1280. /* Check the parameters */
  1281. assert_param(IS_RCC_CECCLKSOURCE(PeriphClkInit->CecClockSelection));
  1282. /* Configure the CEC interface clock source */
  1283. __HAL_RCC_CEC_CONFIG(PeriphClkInit->CecClockSelection);
  1284. }
  1285. if (status == HAL_OK)
  1286. {
  1287. return HAL_OK;
  1288. }
  1289. return HAL_ERROR;
  1290. }
  1291. /**
  1292. * @brief Get the RCC_ClkInitStruct according to the internal RCC configuration registers.
  1293. * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
  1294. * returns the configuration information for the Extended Peripherals clocks :
  1295. * (SDMMC, CKPER, FMC, QSPI*, OSPI*, DSI*, SPI45, SPDIF, DFSDM1, DFSDM2*, FDCAN, SWPMI, SAI23*, SAI1, SPI123,
  1296. * USART234578, USART16, RNG, HRTIM1*, I2C123 (I2C1235*), USB, CEC, LPTIM1, LPUART1, I2C4, LPTIM2, LPTIM345, ADC.
  1297. * SAI4A*, SAI4B*, SPI6, RTC, TIM).
  1298. * @retval None
  1299. *
  1300. * (*) : Available on some STM32H7 lines only.
  1301. */
  1302. void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  1303. {
  1304. /* Set all possible values for the extended clock type parameter------------*/
  1305. PeriphClkInit->PeriphClockSelection =
  1306. RCC_PERIPHCLK_USART16 | RCC_PERIPHCLK_USART234578 | RCC_PERIPHCLK_LPUART1 |
  1307. RCC_PERIPHCLK_I2C4 | RCC_PERIPHCLK_LPTIM1 | RCC_PERIPHCLK_LPTIM2 | RCC_PERIPHCLK_LPTIM345 |
  1308. RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SPI123 | RCC_PERIPHCLK_SPI45 | RCC_PERIPHCLK_SPI6 |
  1309. RCC_PERIPHCLK_FDCAN | RCC_PERIPHCLK_SDMMC | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_USB |
  1310. RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_SWPMI1 | RCC_PERIPHCLK_DFSDM1 | RCC_PERIPHCLK_RTC |
  1311. RCC_PERIPHCLK_CEC | RCC_PERIPHCLK_FMC | RCC_PERIPHCLK_SPDIFRX | RCC_PERIPHCLK_TIM |
  1312. RCC_PERIPHCLK_CKPER;
  1313. #if defined(I2C5)
  1314. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2C1235;
  1315. #else
  1316. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_I2C123;
  1317. #endif /*I2C5*/
  1318. #if defined(RCC_CDCCIP1R_SAI2ASEL)
  1319. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_SAI2A;
  1320. #endif /* RCC_CDCCIP1R_SAI2ASEL */
  1321. #if defined(RCC_CDCCIP1R_SAI2BSEL)
  1322. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_SAI2B;
  1323. #endif /* RCC_CDCCIP1R_SAI2BSEL */
  1324. #if defined(SAI3)
  1325. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_SAI23;
  1326. #endif /* SAI3 */
  1327. #if defined(SAI4)
  1328. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_SAI4A;
  1329. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_SAI4B;
  1330. #endif /* SAI4 */
  1331. #if defined(DFSDM2_BASE)
  1332. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_DFSDM2;
  1333. #endif /* DFSDM2 */
  1334. #if defined(QUADSPI)
  1335. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_QSPI;
  1336. #endif /* QUADSPI */
  1337. #if defined(OCTOSPI1) || defined(OCTOSPI2)
  1338. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_OSPI;
  1339. #endif /* OCTOSPI1 || OCTOSPI2 */
  1340. #if defined(HRTIM1)
  1341. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_HRTIM1;
  1342. #endif /* HRTIM1 */
  1343. #if defined(LTDC)
  1344. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_LTDC;
  1345. #endif /* LTDC */
  1346. #if defined(DSI)
  1347. PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_DSI;
  1348. #endif /* DSI */
  1349. /* Get the PLL3 Clock configuration -----------------------------------------------*/
  1350. PeriphClkInit->PLL3.PLL3M = (uint32_t)((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM3)>> RCC_PLLCKSELR_DIVM3_Pos);
  1351. PeriphClkInit->PLL3.PLL3N = (uint32_t)((RCC->PLL3DIVR & RCC_PLL3DIVR_N3) >> RCC_PLL3DIVR_N3_Pos)+ 1U;
  1352. PeriphClkInit->PLL3.PLL3R = (uint32_t)((RCC->PLL3DIVR & RCC_PLL3DIVR_R3) >> RCC_PLL3DIVR_R3_Pos)+ 1U;
  1353. PeriphClkInit->PLL3.PLL3P = (uint32_t)((RCC->PLL3DIVR & RCC_PLL3DIVR_P3) >> RCC_PLL3DIVR_P3_Pos)+ 1U;
  1354. PeriphClkInit->PLL3.PLL3Q = (uint32_t)((RCC->PLL3DIVR & RCC_PLL3DIVR_Q3) >> RCC_PLL3DIVR_Q3_Pos)+ 1U;
  1355. PeriphClkInit->PLL3.PLL3RGE = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLL3RGE) >> RCC_PLLCFGR_PLL3RGE_Pos);
  1356. PeriphClkInit->PLL3.PLL3VCOSEL = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLL3VCOSEL) >> RCC_PLLCFGR_PLL3VCOSEL_Pos);
  1357. /* Get the PLL2 Clock configuration -----------------------------------------------*/
  1358. PeriphClkInit->PLL2.PLL2M = (uint32_t)((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM2)>> RCC_PLLCKSELR_DIVM2_Pos);
  1359. PeriphClkInit->PLL2.PLL2N = (uint32_t)((RCC->PLL2DIVR & RCC_PLL2DIVR_N2) >> RCC_PLL2DIVR_N2_Pos)+ 1U;
  1360. PeriphClkInit->PLL2.PLL2R = (uint32_t)((RCC->PLL2DIVR & RCC_PLL2DIVR_R2) >> RCC_PLL2DIVR_R2_Pos)+ 1U;
  1361. PeriphClkInit->PLL2.PLL2P = (uint32_t)((RCC->PLL2DIVR & RCC_PLL2DIVR_P2) >> RCC_PLL2DIVR_P2_Pos)+ 1U;
  1362. PeriphClkInit->PLL2.PLL2Q = (uint32_t)((RCC->PLL2DIVR & RCC_PLL2DIVR_Q2) >> RCC_PLL2DIVR_Q2_Pos)+ 1U;
  1363. PeriphClkInit->PLL2.PLL2RGE = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLL2RGE) >> RCC_PLLCFGR_PLL2RGE_Pos);
  1364. PeriphClkInit->PLL2.PLL2VCOSEL = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLL2VCOSEL) >> RCC_PLLCFGR_PLL2VCOSEL_Pos);
  1365. /* Get the USART1 configuration --------------------------------------------*/
  1366. PeriphClkInit->Usart16ClockSelection = __HAL_RCC_GET_USART16_SOURCE();
  1367. /* Get the USART2/3/4/5/7/8 clock source -----------------------------------*/
  1368. PeriphClkInit->Usart234578ClockSelection = __HAL_RCC_GET_USART234578_SOURCE();
  1369. /* Get the LPUART1 clock source --------------------------------------------*/
  1370. PeriphClkInit->Lpuart1ClockSelection = __HAL_RCC_GET_LPUART1_SOURCE();
  1371. #if defined(I2C5)
  1372. /* Get the I2C1/2/3/5 clock source -----------------------------------------*/
  1373. PeriphClkInit->I2c1235ClockSelection = __HAL_RCC_GET_I2C1_SOURCE();
  1374. #else
  1375. /* Get the I2C1/2/3 clock source -------------------------------------------*/
  1376. PeriphClkInit->I2c123ClockSelection = __HAL_RCC_GET_I2C1_SOURCE();
  1377. #endif /*I2C5*/
  1378. /* Get the LPTIM1 clock source ---------------------------------------------*/
  1379. PeriphClkInit->Lptim1ClockSelection = __HAL_RCC_GET_LPTIM1_SOURCE();
  1380. /* Get the LPTIM2 clock source ---------------------------------------------*/
  1381. PeriphClkInit->Lptim2ClockSelection = __HAL_RCC_GET_LPTIM2_SOURCE();
  1382. /* Get the LPTIM3/4/5 clock source -----------------------------------------*/
  1383. PeriphClkInit->Lptim345ClockSelection = __HAL_RCC_GET_LPTIM345_SOURCE();
  1384. /* Get the SAI1 clock source -----------------------------------------------*/
  1385. PeriphClkInit->Sai1ClockSelection = __HAL_RCC_GET_SAI1_SOURCE();
  1386. #if defined(SAI3)
  1387. /* Get the SAI2/3 clock source ---------------------------------------------*/
  1388. PeriphClkInit->Sai23ClockSelection = __HAL_RCC_GET_SAI23_SOURCE();
  1389. #endif /*SAI3*/
  1390. #if defined(RCC_CDCCIP1R_SAI2ASEL_0)
  1391. /* Get the SAI2A clock source ---------------------------------------------*/
  1392. PeriphClkInit->Sai2AClockSelection = __HAL_RCC_GET_SAI2A_SOURCE();
  1393. #endif /*SAI2A*/
  1394. #if defined(RCC_CDCCIP1R_SAI2BSEL_0)
  1395. /* Get the SAI2B clock source ---------------------------------------------*/
  1396. PeriphClkInit->Sai2BClockSelection = __HAL_RCC_GET_SAI2B_SOURCE();
  1397. #endif /*SAI2B*/
  1398. #if defined(SAI4)
  1399. /* Get the SAI4A clock source ----------------------------------------------*/
  1400. PeriphClkInit->Sai4AClockSelection = __HAL_RCC_GET_SAI4A_SOURCE();
  1401. /* Get the SAI4B clock source ----------------------------------------------*/
  1402. PeriphClkInit->Sai4BClockSelection = __HAL_RCC_GET_SAI4B_SOURCE();
  1403. #endif /*SAI4*/
  1404. /* Get the RTC clock source ------------------------------------------------*/
  1405. PeriphClkInit->RTCClockSelection = __HAL_RCC_GET_RTC_SOURCE();
  1406. /* Get the USB clock source ------------------------------------------------*/
  1407. PeriphClkInit->UsbClockSelection = __HAL_RCC_GET_USB_SOURCE();
  1408. /* Get the SDMMC clock source ----------------------------------------------*/
  1409. PeriphClkInit->SdmmcClockSelection = __HAL_RCC_GET_SDMMC_SOURCE();
  1410. /* Get the RNG clock source ------------------------------------------------*/
  1411. PeriphClkInit->RngClockSelection = __HAL_RCC_GET_RNG_SOURCE();
  1412. #if defined(HRTIM1)
  1413. /* Get the HRTIM1 clock source ---------------------------------------------*/
  1414. PeriphClkInit->Hrtim1ClockSelection = __HAL_RCC_GET_HRTIM1_SOURCE();
  1415. #endif /* HRTIM1 */
  1416. /* Get the ADC clock source ------------------------------------------------*/
  1417. PeriphClkInit->AdcClockSelection = __HAL_RCC_GET_ADC_SOURCE();
  1418. /* Get the SWPMI1 clock source ---------------------------------------------*/
  1419. PeriphClkInit->Swpmi1ClockSelection = __HAL_RCC_GET_SWPMI1_SOURCE();
  1420. /* Get the DFSDM1 clock source ---------------------------------------------*/
  1421. PeriphClkInit->Dfsdm1ClockSelection = __HAL_RCC_GET_DFSDM1_SOURCE();
  1422. #if defined(DFSDM2_BASE)
  1423. /* Get the DFSDM2 clock source ---------------------------------------------*/
  1424. PeriphClkInit->Dfsdm2ClockSelection = __HAL_RCC_GET_DFSDM2_SOURCE();
  1425. #endif /* DFSDM2 */
  1426. /* Get the SPDIFRX clock source --------------------------------------------*/
  1427. PeriphClkInit->SpdifrxClockSelection = __HAL_RCC_GET_SPDIFRX_SOURCE();
  1428. /* Get the SPI1/2/3 clock source -------------------------------------------*/
  1429. PeriphClkInit->Spi123ClockSelection = __HAL_RCC_GET_SPI123_SOURCE();
  1430. /* Get the SPI4/5 clock source ---------------------------------------------*/
  1431. PeriphClkInit->Spi45ClockSelection = __HAL_RCC_GET_SPI45_SOURCE();
  1432. /* Get the SPI6 clock source -----------------------------------------------*/
  1433. PeriphClkInit->Spi6ClockSelection = __HAL_RCC_GET_SPI6_SOURCE();
  1434. /* Get the FDCAN clock source ----------------------------------------------*/
  1435. PeriphClkInit->FdcanClockSelection = __HAL_RCC_GET_FDCAN_SOURCE();
  1436. /* Get the CEC clock source ------------------------------------------------*/
  1437. PeriphClkInit->CecClockSelection = __HAL_RCC_GET_CEC_SOURCE();
  1438. /* Get the FMC clock source ------------------------------------------------*/
  1439. PeriphClkInit->FmcClockSelection = __HAL_RCC_GET_FMC_SOURCE();
  1440. #if defined(QUADSPI)
  1441. /* Get the QSPI clock source -----------------------------------------------*/
  1442. PeriphClkInit->QspiClockSelection = __HAL_RCC_GET_QSPI_SOURCE();
  1443. #endif /* QUADSPI */
  1444. #if defined(OCTOSPI1) || defined(OCTOSPI2)
  1445. /* Get the OSPI clock source -----------------------------------------------*/
  1446. PeriphClkInit->OspiClockSelection = __HAL_RCC_GET_OSPI_SOURCE();
  1447. #endif /* OCTOSPI1 || OCTOSPI2 */
  1448. #if defined(DSI)
  1449. /* Get the DSI clock source ------------------------------------------------*/
  1450. PeriphClkInit->DsiClockSelection = __HAL_RCC_GET_DSI_SOURCE();
  1451. #endif /*DSI*/
  1452. /* Get the CKPER clock source ----------------------------------------------*/
  1453. PeriphClkInit->CkperClockSelection = __HAL_RCC_GET_CLKP_SOURCE();
  1454. /* Get the TIM Prescaler configuration -------------------------------------*/
  1455. if ((RCC->CFGR & RCC_CFGR_TIMPRE) == 0U)
  1456. {
  1457. PeriphClkInit->TIMPresSelection = RCC_TIMPRES_DESACTIVATED;
  1458. }
  1459. else
  1460. {
  1461. PeriphClkInit->TIMPresSelection = RCC_TIMPRES_ACTIVATED;
  1462. }
  1463. }
  1464. /**
  1465. * @brief Return the peripheral clock frequency for a given peripheral(SAI..)
  1466. * @note Return 0 if peripheral clock identifier not managed by this API
  1467. * @param PeriphClk: Peripheral clock identifier
  1468. * This parameter can be one of the following values:
  1469. * @arg RCC_PERIPHCLK_SAI1 : SAI1 peripheral clock
  1470. * @arg RCC_PERIPHCLK_SAI23 : SAI2/3 peripheral clock (*)
  1471. * @arg RCC_PERIPHCLK_SAI2A : SAI2A peripheral clock (*)
  1472. * @arg RCC_PERIPHCLK_SAI2B : SAI2B peripheral clock (*)
  1473. * @arg RCC_PERIPHCLK_SAI4A : SAI4A peripheral clock (*)
  1474. * @arg RCC_PERIPHCLK_SAI4B : SAI4B peripheral clock (*)
  1475. * @arg RCC_PERIPHCLK_SPI123: SPI1/2/3 peripheral clock
  1476. * @arg RCC_PERIPHCLK_ADC : ADC peripheral clock
  1477. * @arg RCC_PERIPHCLK_SDMMC : SDMMC peripheral clock
  1478. * @arg RCC_PERIPHCLK_SPI6 : SPI6 peripheral clock
  1479. * @retval Frequency in KHz
  1480. *
  1481. * (*) : Available on some STM32H7 lines only.
  1482. */
  1483. uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
  1484. {
  1485. PLL1_ClocksTypeDef pll1_clocks;
  1486. PLL2_ClocksTypeDef pll2_clocks;
  1487. PLL3_ClocksTypeDef pll3_clocks;
  1488. /* This variable is used to store the clock frequency (value in Hz) */
  1489. uint32_t frequency;
  1490. /* This variable is used to store the SAI and CKP clock source */
  1491. uint32_t saiclocksource;
  1492. uint32_t ckpclocksource;
  1493. uint32_t srcclk;
  1494. if (PeriphClk == RCC_PERIPHCLK_SAI1)
  1495. {
  1496. saiclocksource= __HAL_RCC_GET_SAI1_SOURCE();
  1497. switch (saiclocksource)
  1498. {
  1499. case RCC_SAI1CLKSOURCE_PLL: /* PLL1 is the clock source for SAI1 */
  1500. {
  1501. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL1RDY))
  1502. {
  1503. HAL_RCCEx_GetPLL1ClockFreq(&pll1_clocks);
  1504. frequency = pll1_clocks.PLL1_Q_Frequency;
  1505. }
  1506. else
  1507. {
  1508. frequency = 0;
  1509. }
  1510. break;
  1511. }
  1512. case RCC_SAI1CLKSOURCE_PLL2: /* PLL2 is the clock source for SAI1 */
  1513. {
  1514. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  1515. {
  1516. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  1517. frequency = pll2_clocks.PLL2_P_Frequency;
  1518. }
  1519. else
  1520. {
  1521. frequency = 0;
  1522. }
  1523. break;
  1524. }
  1525. case RCC_SAI1CLKSOURCE_PLL3: /* PLL3 is the clock source for SAI1 */
  1526. {
  1527. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3RDY))
  1528. {
  1529. HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
  1530. frequency = pll3_clocks.PLL3_P_Frequency;
  1531. }
  1532. else
  1533. {
  1534. frequency = 0;
  1535. }
  1536. break;
  1537. }
  1538. case RCC_SAI1CLKSOURCE_CLKP: /* CKPER is the clock source for SAI1*/
  1539. {
  1540. ckpclocksource= __HAL_RCC_GET_CLKP_SOURCE();
  1541. if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSI))
  1542. {
  1543. /* In Case the CKPER Source is HSI */
  1544. frequency = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  1545. }
  1546. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_CSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_CSI))
  1547. {
  1548. /* In Case the CKPER Source is CSI */
  1549. frequency = CSI_VALUE;
  1550. }
  1551. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSE))
  1552. {
  1553. /* In Case the CKPER Source is HSE */
  1554. frequency = HSE_VALUE;
  1555. }
  1556. else
  1557. {
  1558. /* In Case the CKPER is disabled*/
  1559. frequency = 0;
  1560. }
  1561. break;
  1562. }
  1563. case (RCC_SAI1CLKSOURCE_PIN): /* External clock is the clock source for SAI1 */
  1564. {
  1565. frequency = EXTERNAL_CLOCK_VALUE;
  1566. break;
  1567. }
  1568. default :
  1569. {
  1570. frequency = 0;
  1571. break;
  1572. }
  1573. }
  1574. }
  1575. #if defined(SAI3)
  1576. else if (PeriphClk == RCC_PERIPHCLK_SAI23)
  1577. {
  1578. saiclocksource= __HAL_RCC_GET_SAI23_SOURCE();
  1579. switch (saiclocksource)
  1580. {
  1581. case RCC_SAI23CLKSOURCE_PLL: /* PLL1 is the clock source for SAI2/3 */
  1582. {
  1583. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL1RDY))
  1584. {
  1585. HAL_RCCEx_GetPLL1ClockFreq(&pll1_clocks);
  1586. frequency = pll1_clocks.PLL1_Q_Frequency;
  1587. }
  1588. else
  1589. {
  1590. frequency = 0;
  1591. }
  1592. break;
  1593. }
  1594. case RCC_SAI23CLKSOURCE_PLL2: /* PLL2 is the clock source for SAI2/3 */
  1595. {
  1596. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  1597. {
  1598. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  1599. frequency = pll2_clocks.PLL2_P_Frequency;
  1600. }
  1601. else
  1602. {
  1603. frequency = 0;
  1604. }
  1605. break;
  1606. }
  1607. case RCC_SAI23CLKSOURCE_PLL3: /* PLL3 is the clock source for SAI2/3 */
  1608. {
  1609. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3RDY))
  1610. {
  1611. HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
  1612. frequency = pll3_clocks.PLL3_P_Frequency;
  1613. }
  1614. else
  1615. {
  1616. frequency = 0;
  1617. }
  1618. break;
  1619. }
  1620. case RCC_SAI23CLKSOURCE_CLKP: /* CKPER is the clock source for SAI2/3 */
  1621. {
  1622. ckpclocksource= __HAL_RCC_GET_CLKP_SOURCE();
  1623. if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSI))
  1624. {
  1625. /* In Case the CKPER Source is HSI */
  1626. frequency = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  1627. }
  1628. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_CSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_CSI))
  1629. {
  1630. /* In Case the CKPER Source is CSI */
  1631. frequency = CSI_VALUE;
  1632. }
  1633. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSE))
  1634. {
  1635. /* In Case the CKPER Source is HSE */
  1636. frequency = HSE_VALUE;
  1637. }
  1638. else
  1639. {
  1640. /* In Case the CKPER is disabled*/
  1641. frequency = 0;
  1642. }
  1643. break;
  1644. }
  1645. case (RCC_SAI23CLKSOURCE_PIN): /* External clock is the clock source for SAI2/3 */
  1646. {
  1647. frequency = EXTERNAL_CLOCK_VALUE;
  1648. break;
  1649. }
  1650. default :
  1651. {
  1652. frequency = 0;
  1653. break;
  1654. }
  1655. }
  1656. }
  1657. #endif /* SAI3 */
  1658. #if defined(RCC_CDCCIP1R_SAI2ASEL)
  1659. else if (PeriphClk == RCC_PERIPHCLK_SAI2A)
  1660. {
  1661. saiclocksource= __HAL_RCC_GET_SAI2A_SOURCE();
  1662. switch (saiclocksource)
  1663. {
  1664. case RCC_SAI2ACLKSOURCE_PLL: /* PLL1 is the clock source for SAI2A */
  1665. {
  1666. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL1RDY))
  1667. {
  1668. HAL_RCCEx_GetPLL1ClockFreq(&pll1_clocks);
  1669. frequency = pll1_clocks.PLL1_Q_Frequency;
  1670. }
  1671. else
  1672. {
  1673. frequency = 0;
  1674. }
  1675. break;
  1676. }
  1677. case RCC_SAI2ACLKSOURCE_PLL2: /* PLLI2 is the clock source for SAI2A */
  1678. {
  1679. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  1680. {
  1681. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  1682. frequency = pll2_clocks.PLL2_P_Frequency;
  1683. }
  1684. else
  1685. {
  1686. frequency = 0;
  1687. }
  1688. break;
  1689. }
  1690. case RCC_SAI2ACLKSOURCE_PLL3: /* PLLI3 is the clock source for SAI2A */
  1691. {
  1692. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3RDY))
  1693. {
  1694. HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
  1695. frequency = pll3_clocks.PLL3_P_Frequency;
  1696. }
  1697. else
  1698. {
  1699. frequency = 0;
  1700. }
  1701. break;
  1702. }
  1703. case RCC_SAI2ACLKSOURCE_CLKP: /* CKPER is the clock source for SAI2A */
  1704. {
  1705. ckpclocksource= __HAL_RCC_GET_CLKP_SOURCE();
  1706. if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSI))
  1707. {
  1708. /* In Case the CKPER Source is HSI */
  1709. frequency = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  1710. }
  1711. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_CSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_CSI))
  1712. {
  1713. /* In Case the CKPER Source is CSI */
  1714. frequency = CSI_VALUE;
  1715. }
  1716. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSE))
  1717. {
  1718. /* In Case the CKPER Source is HSE */
  1719. frequency = HSE_VALUE;
  1720. }
  1721. else
  1722. {
  1723. /* In Case the CKPER is disabled*/
  1724. frequency = 0;
  1725. }
  1726. break;
  1727. }
  1728. case (RCC_SAI2ACLKSOURCE_PIN): /* External clock is the clock source for SAI2A */
  1729. {
  1730. frequency = EXTERNAL_CLOCK_VALUE;
  1731. break;
  1732. }
  1733. default :
  1734. {
  1735. frequency = 0;
  1736. break;
  1737. }
  1738. }
  1739. }
  1740. #endif
  1741. #if defined(RCC_CDCCIP1R_SAI2BSEL_0)
  1742. else if (PeriphClk == RCC_PERIPHCLK_SAI2B)
  1743. {
  1744. saiclocksource= __HAL_RCC_GET_SAI2B_SOURCE();
  1745. switch (saiclocksource)
  1746. {
  1747. case RCC_SAI2BCLKSOURCE_PLL: /* PLL1 is the clock source for SAI2B */
  1748. {
  1749. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL1RDY))
  1750. {
  1751. HAL_RCCEx_GetPLL1ClockFreq(&pll1_clocks);
  1752. frequency = pll1_clocks.PLL1_Q_Frequency;
  1753. }
  1754. else
  1755. {
  1756. frequency = 0;
  1757. }
  1758. break;
  1759. }
  1760. case RCC_SAI2BCLKSOURCE_PLL2: /* PLLI2 is the clock source for SAI2B */
  1761. {
  1762. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  1763. {
  1764. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  1765. frequency = pll2_clocks.PLL2_P_Frequency;
  1766. }
  1767. else
  1768. {
  1769. frequency = 0;
  1770. }
  1771. break;
  1772. }
  1773. case RCC_SAI2BCLKSOURCE_PLL3: /* PLLI3 is the clock source for SAI2B */
  1774. {
  1775. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3RDY))
  1776. {
  1777. HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
  1778. frequency = pll3_clocks.PLL3_P_Frequency;
  1779. }
  1780. else
  1781. {
  1782. frequency = 0;
  1783. }
  1784. break;
  1785. }
  1786. case RCC_SAI2BCLKSOURCE_CLKP: /* CKPER is the clock source for SAI2B*/
  1787. {
  1788. ckpclocksource= __HAL_RCC_GET_CLKP_SOURCE();
  1789. if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSI))
  1790. {
  1791. /* In Case the CKPER Source is HSI */
  1792. frequency = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  1793. }
  1794. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_CSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_CSI))
  1795. {
  1796. /* In Case the CKPER Source is CSI */
  1797. frequency = CSI_VALUE;
  1798. }
  1799. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSE))
  1800. {
  1801. /* In Case the CKPER Source is HSE */
  1802. frequency = HSE_VALUE;
  1803. }
  1804. else
  1805. {
  1806. /* In Case the CKPER is disabled*/
  1807. frequency = 0;
  1808. }
  1809. break;
  1810. }
  1811. case (RCC_SAI2BCLKSOURCE_PIN): /* External clock is the clock source for SAI2B */
  1812. {
  1813. frequency = EXTERNAL_CLOCK_VALUE;
  1814. break;
  1815. }
  1816. default :
  1817. {
  1818. frequency = 0;
  1819. break;
  1820. }
  1821. }
  1822. }
  1823. #endif
  1824. #if defined(SAI4)
  1825. else if (PeriphClk == RCC_PERIPHCLK_SAI4A)
  1826. {
  1827. saiclocksource= __HAL_RCC_GET_SAI4A_SOURCE();
  1828. switch (saiclocksource)
  1829. {
  1830. case RCC_SAI4ACLKSOURCE_PLL: /* PLL1 is the clock source for SAI4A */
  1831. {
  1832. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL1RDY))
  1833. {
  1834. HAL_RCCEx_GetPLL1ClockFreq(&pll1_clocks);
  1835. frequency = pll1_clocks.PLL1_Q_Frequency;
  1836. }
  1837. else
  1838. {
  1839. frequency = 0;
  1840. }
  1841. break;
  1842. }
  1843. case RCC_SAI4ACLKSOURCE_PLL2: /* PLLI2 is the clock source for SAI4A */
  1844. {
  1845. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  1846. {
  1847. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  1848. frequency = pll2_clocks.PLL2_P_Frequency;
  1849. }
  1850. else
  1851. {
  1852. frequency = 0;
  1853. }
  1854. break;
  1855. }
  1856. case RCC_SAI4ACLKSOURCE_PLL3: /* PLLI3 is the clock source for SAI4A */
  1857. {
  1858. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3RDY))
  1859. {
  1860. HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
  1861. frequency = pll3_clocks.PLL3_P_Frequency;
  1862. }
  1863. else
  1864. {
  1865. frequency = 0;
  1866. }
  1867. break;
  1868. }
  1869. case RCC_SAI4ACLKSOURCE_CLKP: /* CKPER is the clock source for SAI4A*/
  1870. {
  1871. ckpclocksource= __HAL_RCC_GET_CLKP_SOURCE();
  1872. if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSI))
  1873. {
  1874. /* In Case the CKPER Source is HSI */
  1875. frequency = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  1876. }
  1877. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_CSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_CSI))
  1878. {
  1879. /* In Case the CKPER Source is CSI */
  1880. frequency = CSI_VALUE;
  1881. }
  1882. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSE))
  1883. {
  1884. /* In Case the CKPER Source is HSE */
  1885. frequency = HSE_VALUE;
  1886. }
  1887. else
  1888. {
  1889. /* In Case the CKPER is disabled*/
  1890. frequency = 0;
  1891. }
  1892. break;
  1893. }
  1894. case RCC_SAI4ACLKSOURCE_PIN: /* External clock is the clock source for SAI4A */
  1895. {
  1896. frequency = EXTERNAL_CLOCK_VALUE;
  1897. break;
  1898. }
  1899. default :
  1900. {
  1901. frequency = 0;
  1902. break;
  1903. }
  1904. }
  1905. }
  1906. else if (PeriphClk == RCC_PERIPHCLK_SAI4B)
  1907. {
  1908. saiclocksource= __HAL_RCC_GET_SAI4B_SOURCE();
  1909. switch (saiclocksource)
  1910. {
  1911. case RCC_SAI4BCLKSOURCE_PLL: /* PLL1 is the clock source for SAI4B */
  1912. {
  1913. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL1RDY))
  1914. {
  1915. HAL_RCCEx_GetPLL1ClockFreq(&pll1_clocks);
  1916. frequency = pll1_clocks.PLL1_Q_Frequency;
  1917. }
  1918. else
  1919. {
  1920. frequency = 0;
  1921. }
  1922. break;
  1923. }
  1924. case RCC_SAI4BCLKSOURCE_PLL2: /* PLLI2 is the clock source for SAI4B */
  1925. {
  1926. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  1927. {
  1928. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  1929. frequency = pll2_clocks.PLL2_P_Frequency;
  1930. }
  1931. else
  1932. {
  1933. frequency = 0;
  1934. }
  1935. break;
  1936. }
  1937. case RCC_SAI4BCLKSOURCE_PLL3: /* PLLI3 is the clock source for SAI4B */
  1938. {
  1939. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3RDY))
  1940. {
  1941. HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
  1942. frequency = pll3_clocks.PLL3_P_Frequency;
  1943. }
  1944. else
  1945. {
  1946. frequency = 0;
  1947. }
  1948. break;
  1949. }
  1950. case RCC_SAI4BCLKSOURCE_CLKP: /* CKPER is the clock source for SAI4B*/
  1951. {
  1952. ckpclocksource= __HAL_RCC_GET_CLKP_SOURCE();
  1953. if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSI))
  1954. {
  1955. /* In Case the CKPER Source is HSI */
  1956. frequency = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  1957. }
  1958. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_CSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_CSI))
  1959. {
  1960. /* In Case the CKPER Source is CSI */
  1961. frequency = CSI_VALUE;
  1962. }
  1963. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSE))
  1964. {
  1965. /* In Case the CKPER Source is HSE */
  1966. frequency = HSE_VALUE;
  1967. }
  1968. else
  1969. {
  1970. /* In Case the CKPER is disabled*/
  1971. frequency = 0;
  1972. }
  1973. break;
  1974. }
  1975. case RCC_SAI4BCLKSOURCE_PIN: /* External clock is the clock source for SAI4B */
  1976. {
  1977. frequency = EXTERNAL_CLOCK_VALUE;
  1978. break;
  1979. }
  1980. default :
  1981. {
  1982. frequency = 0;
  1983. break;
  1984. }
  1985. }
  1986. }
  1987. #endif /*SAI4*/
  1988. else if (PeriphClk == RCC_PERIPHCLK_SPI123)
  1989. {
  1990. /* Get SPI1/2/3 clock source */
  1991. srcclk= __HAL_RCC_GET_SPI123_SOURCE();
  1992. switch (srcclk)
  1993. {
  1994. case RCC_SPI123CLKSOURCE_PLL: /* PLL1 is the clock source for SPI123 */
  1995. {
  1996. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL1RDY))
  1997. {
  1998. HAL_RCCEx_GetPLL1ClockFreq(&pll1_clocks);
  1999. frequency = pll1_clocks.PLL1_Q_Frequency;
  2000. }
  2001. else
  2002. {
  2003. frequency = 0;
  2004. }
  2005. break;
  2006. }
  2007. case RCC_SPI123CLKSOURCE_PLL2: /* PLL2 is the clock source for SPI123 */
  2008. {
  2009. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  2010. {
  2011. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  2012. frequency = pll2_clocks.PLL2_P_Frequency;
  2013. }
  2014. else
  2015. {
  2016. frequency = 0;
  2017. }
  2018. break;
  2019. }
  2020. case RCC_SPI123CLKSOURCE_PLL3: /* PLL3 is the clock source for SPI123 */
  2021. {
  2022. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3RDY))
  2023. {
  2024. HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
  2025. frequency = pll3_clocks.PLL3_P_Frequency;
  2026. }
  2027. else
  2028. {
  2029. frequency = 0;
  2030. }
  2031. break;
  2032. }
  2033. case RCC_SPI123CLKSOURCE_CLKP: /* CKPER is the clock source for SPI123 */
  2034. {
  2035. ckpclocksource= __HAL_RCC_GET_CLKP_SOURCE();
  2036. if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSI))
  2037. {
  2038. /* In Case the CKPER Source is HSI */
  2039. frequency = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  2040. }
  2041. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_CSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_CSI))
  2042. {
  2043. /* In Case the CKPER Source is CSI */
  2044. frequency = CSI_VALUE;
  2045. }
  2046. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSE))
  2047. {
  2048. /* In Case the CKPER Source is HSE */
  2049. frequency = HSE_VALUE;
  2050. }
  2051. else
  2052. {
  2053. /* In Case the CKPER is disabled*/
  2054. frequency = 0;
  2055. }
  2056. break;
  2057. }
  2058. case (RCC_SPI123CLKSOURCE_PIN): /* External clock is the clock source for I2S */
  2059. {
  2060. frequency = EXTERNAL_CLOCK_VALUE;
  2061. break;
  2062. }
  2063. default :
  2064. {
  2065. frequency = 0;
  2066. break;
  2067. }
  2068. }
  2069. }
  2070. else if (PeriphClk == RCC_PERIPHCLK_ADC)
  2071. {
  2072. /* Get ADC clock source */
  2073. srcclk= __HAL_RCC_GET_ADC_SOURCE();
  2074. switch (srcclk)
  2075. {
  2076. case RCC_ADCCLKSOURCE_PLL2:
  2077. {
  2078. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  2079. {
  2080. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  2081. frequency = pll2_clocks.PLL2_P_Frequency;
  2082. }
  2083. else
  2084. {
  2085. frequency = 0;
  2086. }
  2087. break;
  2088. }
  2089. case RCC_ADCCLKSOURCE_PLL3:
  2090. {
  2091. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3RDY))
  2092. {
  2093. HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
  2094. frequency = pll3_clocks.PLL3_R_Frequency;
  2095. }
  2096. else
  2097. {
  2098. frequency = 0;
  2099. }
  2100. break;
  2101. }
  2102. case RCC_ADCCLKSOURCE_CLKP:
  2103. {
  2104. ckpclocksource= __HAL_RCC_GET_CLKP_SOURCE();
  2105. if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSI))
  2106. {
  2107. /* In Case the CKPER Source is HSI */
  2108. frequency = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  2109. }
  2110. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_CSIRDY)) && (ckpclocksource == RCC_CLKPSOURCE_CSI))
  2111. {
  2112. /* In Case the CKPER Source is CSI */
  2113. frequency = CSI_VALUE;
  2114. }
  2115. else if ((HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) && (ckpclocksource == RCC_CLKPSOURCE_HSE))
  2116. {
  2117. /* In Case the CKPER Source is HSE */
  2118. frequency = HSE_VALUE;
  2119. }
  2120. else
  2121. {
  2122. /* In Case the CKPER is disabled*/
  2123. frequency = 0;
  2124. }
  2125. break;
  2126. }
  2127. default :
  2128. {
  2129. frequency = 0;
  2130. break;
  2131. }
  2132. }
  2133. }
  2134. else if (PeriphClk == RCC_PERIPHCLK_SDMMC)
  2135. {
  2136. /* Get SDMMC clock source */
  2137. srcclk= __HAL_RCC_GET_SDMMC_SOURCE();
  2138. switch (srcclk)
  2139. {
  2140. case RCC_SDMMCCLKSOURCE_PLL: /* PLL1 is the clock source for SDMMC */
  2141. {
  2142. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL1RDY))
  2143. {
  2144. HAL_RCCEx_GetPLL1ClockFreq(&pll1_clocks);
  2145. frequency = pll1_clocks.PLL1_Q_Frequency;
  2146. }
  2147. else
  2148. {
  2149. frequency = 0;
  2150. }
  2151. break;
  2152. }
  2153. case RCC_SDMMCCLKSOURCE_PLL2: /* PLL2 is the clock source for SDMMC */
  2154. {
  2155. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  2156. {
  2157. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  2158. frequency = pll2_clocks.PLL2_R_Frequency;
  2159. }
  2160. else
  2161. {
  2162. frequency = 0;
  2163. }
  2164. break;
  2165. }
  2166. default :
  2167. {
  2168. frequency = 0;
  2169. break;
  2170. }
  2171. }
  2172. }
  2173. else if (PeriphClk == RCC_PERIPHCLK_SPI6)
  2174. {
  2175. /* Get SPI6 clock source */
  2176. srcclk= __HAL_RCC_GET_SPI6_SOURCE();
  2177. switch (srcclk)
  2178. {
  2179. case RCC_SPI6CLKSOURCE_D3PCLK1: /* D3PCLK1 (PCLK4) is the clock source for SPI6 */
  2180. {
  2181. frequency = HAL_RCCEx_GetD3PCLK1Freq();
  2182. break;
  2183. }
  2184. case RCC_SPI6CLKSOURCE_PLL2: /* PLL2 is the clock source for SPI6 */
  2185. {
  2186. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  2187. {
  2188. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  2189. frequency = pll2_clocks.PLL2_Q_Frequency;
  2190. }
  2191. else
  2192. {
  2193. frequency = 0;
  2194. }
  2195. break;
  2196. }
  2197. case RCC_SPI6CLKSOURCE_PLL3: /* PLL3 is the clock source for SPI6 */
  2198. {
  2199. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3RDY))
  2200. {
  2201. HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
  2202. frequency = pll3_clocks.PLL3_Q_Frequency;
  2203. }
  2204. else
  2205. {
  2206. frequency = 0;
  2207. }
  2208. break;
  2209. }
  2210. case RCC_SPI6CLKSOURCE_HSI: /* HSI is the clock source for SPI6 */
  2211. {
  2212. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSIRDY))
  2213. {
  2214. frequency = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  2215. }
  2216. else
  2217. {
  2218. frequency = 0;
  2219. }
  2220. break;
  2221. }
  2222. case RCC_SPI6CLKSOURCE_CSI: /* CSI is the clock source for SPI6 */
  2223. {
  2224. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_CSIRDY))
  2225. {
  2226. frequency = CSI_VALUE;
  2227. }
  2228. else
  2229. {
  2230. frequency = 0;
  2231. }
  2232. break;
  2233. }
  2234. case RCC_SPI6CLKSOURCE_HSE: /* HSE is the clock source for SPI6 */
  2235. {
  2236. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))
  2237. {
  2238. frequency = HSE_VALUE;
  2239. }
  2240. else
  2241. {
  2242. frequency = 0;
  2243. }
  2244. break;
  2245. }
  2246. #if defined(RCC_SPI6CLKSOURCE_PIN)
  2247. case RCC_SPI6CLKSOURCE_PIN: /* External clock is the clock source for SPI6 */
  2248. {
  2249. frequency = EXTERNAL_CLOCK_VALUE;
  2250. break;
  2251. }
  2252. #endif /* RCC_SPI6CLKSOURCE_PIN */
  2253. default :
  2254. {
  2255. frequency = 0;
  2256. break;
  2257. }
  2258. }
  2259. }
  2260. else if (PeriphClk == RCC_PERIPHCLK_FDCAN)
  2261. {
  2262. /* Get FDCAN clock source */
  2263. srcclk= __HAL_RCC_GET_FDCAN_SOURCE();
  2264. switch (srcclk)
  2265. {
  2266. case RCC_FDCANCLKSOURCE_HSE: /* HSE is the clock source for FDCAN */
  2267. {
  2268. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))
  2269. {
  2270. frequency = HSE_VALUE;
  2271. }
  2272. else
  2273. {
  2274. frequency = 0;
  2275. }
  2276. break;
  2277. }
  2278. case RCC_FDCANCLKSOURCE_PLL: /* PLL is the clock source for FDCAN */
  2279. {
  2280. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL1RDY))
  2281. {
  2282. HAL_RCCEx_GetPLL1ClockFreq(&pll1_clocks);
  2283. frequency = pll1_clocks.PLL1_Q_Frequency;
  2284. }
  2285. else
  2286. {
  2287. frequency = 0;
  2288. }
  2289. break;
  2290. }
  2291. case RCC_FDCANCLKSOURCE_PLL2: /* PLL2 is the clock source for FDCAN */
  2292. {
  2293. if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2RDY))
  2294. {
  2295. HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
  2296. frequency = pll2_clocks.PLL2_Q_Frequency;
  2297. }
  2298. else
  2299. {
  2300. frequency = 0;
  2301. }
  2302. break;
  2303. }
  2304. default :
  2305. {
  2306. frequency = 0;
  2307. break;
  2308. }
  2309. }
  2310. }
  2311. else
  2312. {
  2313. frequency = 0;
  2314. }
  2315. return frequency;
  2316. }
  2317. /**
  2318. * @brief Returns the D1PCLK1 frequency
  2319. * @note Each time D1PCLK1 changes, this function must be called to update the
  2320. * right D1PCLK1 value. Otherwise, any configuration based on this function will be incorrect.
  2321. * @retval D1PCLK1 frequency
  2322. */
  2323. uint32_t HAL_RCCEx_GetD1PCLK1Freq(void)
  2324. {
  2325. #if defined(RCC_D1CFGR_D1PPRE)
  2326. /* Get HCLK source and Compute D1PCLK1 frequency ---------------------------*/
  2327. return (HAL_RCC_GetHCLKFreq() >> (D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1PPRE)>> RCC_D1CFGR_D1PPRE_Pos] & 0x1FU));
  2328. #else
  2329. /* Get HCLK source and Compute D1PCLK1 frequency ---------------------------*/
  2330. return (HAL_RCC_GetHCLKFreq() >> (D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDPPRE)>> RCC_CDCFGR1_CDPPRE_Pos] & 0x1FU));
  2331. #endif
  2332. }
  2333. /**
  2334. * @brief Returns the D3PCLK1 frequency
  2335. * @note Each time D3PCLK1 changes, this function must be called to update the
  2336. * right D3PCLK1 value. Otherwise, any configuration based on this function will be incorrect.
  2337. * @retval D3PCLK1 frequency
  2338. */
  2339. uint32_t HAL_RCCEx_GetD3PCLK1Freq(void)
  2340. {
  2341. #if defined(RCC_D3CFGR_D3PPRE)
  2342. /* Get HCLK source and Compute D3PCLK1 frequency ---------------------------*/
  2343. return (HAL_RCC_GetHCLKFreq() >> (D1CorePrescTable[(RCC->D3CFGR & RCC_D3CFGR_D3PPRE)>> RCC_D3CFGR_D3PPRE_Pos] & 0x1FU));
  2344. #else
  2345. /* Get HCLK source and Compute D3PCLK1 frequency ---------------------------*/
  2346. return (HAL_RCC_GetHCLKFreq() >> (D1CorePrescTable[(RCC->SRDCFGR & RCC_SRDCFGR_SRDPPRE)>> RCC_SRDCFGR_SRDPPRE_Pos] & 0x1FU));
  2347. #endif
  2348. }
  2349. /**
  2350. * @brief Returns the PLL2 clock frequencies :PLL2_P_Frequency,PLL2_R_Frequency and PLL2_Q_Frequency
  2351. * @note The PLL2 clock frequencies computed by this function is not the real
  2352. * frequency in the chip. It is calculated based on the predefined
  2353. * constant and the selected clock source:
  2354. * @note The function returns values based on HSE_VALUE, HSI_VALUE or CSI Value multiplied/divided by the PLL factors.
  2355. * @note This function can be used by the user application to compute the
  2356. * baud-rate for the communication peripherals or configure other parameters.
  2357. *
  2358. * @note Each time PLL2CLK changes, this function must be called to update the
  2359. * right PLL2CLK value. Otherwise, any configuration based on this function will be incorrect.
  2360. * @param PLL2_Clocks structure.
  2361. * @retval None
  2362. */
  2363. void HAL_RCCEx_GetPLL2ClockFreq(PLL2_ClocksTypeDef* PLL2_Clocks)
  2364. {
  2365. uint32_t pllsource, pll2m, pll2fracen, hsivalue;
  2366. float_t fracn2, pll2vco;
  2367. /* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLL2M) * PLL2N
  2368. PLL2xCLK = PLL2_VCO / PLL2x
  2369. */
  2370. pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
  2371. pll2m = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM2)>> 12);
  2372. pll2fracen = (RCC->PLLCFGR & RCC_PLLCFGR_PLL2FRACEN) >> RCC_PLLCFGR_PLL2FRACEN_Pos;
  2373. fracn2 =(float_t)(uint32_t)(pll2fracen* ((RCC->PLL2FRACR & RCC_PLL2FRACR_FRACN2)>> 3));
  2374. if (pll2m != 0U)
  2375. {
  2376. switch (pllsource)
  2377. {
  2378. case RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  2379. if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIDIV) != 0U)
  2380. {
  2381. hsivalue = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  2382. pll2vco = ( (float_t)hsivalue / (float_t)pll2m) * ((float_t)(uint32_t)(RCC->PLL2DIVR & RCC_PLL2DIVR_N2) + (fracn2/(float_t)0x2000) +(float_t)1 );
  2383. }
  2384. else
  2385. {
  2386. pll2vco = ((float_t)HSI_VALUE / (float_t)pll2m) * ((float_t)(uint32_t)(RCC->PLL2DIVR & RCC_PLL2DIVR_N2) + (fracn2/(float_t)0x2000) +(float_t)1 );
  2387. }
  2388. break;
  2389. case RCC_PLLSOURCE_CSI: /* CSI used as PLL clock source */
  2390. pll2vco = ((float_t)CSI_VALUE / (float_t)pll2m) * ((float_t)(uint32_t)(RCC->PLL2DIVR & RCC_PLL2DIVR_N2) + (fracn2/(float_t)0x2000) +(float_t)1 );
  2391. break;
  2392. case RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  2393. pll2vco = ((float_t)HSE_VALUE / (float_t)pll2m) * ((float_t)(uint32_t)(RCC->PLL2DIVR & RCC_PLL2DIVR_N2) + (fracn2/(float_t)0x2000) +(float_t)1 );
  2394. break;
  2395. default:
  2396. pll2vco = ((float_t)CSI_VALUE / (float_t)pll2m) * ((float_t)(uint32_t)(RCC->PLL2DIVR & RCC_PLL2DIVR_N2) + (fracn2/(float_t)0x2000) +(float_t)1 );
  2397. break;
  2398. }
  2399. PLL2_Clocks->PLL2_P_Frequency = (uint32_t)(float_t)(pll2vco/((float_t)(uint32_t)((RCC->PLL2DIVR & RCC_PLL2DIVR_P2) >>9) + (float_t)1 )) ;
  2400. PLL2_Clocks->PLL2_Q_Frequency = (uint32_t)(float_t)(pll2vco/((float_t)(uint32_t)((RCC->PLL2DIVR & RCC_PLL2DIVR_Q2) >>16) + (float_t)1 )) ;
  2401. PLL2_Clocks->PLL2_R_Frequency = (uint32_t)(float_t)(pll2vco/((float_t)(uint32_t)((RCC->PLL2DIVR & RCC_PLL2DIVR_R2) >>24) + (float_t)1 )) ;
  2402. }
  2403. else
  2404. {
  2405. PLL2_Clocks->PLL2_P_Frequency = 0U;
  2406. PLL2_Clocks->PLL2_Q_Frequency = 0U;
  2407. PLL2_Clocks->PLL2_R_Frequency = 0U;
  2408. }
  2409. }
  2410. /**
  2411. * @brief Returns the PLL3 clock frequencies :PLL3_P_Frequency,PLL3_R_Frequency and PLL3_Q_Frequency
  2412. * @note The PLL3 clock frequencies computed by this function is not the real
  2413. * frequency in the chip. It is calculated based on the predefined
  2414. * constant and the selected clock source:
  2415. * @note The function returns values based on HSE_VALUE, HSI_VALUE or CSI Value multiplied/divided by the PLL factors.
  2416. * @note This function can be used by the user application to compute the
  2417. * baud-rate for the communication peripherals or configure other parameters.
  2418. *
  2419. * @note Each time PLL3CLK changes, this function must be called to update the
  2420. * right PLL3CLK value. Otherwise, any configuration based on this function will be incorrect.
  2421. * @param PLL3_Clocks structure.
  2422. * @retval None
  2423. */
  2424. void HAL_RCCEx_GetPLL3ClockFreq(PLL3_ClocksTypeDef* PLL3_Clocks)
  2425. {
  2426. uint32_t pllsource, pll3m, pll3fracen, hsivalue;
  2427. float_t fracn3, pll3vco;
  2428. /* PLL3_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLL3M) * PLL3N
  2429. PLL3xCLK = PLL3_VCO / PLLxR
  2430. */
  2431. pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
  2432. pll3m = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM3)>> 20) ;
  2433. pll3fracen = (RCC->PLLCFGR & RCC_PLLCFGR_PLL3FRACEN) >> RCC_PLLCFGR_PLL3FRACEN_Pos;
  2434. fracn3 = (float_t)(uint32_t)(pll3fracen* ((RCC->PLL3FRACR & RCC_PLL3FRACR_FRACN3)>> 3));
  2435. if (pll3m != 0U)
  2436. {
  2437. switch (pllsource)
  2438. {
  2439. case RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  2440. if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIDIV) != 0U)
  2441. {
  2442. hsivalue = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  2443. pll3vco = ((float_t)hsivalue / (float_t)pll3m) * ((float_t)(uint32_t)(RCC->PLL3DIVR & RCC_PLL3DIVR_N3) + (fracn3/(float_t)0x2000) +(float_t)1 );
  2444. }
  2445. else
  2446. {
  2447. pll3vco = ((float_t)HSI_VALUE / (float_t)pll3m) * ((float_t)(uint32_t)(RCC->PLL3DIVR & RCC_PLL3DIVR_N3) + (fracn3/(float_t)0x2000) +(float_t)1 );
  2448. }
  2449. break;
  2450. case RCC_PLLSOURCE_CSI: /* CSI used as PLL clock source */
  2451. pll3vco = ((float_t)CSI_VALUE / (float_t)pll3m) * ((float_t)(uint32_t)(RCC->PLL3DIVR & RCC_PLL3DIVR_N3) + (fracn3/(float_t)0x2000) +(float_t)1 );
  2452. break;
  2453. case RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  2454. pll3vco = ((float_t)HSE_VALUE / (float_t)pll3m) * ((float_t)(uint32_t)(RCC->PLL3DIVR & RCC_PLL3DIVR_N3) + (fracn3/(float_t)0x2000) +(float_t)1 );
  2455. break;
  2456. default:
  2457. pll3vco = ((float_t)CSI_VALUE / (float_t)pll3m) * ((float_t)(uint32_t)(RCC->PLL3DIVR & RCC_PLL3DIVR_N3) + (fracn3/(float_t)0x2000) +(float_t)1 );
  2458. break;
  2459. }
  2460. PLL3_Clocks->PLL3_P_Frequency = (uint32_t)(float_t)(pll3vco/((float_t)(uint32_t)((RCC->PLL3DIVR & RCC_PLL3DIVR_P3) >>9) + (float_t)1 )) ;
  2461. PLL3_Clocks->PLL3_Q_Frequency = (uint32_t)(float_t)(pll3vco/((float_t)(uint32_t)((RCC->PLL3DIVR & RCC_PLL3DIVR_Q3) >>16) + (float_t)1 )) ;
  2462. PLL3_Clocks->PLL3_R_Frequency = (uint32_t)(float_t)(pll3vco/((float_t)(uint32_t)((RCC->PLL3DIVR & RCC_PLL3DIVR_R3) >>24) + (float_t)1 )) ;
  2463. }
  2464. else
  2465. {
  2466. PLL3_Clocks->PLL3_P_Frequency = 0U;
  2467. PLL3_Clocks->PLL3_Q_Frequency = 0U;
  2468. PLL3_Clocks->PLL3_R_Frequency = 0U;
  2469. }
  2470. }
  2471. /**
  2472. * @brief Returns the PLL1 clock frequencies :PLL1_P_Frequency,PLL1_R_Frequency and PLL1_Q_Frequency
  2473. * @note The PLL1 clock frequencies computed by this function is not the real
  2474. * frequency in the chip. It is calculated based on the predefined
  2475. * constant and the selected clock source:
  2476. * @note The function returns values based on HSE_VALUE, HSI_VALUE or CSI Value multiplied/divided by the PLL factors.
  2477. * @note This function can be used by the user application to compute the
  2478. * baud-rate for the communication peripherals or configure other parameters.
  2479. *
  2480. * @note Each time PLL1CLK changes, this function must be called to update the
  2481. * right PLL1CLK value. Otherwise, any configuration based on this function will be incorrect.
  2482. * @param PLL1_Clocks structure.
  2483. * @retval None
  2484. */
  2485. void HAL_RCCEx_GetPLL1ClockFreq(PLL1_ClocksTypeDef* PLL1_Clocks)
  2486. {
  2487. uint32_t pllsource, pll1m, pll1fracen, hsivalue;
  2488. float_t fracn1, pll1vco;
  2489. pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
  2490. pll1m = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4);
  2491. pll1fracen = RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN;
  2492. fracn1 = (float_t)(uint32_t)(pll1fracen * ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
  2493. if (pll1m != 0U)
  2494. {
  2495. switch (pllsource)
  2496. {
  2497. case RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  2498. if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIDIV) != 0U)
  2499. {
  2500. hsivalue = (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
  2501. pll1vco = ((float_t)hsivalue / (float_t)pll1m) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
  2502. }
  2503. else
  2504. {
  2505. pll1vco = ((float_t)HSI_VALUE / (float_t)pll1m) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
  2506. }
  2507. break;
  2508. case RCC_PLLSOURCE_CSI: /* CSI used as PLL clock source */
  2509. pll1vco = ((float_t)CSI_VALUE / (float_t)pll1m) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
  2510. break;
  2511. case RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  2512. pll1vco = ((float_t)HSE_VALUE / (float_t)pll1m) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
  2513. break;
  2514. default:
  2515. pll1vco = ((float_t)HSI_VALUE / (float_t)pll1m) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
  2516. break;
  2517. }
  2518. PLL1_Clocks->PLL1_P_Frequency = (uint32_t)(float_t)(pll1vco/((float_t)(uint32_t)((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + (float_t)1 )) ;
  2519. PLL1_Clocks->PLL1_Q_Frequency = (uint32_t)(float_t)(pll1vco/((float_t)(uint32_t)((RCC->PLL1DIVR & RCC_PLL1DIVR_Q1) >>16) + (float_t)1 )) ;
  2520. PLL1_Clocks->PLL1_R_Frequency = (uint32_t)(float_t)(pll1vco/((float_t)(uint32_t)((RCC->PLL1DIVR & RCC_PLL1DIVR_R1) >>24) + (float_t)1 )) ;
  2521. }
  2522. else
  2523. {
  2524. PLL1_Clocks->PLL1_P_Frequency = 0U;
  2525. PLL1_Clocks->PLL1_Q_Frequency = 0U;
  2526. PLL1_Clocks->PLL1_R_Frequency = 0U;
  2527. }
  2528. }
  2529. /**
  2530. * @brief Returns the main System frequency
  2531. * @note Each time System clock changes, this function must be called to update the
  2532. * right core clock value. Otherwise, any configuration based on this function will be incorrect.
  2533. * @note The SystemCoreClock CMSIS variable is used to store System current Core Clock Frequency
  2534. * and updated within this function
  2535. * @retval HCLK frequency
  2536. */
  2537. uint32_t HAL_RCCEx_GetD1SysClockFreq(void)
  2538. {
  2539. uint32_t common_system_clock;
  2540. #if defined(RCC_D1CFGR_D1CPRE)
  2541. common_system_clock = HAL_RCC_GetSysClockFreq() >> (D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> RCC_D1CFGR_D1CPRE_Pos] & 0x1FU);
  2542. #else
  2543. common_system_clock = HAL_RCC_GetSysClockFreq() >> (D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE)>> RCC_CDCFGR1_CDCPRE_Pos] & 0x1FU);
  2544. #endif
  2545. /* Update the SystemD2Clock global variable */
  2546. #if defined(RCC_D1CFGR_HPRE)
  2547. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
  2548. #else
  2549. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE)>> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
  2550. #endif
  2551. #if defined(DUAL_CORE) && defined(CORE_CM4)
  2552. SystemCoreClock = SystemD2Clock;
  2553. #else
  2554. SystemCoreClock = common_system_clock;
  2555. #endif /* DUAL_CORE && CORE_CM4 */
  2556. return common_system_clock;
  2557. }
  2558. /**
  2559. * @}
  2560. */
  2561. /** @defgroup RCCEx_Exported_Functions_Group2 Extended System Control functions
  2562. * @brief Extended Peripheral Control functions
  2563. * @{
  2564. */
  2565. /**
  2566. * @brief Enables the LSE Clock Security System.
  2567. * @note Prior to enable the LSE Clock Security System, LSE oscillator is to be enabled
  2568. * with HAL_RCC_OscConfig() and the LSE oscillator clock is to be selected as RTC
  2569. * clock with HAL_RCCEx_PeriphCLKConfig().
  2570. * @retval None
  2571. */
  2572. void HAL_RCCEx_EnableLSECSS(void)
  2573. {
  2574. SET_BIT(RCC->BDCR, RCC_BDCR_LSECSSON) ;
  2575. }
  2576. /**
  2577. * @brief Disables the LSE Clock Security System.
  2578. * @note LSE Clock Security System can only be disabled after a LSE failure detection.
  2579. * @retval None
  2580. */
  2581. void HAL_RCCEx_DisableLSECSS(void)
  2582. {
  2583. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSECSSON) ;
  2584. /* Disable LSE CSS IT if any */
  2585. __HAL_RCC_DISABLE_IT(RCC_IT_LSECSS);
  2586. }
  2587. /**
  2588. * @brief Enable the LSE Clock Security System Interrupt & corresponding EXTI line.
  2589. * @note LSE Clock Security System Interrupt is mapped on EXTI line 18
  2590. * @retval None
  2591. */
  2592. void HAL_RCCEx_EnableLSECSS_IT(void)
  2593. {
  2594. /* Enable LSE CSS */
  2595. SET_BIT(RCC->BDCR, RCC_BDCR_LSECSSON) ;
  2596. /* Enable LSE CSS IT */
  2597. __HAL_RCC_ENABLE_IT(RCC_IT_LSECSS);
  2598. /* Enable IT on EXTI Line 18 */
  2599. #if defined(DUAL_CORE) && defined(CORE_CM4)
  2600. __HAL_RCC_C2_LSECSS_EXTI_ENABLE_IT();
  2601. #else
  2602. __HAL_RCC_LSECSS_EXTI_ENABLE_IT();
  2603. #endif /* DUAL_CORE && CORE_CM4 */
  2604. __HAL_RCC_LSECSS_EXTI_ENABLE_RISING_EDGE();
  2605. }
  2606. /**
  2607. * @brief Configure the oscillator clock source for wakeup from Stop and CSS backup clock
  2608. * @param WakeUpClk: Wakeup clock
  2609. * This parameter can be one of the following values:
  2610. * @arg RCC_STOP_WAKEUPCLOCK_CSI: CSI oscillator selection
  2611. * @arg RCC_STOP_WAKEUPCLOCK_HSI: HSI oscillator selection
  2612. * @note This function shall not be called after the Clock Security System on HSE has been
  2613. * enabled.
  2614. * @retval None
  2615. */
  2616. void HAL_RCCEx_WakeUpStopCLKConfig(uint32_t WakeUpClk)
  2617. {
  2618. assert_param(IS_RCC_STOP_WAKEUPCLOCK(WakeUpClk));
  2619. __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(WakeUpClk);
  2620. }
  2621. /**
  2622. * @brief Configure the oscillator Kernel clock source for wakeup from Stop
  2623. * @param WakeUpClk: Kernel Wakeup clock
  2624. * This parameter can be one of the following values:
  2625. * @arg RCC_STOP_KERWAKEUPCLOCK_CSI: CSI oscillator selection
  2626. * @arg RCC_STOP_KERWAKEUPCLOCK_HSI: HSI oscillator selection
  2627. * @retval None
  2628. */
  2629. void HAL_RCCEx_KerWakeUpStopCLKConfig(uint32_t WakeUpClk)
  2630. {
  2631. assert_param(IS_RCC_STOP_KERWAKEUPCLOCK(WakeUpClk));
  2632. __HAL_RCC_KERWAKEUPSTOP_CLK_CONFIG(WakeUpClk);
  2633. }
  2634. #if defined(DUAL_CORE)
  2635. /**
  2636. * @brief Enable COREx boot independently of CMx_B option byte value
  2637. * @param RCC_BootCx: Boot Core to be enabled
  2638. * This parameter can be one of the following values:
  2639. * @arg RCC_BOOT_C1: CM7 core selection
  2640. * @arg RCC_BOOT_C2: CM4 core selection
  2641. * @note This bit can be set by software but is cleared by hardware after a system reset or STANDBY
  2642. *
  2643. * @retval None
  2644. */
  2645. void HAL_RCCEx_EnableBootCore(uint32_t RCC_BootCx)
  2646. {
  2647. assert_param(IS_RCC_BOOT_CORE(RCC_BootCx));
  2648. SET_BIT(RCC->GCR, RCC_BootCx) ;
  2649. }
  2650. #endif /*DUAL_CORE*/
  2651. #if defined(DUAL_CORE)
  2652. /**
  2653. * @brief Configure WWDGx to generate a system reset not only CPUx reset(default) when a time-out occurs
  2654. * @param RCC_WWDGx: WWDGx to be configured
  2655. * This parameter can be one of the following values:
  2656. * @arg RCC_WWDG1: WWDG1 generates system reset
  2657. * @arg RCC_WWDG2: WWDG2 generates system reset
  2658. * @note This bit can be set by software but is cleared by hardware during a system reset
  2659. *
  2660. * @retval None
  2661. */
  2662. void HAL_RCCEx_WWDGxSysResetConfig(uint32_t RCC_WWDGx)
  2663. {
  2664. assert_param(IS_RCC_SCOPE_WWDG(RCC_WWDGx));
  2665. SET_BIT(RCC->GCR, RCC_WWDGx) ;
  2666. }
  2667. #else
  2668. #if defined(RCC_GCR_WW1RSC)
  2669. /**
  2670. * @brief Configure WWDG1 to generate a system reset not only CPU reset(default) when a time-out occurs
  2671. * @param RCC_WWDGx: WWDGx to be configured
  2672. * This parameter can be one of the following values:
  2673. * @arg RCC_WWDG1: WWDG1 generates system reset
  2674. * @note This bit can be set by software but is cleared by hardware during a system reset
  2675. *
  2676. * @retval None
  2677. */
  2678. void HAL_RCCEx_WWDGxSysResetConfig(uint32_t RCC_WWDGx)
  2679. {
  2680. assert_param(IS_RCC_SCOPE_WWDG(RCC_WWDGx));
  2681. SET_BIT(RCC->GCR, RCC_WWDGx) ;
  2682. }
  2683. #endif
  2684. #endif /*DUAL_CORE*/
  2685. /**
  2686. * @}
  2687. */
  2688. /** @defgroup RCCEx_Exported_Functions_Group3 Extended Clock Recovery System Control functions
  2689. * @brief Extended Clock Recovery System Control functions
  2690. *
  2691. @verbatim
  2692. ===============================================================================
  2693. ##### Extended Clock Recovery System Control functions #####
  2694. ===============================================================================
  2695. [..]
  2696. For devices with Clock Recovery System feature (CRS), RCC Extension HAL driver can be used as follows:
  2697. (#) In System clock config, HSI48 needs to be enabled
  2698. (#) Enable CRS clock in IP MSP init which will use CRS functions
  2699. (#) Call CRS functions as follows:
  2700. (##) Prepare synchronization configuration necessary for HSI48 calibration
  2701. (+++) Default values can be set for frequency Error Measurement (reload and error limit)
  2702. and also HSI48 oscillator smooth trimming.
  2703. (+++) Macro __HAL_RCC_CRS_RELOADVALUE_CALCULATE can be also used to calculate
  2704. directly reload value with target and synchronization frequencies values
  2705. (##) Call function HAL_RCCEx_CRSConfig which
  2706. (+++) Resets CRS registers to their default values.
  2707. (+++) Configures CRS registers with synchronization configuration
  2708. (+++) Enables automatic calibration and frequency error counter feature
  2709. Note: When using USB LPM (Link Power Management) and the device is in Sleep mode, the
  2710. periodic USB SOF will not be generated by the host. No SYNC signal will therefore be
  2711. provided to the CRS to calibrate the HSI48 on the run. To guarantee the required clock
  2712. precision after waking up from Sleep mode, the LSE or reference clock on the GPIOs
  2713. should be used as SYNC signal.
  2714. (##) A polling function is provided to wait for complete synchronization
  2715. (+++) Call function HAL_RCCEx_CRSWaitSynchronization()
  2716. (+++) According to CRS status, user can decide to adjust again the calibration or continue
  2717. application if synchronization is OK
  2718. (#) User can retrieve information related to synchronization in calling function
  2719. HAL_RCCEx_CRSGetSynchronizationInfo()
  2720. (#) Regarding synchronization status and synchronization information, user can try a new calibration
  2721. in changing synchronization configuration and call again HAL_RCCEx_CRSConfig.
  2722. Note: When the SYNC event is detected during the down-counting phase (before reaching the zero value),
  2723. it means that the actual frequency is lower than the target (and so, that the TRIM value should be
  2724. incremented), while when it is detected during the up-counting phase it means that the actual frequency
  2725. is higher (and that the TRIM value should be decremented).
  2726. (#) In interrupt mode, user can resort to the available macros (__HAL_RCC_CRS_XXX_IT). Interrupts will go
  2727. through CRS Handler (CRS_IRQn/CRS_IRQHandler)
  2728. (++) Call function HAL_RCCEx_CRSConfig()
  2729. (++) Enable CRS_IRQn (thanks to NVIC functions)
  2730. (++) Enable CRS interrupt (__HAL_RCC_CRS_ENABLE_IT)
  2731. (++) Implement CRS status management in the following user callbacks called from
  2732. HAL_RCCEx_CRS_IRQHandler():
  2733. (+++) HAL_RCCEx_CRS_SyncOkCallback()
  2734. (+++) HAL_RCCEx_CRS_SyncWarnCallback()
  2735. (+++) HAL_RCCEx_CRS_ExpectedSyncCallback()
  2736. (+++) HAL_RCCEx_CRS_ErrorCallback()
  2737. (#) To force a SYNC EVENT, user can use the function HAL_RCCEx_CRSSoftwareSynchronizationGenerate().
  2738. This function can be called before calling HAL_RCCEx_CRSConfig (for instance in Systick handler)
  2739. @endverbatim
  2740. * @{
  2741. */
  2742. /**
  2743. * @brief Start automatic synchronization for polling mode
  2744. * @param pInit Pointer on RCC_CRSInitTypeDef structure
  2745. * @retval None
  2746. */
  2747. void HAL_RCCEx_CRSConfig(RCC_CRSInitTypeDef *pInit)
  2748. {
  2749. uint32_t value;
  2750. /* Check the parameters */
  2751. assert_param(IS_RCC_CRS_SYNC_DIV(pInit->Prescaler));
  2752. assert_param(IS_RCC_CRS_SYNC_SOURCE(pInit->Source));
  2753. assert_param(IS_RCC_CRS_SYNC_POLARITY(pInit->Polarity));
  2754. assert_param(IS_RCC_CRS_RELOADVALUE(pInit->ReloadValue));
  2755. assert_param(IS_RCC_CRS_ERRORLIMIT(pInit->ErrorLimitValue));
  2756. assert_param(IS_RCC_CRS_HSI48CALIBRATION(pInit->HSI48CalibrationValue));
  2757. /* CONFIGURATION */
  2758. /* Before configuration, reset CRS registers to their default values*/
  2759. __HAL_RCC_CRS_FORCE_RESET();
  2760. __HAL_RCC_CRS_RELEASE_RESET();
  2761. /* Set the SYNCDIV[2:0] bits according to Pre-scaler value */
  2762. /* Set the SYNCSRC[1:0] bits according to Source value */
  2763. /* Set the SYNCSPOL bit according to Polarity value */
  2764. if ((HAL_GetREVID() <= REV_ID_Y) && (pInit->Source == RCC_CRS_SYNC_SOURCE_USB2))
  2765. {
  2766. /* Use Rev.Y value of USB2 */
  2767. value = (pInit->Prescaler | RCC_CRS_SYNC_SOURCE_PIN | pInit->Polarity);
  2768. }
  2769. else
  2770. {
  2771. value = (pInit->Prescaler | pInit->Source | pInit->Polarity);
  2772. }
  2773. /* Set the RELOAD[15:0] bits according to ReloadValue value */
  2774. value |= pInit->ReloadValue;
  2775. /* Set the FELIM[7:0] bits according to ErrorLimitValue value */
  2776. value |= (pInit->ErrorLimitValue << CRS_CFGR_FELIM_Pos);
  2777. WRITE_REG(CRS->CFGR, value);
  2778. /* Adjust HSI48 oscillator smooth trimming */
  2779. /* Set the TRIM[5:0] bits according to RCC_CRS_HSI48CalibrationValue value */
  2780. MODIFY_REG(CRS->CR, CRS_CR_TRIM, (pInit->HSI48CalibrationValue << CRS_CR_TRIM_Pos));
  2781. /* START AUTOMATIC SYNCHRONIZATION*/
  2782. /* Enable Automatic trimming & Frequency error counter */
  2783. SET_BIT(CRS->CR, CRS_CR_AUTOTRIMEN | CRS_CR_CEN);
  2784. }
  2785. /**
  2786. * @brief Generate the software synchronization event
  2787. * @retval None
  2788. */
  2789. void HAL_RCCEx_CRSSoftwareSynchronizationGenerate(void)
  2790. {
  2791. SET_BIT(CRS->CR, CRS_CR_SWSYNC);
  2792. }
  2793. /**
  2794. * @brief Return synchronization info
  2795. * @param pSynchroInfo Pointer on RCC_CRSSynchroInfoTypeDef structure
  2796. * @retval None
  2797. */
  2798. void HAL_RCCEx_CRSGetSynchronizationInfo(RCC_CRSSynchroInfoTypeDef *pSynchroInfo)
  2799. {
  2800. /* Check the parameter */
  2801. assert_param(pSynchroInfo != (void *)NULL);
  2802. /* Get the reload value */
  2803. pSynchroInfo->ReloadValue = (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_RELOAD));
  2804. /* Get HSI48 oscillator smooth trimming */
  2805. pSynchroInfo->HSI48CalibrationValue = (uint32_t)(READ_BIT(CRS->CR, CRS_CR_TRIM) >> CRS_CR_TRIM_Pos);
  2806. /* Get Frequency error capture */
  2807. pSynchroInfo->FreqErrorCapture = (uint32_t)(READ_BIT(CRS->ISR, CRS_ISR_FECAP) >> CRS_ISR_FECAP_Pos);
  2808. /* Get Frequency error direction */
  2809. pSynchroInfo->FreqErrorDirection = (uint32_t)(READ_BIT(CRS->ISR, CRS_ISR_FEDIR));
  2810. }
  2811. /**
  2812. * @brief Wait for CRS Synchronization status.
  2813. * @param Timeout Duration of the time-out
  2814. * @note Timeout is based on the maximum time to receive a SYNC event based on synchronization
  2815. * frequency.
  2816. * @note If Time-out set to HAL_MAX_DELAY, HAL_TIMEOUT will be never returned.
  2817. * @retval Combination of Synchronization status
  2818. * This parameter can be a combination of the following values:
  2819. * @arg @ref RCC_CRS_TIMEOUT
  2820. * @arg @ref RCC_CRS_SYNCOK
  2821. * @arg @ref RCC_CRS_SYNCWARN
  2822. * @arg @ref RCC_CRS_SYNCERR
  2823. * @arg @ref RCC_CRS_SYNCMISS
  2824. * @arg @ref RCC_CRS_TRIMOVF
  2825. */
  2826. uint32_t HAL_RCCEx_CRSWaitSynchronization(uint32_t Timeout)
  2827. {
  2828. uint32_t crsstatus = RCC_CRS_NONE;
  2829. uint32_t tickstart;
  2830. /* Get time-out */
  2831. tickstart = HAL_GetTick();
  2832. /* Wait for CRS flag or time-out detection */
  2833. do
  2834. {
  2835. if(Timeout != HAL_MAX_DELAY)
  2836. {
  2837. if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
  2838. {
  2839. crsstatus = RCC_CRS_TIMEOUT;
  2840. }
  2841. }
  2842. /* Check CRS SYNCOK flag */
  2843. if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCOK))
  2844. {
  2845. /* CRS SYNC event OK */
  2846. crsstatus |= RCC_CRS_SYNCOK;
  2847. /* Clear CRS SYNC event OK bit */
  2848. __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCOK);
  2849. }
  2850. /* Check CRS SYNCWARN flag */
  2851. if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCWARN))
  2852. {
  2853. /* CRS SYNC warning */
  2854. crsstatus |= RCC_CRS_SYNCWARN;
  2855. /* Clear CRS SYNCWARN bit */
  2856. __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCWARN);
  2857. }
  2858. /* Check CRS TRIM overflow flag */
  2859. if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_TRIMOVF))
  2860. {
  2861. /* CRS SYNC Error */
  2862. crsstatus |= RCC_CRS_TRIMOVF;
  2863. /* Clear CRS Error bit */
  2864. __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_TRIMOVF);
  2865. }
  2866. /* Check CRS Error flag */
  2867. if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCERR))
  2868. {
  2869. /* CRS SYNC Error */
  2870. crsstatus |= RCC_CRS_SYNCERR;
  2871. /* Clear CRS Error bit */
  2872. __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCERR);
  2873. }
  2874. /* Check CRS SYNC Missed flag */
  2875. if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCMISS))
  2876. {
  2877. /* CRS SYNC Missed */
  2878. crsstatus |= RCC_CRS_SYNCMISS;
  2879. /* Clear CRS SYNC Missed bit */
  2880. __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCMISS);
  2881. }
  2882. /* Check CRS Expected SYNC flag */
  2883. if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_ESYNC))
  2884. {
  2885. /* frequency error counter reached a zero value */
  2886. __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_ESYNC);
  2887. }
  2888. } while(RCC_CRS_NONE == crsstatus);
  2889. return crsstatus;
  2890. }
  2891. /**
  2892. * @brief Handle the Clock Recovery System interrupt request.
  2893. * @retval None
  2894. */
  2895. void HAL_RCCEx_CRS_IRQHandler(void)
  2896. {
  2897. uint32_t crserror = RCC_CRS_NONE;
  2898. /* Get current IT flags and IT sources values */
  2899. uint32_t itflags = READ_REG(CRS->ISR);
  2900. uint32_t itsources = READ_REG(CRS->CR);
  2901. /* Check CRS SYNCOK flag */
  2902. if(((itflags & RCC_CRS_FLAG_SYNCOK) != 0U) && ((itsources & RCC_CRS_IT_SYNCOK) != 0U))
  2903. {
  2904. /* Clear CRS SYNC event OK flag */
  2905. WRITE_REG(CRS->ICR, CRS_ICR_SYNCOKC);
  2906. /* user callback */
  2907. HAL_RCCEx_CRS_SyncOkCallback();
  2908. }
  2909. /* Check CRS SYNCWARN flag */
  2910. else if(((itflags & RCC_CRS_FLAG_SYNCWARN) != 0U) && ((itsources & RCC_CRS_IT_SYNCWARN) != 0U))
  2911. {
  2912. /* Clear CRS SYNCWARN flag */
  2913. WRITE_REG(CRS->ICR, CRS_ICR_SYNCWARNC);
  2914. /* user callback */
  2915. HAL_RCCEx_CRS_SyncWarnCallback();
  2916. }
  2917. /* Check CRS Expected SYNC flag */
  2918. else if(((itflags & RCC_CRS_FLAG_ESYNC) != 0U) && ((itsources & RCC_CRS_IT_ESYNC) != 0U))
  2919. {
  2920. /* frequency error counter reached a zero value */
  2921. WRITE_REG(CRS->ICR, CRS_ICR_ESYNCC);
  2922. /* user callback */
  2923. HAL_RCCEx_CRS_ExpectedSyncCallback();
  2924. }
  2925. /* Check CRS Error flags */
  2926. else
  2927. {
  2928. if(((itflags & RCC_CRS_FLAG_ERR) != 0U) && ((itsources & RCC_CRS_IT_ERR) != 0U))
  2929. {
  2930. if((itflags & RCC_CRS_FLAG_SYNCERR) != 0U)
  2931. {
  2932. crserror |= RCC_CRS_SYNCERR;
  2933. }
  2934. if((itflags & RCC_CRS_FLAG_SYNCMISS) != 0U)
  2935. {
  2936. crserror |= RCC_CRS_SYNCMISS;
  2937. }
  2938. if((itflags & RCC_CRS_FLAG_TRIMOVF) != 0U)
  2939. {
  2940. crserror |= RCC_CRS_TRIMOVF;
  2941. }
  2942. /* Clear CRS Error flags */
  2943. WRITE_REG(CRS->ICR, CRS_ICR_ERRC);
  2944. /* user error callback */
  2945. HAL_RCCEx_CRS_ErrorCallback(crserror);
  2946. }
  2947. }
  2948. }
  2949. /**
  2950. * @brief RCCEx Clock Recovery System SYNCOK interrupt callback.
  2951. * @retval none
  2952. */
  2953. __weak void HAL_RCCEx_CRS_SyncOkCallback(void)
  2954. {
  2955. /* NOTE : This function should not be modified, when the callback is needed,
  2956. the @ref HAL_RCCEx_CRS_SyncOkCallback should be implemented in the user file
  2957. */
  2958. }
  2959. /**
  2960. * @brief RCCEx Clock Recovery System SYNCWARN interrupt callback.
  2961. * @retval none
  2962. */
  2963. __weak void HAL_RCCEx_CRS_SyncWarnCallback(void)
  2964. {
  2965. /* NOTE : This function should not be modified, when the callback is needed,
  2966. the @ref HAL_RCCEx_CRS_SyncWarnCallback should be implemented in the user file
  2967. */
  2968. }
  2969. /**
  2970. * @brief RCCEx Clock Recovery System Expected SYNC interrupt callback.
  2971. * @retval none
  2972. */
  2973. __weak void HAL_RCCEx_CRS_ExpectedSyncCallback(void)
  2974. {
  2975. /* NOTE : This function should not be modified, when the callback is needed,
  2976. the @ref HAL_RCCEx_CRS_ExpectedSyncCallback should be implemented in the user file
  2977. */
  2978. }
  2979. /**
  2980. * @brief RCCEx Clock Recovery System Error interrupt callback.
  2981. * @param Error Combination of Error status.
  2982. * This parameter can be a combination of the following values:
  2983. * @arg @ref RCC_CRS_SYNCERR
  2984. * @arg @ref RCC_CRS_SYNCMISS
  2985. * @arg @ref RCC_CRS_TRIMOVF
  2986. * @retval none
  2987. */
  2988. __weak void HAL_RCCEx_CRS_ErrorCallback(uint32_t Error)
  2989. {
  2990. /* Prevent unused argument(s) compilation warning */
  2991. UNUSED(Error);
  2992. /* NOTE : This function should not be modified, when the callback is needed,
  2993. the @ref HAL_RCCEx_CRS_ErrorCallback should be implemented in the user file
  2994. */
  2995. }
  2996. /**
  2997. * @}
  2998. */
  2999. /**
  3000. * @}
  3001. */
  3002. /** @defgroup RCCEx_Private_functions RCCEx Private Functions
  3003. * @{
  3004. */
  3005. /**
  3006. * @brief Configure the PLL2 VCI,VCO ranges, multiplication and division factors and enable it
  3007. * @param pll2: Pointer to an RCC_PLL2InitTypeDef structure that
  3008. * contains the configuration parameters as well as VCI, VCO clock ranges.
  3009. * @param Divider divider parameter to be updated
  3010. * @note PLL2 is temporary disabled to apply new parameters
  3011. *
  3012. * @retval HAL status
  3013. */
  3014. static HAL_StatusTypeDef RCCEx_PLL2_Config(RCC_PLL2InitTypeDef *pll2, uint32_t Divider)
  3015. {
  3016. uint32_t tickstart;
  3017. HAL_StatusTypeDef status = HAL_OK;
  3018. assert_param(IS_RCC_PLL2M_VALUE(pll2->PLL2M));
  3019. assert_param(IS_RCC_PLL2N_VALUE(pll2->PLL2N));
  3020. assert_param(IS_RCC_PLL2P_VALUE(pll2->PLL2P));
  3021. assert_param(IS_RCC_PLL2R_VALUE(pll2->PLL2R));
  3022. assert_param(IS_RCC_PLL2Q_VALUE(pll2->PLL2Q));
  3023. assert_param(IS_RCC_PLL2RGE_VALUE(pll2->PLL2RGE));
  3024. assert_param(IS_RCC_PLL2VCO_VALUE(pll2->PLL2VCOSEL));
  3025. assert_param(IS_RCC_PLLFRACN_VALUE(pll2->PLL2FRACN));
  3026. /* Check that PLL2 OSC clock source is already set */
  3027. if(__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_NONE)
  3028. {
  3029. return HAL_ERROR;
  3030. }
  3031. else
  3032. {
  3033. /* Disable PLL2. */
  3034. __HAL_RCC_PLL2_DISABLE();
  3035. /* Get Start Tick*/
  3036. tickstart = HAL_GetTick();
  3037. /* Wait till PLL is disabled */
  3038. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != 0U)
  3039. {
  3040. if( (HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
  3041. {
  3042. return HAL_TIMEOUT;
  3043. }
  3044. }
  3045. /* Configure PLL2 multiplication and division factors. */
  3046. __HAL_RCC_PLL2_CONFIG(pll2->PLL2M,
  3047. pll2->PLL2N,
  3048. pll2->PLL2P,
  3049. pll2->PLL2Q,
  3050. pll2->PLL2R);
  3051. /* Select PLL2 input reference frequency range: VCI */
  3052. __HAL_RCC_PLL2_VCIRANGE(pll2->PLL2RGE) ;
  3053. /* Select PLL2 output frequency range : VCO */
  3054. __HAL_RCC_PLL2_VCORANGE(pll2->PLL2VCOSEL) ;
  3055. /* Disable PLL2FRACN . */
  3056. __HAL_RCC_PLL2FRACN_DISABLE();
  3057. /* Configures PLL2 clock Fractional Part Of The Multiplication Factor */
  3058. __HAL_RCC_PLL2FRACN_CONFIG(pll2->PLL2FRACN);
  3059. /* Enable PLL2FRACN . */
  3060. __HAL_RCC_PLL2FRACN_ENABLE();
  3061. /* Enable the PLL2 clock output */
  3062. if(Divider == DIVIDER_P_UPDATE)
  3063. {
  3064. __HAL_RCC_PLL2CLKOUT_ENABLE(RCC_PLL2_DIVP);
  3065. }
  3066. else if(Divider == DIVIDER_Q_UPDATE)
  3067. {
  3068. __HAL_RCC_PLL2CLKOUT_ENABLE(RCC_PLL2_DIVQ);
  3069. }
  3070. else
  3071. {
  3072. __HAL_RCC_PLL2CLKOUT_ENABLE(RCC_PLL2_DIVR);
  3073. }
  3074. /* Enable PLL2. */
  3075. __HAL_RCC_PLL2_ENABLE();
  3076. /* Get Start Tick*/
  3077. tickstart = HAL_GetTick();
  3078. /* Wait till PLL2 is ready */
  3079. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == 0U)
  3080. {
  3081. if( (HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
  3082. {
  3083. return HAL_TIMEOUT;
  3084. }
  3085. }
  3086. }
  3087. return status;
  3088. }
  3089. /**
  3090. * @brief Configure the PLL3 VCI,VCO ranges, multiplication and division factors and enable it
  3091. * @param pll3: Pointer to an RCC_PLL3InitTypeDef structure that
  3092. * contains the configuration parameters as well as VCI, VCO clock ranges.
  3093. * @param Divider divider parameter to be updated
  3094. * @note PLL3 is temporary disabled to apply new parameters
  3095. *
  3096. * @retval HAL status
  3097. */
  3098. static HAL_StatusTypeDef RCCEx_PLL3_Config(RCC_PLL3InitTypeDef *pll3, uint32_t Divider)
  3099. {
  3100. uint32_t tickstart;
  3101. HAL_StatusTypeDef status = HAL_OK;
  3102. assert_param(IS_RCC_PLL3M_VALUE(pll3->PLL3M));
  3103. assert_param(IS_RCC_PLL3N_VALUE(pll3->PLL3N));
  3104. assert_param(IS_RCC_PLL3P_VALUE(pll3->PLL3P));
  3105. assert_param(IS_RCC_PLL3R_VALUE(pll3->PLL3R));
  3106. assert_param(IS_RCC_PLL3Q_VALUE(pll3->PLL3Q));
  3107. assert_param(IS_RCC_PLL3RGE_VALUE(pll3->PLL3RGE));
  3108. assert_param(IS_RCC_PLL3VCO_VALUE(pll3->PLL3VCOSEL));
  3109. assert_param(IS_RCC_PLLFRACN_VALUE(pll3->PLL3FRACN));
  3110. /* Check that PLL3 OSC clock source is already set */
  3111. if(__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_NONE)
  3112. {
  3113. return HAL_ERROR;
  3114. }
  3115. else
  3116. {
  3117. /* Disable PLL3. */
  3118. __HAL_RCC_PLL3_DISABLE();
  3119. /* Get Start Tick*/
  3120. tickstart = HAL_GetTick();
  3121. /* Wait till PLL3 is ready */
  3122. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL3RDY) != 0U)
  3123. {
  3124. if( (HAL_GetTick() - tickstart ) > PLL3_TIMEOUT_VALUE)
  3125. {
  3126. return HAL_TIMEOUT;
  3127. }
  3128. }
  3129. /* Configure the PLL3 multiplication and division factors. */
  3130. __HAL_RCC_PLL3_CONFIG(pll3->PLL3M,
  3131. pll3->PLL3N,
  3132. pll3->PLL3P,
  3133. pll3->PLL3Q,
  3134. pll3->PLL3R);
  3135. /* Select PLL3 input reference frequency range: VCI */
  3136. __HAL_RCC_PLL3_VCIRANGE(pll3->PLL3RGE) ;
  3137. /* Select PLL3 output frequency range : VCO */
  3138. __HAL_RCC_PLL3_VCORANGE(pll3->PLL3VCOSEL) ;
  3139. /* Disable PLL3FRACN . */
  3140. __HAL_RCC_PLL3FRACN_DISABLE();
  3141. /* Configures PLL3 clock Fractional Part Of The Multiplication Factor */
  3142. __HAL_RCC_PLL3FRACN_CONFIG(pll3->PLL3FRACN);
  3143. /* Enable PLL3FRACN . */
  3144. __HAL_RCC_PLL3FRACN_ENABLE();
  3145. /* Enable the PLL3 clock output */
  3146. if(Divider == DIVIDER_P_UPDATE)
  3147. {
  3148. __HAL_RCC_PLL3CLKOUT_ENABLE(RCC_PLL3_DIVP);
  3149. }
  3150. else if(Divider == DIVIDER_Q_UPDATE)
  3151. {
  3152. __HAL_RCC_PLL3CLKOUT_ENABLE(RCC_PLL3_DIVQ);
  3153. }
  3154. else
  3155. {
  3156. __HAL_RCC_PLL3CLKOUT_ENABLE(RCC_PLL3_DIVR);
  3157. }
  3158. /* Enable PLL3. */
  3159. __HAL_RCC_PLL3_ENABLE();
  3160. /* Get Start Tick*/
  3161. tickstart = HAL_GetTick();
  3162. /* Wait till PLL3 is ready */
  3163. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL3RDY) == 0U)
  3164. {
  3165. if( (HAL_GetTick() - tickstart ) > PLL3_TIMEOUT_VALUE)
  3166. {
  3167. return HAL_TIMEOUT;
  3168. }
  3169. }
  3170. }
  3171. return status;
  3172. }
  3173. /**
  3174. * @brief Handle the RCC LSE Clock Security System interrupt request.
  3175. * @retval None
  3176. */
  3177. void HAL_RCCEx_LSECSS_IRQHandler(void)
  3178. {
  3179. /* Check RCC LSE CSSF flag */
  3180. if(__HAL_RCC_GET_IT(RCC_IT_LSECSS))
  3181. {
  3182. /* Clear RCC LSE CSS pending bit */
  3183. __HAL_RCC_CLEAR_IT(RCC_IT_LSECSS);
  3184. /* RCC LSE Clock Security System interrupt user callback */
  3185. HAL_RCCEx_LSECSS_Callback();
  3186. }
  3187. }
  3188. /**
  3189. * @brief RCCEx LSE Clock Security System interrupt callback.
  3190. * @retval none
  3191. */
  3192. __weak void HAL_RCCEx_LSECSS_Callback(void)
  3193. {
  3194. /* NOTE : This function should not be modified, when the callback is needed,
  3195. the @ref HAL_RCCEx_LSECSS_Callback should be implemented in the user file
  3196. */
  3197. }
  3198. /**
  3199. * @}
  3200. */
  3201. #endif /* HAL_RCC_MODULE_ENABLED */
  3202. /**
  3203. * @}
  3204. */
  3205. /**
  3206. * @}
  3207. */