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
263
264
268
269
270
271
279
280
281
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
310
311
312
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
357
358
359
360
364
365
366
374
378
379
380
381
382
383
384
385
386
387
396
397
399
400
401
402
403
404
405
406
407
408
409
410
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
435
436
437
438
442
443
444
445
446
447
448
449
450
451
452
453
454
463
464
466
467
468
469
470
471
472
473
474
475
476
477
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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
540
541
543
544
545
546
547
548
549
550
551
552
553
554
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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
623
624
626
627
628
629
630
631
632
633
634
635
636
637
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
669
670
671
672
676
677
678
679
680
681
682
683
684
685
686
692
693
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
715
723
724
730
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
773
774
775
776
777
778
782
786
790
794
798
802
806
810
814
818
825
826
827
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
893
897
901
905
909
913
917
921
925
929
936
937
938
959
960
961
962
963
964
965
966
967
968
969
970
971
978
979
980
981
982
988
989
990
991
992
996
1002
1003
1004
1005
1006
1007
1008
1009
1015
1016
1017
1018
1019
1020
1021
1022
1026
1032
1033
1034
1035
1036
1037
1038
1039
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
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1164
1169
1170
1171
1172
1178
1183
1188
1189
1190
1191
1197
1198
1199
1200
1201
1202
1203
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1251
1256
1257
1258
1259
1260
1266
1271
1283
1284
1285
1286
1287
1288
1289
1290
1291
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1356
1357
1358
1359
1360
1361
1362
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
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
1419
1420
1421
1422
1423
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1450
1451
1452
1453
1454
1455
1456
1460
1461
1462
1468
1469
1470
1471
1472
1473
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1499
1500
1501
1502
1507
1508
1509
1510
1511
1512
1513
1514
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1533
1534
1535
1536
1541
1542
1543
1544
1545
1546
1547
1548
1549
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
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
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1620
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
1657
1658
1659
1663
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1724
1725
1726
1727
1728
1729
1730
1731
1732
1748
1749
1750
1751
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
1784
1785
1786
1787
1788
1789
1790
1791
1792
1808
1809
1810
1811
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
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
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
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
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
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
2073
2074
2076
2077
2090
2091
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2116
2117
2118
2122
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2139
2140
2141
2146
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2172
2173
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2210
2211
2212
2213
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2231
2232
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2249
2250
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2294
2295
2296
2297
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2316
2317
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2335
2336
2338
2339
2340
2341
2342
2343
2344
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2369
2370
2371
2372
2373
2374
2380
2386
2392
2399
2400
2401
2402
2403
2407
2408
2410
2411
2412
2413
2416
2417
2418
2419
2420
2421
2422
2423
2424
2435
2436
2437
2438
2439
2441
2442
2444
2445
2446
2447
2448
2449
2450
2451
2453
2454
2456
2457
2458
2459
2460
2461
2463
2464
2466
2467
2469
2470
2471
2472
2473
2474
2475
2476
2477
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2522
2523
2524
2525
2527
2528
2530
2531
2532
2533
2534
2535
2536
2537
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2557
2558
2559
2560
2562
2563
2565
2566
2567
2568
2569
2570
2571
2578
2579
2584
2585
2586
2592
2600
2601
2607
2615
2616
2622
2630
2631
2637
2645
2646
2652
2660
2661
2666
2667
2668
2669
2670
2671
2674
2675
2676
2681
2682
2683
2684
2685
2686
2689
2690
2691
2696
2697
2698
2699
2700
2701
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2722
2723
2724
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2943
2947
2948
2951
2952
2955
2956
2959
2960
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2988
2989
2990
2991
2992
2993
2994
2995
2996
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3010
3011
3013
3014
3015
3016
3017
3023
3024
3025
3026
3027
3028
3030
3031
3033
3034
3035
3036
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3057
3058
3059
3060
3061
3062
3063
3067
3068
3069
3071
3072
3073
3075
3076
3077
3078
3080
3081
3083
3084
3085
3086
3087
3088
3089
3091
3092
3094
3095
3096
3097
3098
3104
3105
3106
3107
3108
3110
3111
3112
3114
3115
3116
3117
3119
3120
3122
3123
3124
3125
3126
3127
3128
3130
3131
3133
3134
3135
3136
3137
3143
3144
3145
3146
3147
3148
3149
3150
3155
3156
3157
3158
3163
3164
3165
3166
3168
3169
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3199
3200
3201
3202
3203
3204
3205
3206
3207
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3305
3306
3307
3308
3309
3311
3312
3313
3314
3315
3316
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3335
3336
3337
3338
3339
3340
3341
3342
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3368
3369
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3414
3415
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3460
3461
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3488
3489
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3517
3518
3520
3521
3522
3523
3529
3530
3531
3532
3533
3534
3535
3536
3542
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3561
3562
3563
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3580
3581
3583
3584
3585
3586
3587
3588
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3618
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3658
3659
3660
3662
3663
3665
3666
3667
3668
3669
3670
3671
3673
3674
3676
3677
3678
3679
3680
3681
3682
3683
3687
3688
3689
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3711
3712
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3734
3739
3744
3748
3749
3753
3757
3758
3759
3762
3763
3764
3767
3768
3771
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
/* ... */
#ifdef HAL_UART_MODULE_ENABLED
/* ... */
/* ... */
Private define
/* ... */
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart);
#endif
static void UART_EndTxTransfer(UART_HandleTypeDef *huart);
static void UART_EndRxTransfer(UART_HandleTypeDef *huart);
static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma);
static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
static void UART_DMAError(DMA_HandleTypeDef *hdma);
static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma);
static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart);
static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart);
static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart);
static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status,
uint32_t Tickstart, uint32_t Timeout);
static void UART_SetConfig(UART_HandleTypeDef *huart);
/* ... */
Private function prototypes
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
{
if (huart == NULL)
{
return HAL_ERROR;
}if (huart == NULL) { ... }
if (huart->Init.HwFlowCtl != UART_HWCONTROL_NONE)
{
/* ... */
assert_param(IS_UART_HWFLOW_INSTANCE(huart->Instance));
assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart->Init.HwFlowCtl));
}if (huart->Init.HwFlowCtl != UART_HWCONTROL_NONE) { ... }
else
{
assert_param(IS_UART_INSTANCE(huart->Instance));
}else { ... }
assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
if (huart->gState == HAL_UART_STATE_RESET)
{
huart->Lock = HAL_UNLOCKED;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
UART_InitCallbacksToDefault(huart);
if (huart->MspInitCallback == NULL)
{
huart->MspInitCallback = HAL_UART_MspInit;
}if (huart->MspInitCallback == NULL) { ... }
huart->MspInitCallback(huart);/* ... */
#else
HAL_UART_MspInit(huart);/* ... */
#endif
}if (huart->gState == HAL_UART_STATE_RESET) { ... }
huart->gState = HAL_UART_STATE_BUSY;
__HAL_UART_DISABLE(huart);
UART_SetConfig(huart);
/* ... */
CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
CLEAR_BIT(huart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
__HAL_UART_ENABLE(huart);
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_READY;
huart->RxState = HAL_UART_STATE_READY;
huart->RxEventType = HAL_UART_RXEVENT_TC;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart)
{
if (huart == NULL)
{
return HAL_ERROR;
}if (huart == NULL) { ... }
assert_param(IS_UART_HALFDUPLEX_INSTANCE(huart->Instance));
assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
if (huart->gState == HAL_UART_STATE_RESET)
{
huart->Lock = HAL_UNLOCKED;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
UART_InitCallbacksToDefault(huart);
if (huart->MspInitCallback == NULL)
{
huart->MspInitCallback = HAL_UART_MspInit;
}if (huart->MspInitCallback == NULL) { ... }
huart->MspInitCallback(huart);/* ... */
#else
HAL_UART_MspInit(huart);/* ... */
#endif
}if (huart->gState == HAL_UART_STATE_RESET) { ... }
huart->gState = HAL_UART_STATE_BUSY;
__HAL_UART_DISABLE(huart);
UART_SetConfig(huart);
/* ... */
CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
CLEAR_BIT(huart->Instance->CR3, (USART_CR3_IREN | USART_CR3_SCEN));
SET_BIT(huart->Instance->CR3, USART_CR3_HDSEL);
__HAL_UART_ENABLE(huart);
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_READY;
huart->RxState = HAL_UART_STATE_READY;
huart->RxEventType = HAL_UART_RXEVENT_TC;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength)
{
if (huart == NULL)
{
return HAL_ERROR;
}if (huart == NULL) { ... }
assert_param(IS_UART_LIN_INSTANCE(huart->Instance));
assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength));
assert_param(IS_UART_LIN_WORD_LENGTH(huart->Init.WordLength));
assert_param(IS_UART_LIN_OVERSAMPLING(huart->Init.OverSampling));
if (huart->gState == HAL_UART_STATE_RESET)
{
huart->Lock = HAL_UNLOCKED;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
UART_InitCallbacksToDefault(huart);
if (huart->MspInitCallback == NULL)
{
huart->MspInitCallback = HAL_UART_MspInit;
}if (huart->MspInitCallback == NULL) { ... }
huart->MspInitCallback(huart);/* ... */
#else
HAL_UART_MspInit(huart);/* ... */
#endif
}if (huart->gState == HAL_UART_STATE_RESET) { ... }
huart->gState = HAL_UART_STATE_BUSY;
__HAL_UART_DISABLE(huart);
UART_SetConfig(huart);
/* ... */
CLEAR_BIT(huart->Instance->CR2, (USART_CR2_CLKEN));
CLEAR_BIT(huart->Instance->CR3, (USART_CR3_HDSEL | USART_CR3_IREN | USART_CR3_SCEN));
SET_BIT(huart->Instance->CR2, USART_CR2_LINEN);
CLEAR_BIT(huart->Instance->CR2, USART_CR2_LBDL);
SET_BIT(huart->Instance->CR2, BreakDetectLength);
__HAL_UART_ENABLE(huart);
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_READY;
huart->RxState = HAL_UART_STATE_READY;
huart->RxEventType = HAL_UART_RXEVENT_TC;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod)
{
if (huart == NULL)
{
return HAL_ERROR;
}if (huart == NULL) { ... }
assert_param(IS_UART_INSTANCE(huart->Instance));
assert_param(IS_UART_WAKEUPMETHOD(WakeUpMethod));
assert_param(IS_UART_ADDRESS(Address));
assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
if (huart->gState == HAL_UART_STATE_RESET)
{
huart->Lock = HAL_UNLOCKED;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
UART_InitCallbacksToDefault(huart);
if (huart->MspInitCallback == NULL)
{
huart->MspInitCallback = HAL_UART_MspInit;
}if (huart->MspInitCallback == NULL) { ... }
huart->MspInitCallback(huart);/* ... */
#else
HAL_UART_MspInit(huart);/* ... */
#endif
}if (huart->gState == HAL_UART_STATE_RESET) { ... }
huart->gState = HAL_UART_STATE_BUSY;
__HAL_UART_DISABLE(huart);
UART_SetConfig(huart);
/* ... */
CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
CLEAR_BIT(huart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
CLEAR_BIT(huart->Instance->CR2, USART_CR2_ADD);
SET_BIT(huart->Instance->CR2, Address);
CLEAR_BIT(huart->Instance->CR1, USART_CR1_WAKE);
SET_BIT(huart->Instance->CR1, WakeUpMethod);
__HAL_UART_ENABLE(huart);
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_READY;
huart->RxState = HAL_UART_STATE_READY;
huart->RxEventType = HAL_UART_RXEVENT_TC;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart)
{
if (huart == NULL)
{
return HAL_ERROR;
}if (huart == NULL) { ... }
assert_param(IS_UART_INSTANCE(huart->Instance));
huart->gState = HAL_UART_STATE_BUSY;
__HAL_UART_DISABLE(huart);
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
if (huart->MspDeInitCallback == NULL)
{
huart->MspDeInitCallback = HAL_UART_MspDeInit;
}if (huart->MspDeInitCallback == NULL) { ... }
huart->MspDeInitCallback(huart);/* ... */
#else
HAL_UART_MspDeInit(huart);/* ... */
#endif
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_RESET;
huart->RxState = HAL_UART_STATE_RESET;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
huart->RxEventType = HAL_UART_RXEVENT_TC;
__HAL_UNLOCK(huart);
return HAL_OK;
}{ ... }
/* ... */
__weak void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
/* ... */
HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID,
pUART_CallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
if (pCallback == NULL)
{
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
return HAL_ERROR;
}if (pCallback == NULL) { ... }
if (huart->gState == HAL_UART_STATE_READY)
{
switch (CallbackID)
{
case HAL_UART_TX_HALFCOMPLETE_CB_ID :
huart->TxHalfCpltCallback = pCallback;
break;
case HAL_UART_TX_HALFCOMPLETE_CB_ID :
case HAL_UART_TX_COMPLETE_CB_ID :
huart->TxCpltCallback = pCallback;
break;
case HAL_UART_TX_COMPLETE_CB_ID :
case HAL_UART_RX_HALFCOMPLETE_CB_ID :
huart->RxHalfCpltCallback = pCallback;
break;
case HAL_UART_RX_HALFCOMPLETE_CB_ID :
case HAL_UART_RX_COMPLETE_CB_ID :
huart->RxCpltCallback = pCallback;
break;
case HAL_UART_RX_COMPLETE_CB_ID :
case HAL_UART_ERROR_CB_ID :
huart->ErrorCallback = pCallback;
break;
case HAL_UART_ERROR_CB_ID :
case HAL_UART_ABORT_COMPLETE_CB_ID :
huart->AbortCpltCallback = pCallback;
break;
case HAL_UART_ABORT_COMPLETE_CB_ID :
case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID :
huart->AbortTransmitCpltCallback = pCallback;
break;
case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID :
case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID :
huart->AbortReceiveCpltCallback = pCallback;
break;
case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID :
case HAL_UART_MSPINIT_CB_ID :
huart->MspInitCallback = pCallback;
break;
case HAL_UART_MSPINIT_CB_ID :
case HAL_UART_MSPDEINIT_CB_ID :
huart->MspDeInitCallback = pCallback;
break;
case HAL_UART_MSPDEINIT_CB_ID :
default :
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (huart->gState == HAL_UART_STATE_READY) { ... }
else if (huart->gState == HAL_UART_STATE_RESET)
{
switch (CallbackID)
{
case HAL_UART_MSPINIT_CB_ID :
huart->MspInitCallback = pCallback;
break;
case HAL_UART_MSPINIT_CB_ID :
case HAL_UART_MSPDEINIT_CB_ID :
huart->MspDeInitCallback = pCallback;
break;
case HAL_UART_MSPDEINIT_CB_ID :
default :
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (huart->gState == HAL_UART_STATE_RESET) { ... }
else
{
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
return status;
}HAL_UART_RegisterCallback (UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, pUART_CallbackTypeDef pCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
if (HAL_UART_STATE_READY == huart->gState)
{
switch (CallbackID)
{
case HAL_UART_TX_HALFCOMPLETE_CB_ID :
huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback;
break;
case HAL_UART_TX_HALFCOMPLETE_CB_ID :
case HAL_UART_TX_COMPLETE_CB_ID :
huart->TxCpltCallback = HAL_UART_TxCpltCallback;
break;
case HAL_UART_TX_COMPLETE_CB_ID :
case HAL_UART_RX_HALFCOMPLETE_CB_ID :
huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback;
break;
case HAL_UART_RX_HALFCOMPLETE_CB_ID :
case HAL_UART_RX_COMPLETE_CB_ID :
huart->RxCpltCallback = HAL_UART_RxCpltCallback;
break;
case HAL_UART_RX_COMPLETE_CB_ID :
case HAL_UART_ERROR_CB_ID :
huart->ErrorCallback = HAL_UART_ErrorCallback;
break;
case HAL_UART_ERROR_CB_ID :
case HAL_UART_ABORT_COMPLETE_CB_ID :
huart->AbortCpltCallback = HAL_UART_AbortCpltCallback;
break;
case HAL_UART_ABORT_COMPLETE_CB_ID :
case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID :
huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback;
break;
case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID :
case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID :
huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback;
break;
case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID :
case HAL_UART_MSPINIT_CB_ID :
huart->MspInitCallback = HAL_UART_MspInit;
break;
case HAL_UART_MSPINIT_CB_ID :
case HAL_UART_MSPDEINIT_CB_ID :
huart->MspDeInitCallback = HAL_UART_MspDeInit;
break;
case HAL_UART_MSPDEINIT_CB_ID :
default :
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (HAL_UART_STATE_READY == huart->gState) { ... }
else if (HAL_UART_STATE_RESET == huart->gState)
{
switch (CallbackID)
{
case HAL_UART_MSPINIT_CB_ID :
huart->MspInitCallback = HAL_UART_MspInit;
break;
case HAL_UART_MSPINIT_CB_ID :
case HAL_UART_MSPDEINIT_CB_ID :
huart->MspDeInitCallback = HAL_UART_MspDeInit;
break;
case HAL_UART_MSPDEINIT_CB_ID :
default :
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (HAL_UART_STATE_RESET == huart->gState) { ... }
else
{
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
return status;
}HAL_UART_UnRegisterCallback (UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID) { ... }
/* ... */
HAL_StatusTypeDef HAL_UART_RegisterRxEventCallback(UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
if (pCallback == NULL)
{
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
return HAL_ERROR;
}if (pCallback == NULL) { ... }
__HAL_LOCK(huart);
if (huart->gState == HAL_UART_STATE_READY)
{
huart->RxEventCallback = pCallback;
}if (huart->gState == HAL_UART_STATE_READY) { ... }
else
{
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(huart);
return status;
}HAL_UART_RegisterRxEventCallback (UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_UART_UnRegisterRxEventCallback(UART_HandleTypeDef *huart)
{
HAL_StatusTypeDef status = HAL_OK;
__HAL_LOCK(huart);
if (huart->gState == HAL_UART_STATE_READY)
{
huart->RxEventCallback = HAL_UARTEx_RxEventCallback;
}if (huart->gState == HAL_UART_STATE_READY) { ... }
else
{
huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(huart);
return status;
}HAL_UART_UnRegisterRxEventCallback (UART_HandleTypeDef *huart) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout)
{
const uint8_t *pdata8bits;
const uint16_t *pdata16bits;
uint32_t tickstart = 0U;
if (huart->gState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_BUSY_TX;
tickstart = HAL_GetTick();
huart->TxXferSize = Size;
huart->TxXferCount = Size;
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
{
pdata8bits = NULL;
pdata16bits = (const uint16_t *) pData;
}if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) { ... }
else
{
pdata8bits = pData;
pdata16bits = NULL;
}else { ... }
while (huart->TxXferCount > 0U)
{
if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
huart->gState = HAL_UART_STATE_READY;
return HAL_TIMEOUT;
}if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) { ... }
if (pdata8bits == NULL)
{
huart->Instance->DR = (uint16_t)(*pdata16bits & 0x01FFU);
pdata16bits++;
}if (pdata8bits == NULL) { ... }
else
{
huart->Instance->DR = (uint8_t)(*pdata8bits & 0xFFU);
pdata8bits++;
}else { ... }
huart->TxXferCount--;
}while (huart->TxXferCount > 0U) { ... }
if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
{
huart->gState = HAL_UART_STATE_READY;
return HAL_TIMEOUT;
}if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK) { ... }
huart->gState = HAL_UART_STATE_READY;
return HAL_OK;
}if (huart->gState == HAL_UART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
{
uint8_t *pdata8bits;
uint16_t *pdata16bits;
uint32_t tickstart = 0U;
if (huart->RxState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->RxState = HAL_UART_STATE_BUSY_RX;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
tickstart = HAL_GetTick();
huart->RxXferSize = Size;
huart->RxXferCount = Size;
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
{
pdata8bits = NULL;
pdata16bits = (uint16_t *) pData;
}if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) { ... }
else
{
pdata8bits = pData;
pdata16bits = NULL;
}else { ... }
while (huart->RxXferCount > 0U)
{
if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
{
huart->RxState = HAL_UART_STATE_READY;
return HAL_TIMEOUT;
}if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) { ... }
if (pdata8bits == NULL)
{
*pdata16bits = (uint16_t)(huart->Instance->DR & 0x01FF);
pdata16bits++;
}if (pdata8bits == NULL) { ... }
else
{
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE)))
{
*pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
}if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE))) { ... }
else
{
*pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
}else { ... }
pdata8bits++;
}else { ... }
huart->RxXferCount--;
}while (huart->RxXferCount > 0U) { ... }
huart->RxState = HAL_UART_STATE_READY;
return HAL_OK;
}if (huart->RxState == HAL_UART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size)
{
if (huart->gState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
huart->pTxBuffPtr = pData;
huart->TxXferSize = Size;
huart->TxXferCount = Size;
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_BUSY_TX;
__HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
return HAL_OK;
}if (huart->gState == HAL_UART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
if (huart->RxState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
return (UART_Start_Receive_IT(huart, pData, Size));
}if (huart->RxState == HAL_UART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size)
{
const uint32_t *tmp;
if (huart->gState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
huart->pTxBuffPtr = pData;
huart->TxXferSize = Size;
huart->TxXferCount = Size;
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_BUSY_TX;
huart->hdmatx->XferCpltCallback = UART_DMATransmitCplt;
huart->hdmatx->XferHalfCpltCallback = UART_DMATxHalfCplt;
huart->hdmatx->XferErrorCallback = UART_DMAError;
huart->hdmatx->XferAbortCallback = NULL;
tmp = (const uint32_t *)&pData;
HAL_DMA_Start_IT(huart->hdmatx, *(const uint32_t *)tmp, (uint32_t)&huart->Instance->DR, Size);
__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_TC);
/* ... */
ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAT);
return HAL_OK;
}if (huart->gState == HAL_UART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
if (huart->RxState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
return (UART_Start_Receive_DMA(huart, pData, Size));
}if (huart->RxState == HAL_UART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart)
{
uint32_t dmarequest = 0x00U;
dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT);
if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
}if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest) { ... }
dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR);
if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE);
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
}if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest) { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart)
{
if (huart->gState == HAL_UART_STATE_BUSY_TX)
{
ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAT);
}if (huart->gState == HAL_UART_STATE_BUSY_TX) { ... }
if (huart->RxState == HAL_UART_STATE_BUSY_RX)
{
__HAL_UART_CLEAR_OREFLAG(huart);
if (huart->Init.Parity != UART_PARITY_NONE)
{
ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);
}if (huart->Init.Parity != UART_PARITY_NONE) { ... }
ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
}if (huart->RxState == HAL_UART_STATE_BUSY_RX) { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart)
{
uint32_t dmarequest = 0x00U;
/* ... */
dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT);
if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
if (huart->hdmatx != NULL)
{
HAL_DMA_Abort(huart->hdmatx);
}if (huart->hdmatx != NULL) { ... }
UART_EndTxTransfer(huart);
}if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest) { ... }
dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR);
if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
if (huart->hdmarx != NULL)
{
HAL_DMA_Abort(huart->hdmarx);
}if (huart->hdmarx != NULL) { ... }
UART_EndRxTransfer(huart);
}if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest) { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen,
uint32_t Timeout)
{
uint8_t *pdata8bits;
uint16_t *pdata16bits;
uint32_t tickstart;
if (huart->RxState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->RxState = HAL_UART_STATE_BUSY_RX;
huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
huart->RxEventType = HAL_UART_RXEVENT_TC;
tickstart = HAL_GetTick();
huart->RxXferSize = Size;
huart->RxXferCount = Size;
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
{
pdata8bits = NULL;
pdata16bits = (uint16_t *) pData;
}if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) { ... }
else
{
pdata8bits = pData;
pdata16bits = NULL;
}else { ... }
*RxLen = 0U;
while (huart->RxXferCount > 0U)
{
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE))
{
__HAL_UART_CLEAR_IDLEFLAG(huart);
if (*RxLen > 0U)
{
huart->RxEventType = HAL_UART_RXEVENT_IDLE;
huart->RxState = HAL_UART_STATE_READY;
return HAL_OK;
}if (*RxLen > 0U) { ... }
}if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE)) { ... }
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE))
{
if (pdata8bits == NULL)
{
*pdata16bits = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
pdata16bits++;
}if (pdata8bits == NULL) { ... }
else
{
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE)))
{
*pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
}if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE))) { ... }
else
{
*pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
}else { ... }
pdata8bits++;
}else { ... }
*RxLen += 1U;
huart->RxXferCount--;
}if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE)) { ... }
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
huart->RxState = HAL_UART_STATE_READY;
return HAL_TIMEOUT;
}if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
}while (huart->RxXferCount > 0U) { ... }
*RxLen = huart->RxXferSize - huart->RxXferCount;
huart->RxState = HAL_UART_STATE_READY;
return HAL_OK;
}if (huart->RxState == HAL_UART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
HAL_StatusTypeDef status;
if (huart->RxState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
huart->RxEventType = HAL_UART_RXEVENT_TC;
status = UART_Start_Receive_IT(huart, pData, Size);
if (status == HAL_OK)
{
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
__HAL_UART_CLEAR_IDLEFLAG(huart);
ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
else
{
/* ... */
status = HAL_ERROR;
}else { ... }
}if (status == HAL_OK) { ... }
return status;
}if (huart->RxState == HAL_UART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
HAL_StatusTypeDef status;
if (huart->RxState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE;
huart->RxEventType = HAL_UART_RXEVENT_TC;
status = UART_Start_Receive_DMA(huart, pData, Size);
if (status == HAL_OK)
{
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
__HAL_UART_CLEAR_IDLEFLAG(huart);
ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
else
{
/* ... */
status = HAL_ERROR;
}else { ... }
}if (status == HAL_OK) { ... }
return status;
}if (huart->RxState == HAL_UART_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_UART_RxEventTypeTypeDef HAL_UARTEx_GetRxEventType(UART_HandleTypeDef *huart)
{
return(huart->RxEventType);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE));
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
if (huart->hdmatx != NULL)
{
/* ... */
huart->hdmatx->XferAbortCallback = NULL;
if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK)
{
if (HAL_DMA_GetError(huart->hdmatx) == HAL_DMA_ERROR_TIMEOUT)
{
huart->ErrorCode = HAL_UART_ERROR_DMA;
return HAL_TIMEOUT;
}if (HAL_DMA_GetError(huart->hdmatx) == HAL_DMA_ERROR_TIMEOUT) { ... }
}if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK) { ... }
}if (huart->hdmatx != NULL) { ... }
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) { ... }
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
if (huart->hdmarx != NULL)
{
/* ... */
huart->hdmarx->XferAbortCallback = NULL;
if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK)
{
if (HAL_DMA_GetError(huart->hdmarx) == HAL_DMA_ERROR_TIMEOUT)
{
huart->ErrorCode = HAL_UART_ERROR_DMA;
return HAL_TIMEOUT;
}if (HAL_DMA_GetError(huart->hdmarx) == HAL_DMA_ERROR_TIMEOUT) { ... }
}if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK) { ... }
}if (huart->hdmarx != NULL) { ... }
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) { ... }
huart->TxXferCount = 0x00U;
huart->RxXferCount = 0x00U;
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->RxState = HAL_UART_STATE_READY;
huart->gState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
if (huart->hdmatx != NULL)
{
/* ... */
huart->hdmatx->XferAbortCallback = NULL;
if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK)
{
if (HAL_DMA_GetError(huart->hdmatx) == HAL_DMA_ERROR_TIMEOUT)
{
huart->ErrorCode = HAL_UART_ERROR_DMA;
return HAL_TIMEOUT;
}if (HAL_DMA_GetError(huart->hdmatx) == HAL_DMA_ERROR_TIMEOUT) { ... }
}if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK) { ... }
}if (huart->hdmatx != NULL) { ... }
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) { ... }
huart->TxXferCount = 0x00U;
huart->gState = HAL_UART_STATE_READY;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE));
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
if (huart->hdmarx != NULL)
{
/* ... */
huart->hdmarx->XferAbortCallback = NULL;
if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK)
{
if (HAL_DMA_GetError(huart->hdmarx) == HAL_DMA_ERROR_TIMEOUT)
{
huart->ErrorCode = HAL_UART_ERROR_DMA;
return HAL_TIMEOUT;
}if (HAL_DMA_GetError(huart->hdmarx) == HAL_DMA_ERROR_TIMEOUT) { ... }
}if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK) { ... }
}if (huart->hdmarx != NULL) { ... }
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) { ... }
huart->RxXferCount = 0x00U;
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart)
{
uint32_t AbortCplt = 0x01U;
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE));
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
/* ... */
if (huart->hdmatx != NULL)
{
/* ... */
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
{
huart->hdmatx->XferAbortCallback = UART_DMATxAbortCallback;
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) { ... }
else
{
huart->hdmatx->XferAbortCallback = NULL;
}else { ... }
}if (huart->hdmatx != NULL) { ... }
if (huart->hdmarx != NULL)
{
/* ... */
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
{
huart->hdmarx->XferAbortCallback = UART_DMARxAbortCallback;
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) { ... }
else
{
huart->hdmarx->XferAbortCallback = NULL;
}else { ... }
}if (huart->hdmarx != NULL) { ... }
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
if (huart->hdmatx != NULL)
{
/* ... */
if (HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK)
{
huart->hdmatx->XferAbortCallback = NULL;
}if (HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK) { ... }
else
{
AbortCplt = 0x00U;
}else { ... }
}if (huart->hdmatx != NULL) { ... }
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) { ... }
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
if (huart->hdmarx != NULL)
{
/* ... */
if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK)
{
huart->hdmarx->XferAbortCallback = NULL;
AbortCplt = 0x01U;
}if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK) { ... }
else
{
AbortCplt = 0x00U;
}else { ... }
}if (huart->hdmarx != NULL) { ... }
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) { ... }
if (AbortCplt == 0x01U)
{
huart->TxXferCount = 0x00U;
huart->RxXferCount = 0x00U;
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_READY;
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->AbortCpltCallback(huart);/* ... */
#else
HAL_UART_AbortCpltCallback(huart);/* ... */
#endif
}if (AbortCplt == 0x01U) { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
if (huart->hdmatx != NULL)
{
/* ... */
huart->hdmatx->XferAbortCallback = UART_DMATxOnlyAbortCallback;
if (HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK)
{
huart->hdmatx->XferAbortCallback(huart->hdmatx);
}if (HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK) { ... }
}if (huart->hdmatx != NULL) { ... }
else
{
huart->TxXferCount = 0x00U;
huart->gState = HAL_UART_STATE_READY;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->AbortTransmitCpltCallback(huart);/* ... */
#else
HAL_UART_AbortTransmitCpltCallback(huart);/* ... */
#endif
}else { ... }
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) { ... }
else
{
huart->TxXferCount = 0x00U;
huart->gState = HAL_UART_STATE_READY;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->AbortTransmitCpltCallback(huart);/* ... */
#else
HAL_UART_AbortTransmitCpltCallback(huart);/* ... */
#endif
}else { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE));
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
if (huart->hdmarx != NULL)
{
/* ... */
huart->hdmarx->XferAbortCallback = UART_DMARxOnlyAbortCallback;
if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK)
{
huart->hdmarx->XferAbortCallback(huart->hdmarx);
}if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK) { ... }
}if (huart->hdmarx != NULL) { ... }
else
{
huart->RxXferCount = 0x00U;
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->AbortReceiveCpltCallback(huart);/* ... */
#else
HAL_UART_AbortReceiveCpltCallback(huart);/* ... */
#endif
}else { ... }
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) { ... }
else
{
huart->RxXferCount = 0x00U;
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->AbortReceiveCpltCallback(huart);/* ... */
#else
HAL_UART_AbortReceiveCpltCallback(huart);/* ... */
#endif
}else { ... }
return HAL_OK;
}{ ... }
/* ... */
void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
{
uint32_t isrflags = READ_REG(huart->Instance->SR);
uint32_t cr1its = READ_REG(huart->Instance->CR1);
uint32_t cr3its = READ_REG(huart->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))
{
UART_Receive_IT(huart);
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))
{
huart->ErrorCode |= HAL_UART_ERROR_PE;
}if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET)) { ... }
UART parity error interrupt occurred
if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
{
huart->ErrorCode |= HAL_UART_ERROR_NE;
}if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) { ... }
UART noise error interrupt occurred
if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
{
huart->ErrorCode |= HAL_UART_ERROR_FE;
}if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) { ... }
UART frame error interrupt occurred
if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET)
|| ((cr3its & USART_CR3_EIE) != RESET)))
{
huart->ErrorCode |= HAL_UART_ERROR_ORE;
}if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET))) { ... }
UART Over-Run interrupt occurred
if (huart->ErrorCode != HAL_UART_ERROR_NONE)
{
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
{
UART_Receive_IT(huart);
}if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) { ... }
/* ... */
dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR);
if (((huart->ErrorCode & HAL_UART_ERROR_ORE) != RESET) || dmarequest)
{
/* ... */
UART_EndRxTransfer(huart);
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
if (huart->hdmarx != NULL)
{
/* ... */
huart->hdmarx->XferAbortCallback = UART_DMAAbortOnError;
if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK)
{
huart->hdmarx->XferAbortCallback(huart->hdmarx);
}if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK) { ... }
}if (huart->hdmarx != NULL) { ... }
else
{
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->ErrorCallback(huart);/* ... */
#else
HAL_UART_ErrorCallback(huart);/* ... */
#endif
}else { ... }
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) { ... }
else
{
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->ErrorCallback(huart);/* ... */
#else
HAL_UART_ErrorCallback(huart);/* ... */
#endif
}else { ... }
}if (((huart->ErrorCode & HAL_UART_ERROR_ORE) != RESET) || dmarequest) { ... }
else
{
/* ... */
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->ErrorCallback(huart);/* ... */
#else
HAL_UART_ErrorCallback(huart);/* ... */
#endif
huart->ErrorCode = HAL_UART_ERROR_NONE;
}else { ... }
}if (huart->ErrorCode != HAL_UART_ERROR_NONE) { ... }
return;
}if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET))) { ... }
/* ... */
if ((huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
&& ((isrflags & USART_SR_IDLE) != 0U)
&& ((cr1its & USART_SR_IDLE) != 0U))
{
__HAL_UART_CLEAR_IDLEFLAG(huart);
if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
{
/* ... */
uint16_t nb_remaining_rx_data = (uint16_t) __HAL_DMA_GET_COUNTER(huart->hdmarx);
if ((nb_remaining_rx_data > 0U)
&& (nb_remaining_rx_data < huart->RxXferSize))
{
huart->RxXferCount = nb_remaining_rx_data;
if (huart->hdmarx->Init.Mode != DMA_CIRCULAR)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE);
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
/* ... */
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
(void)HAL_DMA_Abort(huart->hdmarx);
}if (huart->hdmarx->Init.Mode != DMA_CIRCULAR) { ... }
/* ... */
huart->RxEventType = HAL_UART_RXEVENT_IDLE;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->RxEventCallback(huart, (huart->RxXferSize - huart->RxXferCount));/* ... */
#else
HAL_UARTEx_RxEventCallback(huart, (huart->RxXferSize - huart->RxXferCount));/* ... */
#endif
}if ((nb_remaining_rx_data > 0U) && (nb_remaining_rx_data < huart->RxXferSize)) { ... }
return;
}if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) { ... }
else
{
/* ... */
uint16_t nb_rx_data = huart->RxXferSize - huart->RxXferCount;
if ((huart->RxXferCount > 0U)
&& (nb_rx_data > 0U))
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
/* ... */
huart->RxEventType = HAL_UART_RXEVENT_IDLE;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->RxEventCallback(huart, nb_rx_data);/* ... */
#else
HAL_UARTEx_RxEventCallback(huart, nb_rx_data);/* ... */
#endif
}if ((huart->RxXferCount > 0U) && (nb_rx_data > 0U)) { ... }
return;
}else { ... }
}if ((huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) && ((isrflags & USART_SR_IDLE) != 0U) && ((cr1its & USART_SR_IDLE) != 0U)) { ... }
if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
{
UART_Transmit_IT(huart);
return;
}if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) { ... }
UART in mode Transmitter
if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
{
UART_EndTransmit_IT(huart);
return;
}if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) { ... }
}{ ... }
/* ... */
__weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart)
{
UNUSED(huart);
/* ... */
}{ ... }
/* ... */
__weak void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
UNUSED(huart);
UNUSED(Size);
/* ... */
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart)
{
assert_param(IS_UART_INSTANCE(huart->Instance));
__HAL_LOCK(huart);
huart->gState = HAL_UART_STATE_BUSY;
ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_SBK);
huart->gState = HAL_UART_STATE_READY;
__HAL_UNLOCK(huart);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart)
{
assert_param(IS_UART_INSTANCE(huart->Instance));
__HAL_LOCK(huart);
huart->gState = HAL_UART_STATE_BUSY;
ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_RWU);
huart->gState = HAL_UART_STATE_READY;
huart->RxEventType = HAL_UART_RXEVENT_TC;
__HAL_UNLOCK(huart);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart)
{
assert_param(IS_UART_INSTANCE(huart->Instance));
__HAL_LOCK(huart);
huart->gState = HAL_UART_STATE_BUSY;
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_RWU);
huart->gState = HAL_UART_STATE_READY;
huart->RxEventType = HAL_UART_RXEVENT_TC;
__HAL_UNLOCK(huart);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart)
{
uint32_t tmpreg = 0x00U;
__HAL_LOCK(huart);
huart->gState = HAL_UART_STATE_BUSY;
tmpreg = huart->Instance->CR1;
tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE));
tmpreg |= (uint32_t)USART_CR1_TE;
WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg);
huart->gState = HAL_UART_STATE_READY;
__HAL_UNLOCK(huart);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart)
{
uint32_t tmpreg = 0x00U;
__HAL_LOCK(huart);
huart->gState = HAL_UART_STATE_BUSY;
tmpreg = huart->Instance->CR1;
tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE));
tmpreg |= (uint32_t)USART_CR1_RE;
WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg);
huart->gState = HAL_UART_STATE_READY;
__HAL_UNLOCK(huart);
return HAL_OK;
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_UART_StateTypeDef HAL_UART_GetState(const UART_HandleTypeDef *huart)
{
uint32_t temp1 = 0x00U, temp2 = 0x00U;
temp1 = huart->gState;
temp2 = huart->RxState;
return (HAL_UART_StateTypeDef)(temp1 | temp2);
}{ ... }
/* ... */
uint32_t HAL_UART_GetError(const UART_HandleTypeDef *huart)
{
return huart->ErrorCode;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart)
{
huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback;
huart->TxCpltCallback = HAL_UART_TxCpltCallback;
huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback;
huart->RxCpltCallback = HAL_UART_RxCpltCallback;
huart->ErrorCallback = HAL_UART_ErrorCallback;
huart->AbortCpltCallback = HAL_UART_AbortCpltCallback;
huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback;
huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback;
huart->RxEventCallback = HAL_UARTEx_RxEventCallback;
}UART_InitCallbacksToDefault (UART_HandleTypeDef *huart) { ... }
/* ... */#endif
/* ... */
static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
{
huart->TxXferCount = 0x00U;
/* ... */
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_TCIE);
}if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U) { ... }
else
{
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->TxCpltCallback(huart);/* ... */
#else
HAL_UART_TxCpltCallback(huart);/* ... */
#endif
}else { ... }
}{ ... }
/* ... */
static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->TxHalfCpltCallback(huart);/* ... */
#else
HAL_UART_TxHalfCpltCallback(huart);/* ... */
#endif
}{ ... }
/* ... */
static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
{
huart->RxXferCount = 0U;
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE);
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
/* ... */
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
huart->RxState = HAL_UART_STATE_READY;
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
}if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U) { ... }
/* ... */
huart->RxEventType = HAL_UART_RXEVENT_TC;
/* ... */
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->RxEventCallback(huart, huart->RxXferSize);/* ... */
#else
HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize);/* ... */
#endif
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
else
{
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->RxCpltCallback(huart);/* ... */
#else
HAL_UART_RxCpltCallback(huart);/* ... */
#endif
}else { ... }
}{ ... }
/* ... */
static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
/* ... */
huart->RxEventType = HAL_UART_RXEVENT_HT;
/* ... */
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->RxEventCallback(huart, huart->RxXferSize / 2U);/* ... */
#else
HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize / 2U);/* ... */
#endif
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
else
{
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->RxHalfCpltCallback(huart);/* ... */
#else
HAL_UART_RxHalfCpltCallback(huart);/* ... */
#endif
}else { ... }
}{ ... }
/* ... */
static void UART_DMAError(DMA_HandleTypeDef *hdma)
{
uint32_t dmarequest = 0x00U;
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT);
if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest)
{
huart->TxXferCount = 0x00U;
UART_EndTxTransfer(huart);
}if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest) { ... }
dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR);
if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest)
{
huart->RxXferCount = 0x00U;
UART_EndRxTransfer(huart);
}if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest) { ... }
huart->ErrorCode |= HAL_UART_ERROR_DMA;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->ErrorCallback(huart);/* ... */
#else
HAL_UART_ErrorCallback(huart);/* ... */
#endif
}{ ... }
/* ... */
static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status,
uint32_t Tickstart, uint32_t Timeout)
{
while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status)
{
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
{
return HAL_TIMEOUT;
}if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U)) { ... }
if ((READ_BIT(huart->Instance->CR1, USART_CR1_RE) != 0U) && (Flag != UART_FLAG_TXE) && (Flag != UART_FLAG_TC))
{
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) == SET)
{
__HAL_UART_CLEAR_OREFLAG(huart);
/* ... */
UART_EndRxTransfer(huart);
huart->ErrorCode = HAL_UART_ERROR_ORE;
__HAL_UNLOCK(huart);
return HAL_ERROR;
}if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) == SET) { ... }
}if ((READ_BIT(huart->Instance->CR1, USART_CR1_RE) != 0U) && (Flag != UART_FLAG_TXE) && (Flag != UART_FLAG_TC)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
}while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status) { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
huart->pRxBuffPtr = pData;
huart->RxXferSize = Size;
huart->RxXferCount = Size;
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->RxState = HAL_UART_STATE_BUSY_RX;
if (huart->Init.Parity != UART_PARITY_NONE)
{
__HAL_UART_ENABLE_IT(huart, UART_IT_PE);
}if (huart->Init.Parity != UART_PARITY_NONE) { ... }
__HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
__HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef UART_Start_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
uint32_t *tmp;
huart->pRxBuffPtr = pData;
huart->RxXferSize = Size;
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->RxState = HAL_UART_STATE_BUSY_RX;
huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt;
huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt;
huart->hdmarx->XferErrorCallback = UART_DMAError;
huart->hdmarx->XferAbortCallback = NULL;
tmp = (uint32_t *)&pData;
HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->DR, *(uint32_t *)tmp, Size);
__HAL_UART_CLEAR_OREFLAG(huart);
if (huart->Init.Parity != UART_PARITY_NONE)
{
ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);
}if (huart->Init.Parity != UART_PARITY_NONE) { ... }
ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
/* ... */
ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
return HAL_OK;
}{ ... }
/* ... */
static void UART_EndTxTransfer(UART_HandleTypeDef *huart)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
huart->gState = HAL_UART_STATE_READY;
}{ ... }
/* ... */
static void UART_EndRxTransfer(UART_HandleTypeDef *huart)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
}{ ... }
/* ... */
static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
huart->RxXferCount = 0x00U;
huart->TxXferCount = 0x00U;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->ErrorCallback(huart);/* ... */
#else
HAL_UART_ErrorCallback(huart);/* ... */
#endif
}{ ... }
/* ... */
static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
huart->hdmatx->XferAbortCallback = NULL;
if (huart->hdmarx != NULL)
{
if (huart->hdmarx->XferAbortCallback != NULL)
{
return;
}if (huart->hdmarx->XferAbortCallback != NULL) { ... }
}if (huart->hdmarx != NULL) { ... }
huart->TxXferCount = 0x00U;
huart->RxXferCount = 0x00U;
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_READY;
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->AbortCpltCallback(huart);/* ... */
#else
HAL_UART_AbortCpltCallback(huart);/* ... */
#endif
}{ ... }
/* ... */
static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
huart->hdmarx->XferAbortCallback = NULL;
if (huart->hdmatx != NULL)
{
if (huart->hdmatx->XferAbortCallback != NULL)
{
return;
}if (huart->hdmatx->XferAbortCallback != NULL) { ... }
}if (huart->hdmatx != NULL) { ... }
huart->TxXferCount = 0x00U;
huart->RxXferCount = 0x00U;
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_READY;
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->AbortCpltCallback(huart);/* ... */
#else
HAL_UART_AbortCpltCallback(huart);/* ... */
#endif
}{ ... }
/* ... */
static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
huart->TxXferCount = 0x00U;
huart->gState = HAL_UART_STATE_READY;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->AbortTransmitCpltCallback(huart);/* ... */
#else
HAL_UART_AbortTransmitCpltCallback(huart);/* ... */
#endif
}{ ... }
/* ... */
static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
{
UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
huart->RxXferCount = 0x00U;
huart->RxState = HAL_UART_STATE_READY;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->AbortReceiveCpltCallback(huart);/* ... */
#else
HAL_UART_AbortReceiveCpltCallback(huart);/* ... */
#endif
}{ ... }
/* ... */
static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart)
{
const uint16_t *tmp;
if (huart->gState == HAL_UART_STATE_BUSY_TX)
{
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
{
tmp = (const uint16_t *) huart->pTxBuffPtr;
huart->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
huart->pTxBuffPtr += 2U;
}if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) { ... }
else
{
huart->Instance->DR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0x00FF);
}else { ... }
if (--huart->TxXferCount == 0U)
{
__HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
__HAL_UART_ENABLE_IT(huart, UART_IT_TC);
}if (--huart->TxXferCount == 0U) { ... }
return HAL_OK;
}if (huart->gState == HAL_UART_STATE_BUSY_TX) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart)
{
__HAL_UART_DISABLE_IT(huart, UART_IT_TC);
huart->gState = HAL_UART_STATE_READY;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->TxCpltCallback(huart);/* ... */
#else
HAL_UART_TxCpltCallback(huart);/* ... */
#endif
return HAL_OK;
}{ ... }
/* ... */
static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
{
uint8_t *pdata8bits;
uint16_t *pdata16bits;
if (huart->RxState == HAL_UART_STATE_BUSY_RX)
{
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
{
pdata8bits = NULL;
pdata16bits = (uint16_t *) huart->pRxBuffPtr;
*pdata16bits = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
huart->pRxBuffPtr += 2U;
}if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) { ... }
else
{
pdata8bits = (uint8_t *) huart->pRxBuffPtr;
pdata16bits = NULL;
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE)))
{
*pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
}if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE))) { ... }
else
{
*pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
}else { ... }
huart->pRxBuffPtr += 1U;
}else { ... }
if (--huart->RxXferCount == 0U)
{
__HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
__HAL_UART_DISABLE_IT(huart, UART_IT_PE);
__HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
huart->RxState = HAL_UART_STATE_READY;
huart->RxEventType = HAL_UART_RXEVENT_TC;
/* ... */
if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE)
{
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE);
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE))
{
__HAL_UART_CLEAR_IDLEFLAG(huart);
}if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE)) { ... }
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->RxEventCallback(huart, huart->RxXferSize);/* ... */
#else
HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize);/* ... */
#endif
}if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { ... }
else
{
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
huart->RxCpltCallback(huart);/* ... */
#else
HAL_UART_RxCpltCallback(huart);/* ... */
#endif
}else { ... }
return HAL_OK;
}if (--huart->RxXferCount == 0U) { ... }
return HAL_OK;
}if (huart->RxState == HAL_UART_STATE_BUSY_RX) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
static void UART_SetConfig(UART_HandleTypeDef *huart)
{
uint32_t tmpreg;
uint32_t pclk;
assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate));
assert_param(IS_UART_STOPBITS(huart->Init.StopBits));
assert_param(IS_UART_PARITY(huart->Init.Parity));
assert_param(IS_UART_MODE(huart->Init.Mode));
/* ... */
MODIFY_REG(huart->Instance->CR2, USART_CR2_STOP, huart->Init.StopBits);
-------------------------- USART CR2 Configuration
/* ... */
tmpreg = (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode | huart->Init.OverSampling;
MODIFY_REG(huart->Instance->CR1,
(uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8),
tmpreg);
-------------------------- USART CR1 Configuration
MODIFY_REG(huart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE), huart->Init.HwFlowCtl);
#if defined(USART6) && defined(UART9) && defined(UART10)
if ((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9) || (huart->Instance == UART10))
{
pclk = HAL_RCC_GetPCLK2Freq();
}if ((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9) || (huart->Instance == UART10)) { ... }
/* ... */#elif defined(USART6)
if ((huart->Instance == USART1) || (huart->Instance == USART6))
{
pclk = HAL_RCC_GetPCLK2Freq();
}if ((huart->Instance == USART1) || (huart->Instance == USART6)) { ... }
/* ... */#else
if (huart->Instance == USART1)
{
pclk = HAL_RCC_GetPCLK2Freq();
}if (huart->Instance == USART1) { ... }
/* ... */#endif
else
{
pclk = HAL_RCC_GetPCLK1Freq();
}else { ... }
-------------------------- USART CR3 Configuration
if (huart->Init.OverSampling == UART_OVERSAMPLING_8)
{
huart->Instance->BRR = UART_BRR_SAMPLING8(pclk, huart->Init.BaudRate);
}if (huart->Init.OverSampling == UART_OVERSAMPLING_8) { ... }
else
{
huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate);
}else { ... }
}{ ... }
/* ... */
/* ... */
#endif
/* ... */
/* ... */