51#ifdef HAL_SAI_MODULE_ENABLED
53#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
54 defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || \
98void SAI_BlockSynchroConfig(
const SAI_HandleTypeDef *hsai)
100 uint32_t tmpregisterGCR;
102#if defined(STM32F446xx)
104 switch (hsai->Init.SynchroExt)
106 case SAI_SYNCEXT_DISABLE :
109 case SAI_SYNCEXT_OUTBLOCKA_ENABLE :
110 tmpregisterGCR = SAI_GCR_SYNCOUT_0;
112 case SAI_SYNCEXT_OUTBLOCKB_ENABLE :
113 tmpregisterGCR = SAI_GCR_SYNCOUT_1;
120 if ((hsai->Init.Synchro) == SAI_SYNCHRONOUS_EXT_SAI2)
122 tmpregisterGCR |= SAI_GCR_SYNCIN_0;
125 if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B))
127 SAI1->GCR = tmpregisterGCR;
131 SAI2->GCR = tmpregisterGCR;
134#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
135 defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx)
137 switch (hsai->Init.SynchroExt)
139 case SAI_SYNCEXT_DISABLE :
142 case SAI_SYNCEXT_OUTBLOCKA_ENABLE :
143 tmpregisterGCR = SAI_GCR_SYNCOUT_0;
145 case SAI_SYNCEXT_OUTBLOCKB_ENABLE :
146 tmpregisterGCR = SAI_GCR_SYNCOUT_1;
152 SAI1->GCR = tmpregisterGCR;
161uint32_t SAI_GetInputClock(
const SAI_HandleTypeDef *hsai)
164 uint32_t saiclocksource = 0U;
166#if defined(STM32F446xx)
167 if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B))
176#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
177 defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx)
178 uint32_t vcoinput = 0U, tmpreg = 0U;
181 assert_param(IS_SAI_CLK_SOURCE(hsai->Init.ClockSource));
184 if (hsai->Instance == SAI1_Block_A)
186 __HAL_RCC_SAI_BLOCKACLKSOURCE_CONFIG(hsai->Init.ClockSource);
190 __HAL_RCC_SAI_BLOCKBCLKSOURCE_CONFIG((uint32_t)(hsai->Init.ClockSource << 2U));
197 vcoinput = (
HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
202 vcoinput = ((
HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
204#if defined(STM32F413xx) || defined(STM32F423xx)
206 if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLR)
212 tmpreg = (RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 28U;
213 saiclocksource = (vcoinput * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6U)) / (tmpreg);
216 tmpreg = (((RCC->DCKCFGR & RCC_DCKCFGR_PLLDIVR) >> 8U) + 1U);
218 saiclocksource = saiclocksource / (tmpreg);
221 else if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLI2S)
227 tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> 28U;
228 saiclocksource = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6U)) / (tmpreg);
231 tmpreg = ((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVR) + 1U);
232 saiclocksource = saiclocksource / (tmpreg);
234 else if (hsai->Init.ClockSource == SAI_CLKSOURCE_HS)
253 if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLSAI)
259 tmpreg = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24U;
260 saiclocksource = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6U)) / (tmpreg);
263 tmpreg = (((RCC->DCKCFGR & RCC_DCKCFGR_PLLSAIDIVQ) >> 8U) + 1U);
264 saiclocksource = saiclocksource / (tmpreg);
267 else if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLI2S)
273 tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24U;
274 saiclocksource = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6U)) / (tmpreg);
277 tmpreg = ((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVQ) + 1U);
278 saiclocksource = saiclocksource / (tmpreg);
283 __HAL_RCC_I2S_CONFIG(RCC_I2SCLKSOURCE_EXT);
290 return saiclocksource;
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
#define RCC_PLLSOURCE_HSI
#define RCC_PLLSOURCE_HSE
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
#define EXTERNAL_CLOCK_VALUE
External clock source for I2S peripheral This value is used by the I2S HAL module to compute the I2S ...
#define HSI_VALUE
Internal High Speed oscillator (HSI) value. This value is used by the RCC HAL module to compute the s...
#define HSE_VALUE
Adjust the value of External High Speed oscillator (HSE) used in your application....