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
211
212
222
223
224
225
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
252
253
254
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
300
301
302
303
307
308
309
310
311
312
313
314
315
316
317
326
327
329
330
331
332
333
334
335
336
337
340
341
342
343
344
345
346
347
348
349
350
351
352
353
359
360
361
362
366
367
368
369
370
371
372
373
374
375
376
382
383
385
386
387
388
389
390
391
392
393
394
395
396
402
410
411
417
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
459
460
461
462
463
464
468
472
476
480
484
488
492
496
500
507
508
509
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
573
577
581
585
589
593
597
601
605
612
613
614
635
636
637
638
639
640
641
642
643
644
645
646
647
648
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
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
774
779
780
781
782
783
787
792
797
798
799
800
801
805
806
807
808
809
810
811
812
813
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
844
845
846
847
848
849
850
851
852
853
854
855
856
857
862
867
868
869
870
871
875
879
880
881
882
886
887
892
904
905
906
907
908
909
910
911
912
913
914
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
949
950
953
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
982
989
990
991
992
993
994
995
996
997
998
1002
1003
1008
1013
1014
1015
1016
1017
1018
1019
1020
1024
1029
1030
1031
1035
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
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
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1152
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
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
1287
1288
1289
1290
1291
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
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
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1362
1363
1364
1365
1366
1367
1368
1369
1370
1375
1376
1377
1378
1379
1381
1382
1383
1385
1386
1387
1388
1389
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
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
1473
1474
1475
1476
1477
1479
1480
1481
1483
1484
1485
1486
1487
1491
1492
1493
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1539
1540
1541
1542
1547
1548
1549
1550
1551
1552
1553
1554
1555
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
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
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
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
1672
1673
1686
1687
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1712
1713
1714
1718
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1735
1736
1737
1742
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1766
1767
1769
1770
1771
1772
1773
1774
1775
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1807
1808
1809
1810
1816
1822
1828
1829
1833
1834
1835
1836
1837
1848
1850
1851
1852
1853
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1867
1868
1869
1874
1875
1876
1877
1878
1879
1881
1882
1884
1885
1886
1887
1888
1889
1890
1891
1893
1894
1896
1897
1898
1899
1900
1901
1902
1903
1905
1906
1908
1909
1910
1911
1912
1913
1914
1915
1929
1930
1935
1936
1937
1943
1951
1952
1958
1966
1967
1973
1981
1982
1988
1996
1997
2003
2011
2012
2018
2026
2027
2032
2033
2034
2035
2036
2037
2040
2041
2042
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2071
2075
2076
2082
2086
2087
2090
2093
2094
2097
2098
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2148
2149
2151
2152
2153
2154
2155
2156
2162
2163
2164
2165
2166
2167
2169
2170
2172
2173
2174
2175
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2195
2196
2197
2198
2199
2200
2201
2202
2204
2205
2207
2208
2209
2210
2211
2212
2213
2215
2216
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2230
2231
2233
2234
2235
2236
2237
2238
2239
2241
2242
2244
2245
2246
2247
2248
2249
2255
2256
2257
2258
2259
2260
2262
2263
2265
2266
2267
2268
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2287
2288
2289
2290
2294
2295
2296
2297
2298
2299
2301
2302
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2388
2389
2390
2391
2392
2393
2394
2395
2397
2398
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2440
2441
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2483
2484
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2508
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2527
2528
2529
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2548
2549
2551
2552
2553
2554
2555
2556
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2585
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2610
2611
2613
2614
2615
2616
2617
2624
2625
2626
2630
2631
2632
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2655
2659
2660
2661
2662
2663
2667
2668
2669
2670
2671
2672
2673
2674
2680
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2714
2715
2717
2718
2719
2720
2721
2722
2723
2724
2728
2729
2730
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2754
2755
2756
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2782
2783
2784
2785
2786
2787
2791
2792
2793
2799
2805
2811
2816
2817
2818
2821
2822
2823
2826
2827
2830
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
/* ... */
#ifdef HAL_USART_MODULE_ENABLEDIncludes
/* ... */
#define DUMMY_DATA 0xFFFFU
#define USART_TIMEOUT_VALUE 22000U
/* ... */
Private define
/* ... */
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
void USART_InitCallbacksToDefault(USART_HandleTypeDef *husart);
#endif
static void USART_EndTxTransfer(USART_HandleTypeDef *husart);
static void USART_EndRxTransfer(USART_HandleTypeDef *husart);
static HAL_StatusTypeDef USART_Transmit_IT(USART_HandleTypeDef *husart);
static HAL_StatusTypeDef USART_EndTransmit_IT(USART_HandleTypeDef *husart);
static HAL_StatusTypeDef USART_Receive_IT(USART_HandleTypeDef *husart);
static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart);
static void USART_SetConfig(USART_HandleTypeDef *husart);
static void USART_DMATransmitCplt(DMA_HandleTypeDef *hdma);
static void USART_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
static void USART_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
static void USART_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
static void USART_DMAError(DMA_HandleTypeDef *hdma);
static void USART_DMAAbortOnError(DMA_HandleTypeDef *hdma);
static void USART_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
static void USART_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status,
uint32_t Tickstart, uint32_t Timeout);
/* ... */
Private functions
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart)
{
if (husart == NULL)
{
return HAL_ERROR;
}if (husart == NULL) { ... }
assert_param(IS_USART_INSTANCE(husart->Instance));
if (husart->State == HAL_USART_STATE_RESET)
{
husart->Lock = HAL_UNLOCKED;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
USART_InitCallbacksToDefault(husart);
if (husart->MspInitCallback == NULL)
{
husart->MspInitCallback = HAL_USART_MspInit;
}if (husart->MspInitCallback == NULL) { ... }
husart->MspInitCallback(husart);/* ... */
#else
HAL_USART_MspInit(husart);/* ... */
#endif
}if (husart->State == HAL_USART_STATE_RESET) { ... }
husart->State = HAL_USART_STATE_BUSY;
USART_SetConfig(husart);
/* ... */
CLEAR_BIT(husart->Instance->CR2, USART_CR2_LINEN);
CLEAR_BIT(husart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
__HAL_USART_ENABLE(husart);
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_READY;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart)
{
if (husart == NULL)
{
return HAL_ERROR;
}if (husart == NULL) { ... }
assert_param(IS_USART_INSTANCE(husart->Instance));
husart->State = HAL_USART_STATE_BUSY;
__HAL_USART_DISABLE(husart);
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
if (husart->MspDeInitCallback == NULL)
{
husart->MspDeInitCallback = HAL_USART_MspDeInit;
}if (husart->MspDeInitCallback == NULL) { ... }
husart->MspDeInitCallback(husart);/* ... */
#else
HAL_USART_MspDeInit(husart);/* ... */
#endif
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_RESET;
__HAL_UNLOCK(husart);
return HAL_OK;
}{ ... }
/* ... */
__weak void HAL_USART_MspInit(USART_HandleTypeDef *husart)
{
UNUSED(husart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_USART_MspDeInit(USART_HandleTypeDef *husart)
{
UNUSED(husart);
/* ... */
}{ ... }
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
/* ... */
HAL_StatusTypeDef HAL_USART_RegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID,
pUSART_CallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
if (pCallback == NULL)
{
husart->ErrorCode |= HAL_USART_ERROR_INVALID_CALLBACK;
return HAL_ERROR;
}if (pCallback == NULL) { ... }
if (husart->State == HAL_USART_STATE_READY)
{
switch (CallbackID)
{
case HAL_USART_TX_HALFCOMPLETE_CB_ID :
husart->TxHalfCpltCallback = pCallback;
break;
case HAL_USART_TX_HALFCOMPLETE_CB_ID :
case HAL_USART_TX_COMPLETE_CB_ID :
husart->TxCpltCallback = pCallback;
break;
case HAL_USART_TX_COMPLETE_CB_ID :
case HAL_USART_RX_HALFCOMPLETE_CB_ID :
husart->RxHalfCpltCallback = pCallback;
break;
case HAL_USART_RX_HALFCOMPLETE_CB_ID :
case HAL_USART_RX_COMPLETE_CB_ID :
husart->RxCpltCallback = pCallback;
break;
case HAL_USART_RX_COMPLETE_CB_ID :
case HAL_USART_TX_RX_COMPLETE_CB_ID :
husart->TxRxCpltCallback = pCallback;
break;
case HAL_USART_TX_RX_COMPLETE_CB_ID :
case HAL_USART_ERROR_CB_ID :
husart->ErrorCallback = pCallback;
break;
case HAL_USART_ERROR_CB_ID :
case HAL_USART_ABORT_COMPLETE_CB_ID :
husart->AbortCpltCallback = pCallback;
break;
case HAL_USART_ABORT_COMPLETE_CB_ID :
case HAL_USART_MSPINIT_CB_ID :
husart->MspInitCallback = pCallback;
break;
case HAL_USART_MSPINIT_CB_ID :
case HAL_USART_MSPDEINIT_CB_ID :
husart->MspDeInitCallback = pCallback;
break;
case HAL_USART_MSPDEINIT_CB_ID :
default :
husart->ErrorCode |= HAL_USART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (husart->State == HAL_USART_STATE_READY) { ... }
else if (husart->State == HAL_USART_STATE_RESET)
{
switch (CallbackID)
{
case HAL_USART_MSPINIT_CB_ID :
husart->MspInitCallback = pCallback;
break;
case HAL_USART_MSPINIT_CB_ID :
case HAL_USART_MSPDEINIT_CB_ID :
husart->MspDeInitCallback = pCallback;
break;
case HAL_USART_MSPDEINIT_CB_ID :
default :
husart->ErrorCode |= HAL_USART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (husart->State == HAL_USART_STATE_RESET) { ... }
else
{
husart->ErrorCode |= HAL_USART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
return status;
}HAL_USART_RegisterCallback (USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID, pUSART_CallbackTypeDef pCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_USART_UnRegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
if (husart->State == HAL_USART_STATE_READY)
{
switch (CallbackID)
{
case HAL_USART_TX_HALFCOMPLETE_CB_ID :
husart->TxHalfCpltCallback = HAL_USART_TxHalfCpltCallback;
break;
case HAL_USART_TX_HALFCOMPLETE_CB_ID :
case HAL_USART_TX_COMPLETE_CB_ID :
husart->TxCpltCallback = HAL_USART_TxCpltCallback;
break;
case HAL_USART_TX_COMPLETE_CB_ID :
case HAL_USART_RX_HALFCOMPLETE_CB_ID :
husart->RxHalfCpltCallback = HAL_USART_RxHalfCpltCallback;
break;
case HAL_USART_RX_HALFCOMPLETE_CB_ID :
case HAL_USART_RX_COMPLETE_CB_ID :
husart->RxCpltCallback = HAL_USART_RxCpltCallback;
break;
case HAL_USART_RX_COMPLETE_CB_ID :
case HAL_USART_TX_RX_COMPLETE_CB_ID :
husart->TxRxCpltCallback = HAL_USART_TxRxCpltCallback;
break;
case HAL_USART_TX_RX_COMPLETE_CB_ID :
case HAL_USART_ERROR_CB_ID :
husart->ErrorCallback = HAL_USART_ErrorCallback;
break;
case HAL_USART_ERROR_CB_ID :
case HAL_USART_ABORT_COMPLETE_CB_ID :
husart->AbortCpltCallback = HAL_USART_AbortCpltCallback;
break;
case HAL_USART_ABORT_COMPLETE_CB_ID :
case HAL_USART_MSPINIT_CB_ID :
husart->MspInitCallback = HAL_USART_MspInit;
break;
case HAL_USART_MSPINIT_CB_ID :
case HAL_USART_MSPDEINIT_CB_ID :
husart->MspDeInitCallback = HAL_USART_MspDeInit;
break;
case HAL_USART_MSPDEINIT_CB_ID :
default :
husart->ErrorCode |= HAL_USART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (husart->State == HAL_USART_STATE_READY) { ... }
else if (husart->State == HAL_USART_STATE_RESET)
{
switch (CallbackID)
{
case HAL_USART_MSPINIT_CB_ID :
husart->MspInitCallback = HAL_USART_MspInit;
break;
case HAL_USART_MSPINIT_CB_ID :
case HAL_USART_MSPDEINIT_CB_ID :
husart->MspDeInitCallback = HAL_USART_MspDeInit;
break;
case HAL_USART_MSPDEINIT_CB_ID :
default :
husart->ErrorCode |= HAL_USART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (husart->State == HAL_USART_STATE_RESET) { ... }
else
{
husart->ErrorCode |= HAL_USART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
return status;
}HAL_USART_UnRegisterCallback (USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint16_t Size, uint32_t Timeout)
{
const uint8_t *ptxdata8bits;
const uint16_t *ptxdata16bits;
uint32_t tickstart;
if (husart->State == HAL_USART_STATE_READY)
{
if ((pTxData == NULL) || (Size == 0))
{
return HAL_ERROR;
}if ((pTxData == NULL) || (Size == 0)) { ... }
__HAL_LOCK(husart);
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_TX;
tickstart = HAL_GetTick();
husart->TxXferSize = Size;
husart->TxXferCount = Size;
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
{
ptxdata8bits = NULL;
ptxdata16bits = (const uint16_t *) pTxData;
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE)) { ... }
else
{
ptxdata8bits = pTxData;
ptxdata16bits = NULL;
}else { ... }
while (husart->TxXferCount > 0U)
{
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) { ... }
if (ptxdata8bits == NULL)
{
husart->Instance->DR = (uint16_t)(*ptxdata16bits & (uint16_t)0x01FF);
ptxdata16bits++;
}if (ptxdata8bits == NULL) { ... }
else
{
husart->Instance->DR = (uint8_t)(*ptxdata8bits & (uint8_t)0xFF);
ptxdata8bits++;
}else { ... }
husart->TxXferCount--;
}while (husart->TxXferCount > 0U) { ... }
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK) { ... }
husart->State = HAL_USART_STATE_READY;
__HAL_UNLOCK(husart);
return HAL_OK;
}if (husart->State == HAL_USART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
{
uint8_t *prxdata8bits;
uint16_t *prxdata16bits;
uint32_t tickstart;
if (husart->State == HAL_USART_STATE_READY)
{
if ((pRxData == NULL) || (Size == 0))
{
return HAL_ERROR;
}if ((pRxData == NULL) || (Size == 0)) { ... }
__HAL_LOCK(husart);
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_RX;
tickstart = HAL_GetTick();
husart->RxXferSize = Size;
husart->RxXferCount = Size;
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
{
prxdata8bits = NULL;
prxdata16bits = (uint16_t *) pRxData;
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE)) { ... }
else
{
prxdata8bits = pRxData;
prxdata16bits = NULL;
}else { ... }
while (husart->RxXferCount > 0U)
{
/* ... */
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) { ... }
husart->Instance->DR = (DUMMY_DATA & (uint16_t)0x0FF);
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) { ... }
if (prxdata8bits == NULL)
{
*prxdata16bits = (uint16_t)(husart->Instance->DR & (uint16_t)0x01FF);
prxdata16bits++;
}if (prxdata8bits == NULL) { ... }
else
{
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) || ((husart->Init.WordLength == USART_WORDLENGTH_8B) && (husart->Init.Parity == USART_PARITY_NONE)))
{
*prxdata8bits = (uint8_t)(husart->Instance->DR & (uint8_t)0x0FF);
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) || ((husart->Init.WordLength == USART_WORDLENGTH_8B) && (husart->Init.Parity == USART_PARITY_NONE))) { ... }
else
{
*prxdata8bits = (uint8_t)(husart->Instance->DR & (uint8_t)0x07F);
}else { ... }
prxdata8bits++;
}else { ... }
husart->RxXferCount--;
}while (husart->RxXferCount > 0U) { ... }
husart->State = HAL_USART_STATE_READY;
__HAL_UNLOCK(husart);
return HAL_OK;
}if (husart->State == HAL_USART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint8_t *pRxData,
uint16_t Size, uint32_t Timeout)
{
uint8_t *prxdata8bits;
uint16_t *prxdata16bits;
const uint8_t *ptxdata8bits;
const uint16_t *ptxdata16bits;
uint16_t rxdatacount;
uint32_t tickstart;
if (husart->State == HAL_USART_STATE_READY)
{
if ((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
{
return HAL_ERROR;
}if ((pTxData == NULL) || (pRxData == NULL) || (Size == 0)) { ... }
/* ... */
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
{
if (((((uint32_t)pTxData) & 1U) != 0U) || ((((uint32_t)pRxData) & 1U) != 0U))
{
return HAL_ERROR;
}if (((((uint32_t)pTxData) & 1U) != 0U) || ((((uint32_t)pRxData) & 1U) != 0U)) { ... }
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE)) { ... }
__HAL_LOCK(husart);
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_RX;
tickstart = HAL_GetTick();
husart->RxXferSize = Size;
husart->TxXferSize = Size;
husart->TxXferCount = Size;
husart->RxXferCount = Size;
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
{
prxdata8bits = NULL;
ptxdata8bits = NULL;
ptxdata16bits = (const uint16_t *) pTxData;
prxdata16bits = (uint16_t *) pRxData;
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE)) { ... }
else
{
prxdata8bits = pRxData;
ptxdata8bits = pTxData;
ptxdata16bits = NULL;
prxdata16bits = NULL;
}else { ... }
rxdatacount = husart->RxXferCount;
while ((husart->TxXferCount > 0U) || (rxdatacount > 0U))
{
if (husart->TxXferCount > 0U)
{
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) { ... }
if (ptxdata8bits == NULL)
{
husart->Instance->DR = (uint16_t)(*ptxdata16bits & (uint16_t)0x01FF);
ptxdata16bits++;
}if (ptxdata8bits == NULL) { ... }
else
{
husart->Instance->DR = (uint8_t)(*ptxdata8bits & (uint8_t)0xFF);
ptxdata8bits++;
}else { ... }
husart->TxXferCount--;
}if (husart->TxXferCount > 0U) { ... }
if (husart->RxXferCount > 0U)
{
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) { ... }
if (prxdata8bits == NULL)
{
*prxdata16bits = (uint16_t)(husart->Instance->DR & (uint16_t)0x01FF);
prxdata16bits++;
}if (prxdata8bits == NULL) { ... }
else
{
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) || ((husart->Init.WordLength == USART_WORDLENGTH_8B) && (husart->Init.Parity == USART_PARITY_NONE)))
{
*prxdata8bits = (uint8_t)(husart->Instance->DR & (uint8_t)0x0FF);
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) || ((husart->Init.WordLength == USART_WORDLENGTH_8B) && (husart->Init.Parity == USART_PARITY_NONE))) { ... }
else
{
*prxdata8bits = (uint8_t)(husart->Instance->DR & (uint8_t)0x07F);
}else { ... }
prxdata8bits++;
}else { ... }
husart->RxXferCount--;
}if (husart->RxXferCount > 0U) { ... }
rxdatacount = husart->RxXferCount;
}while ((husart->TxXferCount > 0U) || (rxdatacount > 0U)) { ... }
husart->State = HAL_USART_STATE_READY;
__HAL_UNLOCK(husart);
return HAL_OK;
}if (husart->State == HAL_USART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint16_t Size)
{
if (husart->State == HAL_USART_STATE_READY)
{
if ((pTxData == NULL) || (Size == 0))
{
return HAL_ERROR;
}if ((pTxData == NULL) || (Size == 0)) { ... }
__HAL_LOCK(husart);
husart->pTxBuffPtr = pTxData;
husart->TxXferSize = Size;
husart->TxXferCount = Size;
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_TX;
/* ... */
__HAL_UNLOCK(husart);
SET_BIT(husart->Instance->CR1, USART_CR1_TXEIE);
return HAL_OK;
}if (husart->State == HAL_USART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size)
{
if (husart->State == HAL_USART_STATE_READY)
{
if ((pRxData == NULL) || (Size == 0))
{
return HAL_ERROR;
}if ((pRxData == NULL) || (Size == 0)) { ... }
__HAL_LOCK(husart);
husart->pRxBuffPtr = pRxData;
husart->RxXferSize = Size;
husart->RxXferCount = Size;
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_RX;
__HAL_UNLOCK(husart);
if (husart->Init.Parity != USART_PARITY_NONE)
{
SET_BIT(husart->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
}if (husart->Init.Parity != USART_PARITY_NONE) { ... }
else
{
SET_BIT(husart->Instance->CR1, USART_CR1_RXNEIE);
}else { ... }
SET_BIT(husart->Instance->CR3, USART_CR3_EIE);
husart->Instance->DR = (DUMMY_DATA & (uint16_t)0x01FF);
return HAL_OK;
}if (husart->State == HAL_USART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint8_t *pRxData,
uint16_t Size)
{
if (husart->State == HAL_USART_STATE_READY)
{
if ((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
{
return HAL_ERROR;
}if ((pTxData == NULL) || (pRxData == NULL) || (Size == 0)) { ... }
__HAL_LOCK(husart);
husart->pRxBuffPtr = pRxData;
husart->RxXferSize = Size;
husart->RxXferCount = Size;
husart->pTxBuffPtr = pTxData;
husart->TxXferSize = Size;
husart->TxXferCount = Size;
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_TX_RX;
__HAL_UNLOCK(husart);
SET_BIT(husart->Instance->CR1, USART_CR1_RXNEIE);
if (husart->Init.Parity != USART_PARITY_NONE)
{
SET_BIT(husart->Instance->CR1, USART_CR1_PEIE);
}if (husart->Init.Parity != USART_PARITY_NONE) { ... }
SET_BIT(husart->Instance->CR3, USART_CR3_EIE);
SET_BIT(husart->Instance->CR1, USART_CR1_TXEIE);
return HAL_OK;
}if (husart->State == HAL_USART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint16_t Size)
{
const uint32_t *tmp;
if (husart->State == HAL_USART_STATE_READY)
{
if ((pTxData == NULL) || (Size == 0))
{
return HAL_ERROR;
}if ((pTxData == NULL) || (Size == 0)) { ... }
__HAL_LOCK(husart);
husart->pTxBuffPtr = pTxData;
husart->TxXferSize = Size;
husart->TxXferCount = Size;
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_TX;
husart->hdmatx->XferCpltCallback = USART_DMATransmitCplt;
husart->hdmatx->XferHalfCpltCallback = USART_DMATxHalfCplt;
husart->hdmatx->XferErrorCallback = USART_DMAError;
husart->hdmatx->XferAbortCallback = NULL;
tmp = (const uint32_t *)&pTxData;
HAL_DMA_Start_IT(husart->hdmatx, *(const uint32_t *)tmp, (uint32_t)&husart->Instance->DR, Size);
__HAL_USART_CLEAR_FLAG(husart, USART_FLAG_TC);
__HAL_UNLOCK(husart);
/* ... */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAT);
return HAL_OK;
}if (husart->State == HAL_USART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size)
{
uint32_t *tmp;
if (husart->State == HAL_USART_STATE_READY)
{
if ((pRxData == NULL) || (Size == 0))
{
return HAL_ERROR;
}if ((pRxData == NULL) || (Size == 0)) { ... }
__HAL_LOCK(husart);
husart->pRxBuffPtr = pRxData;
husart->RxXferSize = Size;
husart->pTxBuffPtr = pRxData;
husart->TxXferSize = Size;
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_RX;
husart->hdmarx->XferCpltCallback = USART_DMAReceiveCplt;
husart->hdmarx->XferHalfCpltCallback = USART_DMARxHalfCplt;
husart->hdmarx->XferErrorCallback = USART_DMAError;
husart->hdmarx->XferAbortCallback = NULL;
/* ... */
husart->hdmatx->XferHalfCpltCallback = NULL;
husart->hdmatx->XferCpltCallback = NULL;
husart->hdmatx->XferErrorCallback = USART_DMAError;
husart->hdmatx->XferAbortCallback = NULL;
tmp = (uint32_t *)&pRxData;
HAL_DMA_Start_IT(husart->hdmarx, (uint32_t)&husart->Instance->DR, *(uint32_t *)tmp, Size);
/* ... */
HAL_DMA_Start_IT(husart->hdmatx, *(uint32_t *)tmp, (uint32_t)&husart->Instance->DR, Size);
__HAL_USART_CLEAR_OREFLAG(husart);
__HAL_UNLOCK(husart);
if (husart->Init.Parity != USART_PARITY_NONE)
{
SET_BIT(husart->Instance->CR1, USART_CR1_PEIE);
}if (husart->Init.Parity != USART_PARITY_NONE) { ... }
SET_BIT(husart->Instance->CR3, USART_CR3_EIE);
/* ... */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAR);
/* ... */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAT);
return HAL_OK;
}if (husart->State == HAL_USART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint8_t *pRxData,
uint16_t Size)
{
const uint32_t *tmp;
if (husart->State == HAL_USART_STATE_READY)
{
if ((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
{
return HAL_ERROR;
}if ((pTxData == NULL) || (pRxData == NULL) || (Size == 0)) { ... }
__HAL_LOCK(husart);
husart->pRxBuffPtr = pRxData;
husart->RxXferSize = Size;
husart->pTxBuffPtr = pTxData;
husart->TxXferSize = Size;
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_BUSY_TX_RX;
husart->hdmarx->XferCpltCallback = USART_DMAReceiveCplt;
husart->hdmarx->XferHalfCpltCallback = USART_DMARxHalfCplt;
husart->hdmatx->XferCpltCallback = USART_DMATransmitCplt;
husart->hdmatx->XferHalfCpltCallback = USART_DMATxHalfCplt;
husart->hdmatx->XferErrorCallback = USART_DMAError;
husart->hdmarx->XferErrorCallback = USART_DMAError;
husart->hdmarx->XferAbortCallback = NULL;
tmp = (uint32_t *)&pRxData;
HAL_DMA_Start_IT(husart->hdmarx, (uint32_t)&husart->Instance->DR, *(const uint32_t *)tmp, Size);
tmp = (const uint32_t *)&pTxData;
HAL_DMA_Start_IT(husart->hdmatx, *(const uint32_t *)tmp, (uint32_t)&husart->Instance->DR, Size);
__HAL_USART_CLEAR_FLAG(husart, USART_FLAG_TC);
__HAL_USART_CLEAR_OREFLAG(husart);
__HAL_UNLOCK(husart);
if (husart->Init.Parity != USART_PARITY_NONE)
{
SET_BIT(husart->Instance->CR1, USART_CR1_PEIE);
}if (husart->Init.Parity != USART_PARITY_NONE) { ... }
SET_BIT(husart->Instance->CR3, USART_CR3_EIE);
/* ... */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAR);
/* ... */
SET_BIT(husart->Instance->CR3, USART_CR3_DMAT);
return HAL_OK;
}if (husart->State == HAL_USART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart)
{
__HAL_LOCK(husart);
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
__HAL_UNLOCK(husart);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart)
{
__HAL_LOCK(husart);
SET_BIT(husart->Instance->CR3, USART_CR3_DMAT);
__HAL_UNLOCK(husart);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart)
{
uint32_t dmarequest = 0x00U;
/* ... */
dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT);
if ((husart->State == HAL_USART_STATE_BUSY_TX) && dmarequest)
{
USART_EndTxTransfer(husart);
if (husart->hdmatx != NULL)
{
HAL_DMA_Abort(husart->hdmatx);
}if (husart->hdmatx != NULL) { ... }
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
}if ((husart->State == HAL_USART_STATE_BUSY_TX) && dmarequest) { ... }
dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR);
if ((husart->State == HAL_USART_STATE_BUSY_RX) && dmarequest)
{
USART_EndRxTransfer(husart);
if (husart->hdmarx != NULL)
{
HAL_DMA_Abort(husart->hdmarx);
}if (husart->hdmarx != NULL) { ... }
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
}if ((husart->State == HAL_USART_STATE_BUSY_RX) && dmarequest) { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart)
{
CLEAR_BIT(husart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT))
{
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
if (husart->hdmatx != NULL)
{
/* ... */
husart->hdmatx->XferAbortCallback = NULL;
HAL_DMA_Abort(husart->hdmatx);
}if (husart->hdmatx != NULL) { ... }
}if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT)) { ... }
if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
if (husart->hdmarx != NULL)
{
/* ... */
husart->hdmarx->XferAbortCallback = NULL;
HAL_DMA_Abort(husart->hdmarx);
}if (husart->hdmarx != NULL) { ... }
}if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR)) { ... }
husart->TxXferCount = 0x00U;
husart->RxXferCount = 0x00U;
husart->State = HAL_USART_STATE_READY;
husart->ErrorCode = HAL_USART_ERROR_NONE;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart)
{
uint32_t AbortCplt = 0x01U;
CLEAR_BIT(husart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
/* ... */
if (husart->hdmatx != NULL)
{
/* ... */
if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT))
{
husart->hdmatx->XferAbortCallback = USART_DMATxAbortCallback;
}if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT)) { ... }
else
{
husart->hdmatx->XferAbortCallback = NULL;
}else { ... }
}if (husart->hdmatx != NULL) { ... }
if (husart->hdmarx != NULL)
{
/* ... */
if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR))
{
husart->hdmarx->XferAbortCallback = USART_DMARxAbortCallback;
}if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR)) { ... }
else
{
husart->hdmarx->XferAbortCallback = NULL;
}else { ... }
}if (husart->hdmarx != NULL) { ... }
if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT))
{
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
if (husart->hdmatx != NULL)
{
/* ... */
if (HAL_DMA_Abort_IT(husart->hdmatx) != HAL_OK)
{
husart->hdmatx->XferAbortCallback = NULL;
}if (HAL_DMA_Abort_IT(husart->hdmatx) != HAL_OK) { ... }
else
{
AbortCplt = 0x00U;
}else { ... }
}if (husart->hdmatx != NULL) { ... }
}if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT)) { ... }
if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
if (husart->hdmarx != NULL)
{
/* ... */
if (HAL_DMA_Abort_IT(husart->hdmarx) != HAL_OK)
{
husart->hdmarx->XferAbortCallback = NULL;
AbortCplt = 0x01U;
}if (HAL_DMA_Abort_IT(husart->hdmarx) != HAL_OK) { ... }
else
{
AbortCplt = 0x00U;
}else { ... }
}if (husart->hdmarx != NULL) { ... }
}if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR)) { ... }
if (AbortCplt == 0x01U)
{
husart->TxXferCount = 0x00U;
husart->RxXferCount = 0x00U;
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_READY;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->AbortCpltCallback(husart);/* ... */
#else
HAL_USART_AbortCpltCallback(husart);/* ... */
#endif
}if (AbortCplt == 0x01U) { ... }
return HAL_OK;
}{ ... }
/* ... */
void HAL_USART_IRQHandler(USART_HandleTypeDef *husart)
{
uint32_t isrflags = READ_REG(husart->Instance->SR);
uint32_t cr1its = READ_REG(husart->Instance->CR1);
uint32_t cr3its = READ_REG(husart->Instance->CR3);
uint32_t errorflags = 0x00U;
uint32_t dmarequest = 0x00U;
errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
if (errorflags == RESET)
{
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
{
if (husart->State == HAL_USART_STATE_BUSY_RX)
{
USART_Receive_IT(husart);
}if (husart->State == HAL_USART_STATE_BUSY_RX) { ... }
else
{
USART_TransmitReceive_IT(husart);
}else { ... }
return;
}if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) { ... }
}if (errorflags == RESET) { ... }
if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
{
if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
{
husart->ErrorCode |= HAL_USART_ERROR_PE;
}if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET)) { ... }
USART parity error interrupt occurred
if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
{
husart->ErrorCode |= HAL_USART_ERROR_NE;
}if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) { ... }
USART noise error interrupt occurred
if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
{
husart->ErrorCode |= HAL_USART_ERROR_FE;
}if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) { ... }
USART frame error interrupt occurred
if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET)))
{
husart->ErrorCode |= HAL_USART_ERROR_ORE;
}if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET))) { ... }
if (husart->ErrorCode != HAL_USART_ERROR_NONE)
{
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
{
if (husart->State == HAL_USART_STATE_BUSY_RX)
{
USART_Receive_IT(husart);
}if (husart->State == HAL_USART_STATE_BUSY_RX) { ... }
else
{
USART_TransmitReceive_IT(husart);
}else { ... }
}if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) { ... }
/* ... */
dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR);
if (((husart->ErrorCode & HAL_USART_ERROR_ORE) != RESET) || dmarequest)
{
/* ... */
USART_EndRxTransfer(husart);
if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
if (husart->hdmarx != NULL)
{
/* ... */
husart->hdmarx->XferAbortCallback = USART_DMAAbortOnError;
if (HAL_DMA_Abort_IT(husart->hdmarx) != HAL_OK)
{
husart->hdmarx->XferAbortCallback(husart->hdmarx);
}if (HAL_DMA_Abort_IT(husart->hdmarx) != HAL_OK) { ... }
}if (husart->hdmarx != NULL) { ... }
else
{
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->ErrorCallback(husart);/* ... */
#else
HAL_USART_ErrorCallback(husart);/* ... */
#endif
}else { ... }
}if (HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR)) { ... }
else
{
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->ErrorCallback(husart);/* ... */
#else
HAL_USART_ErrorCallback(husart);/* ... */
#endif
}else { ... }
}if (((husart->ErrorCode & HAL_USART_ERROR_ORE) != RESET) || dmarequest) { ... }
else
{
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->ErrorCallback(husart);/* ... */
#else
HAL_USART_ErrorCallback(husart);/* ... */
#endif
husart->ErrorCode = HAL_USART_ERROR_NONE;
}else { ... }
}if (husart->ErrorCode != HAL_USART_ERROR_NONE) { ... }
return;
}if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET))) { ... }
if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
{
if (husart->State == HAL_USART_STATE_BUSY_TX)
{
USART_Transmit_IT(husart);
}if (husart->State == HAL_USART_STATE_BUSY_TX) { ... }
else
{
USART_TransmitReceive_IT(husart);
}else { ... }
return;
}if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) { ... }
USART in mode Transmitter
if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
{
USART_EndTransmit_IT(husart);
return;
}if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) { ... }
}{ ... }
/* ... */
__weak void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart)
{
UNUSED(husart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart)
{
UNUSED(husart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart)
{
UNUSED(husart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart)
{
UNUSED(husart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart)
{
UNUSED(husart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart)
{
UNUSED(husart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_USART_AbortCpltCallback(USART_HandleTypeDef *husart)
{
UNUSED(husart);
/* ... */
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_USART_StateTypeDef HAL_USART_GetState(const USART_HandleTypeDef *husart)
{
return husart->State;
}{ ... }
/* ... */
uint32_t HAL_USART_GetError(const USART_HandleTypeDef *husart)
{
return husart->ErrorCode;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
void USART_InitCallbacksToDefault(USART_HandleTypeDef *husart)
{
husart->TxHalfCpltCallback = HAL_USART_TxHalfCpltCallback;
husart->TxCpltCallback = HAL_USART_TxCpltCallback;
husart->RxHalfCpltCallback = HAL_USART_RxHalfCpltCallback;
husart->RxCpltCallback = HAL_USART_RxCpltCallback;
husart->TxRxCpltCallback = HAL_USART_TxRxCpltCallback;
husart->ErrorCallback = HAL_USART_ErrorCallback;
husart->AbortCpltCallback = HAL_USART_AbortCpltCallback;
}USART_InitCallbacksToDefault (USART_HandleTypeDef *husart) { ... }
/* ... */#endif
/* ... */
static void USART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef *husart = (USART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
{
husart->TxXferCount = 0U;
if (husart->State == HAL_USART_STATE_BUSY_TX)
{
/* ... */
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
SET_BIT(husart->Instance->CR1, USART_CR1_TCIE);
}if (husart->State == HAL_USART_STATE_BUSY_TX) { ... }
}if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U) { ... }
else
{
if (husart->State == HAL_USART_STATE_BUSY_TX)
{
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->TxCpltCallback(husart);/* ... */
#else
HAL_USART_TxCpltCallback(husart);/* ... */
#endif
}if (husart->State == HAL_USART_STATE_BUSY_TX) { ... }
}else { ... }
}{ ... }
/* ... */
static void USART_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef *husart = (USART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->TxHalfCpltCallback(husart);/* ... */
#else
HAL_USART_TxHalfCpltCallback(husart);/* ... */
#endif
}{ ... }
/* ... */
static void USART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef *husart = (USART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
{
husart->RxXferCount = 0x00U;
CLEAR_BIT(husart->Instance->CR1, USART_CR1_PEIE);
CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
/* ... */
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAR);
CLEAR_BIT(husart->Instance->CR3, USART_CR3_DMAT);
if (husart->State == HAL_USART_STATE_BUSY_RX)
{
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->RxCpltCallback(husart);/* ... */
#else
HAL_USART_RxCpltCallback(husart);/* ... */
#endif
}if (husart->State == HAL_USART_STATE_BUSY_RX) { ... }
else
{
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->TxRxCpltCallback(husart);/* ... */
#else
HAL_USART_TxRxCpltCallback(husart);/* ... */
#endif
}else { ... }
husart->State = HAL_USART_STATE_READY;
}if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U) { ... }
else
{
if (husart->State == HAL_USART_STATE_BUSY_RX)
{
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->RxCpltCallback(husart);/* ... */
#else
HAL_USART_RxCpltCallback(husart);/* ... */
#endif
}if (husart->State == HAL_USART_STATE_BUSY_RX) { ... }
else
{
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->TxRxCpltCallback(husart);/* ... */
#else
HAL_USART_TxRxCpltCallback(husart);/* ... */
#endif
}else { ... }
}else { ... }
}{ ... }
/* ... */
static void USART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef *husart = (USART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->RxHalfCpltCallback(husart);/* ... */
#else
HAL_USART_RxHalfCpltCallback(husart);/* ... */
#endif
}{ ... }
/* ... */
static void USART_DMAError(DMA_HandleTypeDef *hdma)
{
uint32_t dmarequest = 0x00U;
USART_HandleTypeDef *husart = (USART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
husart->RxXferCount = 0x00U;
husart->TxXferCount = 0x00U;
dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAT);
if ((husart->State == HAL_USART_STATE_BUSY_TX) && dmarequest)
{
USART_EndTxTransfer(husart);
}if ((husart->State == HAL_USART_STATE_BUSY_TX) && dmarequest) { ... }
dmarequest = HAL_IS_BIT_SET(husart->Instance->CR3, USART_CR3_DMAR);
if ((husart->State == HAL_USART_STATE_BUSY_RX) && dmarequest)
{
USART_EndRxTransfer(husart);
}if ((husart->State == HAL_USART_STATE_BUSY_RX) && dmarequest) { ... }
husart->ErrorCode |= HAL_USART_ERROR_DMA;
husart->State = HAL_USART_STATE_READY;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->ErrorCallback(husart);/* ... */
#else
HAL_USART_ErrorCallback(husart);/* ... */
#endif
}{ ... }
/* ... */
static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status,
uint32_t Tickstart, uint32_t Timeout)
{
while ((__HAL_USART_GET_FLAG(husart, Flag) ? SET : RESET) == Status)
{
if (Timeout != HAL_MAX_DELAY)
{
if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout))
{
CLEAR_BIT(husart->Instance->CR1, USART_CR1_TXEIE);
CLEAR_BIT(husart->Instance->CR1, USART_CR1_RXNEIE);
CLEAR_BIT(husart->Instance->CR1, USART_CR1_PEIE);
CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
husart->State = HAL_USART_STATE_READY;
__HAL_UNLOCK(husart);
return HAL_TIMEOUT;
}if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
}while ((__HAL_USART_GET_FLAG(husart, Flag) ? SET : RESET) == Status) { ... }
return HAL_OK;
}{ ... }
/* ... */
static void USART_EndTxTransfer(USART_HandleTypeDef *husart)
{
CLEAR_BIT(husart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
husart->State = HAL_USART_STATE_READY;
}{ ... }
/* ... */
static void USART_EndRxTransfer(USART_HandleTypeDef *husart)
{
CLEAR_BIT(husart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
husart->State = HAL_USART_STATE_READY;
}{ ... }
/* ... */
static void USART_DMAAbortOnError(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef *husart = (USART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
husart->RxXferCount = 0x00U;
husart->TxXferCount = 0x00U;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->ErrorCallback(husart);/* ... */
#else
HAL_USART_ErrorCallback(husart);/* ... */
#endif
}{ ... }
/* ... */
static void USART_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef *husart = (USART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
husart->hdmatx->XferAbortCallback = NULL;
if (husart->hdmarx != NULL)
{
if (husart->hdmarx->XferAbortCallback != NULL)
{
return;
}if (husart->hdmarx->XferAbortCallback != NULL) { ... }
}if (husart->hdmarx != NULL) { ... }
husart->TxXferCount = 0x00U;
husart->RxXferCount = 0x00U;
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_READY;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->AbortCpltCallback(husart);/* ... */
#else
HAL_USART_AbortCpltCallback(husart);/* ... */
#endif
}{ ... }
/* ... */
static void USART_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
{
USART_HandleTypeDef *husart = (USART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
husart->hdmarx->XferAbortCallback = NULL;
if (husart->hdmatx != NULL)
{
if (husart->hdmatx->XferAbortCallback != NULL)
{
return;
}if (husart->hdmatx->XferAbortCallback != NULL) { ... }
}if (husart->hdmatx != NULL) { ... }
husart->TxXferCount = 0x00U;
husart->RxXferCount = 0x00U;
husart->ErrorCode = HAL_USART_ERROR_NONE;
husart->State = HAL_USART_STATE_READY;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->AbortCpltCallback(husart);/* ... */
#else
HAL_USART_AbortCpltCallback(husart);/* ... */
#endif
}{ ... }
/* ... */
static HAL_StatusTypeDef USART_Transmit_IT(USART_HandleTypeDef *husart)
{
const uint16_t *tmp;
if (husart->State == HAL_USART_STATE_BUSY_TX)
{
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
{
tmp = (const uint16_t *) husart->pTxBuffPtr;
husart->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
husart->pTxBuffPtr += 2U;
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE)) { ... }
else
{
husart->Instance->DR = (uint8_t)(*husart->pTxBuffPtr++ & (uint8_t)0x00FF);
}else { ... }
if (--husart->TxXferCount == 0U)
{
CLEAR_BIT(husart->Instance->CR1, USART_CR1_TXEIE);
SET_BIT(husart->Instance->CR1, USART_CR1_TCIE);
}if (--husart->TxXferCount == 0U) { ... }
return HAL_OK;
}if (husart->State == HAL_USART_STATE_BUSY_TX) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
static HAL_StatusTypeDef USART_EndTransmit_IT(USART_HandleTypeDef *husart)
{
CLEAR_BIT(husart->Instance->CR1, USART_CR1_TCIE);
CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
husart->State = HAL_USART_STATE_READY;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->TxCpltCallback(husart);/* ... */
#else
HAL_USART_TxCpltCallback(husart);/* ... */
#endif
return HAL_OK;
}{ ... }
/* ... */
static HAL_StatusTypeDef USART_Receive_IT(USART_HandleTypeDef *husart)
{
uint8_t *pdata8bits;
uint16_t *pdata16bits;
if (husart->State == HAL_USART_STATE_BUSY_RX)
{
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
{
pdata8bits = NULL;
pdata16bits = (uint16_t *) husart->pRxBuffPtr;
*pdata16bits = (uint16_t)(husart->Instance->DR & (uint16_t)0x01FF);
husart->pRxBuffPtr += 2U;
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE)) { ... }
else
{
pdata8bits = (uint8_t *) husart->pRxBuffPtr;
pdata16bits = NULL;
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) || ((husart->Init.WordLength == USART_WORDLENGTH_8B) && (husart->Init.Parity == USART_PARITY_NONE)))
{
*pdata8bits = (uint8_t)(husart->Instance->DR & (uint8_t)0x00FF);
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) || ((husart->Init.WordLength == USART_WORDLENGTH_8B) && (husart->Init.Parity == USART_PARITY_NONE))) { ... }
else
{
*pdata8bits = (uint8_t)(husart->Instance->DR & (uint8_t)0x007F);
}else { ... }
husart->pRxBuffPtr += 1U;
}else { ... }
husart->RxXferCount--;
if (husart->RxXferCount == 0U)
{
CLEAR_BIT(husart->Instance->CR1, USART_CR1_RXNEIE);
CLEAR_BIT(husart->Instance->CR1, USART_CR1_PEIE);
CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
husart->State = HAL_USART_STATE_READY;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->RxCpltCallback(husart);/* ... */
#else
HAL_USART_RxCpltCallback(husart);/* ... */
#endif
return HAL_OK;
}if (husart->RxXferCount == 0U) { ... }
else
{
/* ... */
husart->Instance->DR = (DUMMY_DATA & (uint16_t)0x0FF);
}else { ... }
return HAL_OK;
}if (husart->State == HAL_USART_STATE_BUSY_RX) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart)
{
const uint16_t *pdatatx16bits;
uint16_t *pdatarx16bits;
if (husart->State == HAL_USART_STATE_BUSY_TX_RX)
{
if (husart->TxXferCount != 0x00U)
{
if (__HAL_USART_GET_FLAG(husart, USART_FLAG_TXE) != RESET)
{
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
{
pdatatx16bits = (const uint16_t *) husart->pTxBuffPtr;
husart->Instance->DR = (uint16_t)(*pdatatx16bits & (uint16_t)0x01FF);
husart->pTxBuffPtr += 2U;
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE)) { ... }
else
{
husart->Instance->DR = (uint8_t)(*husart->pTxBuffPtr++ & (uint8_t)0x00FF);
}else { ... }
husart->TxXferCount--;
if (husart->TxXferCount == 0U)
{
CLEAR_BIT(husart->Instance->CR1, USART_CR1_TXEIE);
}if (husart->TxXferCount == 0U) { ... }
}if (__HAL_USART_GET_FLAG(husart, USART_FLAG_TXE) != RESET) { ... }
}if (husart->TxXferCount != 0x00U) { ... }
if (husart->RxXferCount != 0x00U)
{
if (__HAL_USART_GET_FLAG(husart, USART_FLAG_RXNE) != RESET)
{
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
{
pdatarx16bits = (uint16_t *) husart->pRxBuffPtr;
*pdatarx16bits = (uint16_t)(husart->Instance->DR & (uint16_t)0x01FF);
husart->pRxBuffPtr += 2U;
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE)) { ... }
else
{
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) || ((husart->Init.WordLength == USART_WORDLENGTH_8B) && (husart->Init.Parity == USART_PARITY_NONE)))
{
*husart->pRxBuffPtr = (uint8_t)(husart->Instance->DR & (uint8_t)0x00FF);
}if ((husart->Init.WordLength == USART_WORDLENGTH_9B) || ((husart->Init.WordLength == USART_WORDLENGTH_8B) && (husart->Init.Parity == USART_PARITY_NONE))) { ... }
else
{
*husart->pRxBuffPtr = (uint8_t)(husart->Instance->DR & (uint8_t)0x007F);
}else { ... }
husart->pRxBuffPtr += 1U;
}else { ... }
husart->RxXferCount--;
}if (__HAL_USART_GET_FLAG(husart, USART_FLAG_RXNE) != RESET) { ... }
}if (husart->RxXferCount != 0x00U) { ... }
if (husart->RxXferCount == 0U)
{
CLEAR_BIT(husart->Instance->CR1, USART_CR1_RXNEIE);
CLEAR_BIT(husart->Instance->CR1, USART_CR1_PEIE);
CLEAR_BIT(husart->Instance->CR3, USART_CR3_EIE);
husart->State = HAL_USART_STATE_READY;
#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
husart->TxRxCpltCallback(husart);/* ... */
#else
HAL_USART_TxRxCpltCallback(husart);/* ... */
#endif
return HAL_OK;
}if (husart->RxXferCount == 0U) { ... }
return HAL_OK;
}if (husart->State == HAL_USART_STATE_BUSY_TX_RX) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
static void USART_SetConfig(USART_HandleTypeDef *husart)
{
uint32_t tmpreg = 0x00U;
uint32_t pclk;
assert_param(IS_USART_INSTANCE(husart->Instance));
assert_param(IS_USART_POLARITY(husart->Init.CLKPolarity));
assert_param(IS_USART_PHASE(husart->Init.CLKPhase));
assert_param(IS_USART_LASTBIT(husart->Init.CLKLastBit));
assert_param(IS_USART_BAUDRATE(husart->Init.BaudRate));
assert_param(IS_USART_WORD_LENGTH(husart->Init.WordLength));
assert_param(IS_USART_STOPBITS(husart->Init.StopBits));
assert_param(IS_USART_PARITY(husart->Init.Parity));
assert_param(IS_USART_MODE(husart->Init.Mode));
/* ... */
CLEAR_BIT(husart->Instance->CR1, (USART_CR1_TE | USART_CR1_RE));
tmpreg = husart->Instance->CR2;
tmpreg &= (uint32_t)~((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_CLKEN | USART_CR2_LBCL | USART_CR2_STOP));---------------------------- USART CR2 Configuration
tmpreg |= (uint32_t)(USART_CLOCK_ENABLE | husart->Init.CLKPolarity |
husart->Init.CLKPhase | husart->Init.CLKLastBit | husart->Init.StopBits);
WRITE_REG(husart->Instance->CR2, (uint32_t)tmpreg);
Configure the USART Clock, CPOL, CPHA and LastBit
tmpreg = husart->Instance->CR1;
tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | \
USART_CR1_RE | USART_CR1_OVER8));
/* ... */
tmpreg |= (uint32_t)husart->Init.WordLength | husart->Init.Parity | husart->Init.Mode | USART_CR1_OVER8;
WRITE_REG(husart->Instance->CR1, (uint32_t)tmpreg);
-------------------------- USART CR1 Configuration
CLEAR_BIT(husart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE));
-------------------------- USART CR3 Configuration
#if defined(USART6) && defined(UART9) && defined(UART10)
if ((husart->Instance == USART1) || (husart->Instance == USART6) || (husart->Instance == UART9) || (husart->Instance == UART10))
{
pclk = HAL_RCC_GetPCLK2Freq();
husart->Instance->BRR = USART_BRR(pclk, husart->Init.BaudRate);
}if ((husart->Instance == USART1) || (husart->Instance == USART6) || (husart->Instance == UART9) || (husart->Instance == UART10)) { ... }
/* ... */#elif defined(USART6)
if((husart->Instance == USART1) || (husart->Instance == USART6))
{
pclk = HAL_RCC_GetPCLK2Freq();
husart->Instance->BRR = USART_BRR(pclk, husart->Init.BaudRate);
}if ((husart->Instance == USART1) || (husart->Instance == USART6)) { ... }
/* ... */#else
if(husart->Instance == USART1)
{
pclk = HAL_RCC_GetPCLK2Freq();
husart->Instance->BRR = USART_BRR(pclk, husart->Init.BaudRate);
}if (husart->Instance == USART1) { ... }
/* ... */#endif
else
{
pclk = HAL_RCC_GetPCLK1Freq();
husart->Instance->BRR = USART_BRR(pclk, husart->Init.BaudRate);
}else { ... }
}{ ... }
/* ... */
/* ... */
#endif
/* ... */
/* ... */