You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

862 lines
36 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_rcc_ex.c
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  7. * @brief Extension RCC HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities RCC extension peripheral:
  10. * + Extended Peripheral Control functions
  11. *
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  16. *
  17. * Redistribution and use in source and binary forms, with or without modification,
  18. * are permitted provided that the following conditions are met:
  19. * 1. Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  25. * may be used to endorse or promote products derived from this software
  26. * without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  29. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  32. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  34. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  36. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. ******************************************************************************
  40. */
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f7xx_hal.h"
  43. /** @addtogroup STM32F7xx_HAL_Driver
  44. * @{
  45. */
  46. /** @defgroup RCCEx RCCEx
  47. * @brief RCCEx HAL module driver
  48. * @{
  49. */
  50. #ifdef HAL_RCC_MODULE_ENABLED
  51. /* Private typedef -----------------------------------------------------------*/
  52. /* Private define ------------------------------------------------------------*/
  53. /** @defgroup RCCEx_Private_Defines RCCEx Private Defines
  54. * @{
  55. */
  56. #define PLLI2S_TIMEOUT_VALUE 100 /* Timeout value fixed to 100 ms */
  57. #define PLLSAI_TIMEOUT_VALUE 100 /* Timeout value fixed to 100 ms */
  58. /**
  59. * @}
  60. */
  61. /* Private macro -------------------------------------------------------------*/
  62. /** @defgroup RCCEx_Private_Macros RCCEx Private Macros
  63. * @{
  64. */
  65. /**
  66. * @}
  67. */
  68. /** @defgroup RCCEx_Private_Macros RCCEx Private Macros
  69. * @{
  70. */
  71. /**
  72. * @}
  73. */
  74. /* Private variables ---------------------------------------------------------*/
  75. /* Private function prototypes -----------------------------------------------*/
  76. /* Private functions ---------------------------------------------------------*/
  77. /** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
  78. * @{
  79. */
  80. /** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions
  81. * @brief Extended Peripheral Control functions
  82. *
  83. @verbatim
  84. ===============================================================================
  85. ##### Extended Peripheral Control functions #####
  86. ===============================================================================
  87. [..]
  88. This subsection provides a set of functions allowing to control the RCC Clocks
  89. frequencies.
  90. [..]
  91. (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to
  92. select the RTC clock source; in this case the Backup domain will be reset in
  93. order to modify the RTC Clock source, as consequence RTC registers (including
  94. the backup registers) and RCC_BDCR register will be set to their reset values.
  95. @endverbatim
  96. * @{
  97. */
  98. /**
  99. * @brief Initializes the RCC extended peripherals clocks according to the specified
  100. * parameters in the RCC_PeriphCLKInitTypeDef.
  101. * @param PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that
  102. * contains the configuration information for the Extended Peripherals
  103. * clocks(I2S, SAI, LTDC RTC, TIM, UARTs, USARTs, LTPIM, SDMMC...).
  104. *
  105. * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
  106. * the RTC clock source; in this case the Backup domain will be reset in
  107. * order to modify the RTC Clock source, as consequence RTC registers (including
  108. * the backup registers) and RCC_BDCR register are set to their reset values.
  109. *
  110. * @retval HAL status
  111. */
  112. HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  113. {
  114. uint32_t tickstart = 0;
  115. uint32_t tmpreg0 = 0;
  116. uint32_t tmpreg1 = 0;
  117. uint32_t plli2sused = 0;
  118. uint32_t pllsaiused = 0;
  119. /* Check the parameters */
  120. assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
  121. /*----------------------------------- I2S configuration ----------------------------------*/
  122. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == (RCC_PERIPHCLK_I2S))
  123. {
  124. /* Check the parameters */
  125. assert_param(IS_RCC_I2SCLKSOURCE(PeriphClkInit->I2sClockSelection));
  126. /* Configure I2S Clock source */
  127. __HAL_RCC_I2S_CONFIG(PeriphClkInit->I2sClockSelection);
  128. /* Enable the PLLI2S when it's used as clock source for I2S */
  129. if(PeriphClkInit->I2sClockSelection == RCC_I2SCLKSOURCE_PLLI2S)
  130. {
  131. plli2sused = 1;
  132. }
  133. }
  134. /*------------------------------------ SAI1 configuration --------------------------------------*/
  135. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == (RCC_PERIPHCLK_SAI1))
  136. {
  137. /* Check the parameters */
  138. assert_param(IS_RCC_SAI1CLKSOURCE(PeriphClkInit->Sai1ClockSelection));
  139. /* Configure SAI1 Clock source */
  140. __HAL_RCC_SAI1_CONFIG(PeriphClkInit->Sai1ClockSelection);
  141. /* Enable the PLLI2S when it's used as clock source for SAI */
  142. if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S)
  143. {
  144. plli2sused = 1;
  145. }
  146. /* Enable the PLLSAI when it's used as clock source for SAI */
  147. if(PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI)
  148. {
  149. pllsaiused = 1;
  150. }
  151. }
  152. /*------------------------------------ SAI2 configuration --------------------------------------*/
  153. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == (RCC_PERIPHCLK_SAI2))
  154. {
  155. /* Check the parameters */
  156. assert_param(IS_RCC_SAI2CLKSOURCE(PeriphClkInit->Sai2ClockSelection));
  157. /* Configure SAI2 Clock source */
  158. __HAL_RCC_SAI2_CONFIG(PeriphClkInit->Sai2ClockSelection);
  159. /* Enable the PLLI2S when it's used as clock source for SAI */
  160. if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S)
  161. {
  162. plli2sused = 1;
  163. }
  164. /* Enable the PLLSAI when it's used as clock source for SAI */
  165. if(PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI)
  166. {
  167. pllsaiused = 1;
  168. }
  169. }
  170. /*-------------------------------------- SPDIF-RX Configuration -----------------------------------*/
  171. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPDIFRX) == RCC_PERIPHCLK_SPDIFRX)
  172. {
  173. plli2sused = 1;
  174. }
  175. /*------------------------------------ RTC configuration --------------------------------------*/
  176. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == (RCC_PERIPHCLK_RTC))
  177. {
  178. /* Reset the Backup domain only if the RTC Clock source selection is modified */
  179. if((RCC->BDCR & RCC_BDCR_RTCSEL) != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL))
  180. {
  181. /* Enable Power Clock*/
  182. __HAL_RCC_PWR_CLK_ENABLE();
  183. /* Enable write access to Backup domain */
  184. PWR->CR1 |= PWR_CR1_DBP;
  185. /* Get Start Tick*/
  186. tickstart = HAL_GetTick();
  187. /* Wait for Backup domain Write protection disable */
  188. while((PWR->CR1 & PWR_CR1_DBP) == RESET)
  189. {
  190. if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
  191. {
  192. return HAL_TIMEOUT;
  193. }
  194. }
  195. /* Store the content of BDCR register before the reset of Backup Domain */
  196. tmpreg0 = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
  197. /* RTC Clock selection can be changed only if the Backup Domain is reset */
  198. __HAL_RCC_BACKUPRESET_FORCE();
  199. __HAL_RCC_BACKUPRESET_RELEASE();
  200. /* Restore the Content of BDCR register */
  201. RCC->BDCR = tmpreg0;
  202. /* If LSE is selected as RTC clock source, wait for LSE reactivation */
  203. if (HAL_IS_BIT_SET(tmpreg0, RCC_BDCR_LSERDY))
  204. {
  205. /* Get Start Tick*/
  206. tickstart = HAL_GetTick();
  207. /* Wait till LSE is ready */
  208. while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
  209. {
  210. if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
  211. {
  212. return HAL_TIMEOUT;
  213. }
  214. }
  215. }
  216. __HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
  217. }
  218. }
  219. /*------------------------------------ TIM configuration --------------------------------------*/
  220. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_TIM) == (RCC_PERIPHCLK_TIM))
  221. {
  222. /* Check the parameters */
  223. assert_param(IS_RCC_TIMPRES(PeriphClkInit->TIMPresSelection));
  224. /* Configure Timer Prescaler */
  225. __HAL_RCC_TIMCLKPRESCALER(PeriphClkInit->TIMPresSelection);
  226. }
  227. /*-------------------------------------- I2C1 Configuration -----------------------------------*/
  228. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C1) == RCC_PERIPHCLK_I2C1)
  229. {
  230. /* Check the parameters */
  231. assert_param(IS_RCC_I2C1CLKSOURCE(PeriphClkInit->I2c1ClockSelection));
  232. /* Configure the I2C1 clock source */
  233. __HAL_RCC_I2C1_CONFIG(PeriphClkInit->I2c1ClockSelection);
  234. }
  235. /*-------------------------------------- I2C2 Configuration -----------------------------------*/
  236. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C2) == RCC_PERIPHCLK_I2C2)
  237. {
  238. /* Check the parameters */
  239. assert_param(IS_RCC_I2C2CLKSOURCE(PeriphClkInit->I2c2ClockSelection));
  240. /* Configure the I2C2 clock source */
  241. __HAL_RCC_I2C2_CONFIG(PeriphClkInit->I2c2ClockSelection);
  242. }
  243. /*-------------------------------------- I2C3 Configuration -----------------------------------*/
  244. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C3) == RCC_PERIPHCLK_I2C3)
  245. {
  246. /* Check the parameters */
  247. assert_param(IS_RCC_I2C3CLKSOURCE(PeriphClkInit->I2c3ClockSelection));
  248. /* Configure the I2C3 clock source */
  249. __HAL_RCC_I2C3_CONFIG(PeriphClkInit->I2c3ClockSelection);
  250. }
  251. /*-------------------------------------- I2C4 Configuration -----------------------------------*/
  252. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2C4) == RCC_PERIPHCLK_I2C4)
  253. {
  254. /* Check the parameters */
  255. assert_param(IS_RCC_I2C4CLKSOURCE(PeriphClkInit->I2c4ClockSelection));
  256. /* Configure the I2C4 clock source */
  257. __HAL_RCC_I2C4_CONFIG(PeriphClkInit->I2c4ClockSelection);
  258. }
  259. /*-------------------------------------- USART1 Configuration -----------------------------------*/
  260. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART1) == RCC_PERIPHCLK_USART1)
  261. {
  262. /* Check the parameters */
  263. assert_param(IS_RCC_USART1CLKSOURCE(PeriphClkInit->Usart1ClockSelection));
  264. /* Configure the USART1 clock source */
  265. __HAL_RCC_USART1_CONFIG(PeriphClkInit->Usart1ClockSelection);
  266. }
  267. /*-------------------------------------- USART2 Configuration -----------------------------------*/
  268. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART2) == RCC_PERIPHCLK_USART2)
  269. {
  270. /* Check the parameters */
  271. assert_param(IS_RCC_USART2CLKSOURCE(PeriphClkInit->Usart2ClockSelection));
  272. /* Configure the USART2 clock source */
  273. __HAL_RCC_USART2_CONFIG(PeriphClkInit->Usart2ClockSelection);
  274. }
  275. /*-------------------------------------- USART3 Configuration -----------------------------------*/
  276. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART3) == RCC_PERIPHCLK_USART3)
  277. {
  278. /* Check the parameters */
  279. assert_param(IS_RCC_USART3CLKSOURCE(PeriphClkInit->Usart3ClockSelection));
  280. /* Configure the USART3 clock source */
  281. __HAL_RCC_USART3_CONFIG(PeriphClkInit->Usart3ClockSelection);
  282. }
  283. /*-------------------------------------- UART4 Configuration -----------------------------------*/
  284. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART4) == RCC_PERIPHCLK_UART4)
  285. {
  286. /* Check the parameters */
  287. assert_param(IS_RCC_UART4CLKSOURCE(PeriphClkInit->Uart4ClockSelection));
  288. /* Configure the UART4 clock source */
  289. __HAL_RCC_UART4_CONFIG(PeriphClkInit->Uart4ClockSelection);
  290. }
  291. /*-------------------------------------- UART5 Configuration -----------------------------------*/
  292. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART5) == RCC_PERIPHCLK_UART5)
  293. {
  294. /* Check the parameters */
  295. assert_param(IS_RCC_UART5CLKSOURCE(PeriphClkInit->Uart5ClockSelection));
  296. /* Configure the UART5 clock source */
  297. __HAL_RCC_UART5_CONFIG(PeriphClkInit->Uart5ClockSelection);
  298. }
  299. /*-------------------------------------- USART6 Configuration -----------------------------------*/
  300. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USART6) == RCC_PERIPHCLK_USART6)
  301. {
  302. /* Check the parameters */
  303. assert_param(IS_RCC_USART6CLKSOURCE(PeriphClkInit->Usart6ClockSelection));
  304. /* Configure the USART6 clock source */
  305. __HAL_RCC_USART6_CONFIG(PeriphClkInit->Usart6ClockSelection);
  306. }
  307. /*-------------------------------------- UART7 Configuration -----------------------------------*/
  308. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART7) == RCC_PERIPHCLK_UART7)
  309. {
  310. /* Check the parameters */
  311. assert_param(IS_RCC_UART7CLKSOURCE(PeriphClkInit->Uart7ClockSelection));
  312. /* Configure the UART7 clock source */
  313. __HAL_RCC_UART7_CONFIG(PeriphClkInit->Uart7ClockSelection);
  314. }
  315. /*-------------------------------------- UART8 Configuration -----------------------------------*/
  316. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_UART8) == RCC_PERIPHCLK_UART8)
  317. {
  318. /* Check the parameters */
  319. assert_param(IS_RCC_UART8CLKSOURCE(PeriphClkInit->Uart8ClockSelection));
  320. /* Configure the UART8 clock source */
  321. __HAL_RCC_UART8_CONFIG(PeriphClkInit->Uart8ClockSelection);
  322. }
  323. /*--------------------------------------- CEC Configuration -----------------------------------*/
  324. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CEC) == RCC_PERIPHCLK_CEC)
  325. {
  326. /* Check the parameters */
  327. assert_param(IS_RCC_CECCLKSOURCE(PeriphClkInit->CecClockSelection));
  328. /* Configure the CEC clock source */
  329. __HAL_RCC_CEC_CONFIG(PeriphClkInit->CecClockSelection);
  330. }
  331. /*-------------------------------------- CK48 Configuration -----------------------------------*/
  332. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CLK48) == RCC_PERIPHCLK_CLK48)
  333. {
  334. /* Check the parameters */
  335. assert_param(IS_RCC_CLK48SOURCE(PeriphClkInit->Clk48ClockSelection));
  336. /* Configure the CLK48 source */
  337. __HAL_RCC_CLK48_CONFIG(PeriphClkInit->Clk48ClockSelection);
  338. /* Enable the PLLSAI when it's used as clock source for CK48 */
  339. if(PeriphClkInit->Clk48ClockSelection == RCC_CLK48SOURCE_PLLSAIP)
  340. {
  341. pllsaiused = 1;
  342. }
  343. }
  344. /*-------------------------------------- LTDC Configuration -----------------------------------*/
  345. #if defined(STM32F756xx) || defined(STM32F746xx)
  346. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == RCC_PERIPHCLK_LTDC)
  347. {
  348. pllsaiused = 1;
  349. }
  350. #endif /* STM32F756xx || STM32F746xx */
  351. /*-------------------------------------- LPTIM1 Configuration -----------------------------------*/
  352. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LPTIM1) == RCC_PERIPHCLK_LPTIM1)
  353. {
  354. /* Check the parameters */
  355. assert_param(IS_RCC_LPTIM1CLK(PeriphClkInit->Lptim1ClockSelection));
  356. /* Configure the LTPIM1 clock source */
  357. __HAL_RCC_LPTIM1_CONFIG(PeriphClkInit->Lptim1ClockSelection);
  358. }
  359. /*------------------------------------- SDMMC Configuration ------------------------------------*/
  360. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SDMMC1) == RCC_PERIPHCLK_SDMMC1)
  361. {
  362. /* Check the parameters */
  363. assert_param(IS_RCC_SDMMC1CLKSOURCE(PeriphClkInit->Sdmmc1ClockSelection));
  364. /* Configure the SDMMC1 clock source */
  365. __HAL_RCC_SDMMC1_CONFIG(PeriphClkInit->Sdmmc1ClockSelection);
  366. }
  367. /*-------------------------------------- PLLI2S Configuration ---------------------------------*/
  368. /* PLLI2S is configured when a peripheral will use it as source clock : SAI1, SAI2, I2S or SPDIF-RX */
  369. if((plli2sused == 1) || (PeriphClkInit->PeriphClockSelection == RCC_PERIPHCLK_PLLI2S))
  370. {
  371. /* Disable the PLLI2S */
  372. __HAL_RCC_PLLI2S_DISABLE();
  373. /* Get Start Tick*/
  374. tickstart = HAL_GetTick();
  375. /* Wait till PLLI2S is disabled */
  376. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
  377. {
  378. if((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE)
  379. {
  380. /* return in case of Timeout detected */
  381. return HAL_TIMEOUT;
  382. }
  383. }
  384. /* check for common PLLI2S Parameters */
  385. assert_param(IS_RCC_PLLI2SN_VALUE(PeriphClkInit->PLLI2S.PLLI2SN));
  386. /*----------------- In Case of PLLI2S is selected as source clock for I2S -------------------*/
  387. if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S) == RCC_PERIPHCLK_I2S) && (PeriphClkInit->I2sClockSelection == RCC_I2SCLKSOURCE_PLLI2S)))
  388. {
  389. /* check for Parameters */
  390. assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
  391. /* Read PLLI2SP and PLLI2SQ value from PLLI2SCFGR register (this value is not needed for I2S configuration) */
  392. tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP));
  393. tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SQ));
  394. /* Configure the PLLI2S division factors */
  395. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLM) */
  396. /* I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
  397. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , tmpreg0, tmpreg1, PeriphClkInit->PLLI2S.PLLI2SR);
  398. }
  399. /*----------------- In Case of PLLI2S is selected as source clock for SAI -------------------*/
  400. if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLI2S)) ||
  401. ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLI2S)))
  402. {
  403. /* Check for PLLI2S Parameters */
  404. assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ));
  405. /* Check for PLLI2S/DIVQ parameters */
  406. assert_param(IS_RCC_PLLI2S_DIVQ_VALUE(PeriphClkInit->PLLI2SDivQ));
  407. /* Read PLLI2SP and PLLI2SR values from PLLI2SCFGR register (this value is not needed for SAI configuration) */
  408. tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP));
  409. tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR));
  410. /* Configure the PLLI2S division factors */
  411. /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */
  412. /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
  413. /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
  414. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN, tmpreg0, PeriphClkInit->PLLI2S.PLLI2SQ, tmpreg1);
  415. /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
  416. __HAL_RCC_PLLI2S_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLI2SDivQ);
  417. }
  418. /*----------------- In Case of PLLI2S is selected as source clock for SPDIF-RX -------------------*/
  419. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SPDIFRX) == RCC_PERIPHCLK_SPDIFRX)
  420. {
  421. /* check for Parameters */
  422. assert_param(IS_RCC_PLLI2SP_VALUE(PeriphClkInit->PLLI2S.PLLI2SP));
  423. /* Read PLLI2SR value from PLLI2SCFGR register (this value is not needed for SPDIF-RX configuration) */
  424. tmpreg0 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SQ));
  425. tmpreg1 = ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR));
  426. /* Configure the PLLI2S division factors */
  427. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLM) */
  428. /* SPDIFCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SP */
  429. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SP, tmpreg0, tmpreg1);
  430. }
  431. /*----------------- In Case of PLLI2S is just selected -----------------*/
  432. if((PeriphClkInit->PeriphClockSelection & RCC_PERIPHCLK_PLLI2S) == RCC_PERIPHCLK_PLLI2S)
  433. {
  434. /* Check for Parameters */
  435. assert_param(IS_RCC_PLLI2SN_VALUE(PeriphClkInit->PLLI2S.PLLI2SN));
  436. assert_param(IS_RCC_PLLI2SP_VALUE(PeriphClkInit->PLLI2S.PLLI2SP));
  437. assert_param(IS_RCC_PLLI2SR_VALUE(PeriphClkInit->PLLI2S.PLLI2SR));
  438. assert_param(IS_RCC_PLLI2SQ_VALUE(PeriphClkInit->PLLI2S.PLLI2SQ));
  439. /* Configure the PLLI2S division factors */
  440. /* PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) x (PLLI2SN/PLLI2SM) */
  441. /* SPDIFRXCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SP */
  442. __HAL_RCC_PLLI2S_CONFIG(PeriphClkInit->PLLI2S.PLLI2SN , PeriphClkInit->PLLI2S.PLLI2SP, PeriphClkInit->PLLI2S.PLLI2SQ, PeriphClkInit->PLLI2S.PLLI2SR);
  443. }
  444. /* Enable the PLLI2S */
  445. __HAL_RCC_PLLI2S_ENABLE();
  446. /* Get Start Tick*/
  447. tickstart = HAL_GetTick();
  448. /* Wait till PLLI2S is ready */
  449. while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
  450. {
  451. if((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE)
  452. {
  453. /* return in case of Timeout detected */
  454. return HAL_TIMEOUT;
  455. }
  456. }
  457. }
  458. /*-------------------------------------- PLLSAI Configuration ---------------------------------*/
  459. /* PLLSAI is configured when a peripheral will use it as source clock : SAI1, SAI2, LTDC or CK48 */
  460. if(pllsaiused == 1)
  461. {
  462. /* Disable PLLSAI Clock */
  463. __HAL_RCC_PLLSAI_DISABLE();
  464. /* Get Start Tick*/
  465. tickstart = HAL_GetTick();
  466. /* Wait till PLLSAI is disabled */
  467. while(__HAL_RCC_PLLSAI_GET_FLAG() != RESET)
  468. {
  469. if((HAL_GetTick() - tickstart) > PLLSAI_TIMEOUT_VALUE)
  470. {
  471. /* return in case of Timeout detected */
  472. return HAL_TIMEOUT;
  473. }
  474. }
  475. /* Check the PLLSAI division factors */
  476. assert_param(IS_RCC_PLLSAIN_VALUE(PeriphClkInit->PLLSAI.PLLSAIN));
  477. /*----------------- In Case of PLLSAI is selected as source clock for SAI -------------------*/
  478. if(((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI1) == RCC_PERIPHCLK_SAI1) && (PeriphClkInit->Sai1ClockSelection == RCC_SAI1CLKSOURCE_PLLSAI)) ||
  479. ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_SAI2) == RCC_PERIPHCLK_SAI2) && (PeriphClkInit->Sai2ClockSelection == RCC_SAI2CLKSOURCE_PLLSAI)))
  480. {
  481. /* check for PLLSAIQ Parameter */
  482. assert_param(IS_RCC_PLLSAIQ_VALUE(PeriphClkInit->PLLSAI.PLLSAIQ));
  483. /* check for PLLSAI/DIVQ Parameter */
  484. assert_param(IS_RCC_PLLSAI_DIVQ_VALUE(PeriphClkInit->PLLSAIDivQ));
  485. /* Read PLLSAIP value from PLLSAICFGR register (this value is not needed for SAI configuration) */
  486. tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIP));
  487. tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIR));
  488. /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
  489. /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
  490. /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
  491. __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , tmpreg0, PeriphClkInit->PLLSAI.PLLSAIQ, tmpreg1);
  492. /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
  493. __HAL_RCC_PLLSAI_PLLSAICLKDIVQ_CONFIG(PeriphClkInit->PLLSAIDivQ);
  494. }
  495. /*----------------- In Case of PLLSAI is selected as source clock for CLK48 -------------------*/
  496. /* In Case of PLLI2S is selected as source clock for CK48 */
  497. if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_CLK48) == RCC_PERIPHCLK_CLK48) && (PeriphClkInit->Clk48ClockSelection == RCC_CLK48SOURCE_PLLSAIP))
  498. {
  499. /* check for Parameters */
  500. assert_param(IS_RCC_PLLSAIP_VALUE(PeriphClkInit->PLLSAI.PLLSAIP));
  501. /* Read PLLSAIQ and PLLSAIR value from PLLSAICFGR register (this value is not needed for CK48 configuration) */
  502. tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ));
  503. tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIR) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIR));
  504. /* Configure the PLLSAI division factors */
  505. /* PLLSAI_VCO = f(VCO clock) = f(PLLSAI clock input) x (PLLI2SN/PLLM) */
  506. /* 48CLK = f(PLLSAI clock output) = f(VCO clock) / PLLSAIP */
  507. __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , PeriphClkInit->PLLSAI.PLLSAIP, tmpreg0, tmpreg1);
  508. }
  509. #if defined(STM32F756xx) || defined(STM32F746xx)
  510. /*---------------------------- LTDC configuration -------------------------------*/
  511. if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LTDC) == (RCC_PERIPHCLK_LTDC))
  512. {
  513. assert_param(IS_RCC_PLLSAIR_VALUE(PeriphClkInit->PLLSAI.PLLSAIR));
  514. assert_param(IS_RCC_PLLSAI_DIVR_VALUE(PeriphClkInit->PLLSAIDivR));
  515. /* Read PLLSAIP and PLLSAIQ value from PLLSAICFGR register (these value are not needed for LTDC configuration) */
  516. tmpreg0 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ));
  517. tmpreg1 = ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIP));
  518. /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
  519. /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
  520. /* LTDC_CLK(first level) = PLLSAI_VCO Output/PLLSAIR */
  521. __HAL_RCC_PLLSAI_CONFIG(PeriphClkInit->PLLSAI.PLLSAIN , tmpreg1, tmpreg0, PeriphClkInit->PLLSAI.PLLSAIR);
  522. /* LTDC_CLK = LTDC_CLK(first level)/PLLSAIDIVR */
  523. __HAL_RCC_PLLSAI_PLLSAICLKDIVR_CONFIG(PeriphClkInit->PLLSAIDivR);
  524. }
  525. #endif /* STM32F756xx || STM32F746xx */
  526. /* Enable PLLSAI Clock */
  527. __HAL_RCC_PLLSAI_ENABLE();
  528. /* Get Start Tick*/
  529. tickstart = HAL_GetTick();
  530. /* Wait till PLLSAI is ready */
  531. while(__HAL_RCC_PLLSAI_GET_FLAG() == RESET)
  532. {
  533. if((HAL_GetTick() - tickstart) > PLLSAI_TIMEOUT_VALUE)
  534. {
  535. /* return in case of Timeout detected */
  536. return HAL_TIMEOUT;
  537. }
  538. }
  539. }
  540. return HAL_OK;
  541. }
  542. /**
  543. * @brief Get the RCC_PeriphCLKInitTypeDef according to the internal
  544. * RCC configuration registers.
  545. * @param PeriphClkInit: pointer to the configured RCC_PeriphCLKInitTypeDef structure
  546. * @retval None
  547. */
  548. void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
  549. {
  550. uint32_t tempreg = 0;
  551. /* Set all possible values for the extended clock type parameter------------*/
  552. PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_I2S | RCC_PERIPHCLK_LPTIM1 |\
  553. RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SAI2 |\
  554. RCC_PERIPHCLK_TIM | RCC_PERIPHCLK_RTC |\
  555. RCC_PERIPHCLK_CEC | RCC_PERIPHCLK_I2C4 |\
  556. RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_I2C2 |\
  557. RCC_PERIPHCLK_I2C3 | RCC_PERIPHCLK_USART1 |\
  558. RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 |\
  559. RCC_PERIPHCLK_UART4 | RCC_PERIPHCLK_UART5 |\
  560. RCC_PERIPHCLK_USART6 | RCC_PERIPHCLK_UART7 |\
  561. RCC_PERIPHCLK_UART8 | RCC_PERIPHCLK_SDMMC1 |\
  562. RCC_PERIPHCLK_CLK48;
  563. /* Get the PLLI2S Clock configuration -----------------------------------------------*/
  564. PeriphClkInit->PLLI2S.PLLI2SN = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SN));
  565. PeriphClkInit->PLLI2S.PLLI2SP = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SP) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SP));
  566. PeriphClkInit->PLLI2S.PLLI2SQ = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SQ));
  567. PeriphClkInit->PLLI2S.PLLI2SR = (uint32_t)((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> POSITION_VAL(RCC_PLLI2SCFGR_PLLI2SR));
  568. /* Get the PLLSAI Clock configuration -----------------------------------------------*/
  569. PeriphClkInit->PLLSAI.PLLSAIN = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIN));
  570. PeriphClkInit->PLLSAI.PLLSAIP = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIP) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIP));
  571. PeriphClkInit->PLLSAI.PLLSAIQ = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIQ));
  572. PeriphClkInit->PLLSAI.PLLSAIR = (uint32_t)((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIR) >> POSITION_VAL(RCC_PLLSAICFGR_PLLSAIR));
  573. /* Get the PLLSAI/PLLI2S division factors -------------------------------------------*/
  574. PeriphClkInit->PLLI2SDivQ = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLI2SDIVQ) >> POSITION_VAL(RCC_DCKCFGR1_PLLI2SDIVQ));
  575. PeriphClkInit->PLLSAIDivQ = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVQ) >> POSITION_VAL(RCC_DCKCFGR1_PLLSAIDIVQ));
  576. PeriphClkInit->PLLSAIDivR = (uint32_t)((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVR) >> POSITION_VAL(RCC_DCKCFGR1_PLLSAIDIVR));
  577. /* Get the SAI1 clock configuration ----------------------------------------------*/
  578. PeriphClkInit->Sai1ClockSelection = __HAL_RCC_GET_SAI1_SOURCE();
  579. /* Get the SAI2 clock configuration ----------------------------------------------*/
  580. PeriphClkInit->Sai2ClockSelection = __HAL_RCC_GET_SAI2_SOURCE();
  581. /* Get the I2S clock configuration ------------------------------------------*/
  582. PeriphClkInit->I2sClockSelection = __HAL_RCC_GET_I2SCLKSOURCE();
  583. /* Get the I2C1 clock configuration ------------------------------------------*/
  584. PeriphClkInit->I2c1ClockSelection = __HAL_RCC_GET_I2C1_SOURCE();
  585. /* Get the I2C2 clock configuration ------------------------------------------*/
  586. PeriphClkInit->I2c2ClockSelection = __HAL_RCC_GET_I2C2_SOURCE();
  587. /* Get the I2C3 clock configuration ------------------------------------------*/
  588. PeriphClkInit->I2c3ClockSelection = __HAL_RCC_GET_I2C3_SOURCE();
  589. /* Get the I2C4 clock configuration ------------------------------------------*/
  590. PeriphClkInit->I2c4ClockSelection = __HAL_RCC_GET_I2C4_SOURCE();
  591. /* Get the USART1 clock configuration ------------------------------------------*/
  592. PeriphClkInit->Usart1ClockSelection = __HAL_RCC_GET_USART1_SOURCE();
  593. /* Get the USART2 clock configuration ------------------------------------------*/
  594. PeriphClkInit->Usart2ClockSelection = __HAL_RCC_GET_USART2_SOURCE();
  595. /* Get the USART3 clock configuration ------------------------------------------*/
  596. PeriphClkInit->Usart3ClockSelection = __HAL_RCC_GET_USART3_SOURCE();
  597. /* Get the UART4 clock configuration ------------------------------------------*/
  598. PeriphClkInit->Uart4ClockSelection = __HAL_RCC_GET_UART4_SOURCE();
  599. /* Get the UART5 clock configuration ------------------------------------------*/
  600. PeriphClkInit->Uart5ClockSelection = __HAL_RCC_GET_UART5_SOURCE();
  601. /* Get the USART6 clock configuration ------------------------------------------*/
  602. PeriphClkInit->Usart6ClockSelection = __HAL_RCC_GET_USART6_SOURCE();
  603. /* Get the UART7 clock configuration ------------------------------------------*/
  604. PeriphClkInit->Uart7ClockSelection = __HAL_RCC_GET_UART7_SOURCE();
  605. /* Get the UART8 clock configuration ------------------------------------------*/
  606. PeriphClkInit->Uart8ClockSelection = __HAL_RCC_GET_UART8_SOURCE();
  607. /* Get the LPTIM1 clock configuration ------------------------------------------*/
  608. PeriphClkInit->Lptim1ClockSelection = __HAL_RCC_GET_LPTIM1_SOURCE();
  609. /* Get the CEC clock configuration -----------------------------------------------*/
  610. PeriphClkInit->CecClockSelection = __HAL_RCC_GET_CEC_SOURCE();
  611. /* Get the CK48 clock configuration -----------------------------------------------*/
  612. PeriphClkInit->Clk48ClockSelection = __HAL_RCC_GET_CLK48_SOURCE();
  613. /* Get the SDMMC clock configuration -----------------------------------------------*/
  614. PeriphClkInit->Sdmmc1ClockSelection = __HAL_RCC_GET_SDMMC1_SOURCE();
  615. /* Get the RTC Clock configuration -----------------------------------------------*/
  616. tempreg = (RCC->CFGR & RCC_CFGR_RTCPRE);
  617. PeriphClkInit->RTCClockSelection = (uint32_t)((tempreg) | (RCC->BDCR & RCC_BDCR_RTCSEL));
  618. /* Get the TIM Prescaler configuration --------------------------------------------*/
  619. if ((RCC->DCKCFGR1 & RCC_DCKCFGR1_TIMPRE) == RESET)
  620. {
  621. PeriphClkInit->TIMPresSelection = RCC_TIMPRES_DESACTIVATED;
  622. }
  623. else
  624. {
  625. PeriphClkInit->TIMPresSelection = RCC_TIMPRES_ACTIVATED;
  626. }
  627. }
  628. /**
  629. * @brief Return the peripheral clock frequency for a given peripheral(SAI..)
  630. * @note Return 0 if peripheral clock identifier not managed by this API
  631. * @param PeriphClk: Peripheral clock identifier
  632. * This parameter can be one of the following values:
  633. * @arg RCC_PERIPHCLK_SAI1: SAI1 peripheral clock
  634. * @arg RCC_PERIPHCLK_SAI2: SAI2 peripheral clock
  635. * @retval Frequency in KHz
  636. */
  637. uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
  638. {
  639. uint32_t tmpreg = 0;
  640. /* This variable used to store the SAI clock frequency (value in Hz) */
  641. uint32_t frequency = 0;
  642. /* This variable used to store the VCO Input (value in Hz) */
  643. uint32_t vcoinput = 0;
  644. /* This variable used to store the SAI clock source */
  645. uint32_t saiclocksource = 0;
  646. if ((PeriphClk == RCC_PERIPHCLK_SAI1) || (PeriphClk == RCC_PERIPHCLK_SAI2))
  647. {
  648. saiclocksource = RCC->DCKCFGR1;
  649. saiclocksource &= (RCC_DCKCFGR1_SAI1SEL | RCC_DCKCFGR1_SAI2SEL);
  650. switch (saiclocksource)
  651. {
  652. case 0: /* PLLSAI is the clock source for SAI*/
  653. {
  654. /* Configure the PLLSAI division factor */
  655. /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
  656. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
  657. {
  658. /* In Case the PLL Source is HSI (Internal Clock) */
  659. vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  660. }
  661. else
  662. {
  663. /* In Case the PLL Source is HSE (External Clock) */
  664. vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
  665. }
  666. /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
  667. /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
  668. tmpreg = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24;
  669. frequency = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6))/(tmpreg);
  670. /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
  671. tmpreg = (((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLSAIDIVQ) >> 8) + 1);
  672. frequency = frequency/(tmpreg);
  673. break;
  674. }
  675. case RCC_DCKCFGR1_SAI1SEL_0: /* PLLI2S is the clock source for SAI*/
  676. case RCC_DCKCFGR1_SAI2SEL_0: /* PLLI2S is the clock source for SAI*/
  677. {
  678. /* Configure the PLLI2S division factor */
  679. /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */
  680. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
  681. {
  682. /* In Case the PLL Source is HSI (Internal Clock) */
  683. vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  684. }
  685. else
  686. {
  687. /* In Case the PLL Source is HSE (External Clock) */
  688. vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
  689. }
  690. /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
  691. /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
  692. tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24;
  693. frequency = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6))/(tmpreg);
  694. /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
  695. tmpreg = ((RCC->DCKCFGR1 & RCC_DCKCFGR1_PLLI2SDIVQ) + 1);
  696. frequency = frequency/(tmpreg);
  697. break;
  698. }
  699. case RCC_DCKCFGR1_SAI1SEL_1: /* External clock is the clock source for SAI*/
  700. case RCC_DCKCFGR1_SAI2SEL_1: /* External clock is the clock source for SAI*/
  701. {
  702. frequency = EXTERNAL_CLOCK_VALUE;
  703. break;
  704. }
  705. default :
  706. {
  707. break;
  708. }
  709. }
  710. }
  711. return frequency;
  712. }
  713. /**
  714. * @}
  715. */
  716. /**
  717. * @}
  718. */
  719. #endif /* HAL_RCC_MODULE_ENABLED */
  720. /**
  721. * @}
  722. */
  723. /**
  724. * @}
  725. */
  726. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/