Select one of the symbols to view example projects that use it.
 
Outline
#include "stm32f413h_discovery_audio.h"
audio_drv
haudio_i2s
haudio_in_i2sext
hAudioIn
hAudioInDfsdmChannel
hAudioInDfsdmFilter
hDmaDfsdm
pScratchBuff
ScratchSize
DmaRecHalfBuffCplt
DmaRecBuffCplt
AppBuffTrigger
AppBuffHalf
MicBuff
AudioInVolume
BSP_AUDIO_OUT_Init(uint16_t, uint8_t, uint32_t)
BSP_AUDIO_OUT_Play(uint16_t *, uint32_t)
BSP_AUDIO_OUT_ChangeBuffer(uint16_t *, uint16_t)
BSP_AUDIO_OUT_Pause()
BSP_AUDIO_OUT_Resume()
BSP_AUDIO_OUT_Stop(uint32_t)
BSP_AUDIO_OUT_SetVolume(uint8_t)
BSP_AUDIO_OUT_SetMute(uint32_t)
BSP_AUDIO_OUT_SetOutputMode(uint8_t)
BSP_AUDIO_OUT_SetFrequency(uint32_t)
BSP_AUDIO_OUT_DeInit()
HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *)
HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *)
HAL_I2S_ErrorCallback(I2S_HandleTypeDef *)
BSP_AUDIO_OUT_TransferComplete_CallBack()
BSP_AUDIO_OUT_HalfTransfer_CallBack()
BSP_AUDIO_OUT_Error_CallBack()
BSP_AUDIO_OUT_MspInit(I2S_HandleTypeDef *, void *)
BSP_AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *, void *)
BSP_AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *, uint32_t, void *)
I2Sx_Out_Init(uint32_t)
I2Sx_Out_DeInit()
BSP_AUDIO_IN_Init(uint32_t, uint32_t, uint32_t)
BSP_AUDIO_IN_InitEx(uint32_t, uint32_t, uint32_t, uint32_t)
BSP_AUDIO_IN_DeInit()
BSP_AUDIO_IN_ConfigMicDefault(uint32_t)
BSP_AUDIO_IN_ConfigDigitalMic(uint32_t, void *)
BSP_AUDIO_IN_AllocScratch(int32_t *, uint32_t)
BSP_AUDIO_IN_Record(uint16_t *, uint32_t)
BSP_AUDIO_IN_RecordEx(uint32_t *, uint32_t)
I2Sx_In_MspInit()
I2Sx_In_MspDeInit()
BSP_AUDIO_IN_MspInit(void *)
BSP_AUDIO_IN_MspDeInit(void *)
BSP_AUDIO_IN_ClockConfig(uint32_t, void *)
HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *)
HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *)
HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *)
HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *)
BSP_AUDIO_IN_Stop()
BSP_AUDIO_IN_StopEx(uint32_t)
BSP_AUDIO_IN_Pause()
BSP_AUDIO_IN_PauseEx(uint32_t)
BSP_AUDIO_IN_Resume()
BSP_AUDIO_IN_ResumeEx(uint32_t *, uint32_t)
BSP_AUDIO_IN_SetVolume(uint8_t)
BSP_AUDIO_IN_TransferComplete_CallBack()
BSP_AUDIO_IN_HalfTransfer_CallBack()
BSP_AUDIO_IN_TransferComplete_CallBackEx(uint32_t)
BSP_AUDIO_IN_HalfTransfer_CallBackEx(uint32_t)
BSP_AUDIO_IN_Error_Callback()
DFSDMx_DeInit()
DFSDMx_ChannelMspInit()
DFSDMx_ChannelMspDeInit()
DFSDMx_FilterMspInit()
DFSDMx_FilterMspDeInit()
I2Sx_In_Init(uint32_t)
I2Sx_In_DeInit()
Files
loading...
CodeScopeSTM32 Libraries and SamplesSTM32F413H-Discoverystm32f413h_discovery_audio.c
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file STM32f413h_discovery_audio.c * @author MCD Application Team * @brief This file provides the Audio driver for the STM32F413H-DISCOVERY board. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /*============================================================================== User NOTES How To use this driver: ----------------------- + This driver supports STM32F4xx devices on STM32F413H-DISCOVERY boards. + Call the function BSP_AUDIO_OUT_Init( OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE or OUTPUT_DEVICE_BOTH) Volume : Initial volume to be set (0 is min (mute), 100 is max (100%) AudioFreq : Audio frequency in Hz (8000, 16000, 22500, 32000...) this parameter is relative to the audio file/stream type. ) This function configures all the hardware required for the audio application (codec, I2C, I2S, GPIOs, DMA and interrupt if needed). This function returns AUDIO_OK if configuration is OK. If the returned value is different from AUDIO_OK or the function is stuck then the communication with the codec has failed (try to un-plug the power or reset device in this case). - OUTPUT_DEVICE_SPEAKER : only speaker will be set as output for the audio stream. - OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream. - OUTPUT_DEVICE_BOTH : both Speaker and Headphone are used as outputs for the audio stream at the same time. + Call the function BSP_AUDIO_OUT_Play( pBuffer: pointer to the audio data file address Size : size of the buffer to be sent in Bytes ) to start playing (for the first time) from the audio file/stream. + Call the function BSP_AUDIO_OUT_Pause() to pause playing + Call the function BSP_AUDIO_OUT_Resume() to resume playing. Note. After calling BSP_AUDIO_OUT_Pause() function for pause, only BSP_AUDIO_OUT_Resume() should be called for resume (it is not allowed to call BSP_AUDIO_OUT_Play() in this case). Note. This function should be called only when the audio file is played or paused (not stopped). + For each mode, you may need to implement the relative callback functions into your code. The Callback functions are named AUDIO_OUT_XXX_CallBack() and only their prototypes are declared in the STM32F413H_discovery_audio.h file. (refer to the example for more details on the callbacks implementations) + To Stop playing, to modify the volume level, the frequency, use the functions: BSP_AUDIO_OUT_SetVolume(), AUDIO_OUT_SetFrequency(), BSP_AUDIO_OUT_SetOutputMode(), BSP_AUDIO_OUT_SetMute() and BSP_AUDIO_OUT_Stop(). + The driver API and the callback functions are at the end of the STM32F413H_discovery_audio.h file. Driver architecture: -------------------- + This driver provides the High Audio Layer: consists of the function API exported in the stm32f413h_discovery_audio.h file (BSP_AUDIO_OUT_Init(), BSP_AUDIO_OUT_Play() ...) + This driver provide also the Media Access Layer (MAL): which consists of functions allowing to access the media containing/ providing the audio file/stream. These functions are also included as local functions into the stm32f413h_discovery_audio_codec.c file (I2Sx_Out_Init(), I2Sx_Out_DeInit(), I2Sx_In_Init() and I2Sx_In_DeInit()) Known Limitations: ------------------ 1- If the TDM Format used to play in parallel 2 audio Stream (the first Stream is configured in codec SLOT0 and second Stream in SLOT1) the Pause/Resume, volume and mute feature will control the both streams. 2- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size, File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file. 3- Supports only Stereo audio streaming. 4- Supports only 16-bits audio data size. ==============================================================================*//* ... */ /* Includes ------------------------------------------------------------------*/ #include "stm32f413h_discovery_audio.h" /** @addtogroup BSP * @{ *//* ... */ /** @addtogroup STM32F413H_DISCOVERY * @{ *//* ... */ /** @defgroup STM32F413H_DISCOVERY_AUDIO STM32F413H_DISCOVERY AUDIO * @brief This file includes the low layer driver for wm8994 Audio Codec * available on STM32F413H-DISCOVERY board(MB1209). * @{ *//* ... */ /** @defgroup STM32F413H_DISCOVERY_AUDIO_Private_Macros STM32F413H DISCOVERY Audio Private macros * @{ *//* ... */ #define DFSDM_OVER_SAMPLING(__FREQUENCY__) \ (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? 256 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? 256 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? 128 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? 128 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? 64 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? 64 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? 32 : 25 \ #define DFSDM_CLOCK_DIVIDER(__FREQUENCY__) \ (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? 24 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? 48 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? 24 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? 48 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? 24 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? 48 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? 32 : 72 \ #define DFSDM_FILTER_ORDER(__FREQUENCY__) \ (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? DFSDM_FILTER_SINC3_ORDER \ : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? DFSDM_FILTER_SINC3_ORDER \ : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? DFSDM_FILTER_SINC3_ORDER \ : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? DFSDM_FILTER_SINC3_ORDER \ : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? DFSDM_FILTER_SINC4_ORDER \ : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? DFSDM_FILTER_SINC4_ORDER \ : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? DFSDM_FILTER_SINC4_ORDER : DFSDM_FILTER_SINC4_ORDER \ #define DFSDM_MIC_BIT_SHIFT(__FREQUENCY__) \ (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? 5 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? 4 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? 2 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? 2 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? 5 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? 6 \ : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? 2 : 0 \ /* Saturate the record PCM sample */ #define SaturaLH(N, L, H) (((N)<(L))?(L):(((N)>(H))?(H):(N)))... /** * @} *//* ... */ /** @defgroup STM32F413H_DISCOVERY_AUDIO_Private_Variables STM32F413H DISCOVERY Audio Private Variables * @{ *//* ... */ AUDIO_DrvTypeDef *audio_drv; I2S_HandleTypeDef haudio_i2s; /* for Audio_OUT and Audio_IN_analog mic */ I2S_HandleTypeDef haudio_in_i2sext; /* for Analog mic with full duplex mode */ AUDIOIN_ContextTypeDef hAudioIn; DFSDM_Channel_HandleTypeDef hAudioInDfsdmChannel[DFSDM_MIC_NUMBER]; /* 5 DFSDM channel handle used for all microphones */ DFSDM_Filter_HandleTypeDef hAudioInDfsdmFilter[DFSDM_MIC_NUMBER]; /* 5 DFSDM filter handle */ DMA_HandleTypeDef hDmaDfsdm[DFSDM_MIC_NUMBER]; /* 5 DMA handle used for DFSDM regular conversions */ /* Buffers for right and left samples */ int32_t *pScratchBuff[DEFAULT_AUDIO_IN_CHANNEL_NBR]; int32_t ScratchSize; uint32_t DmaRecHalfBuffCplt[DFSDM_MIC_NUMBER] = {0}; uint32_t DmaRecBuffCplt[DFSDM_MIC_NUMBER] = {0}; /* Application Buffer Trigger */ __IO uint32_t AppBuffTrigger = 0; __IO uint32_t AppBuffHalf = 0; __IO uint32_t MicBuff[DFSDM_MIC_NUMBER] = {0}; __IO uint16_t AudioInVolume = DEFAULT_AUDIO_IN_VOLUME; /** * @} *//* ... */ /** @defgroup STM32F413H_DISCOVERY_AUDIO_Private_Function_Prototypes STM32F413H DISCOVERY Audio Private Prototypes * @{ *//* ... */ static void I2Sx_In_Init(uint32_t AudioFreq); static void I2Sx_In_DeInit(void); static void I2Sx_In_MspInit(void); static void I2Sx_In_MspDeInit(void); static void I2Sx_Out_Init(uint32_t AudioFreq); static void I2Sx_Out_DeInit(void); static uint8_t DFSDMx_DeInit(void); static void DFSDMx_ChannelMspInit(void); static void DFSDMx_ChannelMspDeInit(void); static void DFSDMx_FilterMspInit(void); static void DFSDMx_FilterMspDeInit(void); /** * @} *//* ... */ /** @defgroup STM32F413H_DISCOVERY_AUDIO_out_Private_Functions STM32F413H DISCOVERY AUDIO OUT Private Functions * @{ *//* ... */ /** * @brief Configures the audio peripherals. * @param OutputDevice: OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE, * or OUTPUT_DEVICE_BOTH. * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max)) * @param AudioFreq: Audio frequency used to play the audio stream. * @note The I2S PLL input clock must be done in the user application. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq) { uint8_t ret = AUDIO_ERROR; uint32_t deviceid = 0x00; uint16_t buffer_fake[16] = {0x00}; I2Sx_Out_DeInit(); AUDIO_IO_DeInit(); /* PLL clock is set depending on the AudioFreq (44.1 kHz vs 48kHz groups) */ BSP_AUDIO_OUT_ClockConfig(&haudio_i2s, AudioFreq, NULL); /* Configure the I2S peripheral */ haudio_i2s.Instance = AUDIO_OUT_I2Sx; if(HAL_I2S_GetState(&haudio_i2s) == HAL_I2S_STATE_RESET) { /* Initialize the I2S Msp: this __weak function can be rewritten by the application */ BSP_AUDIO_OUT_MspInit(&haudio_i2s, NULL); }if (HAL_I2S_GetState(&haudio_i2s) == HAL_I2S_STATE_RESET) { ... } I2Sx_Out_Init(AudioFreq); AUDIO_IO_Init(); /* wm8994 codec initialization */ deviceid = wm8994_drv.ReadID(AUDIO_I2C_ADDRESS); if(deviceid == WM8994_ID) { /* Reset the Codec Registers */ wm8994_drv.Reset(AUDIO_I2C_ADDRESS); /* Initialize the audio driver structure */ audio_drv = &wm8994_drv; ret = AUDIO_OK; }if (deviceid == WM8994_ID) { ... } else { ret = AUDIO_ERROR; }else { ... } if(ret == AUDIO_OK) { /* Send fake I2S data in order to generate MCLK needed by WM8994 to set its registers * MCLK is generated only when a data stream is sent on I2S *//* ... */ HAL_I2S_Transmit_DMA(&haudio_i2s, buffer_fake, 16); /* Initialize the codec internal registers */ audio_drv->Init(AUDIO_I2C_ADDRESS, OutputDevice, Volume, AudioFreq); /* Stop sending fake I2S data */ HAL_I2S_DMAStop(&haudio_i2s); }if (ret == AUDIO_OK) { ... } return ret; }{ ... } /** * @brief Starts playing audio stream from a data buffer for a determined size. * @param pBuffer: Pointer to the buffer * @param Size: Number of audio data BYTES. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size) { /* Call the audio Codec Play function */ if(audio_drv->Play(AUDIO_I2C_ADDRESS, pBuffer, Size) != 0) { return AUDIO_ERROR; }if (audio_drv->Play(AUDIO_I2C_ADDRESS, pBuffer, Size) != 0) { ... } else { /* Update the Media layer and enable it for play */ HAL_I2S_Transmit_DMA(&haudio_i2s, pBuffer, DMA_MAX(Size / AUDIODATA_SIZE)); return AUDIO_OK; }else { ... } }{ ... } /** * @brief Sends n-Bytes on the I2S interface. * @param pData: pointer on data address * @param Size: number of data to be written *//* ... */ void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size) { HAL_I2S_Transmit_DMA(&haudio_i2s, pData, Size); }{ ... } /** * @brief This function Pauses the audio file stream. In case * of using DMA, the DMA Pause feature is used. * @note When calling BSP_AUDIO_OUT_Pause() function for pause, only * BSP_AUDIO_OUT_Resume() function should be called for resume (use of BSP_AUDIO_OUT_Play() * function for resume could lead to unexpected behavior). * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_OUT_Pause(void) { /* Call the Audio Codec Pause/Resume function */ if(audio_drv->Pause(AUDIO_I2C_ADDRESS) != 0) { return AUDIO_ERROR; }if (audio_drv->Pause(AUDIO_I2C_ADDRESS) != 0) { ... } else { /* Call the Media layer pause function */ HAL_I2S_DMAPause(&haudio_i2s); /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }else { ... } }{ ... } /** * @brief This function Resumes the audio file stream. * @note When calling BSP_AUDIO_OUT_Pause() function for pause, only * BSP_AUDIO_OUT_Resume() function should be called for resume (use of BSP_AUDIO_OUT_Play() * function for resume could lead to unexpected behavior). * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_OUT_Resume(void) { /* Call the Media layer pause/resume function */ /* DMA stream resumed before accessing WM8994 register as WM8994 needs the MCLK to be generated to access its registers * MCLK is generated only when a data stream is sent on I2S *//* ... */ HAL_I2S_DMAResume(&haudio_i2s); /* Call the Audio Codec Pause/Resume function */ if(audio_drv->Resume(AUDIO_I2C_ADDRESS) != 0) { return AUDIO_ERROR; }if (audio_drv->Resume(AUDIO_I2C_ADDRESS) != 0) { ... } else { /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }else { ... } }{ ... } /** * @brief Stops audio playing and Power down the Audio Codec. * @param Option: could be one of the following parameters * - CODEC_PDWN_SW: for software power off (by writing registers). * Then no need to reconfigure the Codec after power on. * - CODEC_PDWN_HW: completely shut down the codec (physically). * Then need to reconfigure the Codec after power on. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option) { /* Call the Media layer stop function */ HAL_I2S_DMAStop(&haudio_i2s); /* Call Audio Codec Stop function */ if(audio_drv->Stop(AUDIO_I2C_ADDRESS, Option) != 0) { return AUDIO_ERROR; }if (audio_drv->Stop(AUDIO_I2C_ADDRESS, Option) != 0) { ... } else { if(Option == CODEC_PDWN_HW) { /* Wait at least 100us */ HAL_Delay(1); }if (Option == CODEC_PDWN_HW) { ... } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }else { ... } }{ ... } /** * @brief Controls the current audio volume level. * @param Volume: Volume level to be set in percentage from 0% to 100% (0 for * Mute and 100 for Max volume level). * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume) { /* Call the codec volume control function with converted volume value */ if(audio_drv->SetVolume(AUDIO_I2C_ADDRESS, Volume) != 0) { return AUDIO_ERROR; }if (audio_drv->SetVolume(AUDIO_I2C_ADDRESS, Volume) != 0) { ... } else { /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }else { ... } }{ ... } /** * @brief Enables or disables the MUTE mode by software * @param Cmd: Could be AUDIO_MUTE_ON to mute sound or AUDIO_MUTE_OFF to * unmute the codec and restore previous volume level. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd) { /* Call the Codec Mute function */ if(audio_drv->SetMute(AUDIO_I2C_ADDRESS, Cmd) != 0) { return AUDIO_ERROR; }if (audio_drv->SetMute(AUDIO_I2C_ADDRESS, Cmd) != 0) { ... } else { /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }else { ... } }{ ... } /** * @brief Switch dynamically (while audio file is played) the output target * (speaker or headphone). * @param Output: The audio output target: OUTPUT_DEVICE_SPEAKER, * OUTPUT_DEVICE_HEADPHONE or OUTPUT_DEVICE_BOTH * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output) { /* Call the Codec output device function */ if(audio_drv->SetOutputMode(AUDIO_I2C_ADDRESS, Output) != 0) { return AUDIO_ERROR; }if (audio_drv->SetOutputMode(AUDIO_I2C_ADDRESS, Output) != 0) { ... } else { /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }else { ... } }{ ... } /** * @brief Updates the audio frequency. * @param AudioFreq: Audio frequency used to play the audio stream. * @note This API should be called after the BSP_AUDIO_OUT_Init() to adjust the * audio frequency. * @retval None *//* ... */ void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq) { /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */ BSP_AUDIO_OUT_ClockConfig(&haudio_i2s, AudioFreq, NULL); /* Disable I2S peripheral to allow access to I2S internal registers */ __HAL_I2S_DISABLE(&haudio_i2s); /* Update the I2S audio frequency configuration */ haudio_i2s.Init.AudioFreq = AudioFreq; HAL_I2S_Init(&haudio_i2s); /* Enable I2S peripheral to generate MCLK */ __HAL_I2S_ENABLE(&haudio_i2s); }{ ... } /** * @brief Deinit the audio peripherals. *//* ... */ void BSP_AUDIO_OUT_DeInit(void) { I2Sx_Out_DeInit(); /* DeInit the I2S MSP : this __weak function can be rewritten by the application */ BSP_AUDIO_OUT_MspDeInit(&haudio_i2s, NULL); }{ ... } /** * @brief Tx Transfer completed callbacks. * @param hi2s: I2S handle *//* ... */ void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s) { /* Manage the remaining file size and new address offset: This function should be coded by user (its prototype is already declared in STM32F413H_discovery_audio.h) *//* ... */ BSP_AUDIO_OUT_TransferComplete_CallBack(); }{ ... } /** * @brief Tx Half Transfer completed callbacks. * @param hi2s: I2S handle *//* ... */ void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) { /* Manage the remaining file size and new address offset: This function should be coded by user (its prototype is already declared in STM32F413H_discovery_audio.h) *//* ... */ BSP_AUDIO_OUT_HalfTransfer_CallBack(); }{ ... } /** * @brief I2S error callbacks. * @param hi2s: I2S handle *//* ... */ void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s) { BSP_AUDIO_OUT_Error_CallBack(); }{ ... } /** * @brief Manages the DMA full Transfer complete event. *//* ... */ __weak void BSP_AUDIO_OUT_TransferComplete_CallBack(void) { }{ ... } /** * @brief Manages the DMA Half Transfer complete event. *//* ... */ __weak void BSP_AUDIO_OUT_HalfTransfer_CallBack(void) { }{ ... } /** * @brief Manages the DMA FIFO error event. *//* ... */ __weak void BSP_AUDIO_OUT_Error_CallBack(void) { }{ ... } /** * @brief Initializes BSP_AUDIO_OUT MSP. * @param hi2s: I2S handle * @param Params : pointer on additional configuration parameters, can be NULL. *//* ... */ __weak void BSP_AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params) { static DMA_HandleTypeDef hdma_i2s_tx; GPIO_InitTypeDef gpio_init_structure; /* Prevent unused argument(s) compilation warning */ UNUSED(Params); /* Enable I2S clock */ AUDIO_OUT_I2Sx_CLK_ENABLE(); /* Enable MCK, SCK, WS, SD and CODEC_INT GPIO clock */ AUDIO_OUT_I2Sx_MCK_GPIO_CLK_ENABLE(); AUDIO_OUT_I2Sx_SCK_GPIO_CLK_ENABLE(); AUDIO_OUT_I2Sx_SD_GPIO_CLK_ENABLE(); AUDIO_OUT_I2Sx_WS_GPIO_CLK_ENABLE(); /* CODEC_I2S pins configuration: MCK, SCK, WS and SD pins */ gpio_init_structure.Pin = AUDIO_OUT_I2Sx_MCK_PIN; gpio_init_structure.Mode = GPIO_MODE_AF_PP; gpio_init_structure.Pull = GPIO_NOPULL; gpio_init_structure.Speed = GPIO_SPEED_FAST; gpio_init_structure.Alternate = AUDIO_OUT_I2Sx_MCK_AF; HAL_GPIO_Init(AUDIO_OUT_I2Sx_MCK_GPIO_PORT, &gpio_init_structure); gpio_init_structure.Pin = AUDIO_OUT_I2Sx_SCK_PIN; gpio_init_structure.Alternate = AUDIO_OUT_I2Sx_SCK_AF; HAL_GPIO_Init(AUDIO_OUT_I2Sx_SCK_GPIO_PORT, &gpio_init_structure); gpio_init_structure.Pin = AUDIO_OUT_I2Sx_WS_PIN; gpio_init_structure.Alternate = AUDIO_OUT_I2Sx_WS_AF; HAL_GPIO_Init(AUDIO_OUT_I2Sx_WS_GPIO_PORT, &gpio_init_structure); gpio_init_structure.Pin = AUDIO_OUT_I2Sx_SD_PIN; gpio_init_structure.Alternate = AUDIO_OUT_I2Sx_SD_AF; HAL_GPIO_Init(AUDIO_OUT_I2Sx_SD_GPIO_PORT, &gpio_init_structure); /* Enable the DMA clock */ AUDIO_OUT_I2Sx_DMAx_CLK_ENABLE(); if(hi2s->Instance == AUDIO_OUT_I2Sx) { /* Configure the hdma_i2s_rx handle parameters */ hdma_i2s_tx.Init.Channel = AUDIO_OUT_I2Sx_DMAx_CHANNEL; hdma_i2s_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_i2s_tx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_i2s_tx.Init.MemInc = DMA_MINC_ENABLE; hdma_i2s_tx.Init.PeriphDataAlignment = AUDIO_OUT_I2Sx_DMAx_PERIPH_DATA_SIZE; hdma_i2s_tx.Init.MemDataAlignment = AUDIO_OUT_I2Sx_DMAx_MEM_DATA_SIZE; hdma_i2s_tx.Init.Mode = DMA_CIRCULAR; hdma_i2s_tx.Init.Priority = DMA_PRIORITY_HIGH; hdma_i2s_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_i2s_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; hdma_i2s_tx.Init.MemBurst = DMA_MBURST_SINGLE; hdma_i2s_tx.Init.PeriphBurst = DMA_MBURST_SINGLE; hdma_i2s_tx.Instance = AUDIO_OUT_I2Sx_DMAx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(hi2s, hdmatx, hdma_i2s_tx); /* Deinitialize the Stream for new transfer */ HAL_DMA_DeInit(&hdma_i2s_tx); /* Configure the DMA Stream */ HAL_DMA_Init(&hdma_i2s_tx); }if (hi2s->Instance == AUDIO_OUT_I2Sx) { ... } /* Enable and set I2Sx Interrupt to a lower priority */ HAL_NVIC_SetPriority(SPI3_IRQn, 0x0F, 0x00); HAL_NVIC_EnableIRQ(SPI3_IRQn); /* I2S DMA IRQ Channel configuration */ HAL_NVIC_SetPriority(AUDIO_OUT_I2Sx_DMAx_IRQ, AUDIO_OUT_IRQ_PREPRIO, 0); HAL_NVIC_EnableIRQ(AUDIO_OUT_I2Sx_DMAx_IRQ); }{ ... } /** * @brief Deinitializes I2S MSP. * @param hi2s: I2S handle * @param Params : pointer on additional configuration parameters, can be NULL. *//* ... */ __weak void BSP_AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params) { GPIO_InitTypeDef gpio_init_structure; /* Prevent unused argument(s) compilation warning */ UNUSED(Params); /* I2S DMA IRQ Channel deactivation */ HAL_NVIC_DisableIRQ(AUDIO_OUT_I2Sx_DMAx_IRQ); if(hi2s->Instance == AUDIO_OUT_I2Sx) { /* Deinitialize the DMA stream */ HAL_DMA_DeInit(hi2s->hdmatx); }if (hi2s->Instance == AUDIO_OUT_I2Sx) { ... } /* Disable I2S peripheral */ __HAL_I2S_DISABLE(hi2s); /* Deactives CODEC_I2S pins MCK, SCK, WS and SD by putting them in input mode */ gpio_init_structure.Pin = AUDIO_OUT_I2Sx_MCK_PIN; HAL_GPIO_DeInit(AUDIO_OUT_I2Sx_MCK_GPIO_PORT, gpio_init_structure.Pin); gpio_init_structure.Pin = AUDIO_OUT_I2Sx_SCK_PIN; HAL_GPIO_DeInit(AUDIO_OUT_I2Sx_SCK_GPIO_PORT, gpio_init_structure.Pin); gpio_init_structure.Pin = AUDIO_OUT_I2Sx_WS_PIN; HAL_GPIO_DeInit(AUDIO_OUT_I2Sx_WS_GPIO_PORT, gpio_init_structure.Pin); gpio_init_structure.Pin = AUDIO_OUT_I2Sx_SD_PIN; HAL_GPIO_DeInit(AUDIO_OUT_I2Sx_SD_GPIO_PORT, gpio_init_structure.Pin); /* Disable I2S clock */ AUDIO_OUT_I2Sx_CLK_DISABLE(); /* GPIO pins clock and DMA clock can be shut down in the application by surcharging this __weak function *//* ... */ }{ ... } /** * @brief Clock Config. * @param hi2s: might be required to set audio peripheral predivider if any. * @param AudioFreq: Audio frequency used to play the audio stream. * @param Params : pointer on additional configuration parameters, can be NULL. * @note This API is called by BSP_AUDIO_OUT_Init() and BSP_AUDIO_OUT_SetFrequency() * Being __weak it can be overwritten by the application *//* ... */ __weak void BSP_AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params) { RCC_PeriphCLKInitTypeDef rcc_ex_clk_init_struct; /* Prevent unused argument(s) compilation warning */ UNUSED(Params); HAL_RCCEx_GetPeriphCLKConfig(&rcc_ex_clk_init_struct); /* Set the PLL configuration according to the audio frequency */ if((AudioFreq == AUDIO_FREQUENCY_11K) || (AudioFreq == AUDIO_FREQUENCY_22K) || (AudioFreq == AUDIO_FREQUENCY_44K)) { /* Configure PLLI2S prescalers */ rcc_ex_clk_init_struct.PeriphClockSelection = (RCC_PERIPHCLK_I2S_APB1 | RCC_PERIPHCLK_PLLI2S); rcc_ex_clk_init_struct.I2sApb1ClockSelection = RCC_I2SAPB1CLKSOURCE_PLLI2S; rcc_ex_clk_init_struct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC; rcc_ex_clk_init_struct.PLLI2S.PLLI2SM = 8; rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 271; rcc_ex_clk_init_struct.PLLI2S.PLLI2SR = 2; HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct); }if ((AudioFreq == AUDIO_FREQUENCY_11K) || (AudioFreq == AUDIO_FREQUENCY_22K) || (AudioFreq == AUDIO_FREQUENCY_44K)) { ... } else if(AudioFreq == AUDIO_FREQUENCY_96K) /* AUDIO_FREQUENCY_96K */ { /* I2S clock config */ rcc_ex_clk_init_struct.PeriphClockSelection = (RCC_PERIPHCLK_I2S_APB1 | RCC_PERIPHCLK_PLLI2S); rcc_ex_clk_init_struct.I2sApb1ClockSelection = RCC_I2SAPB1CLKSOURCE_PLLI2S; rcc_ex_clk_init_struct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC; rcc_ex_clk_init_struct.PLLI2S.PLLI2SM = 8; rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 344; rcc_ex_clk_init_struct.PLLI2S.PLLI2SR = 2; HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct); ...} else /* AUDIO_FREQUENCY_8K, AUDIO_FREQUENCY_16K, AUDIO_FREQUENCY_48K */ { /* I2S clock config PLLI2S_VCO: VCO_344M I2S_CLK(first level) = PLLI2S_VCO/PLLI2SR = 344/7 = 49.142 Mhz I2S_CLK_x = I2S_CLK(first level)/PLLI2SDIVR = 49.142/1 = 49.142 Mhz *//* ... */ rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_I2S_APB1 | RCC_PERIPHCLK_PLLI2S; rcc_ex_clk_init_struct.I2sApb1ClockSelection = RCC_I2SAPB1CLKSOURCE_PLLI2S; rcc_ex_clk_init_struct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC; rcc_ex_clk_init_struct.PLLI2S.PLLI2SM = 8; rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 344; rcc_ex_clk_init_struct.PLLI2S.PLLI2SR = 7; HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct); }else { ... } }{ ... } /******************************************************************************* Static Functions *******************************************************************************//* ... */ /** * @brief Initializes the Audio Codec audio interface (I2S) * @note This function assumes that the I2S input clock * is already configured and ready to be used. * @param AudioFreq: Audio frequency to be configured for the I2S peripheral. *//* ... */ static void I2Sx_Out_Init(uint32_t AudioFreq) { /* Initialize the hAudioInI2s Instance parameter */ haudio_i2s.Instance = AUDIO_OUT_I2Sx; /* Disable I2S block */ __HAL_I2S_DISABLE(&haudio_i2s); /* I2S peripheral configuration */ haudio_i2s.Init.AudioFreq = AudioFreq; haudio_i2s.Init.ClockSource = I2S_CLOCK_PLL; haudio_i2s.Init.CPOL = I2S_CPOL_LOW; haudio_i2s.Init.DataFormat = I2S_DATAFORMAT_16B; haudio_i2s.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE; haudio_i2s.Init.Mode = I2S_MODE_MASTER_TX; haudio_i2s.Init.Standard = I2S_STANDARD_PHILIPS; haudio_i2s.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE; /* Init the I2S */ HAL_I2S_Init(&haudio_i2s); /* Enable I2S block */ __HAL_I2S_ENABLE(&haudio_i2s); }{ ... } /** * @brief Deinitializes the Audio Codec audio interface (I2S). *//* ... */ static void I2Sx_Out_DeInit(void) { /* Initialize the hAudioInI2s Instance parameter */ haudio_i2s.Instance = AUDIO_OUT_I2Sx; /* Disable I2S block */ __HAL_I2S_DISABLE(&haudio_i2s); /* DeInit the I2S */ HAL_I2S_DeInit(&haudio_i2s); }{ ... } /** * @} *//* ... */ /** @defgroup STM32F413H_DISCOVERY_AUDIO_IN_Private_Functions STM32F413H DISCOVERY AUDIO IN Private functions * @{ *//* ... */ /** * @brief Initializes wave recording. * @param AudioFreq: Audio frequency to be configured for the audio in peripheral. * @param BitRes: Audio bit resolution. * @param ChnlNbr: Audio channel number. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr) { return BSP_AUDIO_IN_InitEx(INPUT_DEVICE_DIGITAL_MIC, AudioFreq, BitRes, ChnlNbr); }{ ... } /** * @brief Initializes wave recording. * @param InputDevice: INPUT_DEVICE_DIGITAL_MICx or INPUT_DEVICE_ANALOG_MIC. * @param AudioFreq: Audio frequency to be configured for the audio in peripheral. * @param BitRes: Audio bit resolution. * @param ChnlNbr: Audio channel number. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_InitEx(uint32_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr) { uint32_t ret = AUDIO_ERROR; uint32_t deviceid =0; uint32_t mic_enabled =0; uint16_t buffer_fake[16] = {0x00}; uint32_t i = 0; /* Store the audio record context */ hAudioIn.Frequency = AudioFreq; hAudioIn.BitResolution = BitRes; hAudioIn.InputDevice = InputDevice; hAudioIn.ChannelNbr = ChnlNbr; /* Store the total number of microphones enabled */ for(i = 0; i < DFSDM_MIC_NUMBER; i ++) { if(((hAudioIn.InputDevice >> i) & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) { mic_enabled++; }if (((hAudioIn.InputDevice >> i) & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) { ... } }for (i = 0; i < DFSDM_MIC_NUMBER; i ++) { ... } if (InputDevice == INPUT_DEVICE_ANALOG_MIC) { InputDevice = INPUT_DEVICE_INPUT_LINE_1; /* INPUT_DEVICE_ANALOG_MIC */ /* Disable I2S */ I2Sx_In_DeInit(); /* PLL clock is set depending on the AudioFreq (44.1khz vs 48khz groups) */ BSP_AUDIO_IN_ClockConfig(AudioFreq, NULL); /* Clock config is shared between AUDIO IN and OUT for analog mic */ /* I2S data transfer preparation: Prepare the Media to be used for the audio transfer from I2S peripheral to memory *//* ... */ haudio_i2s.Instance = AUDIO_IN_I2Sx; if(HAL_I2S_GetState(&haudio_i2s) == HAL_I2S_STATE_RESET) { BSP_AUDIO_OUT_MspInit(&haudio_i2s, NULL); /* Initialize GPIOs for SPI3 Master signals */ /* Init the I2S MSP: this __weak function can be redefined by the application*/ BSP_AUDIO_IN_MspInit(NULL); }if (HAL_I2S_GetState(&haudio_i2s) == HAL_I2S_STATE_RESET) { ... } /* Configure I2S */ I2Sx_In_Init(AudioFreq); AUDIO_IO_Init(); /* wm8994 codec initialization */ deviceid = wm8994_drv.ReadID(AUDIO_I2C_ADDRESS); if((deviceid) == WM8994_ID) { /* Reset the Codec Registers */ wm8994_drv.Reset(AUDIO_I2C_ADDRESS); /* Initialize the audio driver structure */ audio_drv = &wm8994_drv; ret = AUDIO_OK; }if ((deviceid) == WM8994_ID) { ... } else { ret = AUDIO_ERROR; }else { ... } if(ret == AUDIO_OK) { /* Receive fake I2S data in order to generate MCLK needed by WM8994 to set its registers */ HAL_I2S_Receive_DMA(&haudio_i2s, buffer_fake, 16); /* Initialize the codec internal registers */ audio_drv->Init(AUDIO_I2C_ADDRESS, (OUTPUT_DEVICE_HEADPHONE|InputDevice), 100, AudioFreq); /* Stop receiving fake I2S data */ HAL_I2S_DMAStop(&haudio_i2s); }if (ret == AUDIO_OK) { ... } }if (InputDevice == INPUT_DEVICE_ANALOG_MIC) { ... } else { if(hAudioIn.ChannelNbr != mic_enabled) { return AUDIO_ERROR; }if (hAudioIn.ChannelNbr != mic_enabled) { ... } else { /* PLL clock is set depending on the AudioFreq (44.1khz vs 48khz groups) */ BSP_AUDIO_IN_ClockConfig(AudioFreq, NULL); /* Clock config is shared between AUDIO IN and OUT for analog mic */ /* Init the DFSDM MSP: this __weak function can be redefined by the application*/ BSP_AUDIO_IN_MspInit(NULL); /* Default configuration of DFSDM filters and channels */ ret = BSP_AUDIO_IN_ConfigDigitalMic(hAudioIn.InputDevice, NULL); }else { ... } }else { ... } /* Return AUDIO_OK when all operations are correctly done */ return ret; }{ ... } /** * @brief DeInitializes the audio peripheral. *//* ... */ void BSP_AUDIO_IN_DeInit(void) { if(hAudioIn.InputDevice != INPUT_DEVICE_ANALOG_MIC) { /* MSP filters/channels initialization */ BSP_AUDIO_IN_MspDeInit(NULL); DFSDMx_DeInit(); }if (hAudioIn.InputDevice != INPUT_DEVICE_ANALOG_MIC) { ... } else { I2Sx_In_DeInit(); }else { ... } }{ ... } /** * @brief Initializes default configuration of the Digital Filter for Sigma-Delta Modulators interface (DFSDM). * @param InputDevice: The microphone to be configured. Can be INPUT_DEVICE_DIGITAL_MIC1..INPUT_DEVICE_DIGITAL_MIC5 * @note Channel output Clock Divider and Filter Oversampling are calculated as follow: * - Clock_Divider = CLK(input DFSDM)/CLK(micro) with * 1MHZ < CLK(micro) < 3.2MHZ (TYP 2.4MHZ for MP34DT01TR) * - Oversampling = CLK(input DFSDM)/(Clock_Divider * AudioFreq) * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_ConfigMicDefault(uint32_t InputDevice) { uint32_t i = 0, mic_init[DFSDM_MIC_NUMBER] = {0}; uint32_t filter_ch = 0, mic_num = 0; DFSDM_Filter_TypeDef* FilterInstnace[DFSDM_MIC_NUMBER] = {AUDIO_DFSDMx_MIC1_FILTER, AUDIO_DFSDMx_MIC2_FILTER, AUDIO_DFSDMx_MIC3_FILTER, AUDIO_DFSDMx_MIC4_FILTER, AUDIO_DFSDMx_MIC5_FILTER}; DFSDM_Channel_TypeDef* ChannelInstnace[DFSDM_MIC_NUMBER] = {AUDIO_DFSDMx_MIC1_CHANNEL, AUDIO_DFSDMx_MIC2_CHANNEL, AUDIO_DFSDMx_MIC3_CHANNEL, AUDIO_DFSDMx_MIC4_CHANNEL, AUDIO_DFSDMx_MIC5_CHANNEL}; uint32_t DigitalMicPins[DFSDM_MIC_NUMBER] = {DFSDM_CHANNEL_SAME_CHANNEL_PINS, DFSDM_CHANNEL_SAME_CHANNEL_PINS, DFSDM_CHANNEL_FOLLOWING_CHANNEL_PINS, DFSDM_CHANNEL_SAME_CHANNEL_PINS, DFSDM_CHANNEL_FOLLOWING_CHANNEL_PINS}; uint32_t DigitalMicType[DFSDM_MIC_NUMBER] = {DFSDM_CHANNEL_SPI_RISING, DFSDM_CHANNEL_SPI_RISING, DFSDM_CHANNEL_SPI_FALLING, DFSDM_CHANNEL_SPI_RISING, DFSDM_CHANNEL_SPI_FALLING}; uint32_t Channel4Filter[DFSDM_MIC_NUMBER] = {AUDIO_DFSDMx_MIC1_CHANNEL_FOR_FILTER, AUDIO_DFSDMx_MIC2_CHANNEL_FOR_FILTER, AUDIO_DFSDMx_MIC3_CHANNEL_FOR_FILTER, AUDIO_DFSDMx_MIC4_CHANNEL_FOR_FILTER, AUDIO_DFSDMx_MIC5_CHANNEL_FOR_FILTER}; for(i = 0; i < hAudioIn.ChannelNbr; i++) { if(((InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC1); }if (((InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] != 1)) { ... } else if(((InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC2); }else if (((InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] != 1)) { ... } else if(((InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC3); }else if (((InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)] != 1)) { ... } else if(((InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC4); }else if (((InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)] != 1)) { ... } else if(((InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC5); }else if (((InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)] != 1)) { ... } mic_init[mic_num] = 1; HAL_DFSDM_FilterDeInit(&hAudioInDfsdmFilter[mic_num]); /* MIC filters initialization */ __HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&hAudioInDfsdmFilter[mic_num]); hAudioInDfsdmFilter[mic_num].Instance = FilterInstnace[mic_num]; hAudioInDfsdmFilter[mic_num].Init.RegularParam.Trigger = DFSDM_FILTER_SW_TRIGGER; hAudioInDfsdmFilter[mic_num].Init.RegularParam.FastMode = ENABLE; hAudioInDfsdmFilter[mic_num].Init.RegularParam.DmaMode = ENABLE; hAudioInDfsdmFilter[mic_num].Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER; hAudioInDfsdmFilter[mic_num].Init.InjectedParam.ScanMode = DISABLE; hAudioInDfsdmFilter[mic_num].Init.InjectedParam.DmaMode = DISABLE; hAudioInDfsdmFilter[mic_num].Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM8_TRGO; hAudioInDfsdmFilter[mic_num].Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_BOTH_EDGES; hAudioInDfsdmFilter[mic_num].Init.FilterParam.SincOrder = DFSDM_FILTER_ORDER(hAudioIn.Frequency); hAudioInDfsdmFilter[mic_num].Init.FilterParam.Oversampling = DFSDM_OVER_SAMPLING(hAudioIn.Frequency); hAudioInDfsdmFilter[mic_num].Init.FilterParam.IntOversampling = 1; if(HAL_OK != HAL_DFSDM_FilterInit(&hAudioInDfsdmFilter[mic_num])) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterInit(&hAudioInDfsdmFilter[mic_num])) { ... } HAL_DFSDM_ChannelDeInit(&hAudioInDfsdmChannel[mic_num]); /* MIC channels initialization */ __HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hAudioInDfsdmChannel[mic_num]); hAudioInDfsdmChannel[mic_num].Init.OutputClock.Activation = ENABLE; hAudioInDfsdmChannel[mic_num].Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO; hAudioInDfsdmChannel[mic_num].Init.OutputClock.Divider = DFSDM_CLOCK_DIVIDER(hAudioIn.Frequency); hAudioInDfsdmChannel[mic_num].Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS; hAudioInDfsdmChannel[mic_num].Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE; hAudioInDfsdmChannel[mic_num].Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL; hAudioInDfsdmChannel[mic_num].Init.Awd.FilterOrder = DFSDM_CHANNEL_SINC1_ORDER; hAudioInDfsdmChannel[mic_num].Init.Awd.Oversampling = 10; hAudioInDfsdmChannel[mic_num].Init.Offset = 0; hAudioInDfsdmChannel[mic_num].Init.RightBitShift = DFSDM_MIC_BIT_SHIFT(hAudioIn.Frequency); hAudioInDfsdmChannel[mic_num].Instance = ChannelInstnace[mic_num]; hAudioInDfsdmChannel[mic_num].Init.Input.Pins = DigitalMicPins[mic_num]; hAudioInDfsdmChannel[mic_num].Init.SerialInterface.Type = DigitalMicType[mic_num]; if(HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInDfsdmChannel[mic_num])) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInDfsdmChannel[mic_num])) { ... } filter_ch = Channel4Filter[mic_num]; /* Configure injected channel */ if(HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInDfsdmFilter[mic_num], filter_ch, DFSDM_CONTINUOUS_CONV_ON)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInDfsdmFilter[mic_num], filter_ch, DFSDM_CONTINUOUS_CONV_ON)) { ... } }for (i = 0; i < hAudioIn.ChannelNbr; i++) { ... } return AUDIO_OK; }{ ... } /** * @brief Initializes the Digital Filter for Sigma-Delta Modulators interface (DFSDM). * @param InputDevice: The microphone to be configured. Can be INPUT_DEVICE_DIGITAL_MIC1..INPUT_DEVICE_DIGITAL_MIC5 * @param Params : pointer on additional configuration parameters, can be NULL. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ __weak uint8_t BSP_AUDIO_IN_ConfigDigitalMic(uint32_t InputDevice, void *Params) { /* Prevent unused argument(s) compilation warning */ UNUSED(Params); /* Default configuration of DFSDM filters and channels */ return(BSP_AUDIO_IN_ConfigMicDefault(InputDevice)); /* Note: This function can be called at application level and default configuration can be overwritten to fit user's need *//* ... */ }{ ... } /** * @brief Allocate channel buffer scratch * @param pScratch : pointer to scratch tables. * @param size: size of scratch buffer *//* ... */ uint8_t BSP_AUDIO_IN_AllocScratch (int32_t *pScratch, uint32_t size) { uint32_t idx; ScratchSize = size / DEFAULT_AUDIO_IN_CHANNEL_NBR; /* copy scratch pointers */ for (idx = 0; idx < DEFAULT_AUDIO_IN_CHANNEL_NBR ; idx++) { pScratchBuff[idx] = (int32_t *)(pScratch + idx * ScratchSize); }for (idx = 0; idx < DEFAULT_AUDIO_IN_CHANNEL_NBR ; idx++) { ... } /* Return AUDIO_OK */ return AUDIO_OK; }{ ... } /** * @brief Starts audio recording. * @param pBuf: Main buffer pointer for the recorded data storing * @param size: Current size of the recorded buffer * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_Record(uint16_t *pBuf, uint32_t size) { hAudioIn.pRecBuf = pBuf; hAudioIn.RecSize = size; /* Reset Application Buffer Trigger */ AppBuffTrigger = 0; AppBuffHalf = 0; if (hAudioIn.InputDevice == INPUT_DEVICE_DIGITAL_MIC) { /* Call the Media layer start function for MIC1 channel */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], ScratchSize)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], ScratchSize)) { ... } /* Call the Media layer start function for MIC2 channel */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], ScratchSize)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], ScratchSize)) { ... } }if (hAudioIn.InputDevice == INPUT_DEVICE_DIGITAL_MIC) { ... } else { /* Start the process to receive the DMA */ if (HAL_OK != HAL_I2SEx_TransmitReceive_DMA(&haudio_i2s, pBuf, pBuf, size)) { return AUDIO_ERROR; }if (HAL_OK != HAL_I2SEx_TransmitReceive_DMA(&haudio_i2s, pBuf, pBuf, size)) { ... } }else { ... } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }{ ... } /** * @brief Starts audio recording. * @param pBuf: Main buffer pointer for the recorded data storing * @param size: Current size of the recorded buffer * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_RecordEx(uint32_t *pBuf, uint32_t size) { uint8_t ret = AUDIO_ERROR; hAudioIn.RecSize = size; uint32_t i = 0; uint32_t mic_init[DFSDM_MIC_NUMBER] = {0}; if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { return ret; }if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { ... } else { hAudioIn.MultiBuffMode = 1; for(i = 0; i < hAudioIn.ChannelNbr; i++) { if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] != 1)) { /* Call the Media layer start function for MIC1 channel 1 */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], (int32_t*)pBuf[i], size)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], (int32_t*)pBuf[i], size)) { ... } MicBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] = i; mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] = 1; }if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] != 1)) { ... } else if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] != 1)) { /* Call the Media layer start function for MIC2 channel 1 */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], (int32_t*)pBuf[i], size)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], (int32_t*)pBuf[i], size)) { ... } MicBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] = i; mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] = 1; }else if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] != 1)) { ... } else if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)] != 1)) { /* Call the Media layer start function for MIC3 channel 0 */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)], (int32_t*)pBuf[i], size)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)], (int32_t*)pBuf[i], size)) { ... } MicBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)] = i; mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)] = 1; }else if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)] != 1)) { ... } else if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)] != 1)) { /* Call the Media layer start function for MIC4 channel 7 */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)], (int32_t*)pBuf[i], size)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)], (int32_t*)pBuf[i], size)) { ... } MicBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)] = i; mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)] = 1; }else if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)] != 1)) { ... } else if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)] != 1)) { /* Call the Media layer start function for MIC5 channel 6 */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)], (int32_t*)pBuf[i], size)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)], (int32_t*)pBuf[i], size)) { ... } MicBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)] = i; mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)] = 1; }else if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)] != 1)) { ... } }for (i = 0; i < hAudioIn.ChannelNbr; i++) { ... } }else { ... } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }{ ... } /** * @brief Initializes the I2S MSP. *//* ... */ static void I2Sx_In_MspInit(void) { static DMA_HandleTypeDef hdma_i2s_rx; GPIO_InitTypeDef gpio_init_structure; /* Enable I2S clock */ AUDIO_IN_I2Sx_CLK_ENABLE(); /* Enable MCK GPIO clock, needed by the codec */ AUDIO_OUT_I2Sx_MCK_GPIO_CLK_ENABLE(); /* CODEC_I2S pins configuration: MCK pins */ gpio_init_structure.Pin = AUDIO_OUT_I2Sx_MCK_PIN; gpio_init_structure.Mode = GPIO_MODE_AF_PP; gpio_init_structure.Pull = GPIO_NOPULL; gpio_init_structure.Speed = GPIO_SPEED_FAST; gpio_init_structure.Alternate = AUDIO_OUT_I2Sx_MCK_AF; HAL_GPIO_Init(AUDIO_OUT_I2Sx_MCK_GPIO_PORT, &gpio_init_structure); /* Enable SD GPIO clock */ AUDIO_IN_I2Sx_EXT_SD_GPIO_CLK_ENABLE(); /* CODEC_I2S pin configuration: SD pin */ gpio_init_structure.Pin = AUDIO_IN_I2Sx_EXT_SD_PIN; gpio_init_structure.Alternate = AUDIO_IN_I2Sx_EXT_SD_AF; HAL_GPIO_Init(AUDIO_IN_I2Sx_EXT_SD_GPIO_PORT, &gpio_init_structure); /* Enable the DMA clock */ AUDIO_IN_I2Sx_DMAx_CLK_ENABLE(); if(haudio_i2s.Instance == AUDIO_IN_I2Sx) { /* Configure the hdma_i2s_rx handle parameters */ hdma_i2s_rx.Init.Channel = AUDIO_IN_I2Sx_DMAx_CHANNEL; hdma_i2s_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_i2s_rx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_i2s_rx.Init.MemInc = DMA_MINC_ENABLE; hdma_i2s_rx.Init.PeriphDataAlignment = AUDIO_IN_I2Sx_DMAx_PERIPH_DATA_SIZE; hdma_i2s_rx.Init.MemDataAlignment = AUDIO_IN_I2Sx_DMAx_MEM_DATA_SIZE; hdma_i2s_rx.Init.Mode = DMA_CIRCULAR; hdma_i2s_rx.Init.Priority = DMA_PRIORITY_HIGH; hdma_i2s_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_i2s_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; hdma_i2s_rx.Init.MemBurst = DMA_MBURST_SINGLE; hdma_i2s_rx.Init.PeriphBurst = DMA_MBURST_SINGLE; hdma_i2s_rx.Instance = AUDIO_IN_I2Sx_DMAx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(&haudio_i2s, hdmarx, hdma_i2s_rx); /* Deinitialize the Stream for new transfer */ HAL_DMA_DeInit(&hdma_i2s_rx); /* Configure the DMA Stream */ HAL_DMA_Init(&hdma_i2s_rx); }if (haudio_i2s.Instance == AUDIO_IN_I2Sx) { ... } /* I2S DMA IRQ Channel configuration */ HAL_NVIC_SetPriority(AUDIO_IN_I2Sx_DMAx_IRQ, AUDIO_IN_IRQ_PREPRIO, 0); HAL_NVIC_EnableIRQ(AUDIO_IN_I2Sx_DMAx_IRQ); }{ ... } /** * @brief De-Initializes the I2S MSP. *//* ... */ static void I2Sx_In_MspDeInit(void) { GPIO_InitTypeDef gpio_init_structure; /* I2S DMA IRQ Channel deactivation */ HAL_NVIC_DisableIRQ(AUDIO_IN_I2Sx_DMAx_IRQ); if(haudio_i2s.Instance == AUDIO_IN_I2Sx) { /* Deinitialize the DMA stream */ HAL_DMA_DeInit(haudio_i2s.hdmarx); }if (haudio_i2s.Instance == AUDIO_IN_I2Sx) { ... } /* Disable I2S peripheral */ __HAL_I2S_DISABLE(&haudio_i2s); /* Deactives CODEC_I2S pins MCK by putting them in input mode */ gpio_init_structure.Pin = AUDIO_OUT_I2Sx_MCK_PIN; HAL_GPIO_DeInit(AUDIO_OUT_I2Sx_MCK_GPIO_PORT, gpio_init_structure.Pin); gpio_init_structure.Pin = AUDIO_IN_I2Sx_EXT_SD_PIN; HAL_GPIO_DeInit(AUDIO_IN_I2Sx_EXT_SD_GPIO_PORT, gpio_init_structure.Pin); /* Disable I2S clock */ AUDIO_IN_I2Sx_CLK_DISABLE(); }{ ... } /** * @brief Initializes BSP_AUDIO_IN MSP. * @param Params : pointer on additional configuration parameters, can be NULL. *//* ... */ __weak void BSP_AUDIO_IN_MspInit(void *Params) { /* Prevent unused argument(s) compilation warning */ UNUSED(Params); if(hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { I2Sx_In_MspInit(); }if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { ... } else { /* MSP channels initialization */ DFSDMx_ChannelMspInit(); /* MSP filters initialization */ DFSDMx_FilterMspInit(); }else { ... } }{ ... } /** * @brief De-Initializes BSP_AUDIO_IN MSP. * @param Params : pointer on additional configuration parameters, can be NULL. *//* ... */ __weak void BSP_AUDIO_IN_MspDeInit(void *Params) { /* Prevent unused argument(s) compilation warning */ UNUSED(Params); if(hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { I2Sx_In_MspDeInit(); }if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { ... } else { /* MSP channels initialization */ DFSDMx_ChannelMspDeInit(); /* MSP filters initialization */ DFSDMx_FilterMspDeInit(); }else { ... } }{ ... } /** * @brief Clock Config. * @param AudioFreq: Audio frequency used to play the audio stream. * @param Params : pointer on additional configuration parameters, can be NULL. * @note This API is called by BSP_AUDIO_OUT_Init() and BSP_AUDIO_OUT_SetFrequency() * Being __weak it can be overwritten by the application * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ __weak uint8_t BSP_AUDIO_IN_ClockConfig(uint32_t AudioFreq, void *Params) { RCC_PeriphCLKInitTypeDef rcc_ex_clk_init_struct; /* Prevent unused argument(s) compilation warning */ UNUSED(Params); HAL_RCCEx_GetPeriphCLKConfig(&rcc_ex_clk_init_struct); /* Set the PLL configuration according to the audio frequency */ if((AudioFreq == AUDIO_FREQUENCY_11K) || (AudioFreq == AUDIO_FREQUENCY_22K) || (AudioFreq == AUDIO_FREQUENCY_44K)) { /* Configure PLLI2S prescalers */ rcc_ex_clk_init_struct.PeriphClockSelection = (RCC_PERIPHCLK_I2S_APB1 | RCC_PERIPHCLK_DFSDM | RCC_PERIPHCLK_DFSDM2); rcc_ex_clk_init_struct.I2sApb1ClockSelection = RCC_I2SAPB1CLKSOURCE_PLLI2S; rcc_ex_clk_init_struct.Dfsdm1ClockSelection = RCC_DFSDM1CLKSOURCE_APB2; rcc_ex_clk_init_struct.Dfsdm2ClockSelection = RCC_DFSDM2CLKSOURCE_APB2; rcc_ex_clk_init_struct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC; rcc_ex_clk_init_struct.PLLI2S.PLLI2SM = 8; rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 271; rcc_ex_clk_init_struct.PLLI2S.PLLI2SR = 2; HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct); }if ((AudioFreq == AUDIO_FREQUENCY_11K) || (AudioFreq == AUDIO_FREQUENCY_22K) || (AudioFreq == AUDIO_FREQUENCY_44K)) { ... } else if(AudioFreq == AUDIO_FREQUENCY_96K) { /* I2S clock config */ rcc_ex_clk_init_struct.PeriphClockSelection = (RCC_PERIPHCLK_I2S_APB1 | RCC_PERIPHCLK_DFSDM | RCC_PERIPHCLK_DFSDM2); rcc_ex_clk_init_struct.I2sApb1ClockSelection = RCC_I2SAPB1CLKSOURCE_PLLI2S; rcc_ex_clk_init_struct.Dfsdm1ClockSelection = RCC_DFSDM1CLKSOURCE_APB2; rcc_ex_clk_init_struct.Dfsdm2ClockSelection = RCC_DFSDM2CLKSOURCE_APB2; rcc_ex_clk_init_struct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC; rcc_ex_clk_init_struct.PLLI2S.PLLI2SM = 8; rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 344; rcc_ex_clk_init_struct.PLLI2S.PLLI2SR = 2; HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct); }else if (AudioFreq == AUDIO_FREQUENCY_96K) { ... } else /* AUDIO_FREQUENCY_8K, AUDIO_FREQUENCY_16K, AUDIO_FREQUENCY_32K, AUDIO_FREQUENCY_48K */ { /* I2S clock config PLLI2S_VCO: VCO_344M I2S_CLK(first level) = PLLI2S_VCO/PLLI2SR = 344/7 = 49.142 Mhz I2S_CLK_x = I2S_CLK(first level)/PLLI2SDIVR = 49.142/1 = 49.142 Mhz *//* ... */ rcc_ex_clk_init_struct.PeriphClockSelection = (RCC_PERIPHCLK_I2S_APB1 | RCC_PERIPHCLK_DFSDM | RCC_PERIPHCLK_DFSDM2); rcc_ex_clk_init_struct.I2sApb1ClockSelection = RCC_I2SAPB1CLKSOURCE_PLLI2S; rcc_ex_clk_init_struct.DfsdmClockSelection = RCC_DFSDM1CLKSOURCE_APB2|RCC_DFSDM2CLKSOURCE_APB2; rcc_ex_clk_init_struct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC; rcc_ex_clk_init_struct.PLLI2S.PLLI2SM = 8; rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 344; rcc_ex_clk_init_struct.PLLI2S.PLLI2SR = 7; HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct); }else { ... } if(hAudioIn.InputDevice != INPUT_DEVICE_ANALOG_MIC) { /* I2S_APB1 selected as DFSDM audio clock source */ __HAL_RCC_DFSDM1AUDIO_CONFIG(RCC_DFSDM1AUDIOCLKSOURCE_I2SAPB1); /* I2S_APB1 selected as DFSDM audio clock source */ __HAL_RCC_DFSDM2AUDIO_CONFIG(RCC_DFSDM2AUDIOCLKSOURCE_I2SAPB1); }if (hAudioIn.InputDevice != INPUT_DEVICE_ANALOG_MIC) { ... } return AUDIO_OK; }{ ... } /** * @brief Regular conversion complete callback. * @note In interrupt mode, user has to read conversion value in this function using HAL_DFSDM_FilterGetRegularValue. * @param hdfsdm_filter : DFSDM filter handle. *//* ... */ void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) { uint32_t index, input_device = 0; if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC1_FILTER) { DmaRecBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] = 1; input_device = INPUT_DEVICE_DIGITAL_MIC1; }if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC1_FILTER) { ... } else if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC2_FILTER) { DmaRecBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] = 1; input_device = INPUT_DEVICE_DIGITAL_MIC2; }else if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC2_FILTER) { ... } else if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC3_FILTER) { input_device = INPUT_DEVICE_DIGITAL_MIC3; }else if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC3_FILTER) { ... } else if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC4_FILTER) { input_device = INPUT_DEVICE_DIGITAL_MIC4; }else if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC4_FILTER) { ... } else if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC5_FILTER) { input_device = INPUT_DEVICE_DIGITAL_MIC5; }else if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC5_FILTER) { ... } if(hAudioIn.MultiBuffMode == 1) { BSP_AUDIO_IN_TransferComplete_CallBackEx(input_device); }if (hAudioIn.MultiBuffMode == 1) { ... } else { if((DmaRecBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] == 1) && (DmaRecBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] == 1)) { if(AppBuffTrigger >= hAudioIn.RecSize) AppBuffTrigger = 0; for(index = (ScratchSize/2) ; index < ScratchSize; index++) { hAudioIn.pRecBuf[AppBuffTrigger] = (uint16_t)(SaturaLH((pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)][index] >> 8), -32760, 32760)); hAudioIn.pRecBuf[AppBuffTrigger + 1] = (uint16_t)(SaturaLH((pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)][index] >> 8), -32760, 32760)); AppBuffTrigger += 2; }for (index = (ScratchSize/2) ; index < ScratchSize; index++) { ... } DmaRecBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] = DmaRecBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] = 0; }if ((DmaRecBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] == 1) && (DmaRecBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] == 1)) { ... } /* Update Trigger with Remaining Byte before callback if necessary */ if(AppBuffTrigger >= hAudioIn.RecSize) { /* Reset Application Buffer Trigger */ AppBuffTrigger = 0; AppBuffHalf = 0; /* Call the record update function to get the next buffer to fill and its size (size is ignored) */ BSP_AUDIO_IN_TransferComplete_CallBack(); }if (AppBuffTrigger >= hAudioIn.RecSize) { ... } else if((AppBuffTrigger >= hAudioIn.RecSize/2)) { if(AppBuffHalf == 0) { AppBuffHalf = 1; /* Manage the remaining file size and new address offset: This function should be coded by user (its prototype is already declared in stm32l476g_eval_audio.h) *//* ... */ BSP_AUDIO_IN_HalfTransfer_CallBack(); }if (AppBuffHalf == 0) { ... } }else if ((AppBuffTrigger >= hAudioIn.RecSize/2)) { ... } }else { ... } }{ ... } /** * @brief Half regular conversion complete callback. * @param hdfsdm_filter : DFSDM filter handle. *//* ... */ void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) { uint32_t index, input_device = 0; if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC1_FILTER) { DmaRecHalfBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] = 1; input_device = INPUT_DEVICE_DIGITAL_MIC1; }if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC1_FILTER) { ... } else if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC2_FILTER) { DmaRecHalfBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] = 1; input_device = INPUT_DEVICE_DIGITAL_MIC2; }else if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC2_FILTER) { ... } else if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC3_FILTER) { input_device = INPUT_DEVICE_DIGITAL_MIC3; }else if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC3_FILTER) { ... } else if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC4_FILTER) { input_device = INPUT_DEVICE_DIGITAL_MIC4; }else if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC4_FILTER) { ... } else if(hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC5_FILTER) { input_device = INPUT_DEVICE_DIGITAL_MIC5; }else if (hdfsdm_filter->Instance == AUDIO_DFSDMx_MIC5_FILTER) { ... } if(hAudioIn.MultiBuffMode == 1) { BSP_AUDIO_IN_HalfTransfer_CallBackEx(input_device); }if (hAudioIn.MultiBuffMode == 1) { ... } else { if((DmaRecHalfBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] == 1) && (DmaRecHalfBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] == 1)) { if(AppBuffTrigger >= hAudioIn.RecSize) AppBuffTrigger = 0; for(index = 0; index < ScratchSize/2; index++) { hAudioIn.pRecBuf[AppBuffTrigger] = (int16_t)(SaturaLH((pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)][index] >> 8), -32760, 32760)); hAudioIn.pRecBuf[AppBuffTrigger + 1] = (int16_t)(SaturaLH((pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)][index] >> 8), -32760, 32760)); AppBuffTrigger += 2; }for (index = 0; index < ScratchSize/2; index++) { ... } DmaRecHalfBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] = DmaRecHalfBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] = 0; }if ((DmaRecHalfBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] == 1) && (DmaRecHalfBuffCplt[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] == 1)) { ... } /* Update Trigger with Remaining Byte before callback if necessary */ if(AppBuffTrigger >= hAudioIn.RecSize) { /* Reset Application Buffer Trigger */ AppBuffTrigger = 0; AppBuffHalf = 0; /* Call the record update function to get the next buffer to fill and its size (size is ignored) */ BSP_AUDIO_IN_TransferComplete_CallBack(); }if (AppBuffTrigger >= hAudioIn.RecSize) { ... } else if((AppBuffTrigger >= hAudioIn.RecSize/2)) { if(AppBuffHalf == 0) { AppBuffHalf = 1; /* Manage the remaining file size and new address offset: This function should be coded by user *//* ... */ BSP_AUDIO_IN_HalfTransfer_CallBack(); }if (AppBuffHalf == 0) { ... } }else if ((AppBuffTrigger >= hAudioIn.RecSize/2)) { ... } }else { ... } }{ ... } /** * @brief Half reception complete callback. * @param hi2s : I2S handle. *//* ... */ void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) { /* Manage the remaining file size and new address offset: This function should be coded by user (its prototype is already declared in stm32746g_discovery_audio.h) *//* ... */ BSP_AUDIO_IN_HalfTransfer_CallBack(); }{ ... } /** * @brief Reception complete callback. * @param hi2s : I2S handle. *//* ... */ void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) { /* Call the record update function to get the next buffer to fill and its size (size is ignored) */ BSP_AUDIO_IN_TransferComplete_CallBack(); }{ ... } /** * @brief Stops audio recording. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_Stop(void) { AppBuffTrigger = 0; AppBuffHalf = 0; if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { /* Call the Media layer stop function */ if(HAL_OK != HAL_I2S_DMAStop(&haudio_i2s)) { return AUDIO_ERROR; }if (HAL_OK != HAL_I2S_DMAStop(&haudio_i2s)) { ... } /* Call Audio Codec Stop function */ if(audio_drv->Stop(AUDIO_I2C_ADDRESS, CODEC_PDWN_HW) != 0) { return AUDIO_ERROR; }if (audio_drv->Stop(AUDIO_I2C_ADDRESS, CODEC_PDWN_HW) != 0) { ... } /* Wait at least 100us */ HAL_Delay(1); }if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { ... } else /* InputDevice = Digital Mic */ { /* Call the Media layer stop function for MIC1 channel */ if(AUDIO_OK != BSP_AUDIO_IN_PauseEx(INPUT_DEVICE_DIGITAL_MIC1)) { return AUDIO_ERROR; }if (AUDIO_OK != BSP_AUDIO_IN_PauseEx(INPUT_DEVICE_DIGITAL_MIC1)) { ... } /* Call the Media layer stop function for MIC2 channel */ if(AUDIO_OK != BSP_AUDIO_IN_PauseEx(INPUT_DEVICE_DIGITAL_MIC2)) { return AUDIO_ERROR; }if (AUDIO_OK != BSP_AUDIO_IN_PauseEx(INPUT_DEVICE_DIGITAL_MIC2)) { ... } }else { ... } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }{ ... } /** * @brief Stops audio recording. * @param InputDevice: Microphone to be stopped. Can be INPUT_DEVICE_DIGITAL_MIC1 .. INPUT_DEVICE_DIGITAL_MIC5. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_StopEx(uint32_t InputDevice) { if((InputDevice < INPUT_DEVICE_DIGITAL_MIC1) || (InputDevice > INPUT_DEVICE_DIGITAL_MIC5)) { return AUDIO_ERROR; }if ((InputDevice < INPUT_DEVICE_DIGITAL_MIC1) || (InputDevice > INPUT_DEVICE_DIGITAL_MIC5)) { ... } else { BSP_AUDIO_IN_PauseEx(InputDevice); }else { ... } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }{ ... } /** * @brief Pauses the audio file stream. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_Pause(void) { if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { return AUDIO_ERROR; }if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { ... } else { /* Call the Media layer stop function */ if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)])) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)])) { ... } /* Call the Media layer stop function */ if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)])) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)])) { ... } }else { ... } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }{ ... } /** * @brief Pauses the audio file stream. * @param InputDevice: Microphone to be paused. Can be INPUT_DEVICE_DIGITAL_MIC1 .. INPUT_DEVICE_DIGITAL_MIC5. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_PauseEx(uint32_t InputDevice) { if((InputDevice < INPUT_DEVICE_DIGITAL_MIC1) || (InputDevice > INPUT_DEVICE_DIGITAL_MIC5)) { return AUDIO_ERROR; }if ((InputDevice < INPUT_DEVICE_DIGITAL_MIC1) || (InputDevice > INPUT_DEVICE_DIGITAL_MIC5)) { ... } else { /* Call the Media layer stop function */ if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInDfsdmFilter[POS_VAL(InputDevice)])) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInDfsdmFilter[POS_VAL(InputDevice)])) { ... } }else { ... } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }{ ... } /** * @brief Resumes the audio file stream. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_Resume(void) { if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { return AUDIO_ERROR; }if (hAudioIn.InputDevice == INPUT_DEVICE_ANALOG_MIC) { ... } else { /* Call the Media layer start function for MIC2 channel */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], ScratchSize)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)], ScratchSize)) { ... } /* Call the Media layer start function for MIC1 channel */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], ScratchSize)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], pScratchBuff[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)], ScratchSize)) { ... } }else { ... } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }{ ... } /** * @brief Resumes the audio file stream. * @param pBuf: Main buffer pointer for the recorded data storing * @param InputDevice: Microphone to be paused. Can be INPUT_DEVICE_DIGITAL_MIC1 .. INPUT_DEVICE_DIGITAL_MIC5. * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_ResumeEx(uint32_t *pBuf, uint32_t InputDevice) { if((InputDevice < INPUT_DEVICE_DIGITAL_MIC1) || (InputDevice > INPUT_DEVICE_DIGITAL_MIC5)) { return AUDIO_ERROR; }if ((InputDevice < INPUT_DEVICE_DIGITAL_MIC1) || (InputDevice > INPUT_DEVICE_DIGITAL_MIC5)) { ... } else { /* Call the Media layer stop function */ if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(InputDevice)], (int32_t*)pBuf[MicBuff[POS_VAL(InputDevice)]], hAudioIn.RecSize)) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInDfsdmFilter[POS_VAL(InputDevice)], (int32_t*)pBuf[MicBuff[POS_VAL(InputDevice)]], hAudioIn.RecSize)) { ... } }else { ... } /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }{ ... } /** * @brief Controls the audio in volume level. * @param Volume: Volume level to be set in percentage from 0% to 100% (0 for * Mute and 100 for Max volume level). * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume) { /* Set the Global variable AudioInVolume */ AudioInVolume = Volume; /* Return AUDIO_OK when all operations are correctly done */ return AUDIO_OK; }{ ... } /** * @brief User callback when record buffer is filled. *//* ... */ __weak void BSP_AUDIO_IN_TransferComplete_CallBack(void) { /* This function should be implemented by the user application. It is called into this driver when the current buffer is filled to prepare the next buffer pointer and its size. *//* ... */ }{ ... } /** * @brief Manages the DMA Half Transfer complete event. *//* ... */ __weak void BSP_AUDIO_IN_HalfTransfer_CallBack(void) { /* This function should be implemented by the user application. It is called into this driver when the current buffer is filled to prepare the next buffer pointer and its size. *//* ... */ }{ ... } /** * @brief User callback when record buffer is filled. * @param InputDevice: INPUT_DEVICE_DIGITAL_MIC1 .. INPUT_DEVICE_DIGITAL_MIC5. *//* ... */ __weak void BSP_AUDIO_IN_TransferComplete_CallBackEx(uint32_t InputDevice) { /* This function should be implemented by the user application. It is called into this driver when the current buffer is filled to prepare the next buffer pointer and its size. *//* ... */ }{ ... } /** * @brief User callback when record buffer is filled. * @param InputDevice: INPUT_DEVICE_DIGITAL_MIC1 .. INPUT_DEVICE_DIGITAL_MIC5. *//* ... */ __weak void BSP_AUDIO_IN_HalfTransfer_CallBackEx(uint32_t InputDevice) { /* This function should be implemented by the user application. It is called into this driver when the current buffer is filled to prepare the next buffer pointer and its size. *//* ... */ }{ ... } /** * @brief Audio IN Error callback function. *//* ... */ __weak void BSP_AUDIO_IN_Error_Callback(void) { /* This function is called when an Interrupt due to transfer error on or peripheral error occurs. *//* ... */ }{ ... } /** * @} *//* ... */ /******************************************************************************* Static Functions *******************************************************************************//* ... */ /** * @brief De-initializes the Digital Filter for Sigma-Delta Modulators interface (DFSDM). * @retval AUDIO_OK if correct communication, else wrong communication *//* ... */ static uint8_t DFSDMx_DeInit(void) { for(uint32_t i = 0; i < DFSDM_MIC_NUMBER; i++) { if(hAudioInDfsdmFilter[i].Instance != NULL) { if(HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInDfsdmFilter[i])) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInDfsdmFilter[i])) { ... } hAudioInDfsdmFilter[i].Instance = NULL; }if (hAudioInDfsdmFilter[i].Instance != NULL) { ... } if(hAudioInDfsdmChannel[i].Instance != NULL) { if(HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInDfsdmChannel[i])) { return AUDIO_ERROR; }if (HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInDfsdmChannel[i])) { ... } hAudioInDfsdmChannel[i].Instance = NULL; }if (hAudioInDfsdmChannel[i].Instance != NULL) { ... } }for (uint32_t i = 0; i < DFSDM_MIC_NUMBER; i++) { ... } return AUDIO_OK; }{ ... } /** * @brief Initializes the DFSDM channel MSP. *//* ... */ static void DFSDMx_ChannelMspInit(void) { GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; if((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) { /* Enable DFSDM clock */ AUDIO_DFSDMx_MIC1_CLK_ENABLE(); /* Enable GPIO clock */ AUDIO_DFSDMx_MIC1_CKOUT_DMIC_GPIO_CLK_ENABLE(); /* DFSDM MIC1 pins configuration: DFSDM_CKOUT, DMIC_DATIN pins -------------*/ GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC1_CKOUT_PIN; GPIO_InitStruct.Alternate = AUDIO_DFSDMx_MIC1_CKOUT_DMIC_AF; HAL_GPIO_Init(AUDIO_DFSDMx_MIC1_CKOUT_DMIC_GPIO_PORT, &GPIO_InitStruct); AUDIO_DFSDMx_MIC1_DMIC_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC1_DMIC_PIN; GPIO_InitStruct.Alternate = AUDIO_DFSDMx_MIC1_DMIC_AF; HAL_GPIO_Init(AUDIO_DFSDMx_MIC1_DMIC_GPIO_PORT, &GPIO_InitStruct); }if ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) { ... } if(hAudioIn.InputDevice > INPUT_DEVICE_DIGITAL_MIC1) { /* Enable DFSDM clock */ AUDIO_DFSDMx_MIC2_5_CLK_ENABLE(); /* Enable GPIO clock */ AUDIO_DFSDMx_MIC2_5_CKOUT_DMIC_GPIO_CLK_ENABLE(); /* DFSDM MIC2 pins configuration: DFSDM_CKOUT, DMIC_DATIN pins -------------*/ GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC2_5_CKOUT_PIN; GPIO_InitStruct.Alternate = AUDIO_DFSDMx_MIC2_5_CKOUT_DMIC_AF; HAL_GPIO_Init(AUDIO_DFSDMx_MIC2_5_CKOUT_DMIC_GPIO_PORT, &GPIO_InitStruct); if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) ||\ ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3)) { AUDIO_DFSDMx_MIC23_DMIC_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC23_DMIC_PIN; GPIO_InitStruct.Alternate = AUDIO_DFSDMx_MIC23_DMIC_AF; HAL_GPIO_Init(AUDIO_DFSDMx_MIC23_DMIC_GPIO_PORT, &GPIO_InitStruct); }if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) ||\ ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3)) { ... } if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) ||\ ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5)) { AUDIO_DFSDMx_MIC45_DMIC_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC45_DMIC_PIN; GPIO_InitStruct.Alternate = AUDIO_DFSDMx_MIC45_DMIC_AF; HAL_GPIO_Init(AUDIO_DFSDMx_MIC45_DMIC_GPIO_PORT, &GPIO_InitStruct); }if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) ||\ ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5)) { ... } }if (hAudioIn.InputDevice > INPUT_DEVICE_DIGITAL_MIC1) { ... } }{ ... } /** * @brief DeInitializes the DFSDM channel MSP. *//* ... */ static void DFSDMx_ChannelMspDeInit(void) { GPIO_InitTypeDef GPIO_InitStruct; if((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) { /* DFSDM MIC1 pins configuration: DFSDM_CKOUT, DMIC_DATIN pins -------------*/ GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC1_CKOUT_PIN; HAL_GPIO_DeInit(AUDIO_DFSDMx_MIC1_CKOUT_DMIC_GPIO_PORT, GPIO_InitStruct.Pin); GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC1_DMIC_PIN; HAL_GPIO_DeInit(AUDIO_DFSDMx_MIC1_DMIC_GPIO_PORT, GPIO_InitStruct.Pin); }if ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) { ... } if(hAudioIn.InputDevice > INPUT_DEVICE_DIGITAL_MIC1) { /* DFSDM MIC2, MIC3, MIC4 and MIC5 pins configuration: DFSDM_CKOUT pin -----*/ GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC2_5_CKOUT_PIN; HAL_GPIO_DeInit(AUDIO_DFSDMx_MIC2_5_CKOUT_DMIC_GPIO_PORT, GPIO_InitStruct.Pin); if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) ||\ ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3)) { /* DFSDM MIC2, MIC3 pins configuration: DMIC_DATIN pin -----*/ GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC23_DMIC_PIN; HAL_GPIO_DeInit(AUDIO_DFSDMx_MIC23_DMIC_GPIO_PORT, GPIO_InitStruct.Pin); }if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) ||\ ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3)) { ... } if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) ||\ ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5)) { /* DFSDM MIC4, MIC5 pins configuration: DMIC_DATIN pin -----*/ GPIO_InitStruct.Pin = AUDIO_DFSDMx_MIC45_DMIC_PIN; HAL_GPIO_DeInit(AUDIO_DFSDMx_MIC45_DMIC_GPIO_PORT, GPIO_InitStruct.Pin); }if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) ||\ ((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5)) { ... } }if (hAudioIn.InputDevice > INPUT_DEVICE_DIGITAL_MIC1) { ... } }{ ... } /** * @brief Initializes the DFSDM filter MSP. *//* ... */ static void DFSDMx_FilterMspInit(void) { uint32_t i = 0, mic_num = 0, mic_init[DFSDM_MIC_NUMBER] = {0}; IRQn_Type AUDIO_DFSDM_DMAx_MIC_IRQHandler[DFSDM_MIC_NUMBER] = {AUDIO_DFSDMx_DMAx_MIC1_IRQ, AUDIO_DFSDMx_DMAx_MIC2_IRQ, AUDIO_DFSDMx_DMAx_MIC3_IRQ, AUDIO_DFSDMx_DMAx_MIC4_IRQ, AUDIO_DFSDMx_DMAx_MIC5_IRQ}; DMA_Stream_TypeDef* AUDIO_DFSDMx_DMAx_MIC_STREAM[DFSDM_MIC_NUMBER] = {AUDIO_DFSDMx_DMAx_MIC1_STREAM, AUDIO_DFSDMx_DMAx_MIC2_STREAM, AUDIO_DFSDMx_DMAx_MIC3_STREAM, AUDIO_DFSDMx_DMAx_MIC4_STREAM, AUDIO_DFSDMx_DMAx_MIC5_STREAM}; uint32_t AUDIO_DFSDMx_DMAx_MIC_CHANNEL[DFSDM_MIC_NUMBER] = {AUDIO_DFSDMx_DMAx_MIC1_CHANNEL, AUDIO_DFSDMx_DMAx_MIC2_CHANNEL, AUDIO_DFSDMx_DMAx_MIC3_CHANNEL, AUDIO_DFSDMx_DMAx_MIC4_CHANNEL, AUDIO_DFSDMx_DMAx_MIC5_CHANNEL}; /* Enable the DMA clock */ AUDIO_DFSDMx_DMAx_CLK_ENABLE(); for(i = 0; i < hAudioIn.ChannelNbr; i++) { if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC1); mic_init[mic_num] = 1; }if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC1) == INPUT_DEVICE_DIGITAL_MIC1) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC1)] != 1)) { ... } else if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC2); mic_init[mic_num] = 1; }else if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC2) == INPUT_DEVICE_DIGITAL_MIC2) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC2)] != 1)) { ... } else if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC3); mic_init[mic_num] = 1; }else if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC3) == INPUT_DEVICE_DIGITAL_MIC3) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC3)] != 1)) { ... } else if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC4); mic_init[mic_num] = 1; }else if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC4) == INPUT_DEVICE_DIGITAL_MIC4) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC4)] != 1)) { ... } else if(((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)] != 1)) { mic_num = POS_VAL(INPUT_DEVICE_DIGITAL_MIC5); mic_init[mic_num] = 1; }else if (((hAudioIn.InputDevice & INPUT_DEVICE_DIGITAL_MIC5) == INPUT_DEVICE_DIGITAL_MIC5) && (mic_init[POS_VAL(INPUT_DEVICE_DIGITAL_MIC5)] != 1)) { ... } /* Configure the hDmaDfsdm[i] handle parameters */ hDmaDfsdm[mic_num].Init.Channel = AUDIO_DFSDMx_DMAx_MIC_CHANNEL[mic_num]; hDmaDfsdm[mic_num].Instance = AUDIO_DFSDMx_DMAx_MIC_STREAM[mic_num]; hDmaDfsdm[mic_num].Init.Direction = DMA_PERIPH_TO_MEMORY; hDmaDfsdm[mic_num].Init.PeriphInc = DMA_PINC_DISABLE; hDmaDfsdm[mic_num].Init.MemInc = DMA_MINC_ENABLE; hDmaDfsdm[mic_num].Init.PeriphDataAlignment = AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE; hDmaDfsdm[mic_num].Init.MemDataAlignment = AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE; hDmaDfsdm[mic_num].Init.Mode = DMA_CIRCULAR; hDmaDfsdm[mic_num].Init.Priority = DMA_PRIORITY_HIGH; hDmaDfsdm[mic_num].Init.FIFOMode = DMA_FIFOMODE_DISABLE; hDmaDfsdm[mic_num].Init.MemBurst = DMA_MBURST_SINGLE; hDmaDfsdm[mic_num].Init.PeriphBurst = DMA_PBURST_SINGLE; hDmaDfsdm[mic_num].State = HAL_DMA_STATE_RESET; /* Associate the DMA handle */ __HAL_LINKDMA(&hAudioInDfsdmFilter[mic_num], hdmaReg, hDmaDfsdm[mic_num]); /* Reset DMA handle state */ __HAL_DMA_RESET_HANDLE_STATE(&hDmaDfsdm[mic_num]); /* Configure the DMA Channel */ HAL_DMA_Init(&hDmaDfsdm[mic_num]); /* DMA IRQ Channel configuration */ HAL_NVIC_SetPriority(AUDIO_DFSDM_DMAx_MIC_IRQHandler[mic_num], AUDIO_IN_IRQ_PREPRIO, 0); HAL_NVIC_EnableIRQ(AUDIO_DFSDM_DMAx_MIC_IRQHandler[mic_num]); }for (i = 0; i < hAudioIn.ChannelNbr; i++) { ... } }{ ... } /** * @brief DeInitializes the DFSDM filter MSP. *//* ... */ static void DFSDMx_FilterMspDeInit(void) { /* Configure the DMA Channel */ for(uint32_t i = 0; i < DFSDM_MIC_NUMBER; i++) { if(hDmaDfsdm[i].Instance != NULL) { HAL_DMA_DeInit(&hDmaDfsdm[i]); }if (hDmaDfsdm[i].Instance != NULL) { ... } }for (uint32_t i = 0; i < DFSDM_MIC_NUMBER; i++) { ... } }{ ... } /** * @brief Initializes the Audio Codec audio interface (I2S) * @note This function assumes that the I2S input clock * is already configured and ready to be used. * @param AudioFreq: Audio frequency to be configured for the I2S peripheral. *//* ... */ static void I2Sx_In_Init(uint32_t AudioFreq) { /* Initialize the hAudioInI2s and haudio_in_i2sext Instance parameters */ haudio_i2s.Instance = AUDIO_IN_I2Sx; haudio_in_i2sext.Instance = I2S3ext; /* Disable I2S block */ __HAL_I2S_DISABLE(&haudio_i2s); __HAL_I2S_DISABLE(&haudio_in_i2sext); /* I2S peripheral configuration */ haudio_i2s.Init.AudioFreq = AudioFreq; haudio_i2s.Init.ClockSource = I2S_CLOCK_PLL; haudio_i2s.Init.CPOL = I2S_CPOL_LOW; haudio_i2s.Init.DataFormat = I2S_DATAFORMAT_16B; haudio_i2s.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE; haudio_i2s.Init.Mode = I2S_MODE_MASTER_TX; haudio_i2s.Init.Standard = I2S_STANDARD_PHILIPS; haudio_i2s.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_ENABLE; /* Init the I2S */ HAL_I2S_Init(&haudio_i2s); /* I2Sext peripheral configuration */ haudio_in_i2sext.Init.AudioFreq = AudioFreq; haudio_in_i2sext.Init.ClockSource = I2S_CLOCK_PLL; haudio_in_i2sext.Init.CPOL = I2S_CPOL_HIGH; haudio_in_i2sext.Init.DataFormat = I2S_DATAFORMAT_16B; haudio_in_i2sext.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE; haudio_in_i2sext.Init.Mode = I2S_MODE_SLAVE_RX; haudio_in_i2sext.Init.Standard = I2S_STANDARD_PHILIPS; /* Init the I2Sext */ HAL_I2S_Init(&haudio_in_i2sext); /* Enable I2S block */ __HAL_I2S_ENABLE(&haudio_i2s); __HAL_I2S_ENABLE(&haudio_in_i2sext); }{ ... } /** * @brief Deinitializes the Audio Codec audio interface (I2S). *//* ... */ static void I2Sx_In_DeInit(void) { /* Initialize the hAudioInI2s Instance parameter */ haudio_i2s.Instance = AUDIO_IN_I2Sx; /* Disable I2S block */ __HAL_I2S_DISABLE(&haudio_i2s); /* DeInit the I2S */ HAL_I2S_DeInit(&haudio_i2s); /* Initialize the hAudioInI2s Instance parameter */ haudio_in_i2sext.Instance = I2S3ext; /* Disable I2S block */ __HAL_I2S_DISABLE(&haudio_in_i2sext); /* DeInit the I2S */ HAL_I2S_DeInit(&haudio_in_i2sext); }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */