1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
45
46
50
51
52
53
54
55
56
57
58
59
60
61
62
63
72
73
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
98
99
100
101
102
103
104
119
120
124
125
129
133
134
135
136
153
154
155
161
162
163
164
165
166
167
176
177
178
179
180
181
182
183
184
188
192
193
194
199
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
247
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
287
288
289
290
291
292
293
296
297
300
301
302
303
306
307
310
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
/* ... */
#ifdef HAL_SAI_MODULE_ENABLED
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || \
defined(STM32F423xx)
/* ... */
/* ... */
Private functions
/* ... */
/* ... */
/* ... */
void SAI_BlockSynchroConfig(const SAI_HandleTypeDef *hsai)
{
uint32_t tmpregisterGCR;
#if defined(STM32F446xx)
switch (hsai->Init.SynchroExt)
{
case SAI_SYNCEXT_DISABLE :
tmpregisterGCR = 0U;
break;case SAI_SYNCEXT_DISABLE :
case SAI_SYNCEXT_OUTBLOCKA_ENABLE :
tmpregisterGCR = SAI_GCR_SYNCOUT_0;
break;case SAI_SYNCEXT_OUTBLOCKA_ENABLE :
case SAI_SYNCEXT_OUTBLOCKB_ENABLE :
tmpregisterGCR = SAI_GCR_SYNCOUT_1;
break;case SAI_SYNCEXT_OUTBLOCKB_ENABLE :
default:
tmpregisterGCR = 0U;
break;default
}switch (hsai->Init.SynchroExt) { ... }
if ((hsai->Init.Synchro) == SAI_SYNCHRONOUS_EXT_SAI2)
{
tmpregisterGCR |= SAI_GCR_SYNCIN_0;
}if ((hsai->Init.Synchro) == SAI_SYNCHRONOUS_EXT_SAI2) { ... }
if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B))
{
SAI1->GCR = tmpregisterGCR;
}if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B)) { ... }
else
{
SAI2->GCR = tmpregisterGCR;
}else { ... }
/* ... */#endif
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx)
switch (hsai->Init.SynchroExt)
{
case SAI_SYNCEXT_DISABLE :
tmpregisterGCR = 0U;
break;case SAI_SYNCEXT_DISABLE :
case SAI_SYNCEXT_OUTBLOCKA_ENABLE :
tmpregisterGCR = SAI_GCR_SYNCOUT_0;
break;case SAI_SYNCEXT_OUTBLOCKA_ENABLE :
case SAI_SYNCEXT_OUTBLOCKB_ENABLE :
tmpregisterGCR = SAI_GCR_SYNCOUT_1;
break;case SAI_SYNCEXT_OUTBLOCKB_ENABLE :
default:
tmpregisterGCR = 0U;
break;default
}switch (hsai->Init.SynchroExt) { ... }
SAI1->GCR = tmpregisterGCR;/* ... */
#endif
}{ ... }
/* ... */
uint32_t SAI_GetInputClock(const SAI_HandleTypeDef *hsai)
{
uint32_t saiclocksource = 0U;
#if defined(STM32F446xx)
if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B))
{
saiclocksource = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SAI1);
}if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B)) { ... }
else
{
saiclocksource = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SAI2);
}else { ... }
/* ... */#endif
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx)
uint32_t vcoinput = 0U, tmpreg = 0U;
assert_param(IS_SAI_CLK_SOURCE(hsai->Init.ClockSource));
if (hsai->Instance == SAI1_Block_A)
{
__HAL_RCC_SAI_BLOCKACLKSOURCE_CONFIG(hsai->Init.ClockSource);
}if (hsai->Instance == SAI1_Block_A) { ... }
else
{
__HAL_RCC_SAI_BLOCKBCLKSOURCE_CONFIG((uint32_t)(hsai->Init.ClockSource << 2U));
}else { ... }
if ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
{
vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
}if ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI) { ... }
else
{
vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
}else { ... }
#if defined(STM32F413xx) || defined(STM32F423xx)
if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLR)
{
tmpreg = (RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 28U;
saiclocksource = (vcoinput * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6U)) / (tmpreg);
tmpreg = (((RCC->DCKCFGR & RCC_DCKCFGR_PLLDIVR) >> 8U) + 1U);
saiclocksource = saiclocksource / (tmpreg);
}if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLR) { ... }
else if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLI2S)
{
tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> 28U;
saiclocksource = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6U)) / (tmpreg);
tmpreg = ((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVR) + 1U);
saiclocksource = saiclocksource / (tmpreg);
}else if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLI2S) { ... }
else if (hsai->Init.ClockSource == SAI_CLKSOURCE_HS)
{
if ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSE)
{
saiclocksource = (uint32_t)(HSE_VALUE);
}if ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSE) { ... }
else
{
saiclocksource = (uint32_t)(HSI_VALUE);
}else { ... }
}else if (hsai->Init.ClockSource == SAI_CLKSOURCE_HS) { ... }
else
{
saiclocksource = EXTERNAL_CLOCK_VALUE;
}else { ... }
/* ... */#else
if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLSAI)
{
tmpreg = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24U;
saiclocksource = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6U)) / (tmpreg);
tmpreg = (((RCC->DCKCFGR & RCC_DCKCFGR_PLLSAIDIVQ) >> 8U) + 1U);
saiclocksource = saiclocksource / (tmpreg);
}if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLSAI) { ... }
else if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLI2S)
{
tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24U;
saiclocksource = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6U)) / (tmpreg);
tmpreg = ((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVQ) + 1U);
saiclocksource = saiclocksource / (tmpreg);
}else if (hsai->Init.ClockSource == SAI_CLKSOURCE_PLLI2S) { ... }
else
{
__HAL_RCC_I2S_CONFIG(RCC_I2SCLKSOURCE_EXT);
saiclocksource = EXTERNAL_CLOCK_VALUE;
}else { ... }
/* ... */#endif /* ... */
#endif
return saiclocksource;
}{ ... }
/* ... */
/* ... */
/* ... */
#endif /* ... */
#endif
/* ... */
/* ... */