stm32f7xx_hal_rcc_ex.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_rcc_ex.c
  4. * @author MCD Application Team
  5. * @brief Extension 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 "stm32f7xx_hal.h"
  23. /** @addtogroup STM32F7xx_HAL_Driver
  24. * @{
  25. */
  26. /** @defgroup RCCEx RCCEx
  27. * @brief RCCEx HAL module driver
  28. * @{
  29. */
  30. #ifdef HAL_RCC_MODULE_ENABLED
  31. /* Private typedef -----------------------------------------------------------*/
  32. /* Private define ------------------------------------------------------------*/
  33. /** @defgroup RCCEx_Private_Defines RCCEx Private Defines
  34. * @{
  35. */
  36. /**
  37. * @}
  38. */
  39. /* Private macro -------------------------------------------------------------*/
  40. /** @defgroup RCCEx_Private_Macros RCCEx Private Macros
  41. * @{
  42. */
  43. /**
  44. * @}
  45. */
  46. /** @defgroup RCCEx_Private_Macros RCCEx Private Macros
  47. * @{
  48. */
  49. /**
  50. * @}
  51. */
  52. /* Private variables ---------------------------------------------------------*/
  53. /* Private function prototypes -----------------------------------------------*/
  54. /* Private functions ---------------------------------------------------------*/
  55. /** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
  56. * @{
  57. */
  58. /** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions
  59. * @brief Extended Peripheral Control functions
  60. *
  61. @verbatim
  62. ===============================================================================
  63. ##### Extended Peripheral Control functions #####
  64. ===============================================================================
  65. [..]
  66. This subsection provides a set of functions allowing to control the RCC Clocks
  67. frequencies.
  68. [..]
  69. (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to
  70. select the RTC clock source; in this case the Backup domain will be reset in
  71. order to modify the RTC Clock source, as consequence RTC registers (including
  72. the backup registers) and RCC_BDCR register will be set to their reset values.
  73. @endverbatim
  74. * @{
  75. */
  76. #if defined (STM32F745xx) || defined (STM32F746xx) || defined (STM32F756xx) || defined (STM32F765xx) || \
  77. defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx) || \
  78. defined (STM32F750xx)
  79. /**
  80. * @brief Initializes the RCC extended peripherals clocks according to the specified
  81. * parameters in the RCC_PeriphCLKInitTypeDef.
  82. * @param PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
  83. * contains the configuration information for the Extended Peripherals
  84. * clocks(I2S, SAI, LTDC, RTC, TIM, UARTs, USARTs, LTPIM, SDMMC...).
  85. *
  86. * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
  87. * the RTC clock source; in this case the Backup domain will be reset in
  88. * order to modify the RTC Clock source, as consequence RTC registers (including
  89. * the backup registers) are set to their reset values.
  90. *
  91. * @retval HAL status
  92. */
  93. HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  94. {
  95. uint32_t tickstart = 0;
  96. uint32_t tmpreg0 = 0;
  97. uint32_t tmpreg1 = 0;
  98. uint32_t plli2sused = 0;
  99. uint32_t pllsaiused = 0;
  100. /* Check the parameters */
  101. assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
  102. /*----------------------------------- I2S configuration ----------------------------------*/
  103. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == (RCC_PERIPHCLK_I2S))
  104. {
  105. /* Check the parameters */
  106. assert_param(IS_RCC_I2SCLKSOURCE(PeriphClkInit->I2sClockSelection));
  107. /* Configure I2S Clock source */
  108. __HAL_RCC_I2S_CONFIG(PeriphClkInit->I2sClockSelection);
  109. /* Enable the PLLI2S when it's used as clock source for I2S */
  110. if(PeriphClkInit->I2sClockSelection == RCC_I2SCLKSOURCE_PLLI2S)
  111. {
  112. plli2sused = 1;
  113. }
  114. }
  115. /*------------------------------------ SAI1 configuration --------------------------------------*/
  116. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == (RCC_PERIPHCLK_SAI1))
  117. {
  118. /* Check the parameters */
  119. assert_param(IS_RCC_SAI1CLKSOURCE(PeriphClkInit->Sai1ClockSelection));
  120. /* Configure SAI1 Clock source */
  121. __HAL_RCC_SAI1_CONFIG(PeriphClkInit->Sai1ClockSelection);
  122. /* Enable the PLLI2S when it's used as clock source for SAI */
  123. if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S)
  124. {
  125. plli2sused = 1;
  126. }
  127. /* Enable the PLLSAI when it's used as clock source for SAI */
  128. if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI)
  129. {
  130. pllsaiused = 1;
  131. }
  132. }
  133. /*------------------------------------ SAI2 configuration --------------------------------------*/
  134. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == (RCC_PERIPHCLK_SAI2))
  135. {
  136. /* Check the parameters */
  137. assert_param(IS_RCC_SAI2CLKSOURCE(PeriphClkInit->Sai2ClockSelection));
  138. /* Configure SAI2 Clock source */
  139. __HAL_RCC_SAI2_CONFIG(PeriphClkInit->Sai2ClockSelection);
  140. /* Enable the PLLI2S when it's used as clock source for SAI */
  141. if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S)
  142. {
  143. plli2sused = 1;
  144. }
  145. /* Enable the PLLSAI when it's used as clock source for SAI */
  146. if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI)
  147. {
  148. pllsaiused = 1;
  149. }
  150. }
  151. /*-------------------------------------- SPDIF-RX Configuration -----------------------------------*/
  152. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPDIFRX) == RCC_PERIPHCLK_SPDIFRX)
  153. {
  154. plli2sused = 1;
  155. }
  156. /*------------------------------------ RTC configuration --------------------------------------*/
  157. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == (RCC_PERIPHCLK_RTC))
  158. {
  159. /* Check for RTC Parameters used to output RTCCLK */
  160. assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
  161. /* Enable Power Clock*/
  162. __HAL_RCC_PWR_CLK_ENABLE();
  163. /* Enable write access to Backup domain */
  164. PWR->CR1 |= PWR_CR1_DBP;
  165. /* Get Start Tick*/
  166. tickstart = HAL_GetTick();
  167. /* Wait for Backup domain Write protection disable */
  168. while((PWR->CR1 & PWR_CR1_DBP) == RESET)
  169. {
  170. if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
  171. {
  172. return HAL_TIMEOUT;
  173. }
  174. }
  175. /* Reset the Backup domain only if the RTC Clock source selection is modified */
  176. tmpreg0 = (RCC->BDCR & RCC_BDCR_RTCSEL);
  177. if((tmpreg0 != 0x00000000U) && (tmpreg0 != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL)))
  178. {
  179. /* Store the content of BDCR register before the reset of Backup Domain */
  180. tmpreg0 = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
  181. /* RTC Clock selection can be changed only if the Backup Domain is reset */
  182. __HAL_RCC_BACKUPRESET_FORCE();
  183. __HAL_RCC_BACKUPRESET_RELEASE();
  184. /* Restore the Content of BDCR register */
  185. RCC->BDCR = tmpreg0;
  186. /* Wait for LSE reactivation if LSE was enable prior to Backup Domain reset */
  187. if (HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSEON))
  188. {
  189. /* Get Start Tick*/
  190. tickstart = HAL_GetTick();
  191. /* Wait till LSE is ready */
  192. while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
  193. {
  194. if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
  195. {
  196. return HAL_TIMEOUT;
  197. }
  198. }
  199. }
  200. }
  201. __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
  202. }
  203. /*------------------------------------ TIM configuration --------------------------------------*/
  204. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM) == (RCC_PERIPHCLK_TIM))
  205. {
  206. /* Check the parameters */
  207. assert_param(IS_RCC_TIMPRES(PeriphClkInit->TIMPresSelection));
  208. /* Configure Timer Prescaler */
  209. __HAL_RCC_TIMCLKPRESCALER(PeriphClkInit->TIMPresSelection);
  210. }
  211. /*-------------------------------------- I2C1 Configuration -----------------------------------*/
  212. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1)
  213. {
  214. /* Check the parameters */
  215. assert_param(IS_RCC_I2C1CLKSOURCE(PeriphClkInit->I2c1ClockSelection));
  216. /* Configure the I2C1 clock source */
  217. __HAL_RCC_I2C1_CONFIG(PeriphClkInit->I2c1ClockSelection);
  218. }
  219. /*-------------------------------------- I2C2 Configuration -----------------------------------*/
  220. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2)
  221. {
  222. /* Check the parameters */
  223. assert_param(IS_RCC_I2C2CLKSOURCE(PeriphClkInit->I2c2ClockSelection));
  224. /* Configure the I2C2 clock source */
  225. __HAL_RCC_I2C2_CONFIG(PeriphClkInit->I2c2ClockSelection);
  226. }
  227. /*-------------------------------------- I2C3 Configuration -----------------------------------*/
  228. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3)
  229. {
  230. /* Check the parameters */
  231. assert_param(IS_RCC_I2C3CLKSOURCE(PeriphClkInit->I2c3ClockSelection));
  232. /* Configure the I2C3 clock source */
  233. __HAL_RCC_I2C3_CONFIG(PeriphClkInit->I2c3ClockSelection);
  234. }
  235. /*-------------------------------------- I2C4 Configuration -----------------------------------*/
  236. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C4) == RCC_PERIPHCLK_I2C4)
  237. {
  238. /* Check the parameters */
  239. assert_param(IS_RCC_I2C4CLKSOURCE(PeriphClkInit->I2c4ClockSelection));
  240. /* Configure the I2C4 clock source */
  241. __HAL_RCC_I2C4_CONFIG(PeriphClkInit->I2c4ClockSelection);
  242. }
  243. /*-------------------------------------- USART1 Configuration -----------------------------------*/
  244. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1)
  245. {
  246. /* Check the parameters */
  247. assert_param(IS_RCC_USART1CLKSOURCE(PeriphClkInit->Usart1ClockSelection));
  248. /* Configure the USART1 clock source */
  249. __HAL_RCC_USART1_CONFIG(PeriphClkInit->Usart1ClockSelection);
  250. }
  251. /*-------------------------------------- USART2 Configuration -----------------------------------*/
  252. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2)
  253. {
  254. /* Check the parameters */
  255. assert_param(IS_RCC_USART2CLKSOURCE(PeriphClkInit->Usart2ClockSelection));
  256. /* Configure the USART2 clock source */
  257. __HAL_RCC_USART2_CONFIG(PeriphClkInit->Usart2ClockSelection);
  258. }
  259. /*-------------------------------------- USART3 Configuration -----------------------------------*/
  260. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3)
  261. {
  262. /* Check the parameters */
  263. assert_param(IS_RCC_USART3CLKSOURCE(PeriphClkInit->Usart3ClockSelection));
  264. /* Configure the USART3 clock source */
  265. __HAL_RCC_USART3_CONFIG(PeriphClkInit->Usart3ClockSelection);
  266. }
  267. /*-------------------------------------- UART4 Configuration -----------------------------------*/
  268. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4)
  269. {
  270. /* Check the parameters */
  271. assert_param(IS_RCC_UART4CLKSOURCE(PeriphClkInit->Uart4ClockSelection));
  272. /* Configure the UART4 clock source */
  273. __HAL_RCC_UART4_CONFIG(PeriphClkInit->Uart4ClockSelection);
  274. }
  275. /*-------------------------------------- UART5 Configuration -----------------------------------*/
  276. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART5) == RCC_PERIPHCLK_UART5)
  277. {
  278. /* Check the parameters */
  279. assert_param(IS_RCC_UART5CLKSOURCE(PeriphClkInit->Uart5ClockSelection));
  280. /* Configure the UART5 clock source */
  281. __HAL_RCC_UART5_CONFIG(PeriphClkInit->Uart5ClockSelection);
  282. }
  283. /*-------------------------------------- USART6 Configuration -----------------------------------*/
  284. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART6) == RCC_PERIPHCLK_USART6)
  285. {
  286. /* Check the parameters */
  287. assert_param(IS_RCC_USART6CLKSOURCE(PeriphClkInit->Usart6ClockSelection));
  288. /* Configure the USART6 clock source */
  289. __HAL_RCC_USART6_CONFIG(PeriphClkInit->Usart6ClockSelection);
  290. }
  291. /*-------------------------------------- UART7 Configuration -----------------------------------*/
  292. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART7) == RCC_PERIPHCLK_UART7)
  293. {
  294. /* Check the parameters */
  295. assert_param(IS_RCC_UART7CLKSOURCE(PeriphClkInit->Uart7ClockSelection));
  296. /* Configure the UART7 clock source */
  297. __HAL_RCC_UART7_CONFIG(PeriphClkInit->Uart7ClockSelection);
  298. }
  299. /*-------------------------------------- UART8 Configuration -----------------------------------*/
  300. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART8) == RCC_PERIPHCLK_UART8)
  301. {
  302. /* Check the parameters */
  303. assert_param(IS_RCC_UART8CLKSOURCE(PeriphClkInit->Uart8ClockSelection));
  304. /* Configure the UART8 clock source */
  305. __HAL_RCC_UART8_CONFIG(PeriphClkInit->Uart8ClockSelection);
  306. }
  307. /*--------------------------------------- CEC Configuration -----------------------------------*/
  308. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC)
  309. {
  310. /* Check the parameters */
  311. assert_param(IS_RCC_CECCLKSOURCE(PeriphClkInit->CecClockSelection));
  312. /* Configure the CEC clock source */
  313. __HAL_RCC_CEC_CONFIG(PeriphClkInit->CecClockSelection);
  314. }
  315. /*-------------------------------------- CK48 Configuration -----------------------------------*/
  316. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CLK48) == RCC_PERIPHCLK_CLK48)
  317. {
  318. /* Check the parameters */
  319. assert_param(IS_RCC_CLK48SOURCE(PeriphClkInit->Clk48ClockSelection));
  320. /* Configure the CLK48 source */
  321. __HAL_RCC_CLK48_CONFIG(PeriphClkInit->Clk48ClockSelection);
  322. /* Enable the PLLSAI when it's used as clock source for CK48 */
  323. if(PeriphClkInit->Clk48ClockSelection == RCC_CLK48SOURCE_PLLSAIP)
  324. {
  325. pllsaiused = 1;
  326. }
  327. }
  328. /*-------------------------------------- LTDC Configuration -----------------------------------*/
  329. #if defined(STM32F746xx) || defined(STM32F756xx) || defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx) || defined (STM32F750xx)
  330. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == RCC_PERIPHCLK_LTDC)
  331. {
  332. pllsaiused = 1;
  333. }
  334. #endif /* STM32F746xx || STM32F756xx || STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx || STM32F750xx */
  335. /*-------------------------------------- LPTIM1 Configuration -----------------------------------*/
  336. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1)
  337. {
  338. /* Check the parameters */
  339. assert_param(IS_RCC_LPTIM1CLK(PeriphClkInit->Lptim1ClockSelection));
  340. /* Configure the LTPIM1 clock source */
  341. __HAL_RCC_LPTIM1_CONFIG(PeriphClkInit->Lptim1ClockSelection);
  342. }
  343. /*------------------------------------- SDMMC1 Configuration ------------------------------------*/
  344. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1)
  345. {
  346. /* Check the parameters */
  347. assert_param(IS_RCC_SDMMC1CLKSOURCE(PeriphClkInit->Sdmmc1ClockSelection));
  348. /* Configure the SDMMC1 clock source */
  349. __HAL_RCC_SDMMC1_CONFIG(PeriphClkInit->Sdmmc1ClockSelection);
  350. }
  351. #if defined (STM32F765xx) || defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx)
  352. /*------------------------------------- SDMMC2 Configuration ------------------------------------*/
  353. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDMMC2) == RCC_PERIPHCLK_SDMMC2)
  354. {
  355. /* Check the parameters */
  356. assert_param(IS_RCC_SDMMC2CLKSOURCE(PeriphClkInit->Sdmmc2ClockSelection));
  357. /* Configure the SDMMC2 clock source */
  358. __HAL_RCC_SDMMC2_CONFIG(PeriphClkInit->Sdmmc2ClockSelection);
  359. }
  360. /*------------------------------------- DFSDM1 Configuration -------------------------------------*/
  361. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_DFSDM1) == RCC_PERIPHCLK_DFSDM1)
  362. {
  363. /* Check the parameters */
  364. assert_param(IS_RCC_DFSDM1CLKSOURCE(PeriphClkInit->Dfsdm1ClockSelection));
  365. /* Configure the DFSDM1 interface clock source */
  366. __HAL_RCC_DFSDM1_CONFIG(PeriphClkInit->Dfsdm1ClockSelection);
  367. }
  368. /*------------------------------------- DFSDM AUDIO Configuration -------------------------------------*/
  369. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_DFSDM1_AUDIO) == RCC_PERIPHCLK_DFSDM1_AUDIO)
  370. {
  371. /* Check the parameters */
  372. assert_param(IS_RCC_DFSDM1AUDIOCLKSOURCE(PeriphClkInit->Dfsdm1AudioClockSelection));
  373. /* Configure the DFSDM interface clock source */
  374. __HAL_RCC_DFSDM1AUDIO_CONFIG(PeriphClkInit->Dfsdm1AudioClockSelection);
  375. }
  376. #endif /* STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx */
  377. /*-------------------------------------- PLLI2S Configuration ---------------------------------*/
  378. /* PLLI2S is configured when a peripheral will use it as source clock : SAI1, SAI2, I2S or SPDIF-RX */
  379. if((plli2sused == 1) || ((PeriphClkInit->PeriphClockSelection & RCC_PERIPHCLK_PLLI2S) == RCC_PERIPHCLK_PLLI2S))
  380. {
  381. /* Disable the PLLI2S */
  382. __HAL_RCC_PLLI2S_DISABLE();
  383. /* Get Start Tick*/
  384. tickstart = HAL_GetTick();
  385. /* Wait till PLLI2S is disabled */
  386. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
  387. {
  388. if((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE)
  389. {
  390. /* return in case of Timeout detected */
  391. return HAL_TIMEOUT;
  392. }
  393. }
  394. /* check for common PLLI2S Parameters */
  395. assert_param(IS_RCC_PLLI2SN_VALUE(PeriphClkInit->PLLI2S.PLLI2SN));
  396. /*----------------- In Case of PLLI2S is selected as source clock for I2S -------------------*/
  397. if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == RCC_PERIPHCLK_I2S) && (PeriphClkInit->I2sClockSelection == RCC_I2SCLKSOURCE_PLLI2S)))
  398. {
  399. /* check for Parameters */
  400. assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
  401. /* Read PLLI2SP and PLLI2SQ value from PLLI2SCFGR register (this value is not needed for I2S configuration) */
  402. tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> RCC_PLLI2SCFGR_PLLI2SP_Pos);
  403. tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> RCC_PLLI2SCFGR_PLLI2SQ_Pos);
  404. /* Configure the PLLI2S division factors */
  405. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLM) */
  406. /* I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
  407. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , tmpreg0, tmpreg1, PeriphClkInit->PLLI2S.PLLI2SR);
  408. }
  409. /*----------------- In Case of PLLI2S is selected as source clock for SAI -------------------*/
  410. if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S)) ||
  411. ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S)))
  412. {
  413. /* Check for PLLI2S Parameters */
  414. assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ));
  415. /* Check for PLLI2S/DIVQ parameters */
  416. assert_param(IS_RCC_PLLI2S_DIVQ_VALUE(PeriphClkInit->PLLI2SDivQ));
  417. /* Read PLLI2SP and PLLI2SR values from PLLI2SCFGR register (this value is not needed for SAI configuration) */
  418. tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> RCC_PLLI2SCFGR_PLLI2SP_Pos);
  419. tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> RCC_PLLI2SCFGR_PLLI2SR_Pos);
  420. /* Configure the PLLI2S division factors */
  421. /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */
  422. /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
  423. /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
  424. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN, tmpreg0, PeriphClkInit->PLLI2S.PLLI2SQ, tmpreg1);
  425. /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
  426. __HAL_RCC_PLLI2S_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLI2SDivQ);
  427. }
  428. /*----------------- In Case of PLLI2S is selected as source clock for SPDIF-RX -------------------*/
  429. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPDIFRX) == RCC_PERIPHCLK_SPDIFRX)
  430. {
  431. /* check for Parameters */
  432. assert_param(IS_RCC_PLLI2SP_VALUE(PeriphClkInit->PLLI2S.PLLI2SP));
  433. /* Read PLLI2SR value from PLLI2SCFGR register (this value is not needed for SPDIF-RX configuration) */
  434. tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> RCC_PLLI2SCFGR_PLLI2SQ_Pos);
  435. tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> RCC_PLLI2SCFGR_PLLI2SR_Pos);
  436. /* Configure the PLLI2S division factors */
  437. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLM) */
  438. /* SPDIFCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SP */
  439. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SP, tmpreg0, tmpreg1);
  440. }
  441. /*----------------- In Case of PLLI2S is just selected -----------------*/
  442. if((PeriphClkInit->PeriphClockSelection & RCC_PERIPHCLK_PLLI2S) == RCC_PERIPHCLK_PLLI2S)
  443. {
  444. /* Check for Parameters */
  445. assert_param(IS_RCC_PLLI2SP_VALUE(PeriphClkInit->PLLI2S.PLLI2SP));
  446. assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
  447. assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ));
  448. /* Configure the PLLI2S division factors */
  449. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLI2SM) */
  450. /* SPDIFRXCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SP */
  451. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SP, PeriphClkInit->PLLI2S.PLLI2SQ, PeriphClkInit->PLLI2S.PLLI2SR);
  452. }
  453. /* Enable the PLLI2S */
  454. __HAL_RCC_PLLI2S_ENABLE();
  455. /* Get Start Tick*/
  456. tickstart = HAL_GetTick();
  457. /* Wait till PLLI2S is ready */
  458. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
  459. {
  460. if((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE)
  461. {
  462. /* return in case of Timeout detected */
  463. return HAL_TIMEOUT;
  464. }
  465. }
  466. }
  467. /*-------------------------------------- PLLSAI Configuration ---------------------------------*/
  468. /* PLLSAI is configured when a peripheral will use it as source clock : SAI1, SAI2, LTDC or CK48 */
  469. if(pllsaiused == 1)
  470. {
  471. /* Disable PLLSAI Clock */
  472. __HAL_RCC_PLLSAI_DISABLE();
  473. /* Get Start Tick*/
  474. tickstart = HAL_GetTick();
  475. /* Wait till PLLSAI is disabled */
  476. while(__HAL_RCC_PLLSAI_GET_FLAG() != RESET)
  477. {
  478. if((HAL_GetTick() - tickstart) > PLLSAI_TIMEOUT_VALUE)
  479. {
  480. /* return in case of Timeout detected */
  481. return HAL_TIMEOUT;
  482. }
  483. }
  484. /* Check the PLLSAI division factors */
  485. assert_param(IS_RCC_PLLSAIN_VALUE(PeriphClkInit->PLLSAI.PLLSAIN));
  486. /*----------------- In Case of PLLSAI is selected as source clock for SAI -------------------*/
  487. if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI)) ||\
  488. ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI)))
  489. {
  490. /* check for PLLSAIQ Parameter */
  491. assert_param(IS_RCC_PLLSAIQ_VALUE(PeriphClkInit->PLLSAI.PLLSAIQ));
  492. /* check for PLLSAI/DIVQ Parameter */
  493. assert_param(IS_RCC_PLLSAI_DIVQ_VALUE(PeriphClkInit->PLLSAIDivQ));
  494. /* Read PLLSAIP value from PLLSAICFGR register (this value is not needed for SAI configuration) */
  495. tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> RCC_PLLSAICFGR_PLLSAIP_Pos);
  496. tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLI2SCFGR_PLLI2SR) >> RCC_PLLSAICFGR_PLLSAIR_Pos);
  497. /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
  498. /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
  499. /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
  500. __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , tmpreg0, PeriphClkInit->PLLSAI.PLLSAIQ, tmpreg1);
  501. /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
  502. __HAL_RCC_PLLSAI_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLSAIDivQ);
  503. }
  504. /*----------------- In Case of PLLSAI is selected as source clock for CLK48 -------------------*/
  505. /* In Case of PLLI2S is selected as source clock for CK48 */
  506. if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CLK48) == RCC_PERIPHCLK_CLK48) && (PeriphClkInit->Clk48ClockSelection == RCC_CLK48SOURCE_PLLSAIP))
  507. {
  508. /* check for Parameters */
  509. assert_param(IS_RCC_PLLSAIP_VALUE(PeriphClkInit->PLLSAI.PLLSAIP));
  510. /* Read PLLSAIQ and PLLSAIR value from PLLSAICFGR register (this value is not needed for CK48 configuration) */
  511. tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> RCC_PLLSAICFGR_PLLSAIQ_Pos);
  512. tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIR) >> RCC_PLLSAICFGR_PLLSAIR_Pos);
  513. /* Configure the PLLSAI division factors */
  514. /* PLLSAI_VCO = f(VCO clock) = f(PLLSAI clock input) x (PLLI2SN/PLLM) */
  515. /* 48CLK = f(PLLSAI clock output) = f(VCO clock) / PLLSAIP */
  516. __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , PeriphClkInit->PLLSAI.PLLSAIP, tmpreg0, tmpreg1);
  517. }
  518. #if defined(STM32F746xx) || defined(STM32F756xx) || defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx) || defined (STM32F750xx)
  519. /*---------------------------- LTDC configuration -------------------------------*/
  520. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == (RCC_PERIPHCLK_LTDC))
  521. {
  522. assert_param(IS_RCC_PLLSAIR_VALUE(PeriphClkInit->PLLSAI.PLLSAIR));
  523. assert_param(IS_RCC_PLLSAI_DIVR_VALUE(PeriphClkInit->PLLSAIDivR));
  524. /* Read PLLSAIP and PLLSAIQ value from PLLSAICFGR register (these value are not needed for LTDC configuration) */
  525. tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> RCC_PLLSAICFGR_PLLSAIQ_Pos);
  526. tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> RCC_PLLSAICFGR_PLLSAIP_Pos);
  527. /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
  528. /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
  529. /* LTDC_CLK(first level) = PLLSAI_VCO Output/PLLSAIR */
  530. __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , tmpreg1, tmpreg0, PeriphClkInit->PLLSAI.PLLSAIR);
  531. /* LTDC_CLK = LTDC_CLK(first level)/PLLSAIDIVR */
  532. __HAL_RCC_PLLSAI_PLLSAICLKDIVR_CONFIG(PeriphClkInit->PLLSAIDivR);
  533. }
  534. #endif /* STM32F746xx || STM32F756xx || STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx || STM32F750xx */
  535. /* Enable PLLSAI Clock */
  536. __HAL_RCC_PLLSAI_ENABLE();
  537. /* Get Start Tick*/
  538. tickstart = HAL_GetTick();
  539. /* Wait till PLLSAI is ready */
  540. while(__HAL_RCC_PLLSAI_GET_FLAG() == RESET)
  541. {
  542. if((HAL_GetTick() - tickstart) > PLLSAI_TIMEOUT_VALUE)
  543. {
  544. /* return in case of Timeout detected */
  545. return HAL_TIMEOUT;
  546. }
  547. }
  548. }
  549. return HAL_OK;
  550. }
  551. /**
  552. * @brief Get the RCC_PeriphCLKInitTypeDef according to the internal
  553. * RCC configuration registers.
  554. * @param PeriphClkInit pointer to the configured RCC_PeriphCLKInitTypeDef structure
  555. * @retval None
  556. */
  557. void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  558. {
  559. uint32_t tempreg = 0;
  560. /* Set all possible values for the extended clock type parameter------------*/
  561. #if defined (STM32F765xx) || defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx)
  562. PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_I2S | RCC_PERIPHCLK_LPTIM1 |\
  563. RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 |\
  564. RCC_PERIPHCLK_TIM | RCC_PERIPHCLK_RTC |\
  565. RCC_PERIPHCLK_CEC | RCC_PERIPHCLK_I2C4 |\
  566. RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 |\
  567. RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_USART1 |\
  568. RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 |\
  569. RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 |\
  570. RCC_PERIPHCLK_USART6 | RCC_PERIPHCLK_UART7 |\
  571. RCC_PERIPHCLK_UART8 | RCC_PERIPHCLK_SDMMC1 |\
  572. RCC_PERIPHCLK_CLK48 | RCC_PERIPHCLK_SDMMC2 |\
  573. RCC_PERIPHCLK_DFSDM1 | RCC_PERIPHCLK_DFSDM1_AUDIO;
  574. #else
  575. PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_I2S | RCC_PERIPHCLK_LPTIM1 |\
  576. RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 |\
  577. RCC_PERIPHCLK_TIM | RCC_PERIPHCLK_RTC |\
  578. RCC_PERIPHCLK_CEC | RCC_PERIPHCLK_I2C4 |\
  579. RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 |\
  580. RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_USART1 |\
  581. RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 |\
  582. RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 |\
  583. RCC_PERIPHCLK_USART6 | RCC_PERIPHCLK_UART7 |\
  584. RCC_PERIPHCLK_UART8 | RCC_PERIPHCLK_SDMMC1 |\
  585. RCC_PERIPHCLK_CLK48;
  586. #endif /* STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx */
  587. /* Get the PLLI2S Clock configuration -----------------------------------------------*/
  588. PeriphClkInit->PLLI2S.PLLI2SN = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> RCC_PLLI2SCFGR_PLLI2SN_Pos);
  589. PeriphClkInit->PLLI2S.PLLI2SP = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> RCC_PLLI2SCFGR_PLLI2SP_Pos);
  590. PeriphClkInit->PLLI2S.PLLI2SQ = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> RCC_PLLI2SCFGR_PLLI2SQ_Pos);
  591. PeriphClkInit->PLLI2S.PLLI2SR = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> RCC_PLLI2SCFGR_PLLI2SR_Pos);
  592. /* Get the PLLSAI Clock configuration -----------------------------------------------*/
  593. PeriphClkInit->PLLSAI.PLLSAIN = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> RCC_PLLSAICFGR_PLLSAIN_Pos);
  594. PeriphClkInit->PLLSAI.PLLSAIP = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> RCC_PLLSAICFGR_PLLSAIP_Pos);
  595. PeriphClkInit->PLLSAI.PLLSAIQ = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> RCC_PLLSAICFGR_PLLSAIQ_Pos);
  596. PeriphClkInit->PLLSAI.PLLSAIR = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIR) >> RCC_PLLSAICFGR_PLLSAIR_Pos);
  597. /* Get the PLLSAI/PLLI2S division factors -------------------------------------------*/
  598. PeriphClkInit->PLLI2SDivQ = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLI2SDIVQ) >> RCC_DCKCFGR1_PLLI2SDIVQ_Pos);
  599. PeriphClkInit->PLLSAIDivQ = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVQ) >> RCC_DCKCFGR1_PLLSAIDIVQ_Pos);
  600. PeriphClkInit->PLLSAIDivR = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVR) >> RCC_DCKCFGR1_PLLSAIDIVR_Pos);
  601. /* Get the SAI1 clock configuration ----------------------------------------------*/
  602. PeriphClkInit->Sai1ClockSelection = __HAL_RCC_GET_SAI1_SOURCE();
  603. /* Get the SAI2 clock configuration ----------------------------------------------*/
  604. PeriphClkInit->Sai2ClockSelection = __HAL_RCC_GET_SAI2_SOURCE();
  605. /* Get the I2S clock configuration ------------------------------------------*/
  606. PeriphClkInit->I2sClockSelection = __HAL_RCC_GET_I2SCLKSOURCE();
  607. /* Get the I2C1 clock configuration ------------------------------------------*/
  608. PeriphClkInit->I2c1ClockSelection = __HAL_RCC_GET_I2C1_SOURCE();
  609. /* Get the I2C2 clock configuration ------------------------------------------*/
  610. PeriphClkInit->I2c2ClockSelection = __HAL_RCC_GET_I2C2_SOURCE();
  611. /* Get the I2C3 clock configuration ------------------------------------------*/
  612. PeriphClkInit->I2c3ClockSelection = __HAL_RCC_GET_I2C3_SOURCE();
  613. /* Get the I2C4 clock configuration ------------------------------------------*/
  614. PeriphClkInit->I2c4ClockSelection = __HAL_RCC_GET_I2C4_SOURCE();
  615. /* Get the USART1 clock configuration ------------------------------------------*/
  616. PeriphClkInit->Usart1ClockSelection = __HAL_RCC_GET_USART1_SOURCE();
  617. /* Get the USART2 clock configuration ------------------------------------------*/
  618. PeriphClkInit->Usart2ClockSelection = __HAL_RCC_GET_USART2_SOURCE();
  619. /* Get the USART3 clock configuration ------------------------------------------*/
  620. PeriphClkInit->Usart3ClockSelection = __HAL_RCC_GET_USART3_SOURCE();
  621. /* Get the UART4 clock configuration ------------------------------------------*/
  622. PeriphClkInit->Uart4ClockSelection = __HAL_RCC_GET_UART4_SOURCE();
  623. /* Get the UART5 clock configuration ------------------------------------------*/
  624. PeriphClkInit->Uart5ClockSelection = __HAL_RCC_GET_UART5_SOURCE();
  625. /* Get the USART6 clock configuration ------------------------------------------*/
  626. PeriphClkInit->Usart6ClockSelection = __HAL_RCC_GET_USART6_SOURCE();
  627. /* Get the UART7 clock configuration ------------------------------------------*/
  628. PeriphClkInit->Uart7ClockSelection = __HAL_RCC_GET_UART7_SOURCE();
  629. /* Get the UART8 clock configuration ------------------------------------------*/
  630. PeriphClkInit->Uart8ClockSelection = __HAL_RCC_GET_UART8_SOURCE();
  631. /* Get the LPTIM1 clock configuration ------------------------------------------*/
  632. PeriphClkInit->Lptim1ClockSelection = __HAL_RCC_GET_LPTIM1_SOURCE();
  633. /* Get the CEC clock configuration -----------------------------------------------*/
  634. PeriphClkInit->CecClockSelection = __HAL_RCC_GET_CEC_SOURCE();
  635. /* Get the CK48 clock configuration -----------------------------------------------*/
  636. PeriphClkInit->Clk48ClockSelection = __HAL_RCC_GET_CLK48_SOURCE();
  637. /* Get the SDMMC1 clock configuration -----------------------------------------------*/
  638. PeriphClkInit->Sdmmc1ClockSelection = __HAL_RCC_GET_SDMMC1_SOURCE();
  639. #if defined (STM32F765xx) || defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx)
  640. /* Get the SDMMC2 clock configuration -----------------------------------------------*/
  641. PeriphClkInit->Sdmmc2ClockSelection = __HAL_RCC_GET_SDMMC2_SOURCE();
  642. /* Get the DFSDM clock configuration -----------------------------------------------*/
  643. PeriphClkInit->Dfsdm1ClockSelection = __HAL_RCC_GET_DFSDM1_SOURCE();
  644. /* Get the DFSDM AUDIO clock configuration -----------------------------------------------*/
  645. PeriphClkInit->Dfsdm1AudioClockSelection = __HAL_RCC_GET_DFSDM1AUDIO_SOURCE();
  646. #endif /* STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx */
  647. /* Get the RTC Clock configuration -----------------------------------------------*/
  648. tempreg = (RCC->CFGR & RCC_CFGR_RTCPRE);
  649. PeriphClkInit->RTCClockSelection = (uint32_t)((tempreg) | (RCC->BDCR & RCC_BDCR_RTCSEL));
  650. /* Get the TIM Prescaler configuration --------------------------------------------*/
  651. if ((RCC->DCKCFGR1 & RCC_DCKCFGR1_TIMPRE) == RESET)
  652. {
  653. PeriphClkInit->TIMPresSelection = RCC_TIMPRES_DESACTIVATED;
  654. }
  655. else
  656. {
  657. PeriphClkInit->TIMPresSelection = RCC_TIMPRES_ACTIVATED;
  658. }
  659. }
  660. #endif /* STM32F745xx || STM32F746xx || STM32F756xx || STM32F765xx || STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx || STM32F750xx */
  661. #if defined (STM32F722xx) || defined (STM32F723xx) || defined (STM32F732xx) || defined (STM32F733xx) || defined (STM32F730xx)
  662. /**
  663. * @brief Initializes the RCC extended peripherals clocks according to the specified
  664. * parameters in the RCC_PeriphCLKInitTypeDef.
  665. * @param PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
  666. * contains the configuration information for the Extended Peripherals
  667. * clocks(I2S, SAI, RTC, TIM, UARTs, USARTs, LTPIM, SDMMC...).
  668. *
  669. * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
  670. * the RTC clock source; in this case the Backup domain will be reset in
  671. * order to modify the RTC Clock source, as consequence RTC registers (including
  672. * the backup registers) are set to their reset values.
  673. *
  674. * @retval HAL status
  675. */
  676. HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  677. {
  678. uint32_t tickstart = 0;
  679. uint32_t tmpreg0 = 0;
  680. uint32_t plli2sused = 0;
  681. uint32_t pllsaiused = 0;
  682. /* Check the parameters */
  683. assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
  684. /*----------------------------------- I2S configuration ----------------------------------*/
  685. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == (RCC_PERIPHCLK_I2S))
  686. {
  687. /* Check the parameters */
  688. assert_param(IS_RCC_I2SCLKSOURCE(PeriphClkInit->I2sClockSelection));
  689. /* Configure I2S Clock source */
  690. __HAL_RCC_I2S_CONFIG(PeriphClkInit->I2sClockSelection);
  691. /* Enable the PLLI2S when it's used as clock source for I2S */
  692. if(PeriphClkInit->I2sClockSelection == RCC_I2SCLKSOURCE_PLLI2S)
  693. {
  694. plli2sused = 1;
  695. }
  696. }
  697. /*------------------------------------ SAI1 configuration --------------------------------------*/
  698. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == (RCC_PERIPHCLK_SAI1))
  699. {
  700. /* Check the parameters */
  701. assert_param(IS_RCC_SAI1CLKSOURCE(PeriphClkInit->Sai1ClockSelection));
  702. /* Configure SAI1 Clock source */
  703. __HAL_RCC_SAI1_CONFIG(PeriphClkInit->Sai1ClockSelection);
  704. /* Enable the PLLI2S when it's used as clock source for SAI */
  705. if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S)
  706. {
  707. plli2sused = 1;
  708. }
  709. /* Enable the PLLSAI when it's used as clock source for SAI */
  710. if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI)
  711. {
  712. pllsaiused = 1;
  713. }
  714. }
  715. /*------------------------------------ SAI2 configuration --------------------------------------*/
  716. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == (RCC_PERIPHCLK_SAI2))
  717. {
  718. /* Check the parameters */
  719. assert_param(IS_RCC_SAI2CLKSOURCE(PeriphClkInit->Sai2ClockSelection));
  720. /* Configure SAI2 Clock source */
  721. __HAL_RCC_SAI2_CONFIG(PeriphClkInit->Sai2ClockSelection);
  722. /* Enable the PLLI2S when it's used as clock source for SAI */
  723. if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S)
  724. {
  725. plli2sused = 1;
  726. }
  727. /* Enable the PLLSAI when it's used as clock source for SAI */
  728. if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI)
  729. {
  730. pllsaiused = 1;
  731. }
  732. }
  733. /*------------------------------------ RTC configuration --------------------------------------*/
  734. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == (RCC_PERIPHCLK_RTC))
  735. {
  736. /* Check for RTC Parameters used to output RTCCLK */
  737. assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
  738. /* Enable Power Clock*/
  739. __HAL_RCC_PWR_CLK_ENABLE();
  740. /* Enable write access to Backup domain */
  741. PWR->CR1 |= PWR_CR1_DBP;
  742. /* Get Start Tick*/
  743. tickstart = HAL_GetTick();
  744. /* Wait for Backup domain Write protection disable */
  745. while((PWR->CR1 & PWR_CR1_DBP) == RESET)
  746. {
  747. if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
  748. {
  749. return HAL_TIMEOUT;
  750. }
  751. }
  752. /* Reset the Backup domain only if the RTC Clock source selection is modified */
  753. tmpreg0 = (RCC->BDCR & RCC_BDCR_RTCSEL);
  754. if((tmpreg0 != 0x00000000U) && (tmpreg0 != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL)))
  755. {
  756. /* Store the content of BDCR register before the reset of Backup Domain */
  757. tmpreg0 = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
  758. /* RTC Clock selection can be changed only if the Backup Domain is reset */
  759. __HAL_RCC_BACKUPRESET_FORCE();
  760. __HAL_RCC_BACKUPRESET_RELEASE();
  761. /* Restore the Content of BDCR register */
  762. RCC->BDCR = tmpreg0;
  763. /* Wait for LSE reactivation if LSE was enable prior to Backup Domain reset */
  764. if (HAL_IS_BIT_SET(RCC->BDCR, RCC_BDCR_LSEON))
  765. {
  766. /* Get Start Tick*/
  767. tickstart = HAL_GetTick();
  768. /* Wait till LSE is ready */
  769. while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
  770. {
  771. if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
  772. {
  773. return HAL_TIMEOUT;
  774. }
  775. }
  776. }
  777. }
  778. __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
  779. }
  780. /*------------------------------------ TIM configuration --------------------------------------*/
  781. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM) == (RCC_PERIPHCLK_TIM))
  782. {
  783. /* Check the parameters */
  784. assert_param(IS_RCC_TIMPRES(PeriphClkInit->TIMPresSelection));
  785. /* Configure Timer Prescaler */
  786. __HAL_RCC_TIMCLKPRESCALER(PeriphClkInit->TIMPresSelection);
  787. }
  788. /*-------------------------------------- I2C1 Configuration -----------------------------------*/
  789. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1)
  790. {
  791. /* Check the parameters */
  792. assert_param(IS_RCC_I2C1CLKSOURCE(PeriphClkInit->I2c1ClockSelection));
  793. /* Configure the I2C1 clock source */
  794. __HAL_RCC_I2C1_CONFIG(PeriphClkInit->I2c1ClockSelection);
  795. }
  796. /*-------------------------------------- I2C2 Configuration -----------------------------------*/
  797. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2)
  798. {
  799. /* Check the parameters */
  800. assert_param(IS_RCC_I2C2CLKSOURCE(PeriphClkInit->I2c2ClockSelection));
  801. /* Configure the I2C2 clock source */
  802. __HAL_RCC_I2C2_CONFIG(PeriphClkInit->I2c2ClockSelection);
  803. }
  804. /*-------------------------------------- I2C3 Configuration -----------------------------------*/
  805. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3)
  806. {
  807. /* Check the parameters */
  808. assert_param(IS_RCC_I2C3CLKSOURCE(PeriphClkInit->I2c3ClockSelection));
  809. /* Configure the I2C3 clock source */
  810. __HAL_RCC_I2C3_CONFIG(PeriphClkInit->I2c3ClockSelection);
  811. }
  812. /*-------------------------------------- USART1 Configuration -----------------------------------*/
  813. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1)
  814. {
  815. /* Check the parameters */
  816. assert_param(IS_RCC_USART1CLKSOURCE(PeriphClkInit->Usart1ClockSelection));
  817. /* Configure the USART1 clock source */
  818. __HAL_RCC_USART1_CONFIG(PeriphClkInit->Usart1ClockSelection);
  819. }
  820. /*-------------------------------------- USART2 Configuration -----------------------------------*/
  821. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2)
  822. {
  823. /* Check the parameters */
  824. assert_param(IS_RCC_USART2CLKSOURCE(PeriphClkInit->Usart2ClockSelection));
  825. /* Configure the USART2 clock source */
  826. __HAL_RCC_USART2_CONFIG(PeriphClkInit->Usart2ClockSelection);
  827. }
  828. /*-------------------------------------- USART3 Configuration -----------------------------------*/
  829. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3)
  830. {
  831. /* Check the parameters */
  832. assert_param(IS_RCC_USART3CLKSOURCE(PeriphClkInit->Usart3ClockSelection));
  833. /* Configure the USART3 clock source */
  834. __HAL_RCC_USART3_CONFIG(PeriphClkInit->Usart3ClockSelection);
  835. }
  836. /*-------------------------------------- UART4 Configuration -----------------------------------*/
  837. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4)
  838. {
  839. /* Check the parameters */
  840. assert_param(IS_RCC_UART4CLKSOURCE(PeriphClkInit->Uart4ClockSelection));
  841. /* Configure the UART4 clock source */
  842. __HAL_RCC_UART4_CONFIG(PeriphClkInit->Uart4ClockSelection);
  843. }
  844. /*-------------------------------------- UART5 Configuration -----------------------------------*/
  845. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART5) == RCC_PERIPHCLK_UART5)
  846. {
  847. /* Check the parameters */
  848. assert_param(IS_RCC_UART5CLKSOURCE(PeriphClkInit->Uart5ClockSelection));
  849. /* Configure the UART5 clock source */
  850. __HAL_RCC_UART5_CONFIG(PeriphClkInit->Uart5ClockSelection);
  851. }
  852. /*-------------------------------------- USART6 Configuration -----------------------------------*/
  853. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART6) == RCC_PERIPHCLK_USART6)
  854. {
  855. /* Check the parameters */
  856. assert_param(IS_RCC_USART6CLKSOURCE(PeriphClkInit->Usart6ClockSelection));
  857. /* Configure the USART6 clock source */
  858. __HAL_RCC_USART6_CONFIG(PeriphClkInit->Usart6ClockSelection);
  859. }
  860. /*-------------------------------------- UART7 Configuration -----------------------------------*/
  861. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART7) == RCC_PERIPHCLK_UART7)
  862. {
  863. /* Check the parameters */
  864. assert_param(IS_RCC_UART7CLKSOURCE(PeriphClkInit->Uart7ClockSelection));
  865. /* Configure the UART7 clock source */
  866. __HAL_RCC_UART7_CONFIG(PeriphClkInit->Uart7ClockSelection);
  867. }
  868. /*-------------------------------------- UART8 Configuration -----------------------------------*/
  869. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART8) == RCC_PERIPHCLK_UART8)
  870. {
  871. /* Check the parameters */
  872. assert_param(IS_RCC_UART8CLKSOURCE(PeriphClkInit->Uart8ClockSelection));
  873. /* Configure the UART8 clock source */
  874. __HAL_RCC_UART8_CONFIG(PeriphClkInit->Uart8ClockSelection);
  875. }
  876. /*-------------------------------------- CK48 Configuration -----------------------------------*/
  877. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CLK48) == RCC_PERIPHCLK_CLK48)
  878. {
  879. /* Check the parameters */
  880. assert_param(IS_RCC_CLK48SOURCE(PeriphClkInit->Clk48ClockSelection));
  881. /* Configure the CLK48 source */
  882. __HAL_RCC_CLK48_CONFIG(PeriphClkInit->Clk48ClockSelection);
  883. /* Enable the PLLSAI when it's used as clock source for CK48 */
  884. if(PeriphClkInit->Clk48ClockSelection == RCC_CLK48SOURCE_PLLSAIP)
  885. {
  886. pllsaiused = 1;
  887. }
  888. }
  889. /*-------------------------------------- LPTIM1 Configuration -----------------------------------*/
  890. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1)
  891. {
  892. /* Check the parameters */
  893. assert_param(IS_RCC_LPTIM1CLK(PeriphClkInit->Lptim1ClockSelection));
  894. /* Configure the LTPIM1 clock source */
  895. __HAL_RCC_LPTIM1_CONFIG(PeriphClkInit->Lptim1ClockSelection);
  896. }
  897. /*------------------------------------- SDMMC1 Configuration ------------------------------------*/
  898. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1)
  899. {
  900. /* Check the parameters */
  901. assert_param(IS_RCC_SDMMC1CLKSOURCE(PeriphClkInit->Sdmmc1ClockSelection));
  902. /* Configure the SDMMC1 clock source */
  903. __HAL_RCC_SDMMC1_CONFIG(PeriphClkInit->Sdmmc1ClockSelection);
  904. }
  905. /*------------------------------------- SDMMC2 Configuration ------------------------------------*/
  906. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDMMC2) == RCC_PERIPHCLK_SDMMC2)
  907. {
  908. /* Check the parameters */
  909. assert_param(IS_RCC_SDMMC2CLKSOURCE(PeriphClkInit->Sdmmc2ClockSelection));
  910. /* Configure the SDMMC2 clock source */
  911. __HAL_RCC_SDMMC2_CONFIG(PeriphClkInit->Sdmmc2ClockSelection);
  912. }
  913. /*-------------------------------------- PLLI2S Configuration ---------------------------------*/
  914. /* PLLI2S is configured when a peripheral will use it as source clock : SAI1, SAI2 or I2S */
  915. if((plli2sused == 1) || ((PeriphClkInit->PeriphClockSelection & RCC_PERIPHCLK_PLLI2S) == RCC_PERIPHCLK_PLLI2S))
  916. {
  917. /* Disable the PLLI2S */
  918. __HAL_RCC_PLLI2S_DISABLE();
  919. /* Get Start Tick*/
  920. tickstart = HAL_GetTick();
  921. /* Wait till PLLI2S is disabled */
  922. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
  923. {
  924. if((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE)
  925. {
  926. /* return in case of Timeout detected */
  927. return HAL_TIMEOUT;
  928. }
  929. }
  930. /* check for common PLLI2S Parameters */
  931. assert_param(IS_RCC_PLLI2SN_VALUE(PeriphClkInit->PLLI2S.PLLI2SN));
  932. /*----------------- In Case of PLLI2S is selected as source clock for I2S -------------------*/
  933. if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == RCC_PERIPHCLK_I2S) && (PeriphClkInit->I2sClockSelection == RCC_I2SCLKSOURCE_PLLI2S)))
  934. {
  935. /* check for Parameters */
  936. assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
  937. /* Read PLLI2SQ value from PLLI2SCFGR register (this value is not needed for I2S configuration) */
  938. tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> RCC_PLLI2SCFGR_PLLI2SQ_Pos);
  939. /* Configure the PLLI2S division factors */
  940. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLM) */
  941. /* I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
  942. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , tmpreg0, PeriphClkInit->PLLI2S.PLLI2SR);
  943. }
  944. /*----------------- In Case of PLLI2S is selected as source clock for SAI -------------------*/
  945. if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S)) ||
  946. ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S)))
  947. {
  948. /* Check for PLLI2S Parameters */
  949. assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ));
  950. /* Check for PLLI2S/DIVQ parameters */
  951. assert_param(IS_RCC_PLLI2S_DIVQ_VALUE(PeriphClkInit->PLLI2SDivQ));
  952. /* Read PLLI2SP and PLLI2SR values from PLLI2SCFGR register (this value is not needed for SAI configuration) */
  953. tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> RCC_PLLI2SCFGR_PLLI2SR_Pos);
  954. /* Configure the PLLI2S division factors */
  955. /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */
  956. /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
  957. /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
  958. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN, PeriphClkInit->PLLI2S.PLLI2SQ, tmpreg0);
  959. /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
  960. __HAL_RCC_PLLI2S_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLI2SDivQ);
  961. }
  962. /*----------------- In Case of PLLI2S is just selected -----------------*/
  963. if((PeriphClkInit->PeriphClockSelection & RCC_PERIPHCLK_PLLI2S) == RCC_PERIPHCLK_PLLI2S)
  964. {
  965. /* Check for Parameters */
  966. assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
  967. assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ));
  968. /* Configure the PLLI2S division factors */
  969. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLI2SM) */
  970. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SQ, PeriphClkInit->PLLI2S.PLLI2SR);
  971. }
  972. /* Enable the PLLI2S */
  973. __HAL_RCC_PLLI2S_ENABLE();
  974. /* Get Start Tick*/
  975. tickstart = HAL_GetTick();
  976. /* Wait till PLLI2S is ready */
  977. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
  978. {
  979. if((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE)
  980. {
  981. /* return in case of Timeout detected */
  982. return HAL_TIMEOUT;
  983. }
  984. }
  985. }
  986. /*-------------------------------------- PLLSAI Configuration ---------------------------------*/
  987. /* PLLSAI is configured when a peripheral will use it as source clock : SAI1, SAI2, LTDC or CK48 */
  988. if(pllsaiused == 1)
  989. {
  990. /* Disable PLLSAI Clock */
  991. __HAL_RCC_PLLSAI_DISABLE();
  992. /* Get Start Tick*/
  993. tickstart = HAL_GetTick();
  994. /* Wait till PLLSAI is disabled */
  995. while(__HAL_RCC_PLLSAI_GET_FLAG() != RESET)
  996. {
  997. if((HAL_GetTick() - tickstart) > PLLSAI_TIMEOUT_VALUE)
  998. {
  999. /* return in case of Timeout detected */
  1000. return HAL_TIMEOUT;
  1001. }
  1002. }
  1003. /* Check the PLLSAI division factors */
  1004. assert_param(IS_RCC_PLLSAIN_VALUE(PeriphClkInit->PLLSAI.PLLSAIN));
  1005. /*----------------- In Case of PLLSAI is selected as source clock for SAI -------------------*/
  1006. if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI)) ||\
  1007. ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI)))
  1008. {
  1009. /* check for PLLSAIQ Parameter */
  1010. assert_param(IS_RCC_PLLSAIQ_VALUE(PeriphClkInit->PLLSAI.PLLSAIQ));
  1011. /* check for PLLSAI/DIVQ Parameter */
  1012. assert_param(IS_RCC_PLLSAI_DIVQ_VALUE(PeriphClkInit->PLLSAIDivQ));
  1013. /* Read PLLSAIP value from PLLSAICFGR register (this value is not needed for SAI configuration) */
  1014. tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> RCC_PLLSAICFGR_PLLSAIP_Pos);
  1015. /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
  1016. /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
  1017. /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
  1018. __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , tmpreg0, PeriphClkInit->PLLSAI.PLLSAIQ);
  1019. /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
  1020. __HAL_RCC_PLLSAI_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLSAIDivQ);
  1021. }
  1022. /*----------------- In Case of PLLSAI is selected as source clock for CLK48 -------------------*/
  1023. /* In Case of PLLI2S is selected as source clock for CK48 */
  1024. if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CLK48) == RCC_PERIPHCLK_CLK48) && (PeriphClkInit->Clk48ClockSelection == RCC_CLK48SOURCE_PLLSAIP))
  1025. {
  1026. /* check for Parameters */
  1027. assert_param(IS_RCC_PLLSAIP_VALUE(PeriphClkInit->PLLSAI.PLLSAIP));
  1028. /* Read PLLSAIQ and PLLSAIR value from PLLSAICFGR register (this value is not needed for CK48 configuration) */
  1029. tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> RCC_PLLSAICFGR_PLLSAIQ_Pos);
  1030. /* Configure the PLLSAI division factors */
  1031. /* PLLSAI_VCO = f(VCO clock) = f(PLLSAI clock input) x (PLLI2SN/PLLM) */
  1032. /* 48CLK = f(PLLSAI clock output) = f(VCO clock) / PLLSAIP */
  1033. __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , PeriphClkInit->PLLSAI.PLLSAIP, tmpreg0);
  1034. }
  1035. /* Enable PLLSAI Clock */
  1036. __HAL_RCC_PLLSAI_ENABLE();
  1037. /* Get Start Tick*/
  1038. tickstart = HAL_GetTick();
  1039. /* Wait till PLLSAI is ready */
  1040. while(__HAL_RCC_PLLSAI_GET_FLAG() == RESET)
  1041. {
  1042. if((HAL_GetTick() - tickstart) > PLLSAI_TIMEOUT_VALUE)
  1043. {
  1044. /* return in case of Timeout detected */
  1045. return HAL_TIMEOUT;
  1046. }
  1047. }
  1048. }
  1049. return HAL_OK;
  1050. }
  1051. /**
  1052. * @brief Get the RCC_PeriphCLKInitTypeDef according to the internal
  1053. * RCC configuration registers.
  1054. * @param PeriphClkInit pointer to the configured RCC_PeriphCLKInitTypeDef structure
  1055. * @retval None
  1056. */
  1057. void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  1058. {
  1059. uint32_t tempreg = 0;
  1060. /* Set all possible values for the extended clock type parameter------------*/
  1061. PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_I2S | RCC_PERIPHCLK_LPTIM1 |\
  1062. RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 |\
  1063. RCC_PERIPHCLK_TIM | RCC_PERIPHCLK_RTC |\
  1064. RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 |\
  1065. RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_USART1 |\
  1066. RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 |\
  1067. RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 |\
  1068. RCC_PERIPHCLK_USART6 | RCC_PERIPHCLK_UART7 |\
  1069. RCC_PERIPHCLK_UART8 | RCC_PERIPHCLK_SDMMC1 |\
  1070. RCC_PERIPHCLK_CLK48 | RCC_PERIPHCLK_SDMMC2;
  1071. /* Get the PLLI2S Clock configuration -----------------------------------------------*/
  1072. PeriphClkInit->PLLI2S.PLLI2SN = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> RCC_PLLI2SCFGR_PLLI2SN_Pos);
  1073. PeriphClkInit->PLLI2S.PLLI2SQ = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> RCC_PLLI2SCFGR_PLLI2SQ_Pos);
  1074. PeriphClkInit->PLLI2S.PLLI2SR = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> RCC_PLLI2SCFGR_PLLI2SR_Pos);
  1075. /* Get the PLLSAI Clock configuration -----------------------------------------------*/
  1076. PeriphClkInit->PLLSAI.PLLSAIN = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> RCC_PLLSAICFGR_PLLSAIN_Pos);
  1077. PeriphClkInit->PLLSAI.PLLSAIP = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> RCC_PLLSAICFGR_PLLSAIP_Pos);
  1078. PeriphClkInit->PLLSAI.PLLSAIQ = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> RCC_PLLSAICFGR_PLLSAIQ_Pos);
  1079. /* Get the PLLSAI/PLLI2S division factors -------------------------------------------*/
  1080. PeriphClkInit->PLLI2SDivQ = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLI2SDIVQ) >> RCC_DCKCFGR1_PLLI2SDIVQ_Pos);
  1081. PeriphClkInit->PLLSAIDivQ = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVQ) >> RCC_DCKCFGR1_PLLSAIDIVQ_Pos);
  1082. /* Get the SAI1 clock configuration ----------------------------------------------*/
  1083. PeriphClkInit->Sai1ClockSelection = __HAL_RCC_GET_SAI1_SOURCE();
  1084. /* Get the SAI2 clock configuration ----------------------------------------------*/
  1085. PeriphClkInit->Sai2ClockSelection = __HAL_RCC_GET_SAI2_SOURCE();
  1086. /* Get the I2S clock configuration ------------------------------------------*/
  1087. PeriphClkInit->I2sClockSelection = __HAL_RCC_GET_I2SCLKSOURCE();
  1088. /* Get the I2C1 clock configuration ------------------------------------------*/
  1089. PeriphClkInit->I2c1ClockSelection = __HAL_RCC_GET_I2C1_SOURCE();
  1090. /* Get the I2C2 clock configuration ------------------------------------------*/
  1091. PeriphClkInit->I2c2ClockSelection = __HAL_RCC_GET_I2C2_SOURCE();
  1092. /* Get the I2C3 clock configuration ------------------------------------------*/
  1093. PeriphClkInit->I2c3ClockSelection = __HAL_RCC_GET_I2C3_SOURCE();
  1094. /* Get the USART1 clock configuration ------------------------------------------*/
  1095. PeriphClkInit->Usart1ClockSelection = __HAL_RCC_GET_USART1_SOURCE();
  1096. /* Get the USART2 clock configuration ------------------------------------------*/
  1097. PeriphClkInit->Usart2ClockSelection = __HAL_RCC_GET_USART2_SOURCE();
  1098. /* Get the USART3 clock configuration ------------------------------------------*/
  1099. PeriphClkInit->Usart3ClockSelection = __HAL_RCC_GET_USART3_SOURCE();
  1100. /* Get the UART4 clock configuration ------------------------------------------*/
  1101. PeriphClkInit->Uart4ClockSelection = __HAL_RCC_GET_UART4_SOURCE();
  1102. /* Get the UART5 clock configuration ------------------------------------------*/
  1103. PeriphClkInit->Uart5ClockSelection = __HAL_RCC_GET_UART5_SOURCE();
  1104. /* Get the USART6 clock configuration ------------------------------------------*/
  1105. PeriphClkInit->Usart6ClockSelection = __HAL_RCC_GET_USART6_SOURCE();
  1106. /* Get the UART7 clock configuration ------------------------------------------*/
  1107. PeriphClkInit->Uart7ClockSelection = __HAL_RCC_GET_UART7_SOURCE();
  1108. /* Get the UART8 clock configuration ------------------------------------------*/
  1109. PeriphClkInit->Uart8ClockSelection = __HAL_RCC_GET_UART8_SOURCE();
  1110. /* Get the LPTIM1 clock configuration ------------------------------------------*/
  1111. PeriphClkInit->Lptim1ClockSelection = __HAL_RCC_GET_LPTIM1_SOURCE();
  1112. /* Get the CK48 clock configuration -----------------------------------------------*/
  1113. PeriphClkInit->Clk48ClockSelection = __HAL_RCC_GET_CLK48_SOURCE();
  1114. /* Get the SDMMC1 clock configuration -----------------------------------------------*/
  1115. PeriphClkInit->Sdmmc1ClockSelection = __HAL_RCC_GET_SDMMC1_SOURCE();
  1116. /* Get the SDMMC2 clock configuration -----------------------------------------------*/
  1117. PeriphClkInit->Sdmmc2ClockSelection = __HAL_RCC_GET_SDMMC2_SOURCE();
  1118. /* Get the RTC Clock configuration -----------------------------------------------*/
  1119. tempreg = (RCC->CFGR & RCC_CFGR_RTCPRE);
  1120. PeriphClkInit->RTCClockSelection = (uint32_t)((tempreg) | (RCC->BDCR & RCC_BDCR_RTCSEL));
  1121. /* Get the TIM Prescaler configuration --------------------------------------------*/
  1122. if ((RCC->DCKCFGR1 & RCC_DCKCFGR1_TIMPRE) == RESET)
  1123. {
  1124. PeriphClkInit->TIMPresSelection = RCC_TIMPRES_DESACTIVATED;
  1125. }
  1126. else
  1127. {
  1128. PeriphClkInit->TIMPresSelection = RCC_TIMPRES_ACTIVATED;
  1129. }
  1130. }
  1131. #endif /* STM32F722xx || STM32F723xx || STM32F732xx || STM32F733xx || STM32F730xx */
  1132. /**
  1133. * @brief Return the peripheral clock frequency for a given peripheral(SAI..)
  1134. * @note Return 0 if peripheral clock identifier not managed by this API
  1135. * @param PeriphClk Peripheral clock identifier
  1136. * This parameter can be one of the following values:
  1137. * @arg RCC_PERIPHCLK_SAI1: SAI1 peripheral clock
  1138. * @arg RCC_PERIPHCLK_SAI2: SAI2 peripheral clock
  1139. * @retval Frequency in KHz
  1140. */
  1141. uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
  1142. {
  1143. uint32_t tmpreg = 0;
  1144. /* This variable is used to store the SAI clock frequency (value in Hz) */
  1145. uint32_t frequency = 0;
  1146. /* This variable is used to store the VCO Input (value in Hz) */
  1147. uint32_t vcoinput = 0;
  1148. /* This variable is used to store the SAI clock source */
  1149. uint32_t saiclocksource = 0;
  1150. if (PeriphClk == RCC_PERIPHCLK_SAI1)
  1151. {
  1152. saiclocksource = RCC->DCKCFGR1;
  1153. saiclocksource &= RCC_DCKCFGR1_SAI1SEL;
  1154. switch (saiclocksource)
  1155. {
  1156. case 0: /* PLLSAI is the clock source for SAI1 */
  1157. {
  1158. /* Configure the PLLSAI division factor */
  1159. /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
  1160. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
  1161. {
  1162. /* In Case the PLL Source is HSI (Internal Clock) */
  1163. vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  1164. }
  1165. else
  1166. {
  1167. /* In Case the PLL Source is HSE (External Clock) */
  1168. vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
  1169. }
  1170. /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
  1171. /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
  1172. tmpreg = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24;
  1173. frequency = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6))/(tmpreg);
  1174. /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
  1175. tmpreg = (((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVQ) >> 8) + 1);
  1176. frequency = frequency/(tmpreg);
  1177. break;
  1178. }
  1179. case RCC_DCKCFGR1_SAI1SEL_0: /* PLLI2S is the clock source for SAI1 */
  1180. {
  1181. /* Configure the PLLI2S division factor */
  1182. /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */
  1183. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
  1184. {
  1185. /* In Case the PLL Source is HSI (Internal Clock) */
  1186. vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  1187. }
  1188. else
  1189. {
  1190. /* In Case the PLL Source is HSE (External Clock) */
  1191. vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
  1192. }
  1193. /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
  1194. /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
  1195. tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24;
  1196. frequency = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6))/(tmpreg);
  1197. /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
  1198. tmpreg = ((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLI2SDIVQ) + 1);
  1199. frequency = frequency/(tmpreg);
  1200. break;
  1201. }
  1202. case RCC_DCKCFGR1_SAI1SEL_1: /* External clock is the clock source for SAI1 */
  1203. {
  1204. frequency = EXTERNAL_CLOCK_VALUE;
  1205. break;
  1206. }
  1207. #if defined (STM32F765xx) || defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx)
  1208. case RCC_DCKCFGR1_SAI1SEL: /* HSI or HSE is the clock source for SAI*/
  1209. {
  1210. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
  1211. {
  1212. /* In Case the main PLL Source is HSI */
  1213. frequency = HSI_VALUE;
  1214. }
  1215. else
  1216. {
  1217. /* In Case the main PLL Source is HSE */
  1218. frequency = HSE_VALUE;
  1219. }
  1220. break;
  1221. }
  1222. #endif /* STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx */
  1223. default :
  1224. {
  1225. break;
  1226. }
  1227. }
  1228. }
  1229. if (PeriphClk == RCC_PERIPHCLK_SAI2)
  1230. {
  1231. saiclocksource = RCC->DCKCFGR1;
  1232. saiclocksource &= RCC_DCKCFGR1_SAI2SEL;
  1233. switch (saiclocksource)
  1234. {
  1235. case 0: /* PLLSAI is the clock source for SAI*/
  1236. {
  1237. /* Configure the PLLSAI division factor */
  1238. /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
  1239. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
  1240. {
  1241. /* In Case the PLL Source is HSI (Internal Clock) */
  1242. vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  1243. }
  1244. else
  1245. {
  1246. /* In Case the PLL Source is HSE (External Clock) */
  1247. vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
  1248. }
  1249. /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
  1250. /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
  1251. tmpreg = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24;
  1252. frequency = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6))/(tmpreg);
  1253. /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
  1254. tmpreg = (((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVQ) >> 8) + 1);
  1255. frequency = frequency/(tmpreg);
  1256. break;
  1257. }
  1258. case RCC_DCKCFGR1_SAI2SEL_0: /* PLLI2S is the clock source for SAI2 */
  1259. {
  1260. /* Configure the PLLI2S division factor */
  1261. /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */
  1262. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
  1263. {
  1264. /* In Case the PLL Source is HSI (Internal Clock) */
  1265. vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  1266. }
  1267. else
  1268. {
  1269. /* In Case the PLL Source is HSE (External Clock) */
  1270. vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
  1271. }
  1272. /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
  1273. /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
  1274. tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24;
  1275. frequency = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6))/(tmpreg);
  1276. /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
  1277. tmpreg = ((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLI2SDIVQ) + 1);
  1278. frequency = frequency/(tmpreg);
  1279. break;
  1280. }
  1281. case RCC_DCKCFGR1_SAI2SEL_1: /* External clock is the clock source for SAI2 */
  1282. {
  1283. frequency = EXTERNAL_CLOCK_VALUE;
  1284. break;
  1285. }
  1286. #if defined (STM32F765xx) || defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx)
  1287. case RCC_DCKCFGR1_SAI2SEL: /* HSI or HSE is the clock source for SAI2 */
  1288. {
  1289. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
  1290. {
  1291. /* In Case the main PLL Source is HSI */
  1292. frequency = HSI_VALUE;
  1293. }
  1294. else
  1295. {
  1296. /* In Case the main PLL Source is HSE */
  1297. frequency = HSE_VALUE;
  1298. }
  1299. break;
  1300. }
  1301. #endif /* STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx */
  1302. default :
  1303. {
  1304. break;
  1305. }
  1306. }
  1307. }
  1308. return frequency;
  1309. }
  1310. /**
  1311. * @}
  1312. */
  1313. /** @defgroup RCCEx_Exported_Functions_Group2 Extended Clock management functions
  1314. * @brief Extended Clock management functions
  1315. *
  1316. @verbatim
  1317. ===============================================================================
  1318. ##### Extended clock management functions #####
  1319. ===============================================================================
  1320. [..]
  1321. This subsection provides a set of functions allowing to control the
  1322. activation or deactivation of PLLI2S, PLLSAI.
  1323. @endverbatim
  1324. * @{
  1325. */
  1326. /**
  1327. * @brief Enable PLLI2S.
  1328. * @param PLLI2SInit pointer to an RCC_PLLI2SInitTypeDef structure that
  1329. * contains the configuration information for the PLLI2S
  1330. * @retval HAL status
  1331. */
  1332. HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
  1333. {
  1334. uint32_t tickstart;
  1335. /* Check for parameters */
  1336. assert_param(IS_RCC_PLLI2SN_VALUE(PLLI2SInit->PLLI2SN));
  1337. assert_param(IS_RCC_PLLI2SR_VALUE(PLLI2SInit->PLLI2SR));
  1338. assert_param(IS_RCC_PLLI2SQ_VALUE(PLLI2SInit->PLLI2SQ));
  1339. #if defined(RCC_PLLI2SCFGR_PLLI2SP)
  1340. assert_param(IS_RCC_PLLI2SP_VALUE(PLLI2SInit->PLLI2SP));
  1341. #endif /* RCC_PLLI2SCFGR_PLLI2SP */
  1342. /* Disable the PLLI2S */
  1343. __HAL_RCC_PLLI2S_DISABLE();
  1344. /* Wait till PLLI2S is disabled */
  1345. tickstart = HAL_GetTick();
  1346. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
  1347. {
  1348. if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
  1349. {
  1350. /* return in case of Timeout detected */
  1351. return HAL_TIMEOUT;
  1352. }
  1353. }
  1354. /* Configure the PLLI2S division factors */
  1355. #if defined (STM32F722xx) || defined (STM32F723xx) || defined (STM32F732xx) || defined (STM32F733xx) || defined (STM32F730xx)
  1356. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) * PLLI2SN */
  1357. /* I2SQCLK = PLLI2S_VCO / PLLI2SQ */
  1358. /* I2SRCLK = PLLI2S_VCO / PLLI2SR */
  1359. __HAL_RCC_PLLI2S_CONFIG(PLLI2SInit->PLLI2SN, PLLI2SInit->PLLI2SQ, PLLI2SInit->PLLI2SR);
  1360. #else
  1361. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) * PLLI2SN */
  1362. /* I2SPCLK = PLLI2S_VCO / PLLI2SP */
  1363. /* I2SQCLK = PLLI2S_VCO / PLLI2SQ */
  1364. /* I2SRCLK = PLLI2S_VCO / PLLI2SR */
  1365. __HAL_RCC_PLLI2S_CONFIG(PLLI2SInit->PLLI2SN, PLLI2SInit->PLLI2SP, PLLI2SInit->PLLI2SQ, PLLI2SInit->PLLI2SR);
  1366. #endif /* STM32F722xx || STM32F723xx || STM32F732xx || STM32F733xx || STM32F730xx */
  1367. /* Enable the PLLI2S */
  1368. __HAL_RCC_PLLI2S_ENABLE();
  1369. /* Wait till PLLI2S is ready */
  1370. tickstart = HAL_GetTick();
  1371. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
  1372. {
  1373. if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
  1374. {
  1375. /* return in case of Timeout detected */
  1376. return HAL_TIMEOUT;
  1377. }
  1378. }
  1379. return HAL_OK;
  1380. }
  1381. /**
  1382. * @brief Disable PLLI2S.
  1383. * @retval HAL status
  1384. */
  1385. HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void)
  1386. {
  1387. uint32_t tickstart;
  1388. /* Disable the PLLI2S */
  1389. __HAL_RCC_PLLI2S_DISABLE();
  1390. /* Wait till PLLI2S is disabled */
  1391. tickstart = HAL_GetTick();
  1392. while(READ_BIT(RCC->CR, RCC_CR_PLLI2SRDY) != RESET)
  1393. {
  1394. if((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE)
  1395. {
  1396. /* return in case of Timeout detected */
  1397. return HAL_TIMEOUT;
  1398. }
  1399. }
  1400. return HAL_OK;
  1401. }
  1402. /**
  1403. * @brief Enable PLLSAI.
  1404. * @param PLLSAIInit pointer to an RCC_PLLSAIInitTypeDef structure that
  1405. * contains the configuration information for the PLLSAI
  1406. * @retval HAL status
  1407. */
  1408. HAL_StatusTypeDef HAL_RCCEx_EnablePLLSAI(RCC_PLLSAIInitTypeDef *PLLSAIInit)
  1409. {
  1410. uint32_t tickstart;
  1411. /* Check for parameters */
  1412. assert_param(IS_RCC_PLLSAIN_VALUE(PLLSAIInit->PLLSAIN));
  1413. assert_param(IS_RCC_PLLSAIQ_VALUE(PLLSAIInit->PLLSAIQ));
  1414. assert_param(IS_RCC_PLLSAIP_VALUE(PLLSAIInit->PLLSAIP));
  1415. #if defined(RCC_PLLSAICFGR_PLLSAIR)
  1416. assert_param(IS_RCC_PLLSAIR_VALUE(PLLSAIInit->PLLSAIR));
  1417. #endif /* RCC_PLLSAICFGR_PLLSAIR */
  1418. /* Disable the PLLSAI */
  1419. __HAL_RCC_PLLSAI_DISABLE();
  1420. /* Wait till PLLSAI is disabled */
  1421. tickstart = HAL_GetTick();
  1422. while(__HAL_RCC_PLLSAI_GET_FLAG() != RESET)
  1423. {
  1424. if((HAL_GetTick() - tickstart ) > PLLSAI_TIMEOUT_VALUE)
  1425. {
  1426. /* return in case of Timeout detected */
  1427. return HAL_TIMEOUT;
  1428. }
  1429. }
  1430. /* Configure the PLLSAI division factors */
  1431. #if defined (STM32F722xx) || defined (STM32F723xx) || defined (STM32F732xx) || defined (STM32F733xx) || defined (STM32F730xx)
  1432. /* PLLSAI_VCO = f(VCO clock) = f(PLLSAI clock input) * PLLSAIN */
  1433. /* SAIPCLK = PLLSAI_VCO / PLLSAIP */
  1434. /* SAIQCLK = PLLSAI_VCO / PLLSAIQ */
  1435. __HAL_RCC_PLLSAI_CONFIG(PLLSAIInit->PLLSAIN, PLLSAIInit->PLLSAIP, PLLSAIInit->PLLSAIQ);
  1436. #else
  1437. /* PLLSAI_VCO = f(VCO clock) = f(PLLSAI clock input) * PLLSAIN */
  1438. /* SAIPCLK = PLLSAI_VCO / PLLSAIP */
  1439. /* SAIQCLK = PLLSAI_VCO / PLLSAIQ */
  1440. /* SAIRCLK = PLLSAI_VCO / PLLSAIR */
  1441. __HAL_RCC_PLLSAI_CONFIG(PLLSAIInit->PLLSAIN, PLLSAIInit->PLLSAIP, \
  1442. PLLSAIInit->PLLSAIQ, PLLSAIInit->PLLSAIR);
  1443. #endif /* STM32F722xx || STM32F723xx || STM32F732xx || STM32F733xx || STM32F730xx */
  1444. /* Enable the PLLSAI */
  1445. __HAL_RCC_PLLSAI_ENABLE();
  1446. /* Wait till PLLSAI is ready */
  1447. tickstart = HAL_GetTick();
  1448. while(__HAL_RCC_PLLSAI_GET_FLAG() == RESET)
  1449. {
  1450. if((HAL_GetTick() - tickstart ) > PLLSAI_TIMEOUT_VALUE)
  1451. {
  1452. /* return in case of Timeout detected */
  1453. return HAL_TIMEOUT;
  1454. }
  1455. }
  1456. return HAL_OK;
  1457. }
  1458. /**
  1459. * @brief Disable PLLSAI.
  1460. * @retval HAL status
  1461. */
  1462. HAL_StatusTypeDef HAL_RCCEx_DisablePLLSAI(void)
  1463. {
  1464. uint32_t tickstart;
  1465. /* Disable the PLLSAI */
  1466. __HAL_RCC_PLLSAI_DISABLE();
  1467. /* Wait till PLLSAI is disabled */
  1468. tickstart = HAL_GetTick();
  1469. while(__HAL_RCC_PLLSAI_GET_FLAG() != RESET)
  1470. {
  1471. if((HAL_GetTick() - tickstart) > PLLSAI_TIMEOUT_VALUE)
  1472. {
  1473. /* return in case of Timeout detected */
  1474. return HAL_TIMEOUT;
  1475. }
  1476. }
  1477. return HAL_OK;
  1478. }
  1479. /**
  1480. * @}
  1481. */
  1482. /**
  1483. * @}
  1484. */
  1485. #endif /* HAL_RCC_MODULE_ENABLED */
  1486. /**
  1487. * @}
  1488. */
  1489. /**
  1490. * @}
  1491. */