stm32f7xx_hal_rcc_ex.c 74 KB

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