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
62
63
64
65
66
70
71
72
73
74
75
87
88
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
110
111
112
113
114
115
116
117
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
146
147
148
149
150
152
153
154
155
156
157
158
164
165
166
167
168
169
174
175
176
181
182
183
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
238
242
243
244
245
257
258
259
260
261
262
263
264
265
266
267
268
269
276
277
278
279
280
281
282
283
284
285
286
287
292
293
294
295
299
300
301
302
303
310
311
313
314
315
316
317
318
319
320
321
322
327
336
337
342
351
352
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
411
415
416
417
418
419
420
421
422
423
424
429
430
431
436
441
442
456
457
458
459
487
515
519
521
522
523
524
525
526
527
528
529
530
531
532
533
538
539
540
541
542
543
544
545
546
547
548
549
553
554
559
560
565
566
571
572
577
578
579
580
581
582
583
584
585
586
587
588
589
594
595
596
597
598
599
600
601
602
603
604
605
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
661
665
666
667
672
681
682
687
696
697
702
711
712
717
726
727
732
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
798
799
800
801
802
803
804
805
809
813
817
821
825
829
833
839
840
841
861
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
905
909
913
917
921
925
929
936
937
938
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
980
981
982
983
984
985
992
993
994
995
996
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1106
1110
1111
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1135
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1193
1194
1199
1203
1204
1209
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1265
1266
1269
1270
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1292
1298
1304
1310
1316
1320
1321
1326
1327
1328
1329
1330
1331
1336
1337
1341
1342
1343
1344
1345
1346
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1368
1369
1376
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1402
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
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
1458
1459
1460
1461
1465
1466
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1527
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1550
1551
1552
1553
1554
1555
1561
1562
1563
1564
1565
1566
1571
1572
1576
1577
1583
1584
1585
1586
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1630
1631
1632
1633
1634
1635
1636
1637
1638
1643
1644
1645
1646
1647
1648
1653
1654
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1672
1673
1674
1675
1676
1677
1683
1684
1685
1686
1687
1688
1695
1696
1697
1698
1699
1700
1701
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1724
1725
1726
1727
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1749
1750
1759
1760
1761
1770
1771
1772
1773
1774
1775
1780
1781
1786
1791
1792
1793
1794
1795
1796
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1816
1817
1818
1819
1820
1821
1822
1823
1827
1828
1829
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1882
1883
1884
1885
1888
1889
1890
1892
1893
1894
1895
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1946
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1975
1976
1977
1978
1979
1980
1983
1984
1987
1988
1989
1990
1991
1994
1995
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
#ifdef HAL_HCD_MODULE_ENABLED
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
/* ... */
/* ... */
static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd);
static void HCD_Port_IRQHandler(HCD_HandleTypeDef *hhcd);
/* ... */
Private function prototypes
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd)
{
#if defined (USB_OTG_FS)
const USB_OTG_GlobalTypeDef *USBx;
#endif
if (hhcd == NULL)
{
return HAL_ERROR;
}if (hhcd == NULL) { ... }
assert_param(IS_HCD_ALL_INSTANCE(hhcd->Instance));
#if defined (USB_OTG_FS)
USBx = hhcd->Instance;
#endif
if (hhcd->State == HAL_HCD_STATE_RESET)
{
hhcd->Lock = HAL_UNLOCKED;
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->SOFCallback = HAL_HCD_SOF_Callback;
hhcd->ConnectCallback = HAL_HCD_Connect_Callback;
hhcd->DisconnectCallback = HAL_HCD_Disconnect_Callback;
hhcd->PortEnabledCallback = HAL_HCD_PortEnabled_Callback;
hhcd->PortDisabledCallback = HAL_HCD_PortDisabled_Callback;
hhcd->HC_NotifyURBChangeCallback = HAL_HCD_HC_NotifyURBChange_Callback;
if (hhcd->MspInitCallback == NULL)
{
hhcd->MspInitCallback = HAL_HCD_MspInit;
}if (hhcd->MspInitCallback == NULL) { ... }
hhcd->MspInitCallback(hhcd);/* ... */
#else
HAL_HCD_MspInit(hhcd);/* ... */
#endif
}if (hhcd->State == HAL_HCD_STATE_RESET) { ... }
hhcd->State = HAL_HCD_STATE_BUSY;
#if defined (USB_OTG_FS)
if (USBx == USB_OTG_FS)
{
hhcd->Init.dma_enable = 0U;
}if (USBx == USB_OTG_FS) { ... }
/* ... */#endif
__HAL_HCD_DISABLE(hhcd);
if (USB_CoreInit(hhcd->Instance, hhcd->Init) != HAL_OK)
{
hhcd->State = HAL_HCD_STATE_ERROR;
return HAL_ERROR;
}if (USB_CoreInit(hhcd->Instance, hhcd->Init) != HAL_OK) { ... }
if (USB_SetCurrentMode(hhcd->Instance, USB_HOST_MODE) != HAL_OK)
{
hhcd->State = HAL_HCD_STATE_ERROR;
return HAL_ERROR;
}if (USB_SetCurrentMode(hhcd->Instance, USB_HOST_MODE) != HAL_OK) { ... }
if (USB_HostInit(hhcd->Instance, hhcd->Init) != HAL_OK)
{
hhcd->State = HAL_HCD_STATE_ERROR;
return HAL_ERROR;
}if (USB_HostInit(hhcd->Instance, hhcd->Init) != HAL_OK) { ... }
hhcd->State = HAL_HCD_STATE_READY;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd, uint8_t ch_num, uint8_t epnum,
uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
{
HAL_StatusTypeDef status;
uint32_t HostCoreSpeed;
uint32_t HCcharMps = mps;
__HAL_LOCK(hhcd);
hhcd->hc[ch_num].do_ping = 0U;
hhcd->hc[ch_num].dev_addr = dev_address;
hhcd->hc[ch_num].ch_num = ch_num;
hhcd->hc[ch_num].ep_type = ep_type;
hhcd->hc[ch_num].ep_num = epnum & 0x7FU;
(void)HAL_HCD_HC_ClearHubInfo(hhcd, ch_num);
if ((epnum & 0x80U) == 0x80U)
{
hhcd->hc[ch_num].ep_is_in = 1U;
}if ((epnum & 0x80U) == 0x80U) { ... }
else
{
hhcd->hc[ch_num].ep_is_in = 0U;
}else { ... }
HostCoreSpeed = USB_GetHostSpeed(hhcd->Instance);
if (ep_type == EP_TYPE_ISOC)
{
if ((speed == HCD_DEVICE_SPEED_FULL) && (HostCoreSpeed == HPRT0_PRTSPD_HIGH_SPEED))
{
if (HCcharMps > ISO_SPLT_MPS)
{
HCcharMps = ISO_SPLT_MPS;
}if (HCcharMps > ISO_SPLT_MPS) { ... }
}if ((speed == HCD_DEVICE_SPEED_FULL) && (HostCoreSpeed == HPRT0_PRTSPD_HIGH_SPEED)) { ... }
}if (ep_type == EP_TYPE_ISOC) { ... }
hhcd->hc[ch_num].speed = speed;
hhcd->hc[ch_num].max_packet = (uint16_t)HCcharMps;
status = USB_HC_Init(hhcd->Instance, ch_num, epnum,
dev_address, speed, ep_type, (uint16_t)HCcharMps);
__HAL_UNLOCK(hhcd);
return status;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_HC_Halt(HCD_HandleTypeDef *hhcd, uint8_t ch_num)
{
HAL_StatusTypeDef status = HAL_OK;
__HAL_LOCK(hhcd);
(void)USB_HC_Halt(hhcd->Instance, ch_num);
__HAL_UNLOCK(hhcd);
return status;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd)
{
if (hhcd == NULL)
{
return HAL_ERROR;
}if (hhcd == NULL) { ... }
hhcd->State = HAL_HCD_STATE_BUSY;
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
if (hhcd->MspDeInitCallback == NULL)
{
hhcd->MspDeInitCallback = HAL_HCD_MspDeInit;
}if (hhcd->MspDeInitCallback == NULL) { ... }
hhcd->MspDeInitCallback(hhcd);/* ... */
#else
HAL_HCD_MspDeInit(hhcd);/* ... */
#endif
__HAL_HCD_DISABLE(hhcd);
hhcd->State = HAL_HCD_STATE_RESET;
return HAL_OK;
}{ ... }
/* ... */
__weak void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
{
UNUSED(hhcd);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd)
{
UNUSED(hhcd);
/* ... */
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd,
uint8_t ch_num,
uint8_t direction,
uint8_t ep_type,
uint8_t token,
uint8_t *pbuff,
uint16_t length,
uint8_t do_ping)
{
hhcd->hc[ch_num].ep_is_in = direction;
hhcd->hc[ch_num].ep_type = ep_type;
if (token == 0U)
{
hhcd->hc[ch_num].data_pid = HC_PID_SETUP;
hhcd->hc[ch_num].do_ping = do_ping;
}if (token == 0U) { ... }
else
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
}else { ... }
switch (ep_type)
{
case EP_TYPE_CTRL:
if (token == 1U)
{
if (direction == 0U)
{
if (length == 0U)
{
hhcd->hc[ch_num].toggle_out = 1U;
}if (length == 0U) { ... }
if (hhcd->hc[ch_num].toggle_out == 0U)
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
}if (hhcd->hc[ch_num].toggle_out == 0U) { ... }
else
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
}else { ... }
}if (direction == 0U) { ... }
else
{
if (hhcd->hc[ch_num].do_ssplit == 1U)
{
if (hhcd->hc[ch_num].toggle_in == 0U)
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
}if (hhcd->hc[ch_num].toggle_in == 0U) { ... }
else
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
}else { ... }
}if (hhcd->hc[ch_num].do_ssplit == 1U) { ... }
}else { ... }
...}
break;
case EP_TYPE_CTRL:
case EP_TYPE_BULK:
if (direction == 0U)
{
if (hhcd->hc[ch_num].toggle_out == 0U)
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
}if (hhcd->hc[ch_num].toggle_out == 0U) { ... }
else
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
}else { ... }
}if (direction == 0U) { ... }
else
{
if (hhcd->hc[ch_num].toggle_in == 0U)
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
}if (hhcd->hc[ch_num].toggle_in == 0U) { ... }
else
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
}else { ... }
}else { ... }
break;case EP_TYPE_BULK:
case EP_TYPE_INTR:
if (direction == 0U)
{
if (hhcd->hc[ch_num].toggle_out == 0U)
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
}if (hhcd->hc[ch_num].toggle_out == 0U) { ... }
else
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
}else { ... }
}if (direction == 0U) { ... }
else
{
if (hhcd->hc[ch_num].toggle_in == 0U)
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
}if (hhcd->hc[ch_num].toggle_in == 0U) { ... }
else
{
hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
}else { ... }
}else { ... }
break;
case EP_TYPE_INTR:
case EP_TYPE_ISOC:
hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
break;
case EP_TYPE_ISOC:
default:
break;default
}switch (ep_type) { ... }
hhcd->hc[ch_num].xfer_buff = pbuff;
hhcd->hc[ch_num].xfer_len = length;
hhcd->hc[ch_num].urb_state = URB_IDLE;
hhcd->hc[ch_num].xfer_count = 0U;
hhcd->hc[ch_num].ch_num = ch_num;
hhcd->hc[ch_num].state = HC_IDLE;
return USB_HC_StartXfer(hhcd->Instance, &hhcd->hc[ch_num], (uint8_t)hhcd->Init.dma_enable);
}{ ... }
/* ... */
void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd)
{
USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
uint32_t USBx_BASE = (uint32_t)USBx;
uint32_t i;
uint32_t interrupt;
if (USB_GetMode(hhcd->Instance) == USB_OTG_MODE_HOST)
{
if (__HAL_HCD_IS_INVALID_INTERRUPT(hhcd))
{
return;
}if (__HAL_HCD_IS_INVALID_INTERRUPT(hhcd)) { ... }
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT))
{
__HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT);
}if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT)) { ... }
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR))
{
__HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR);
}if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR)) { ... }
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE))
{
__HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE);
}if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE)) { ... }
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_MMIS))
{
__HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_MMIS);
}if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_MMIS)) { ... }
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT))
{
__HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT);
if ((USBx_HPRT0 & USB_OTG_HPRT_PCSTS) == 0U)
{
(void)USB_FlushTxFifo(USBx, 0x10U);
(void)USB_FlushRxFifo(USBx);
if (hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY)
{
(void)USB_InitFSLSPClkSel(hhcd->Instance, HCFG_48_MHZ);
}if (hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY) { ... }
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->DisconnectCallback(hhcd);
#else
HAL_HCD_Disconnect_Callback(hhcd);
#endif
}if ((USBx_HPRT0 & USB_OTG_HPRT_PCSTS) == 0U) { ... }
}if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT)) { ... }
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HPRTINT))
{
HCD_Port_IRQHandler(hhcd);
}if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HPRTINT)) { ... }
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_SOF))
{
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->SOFCallback(hhcd);
#else
HAL_HCD_SOF_Callback(hhcd);
#endif
__HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_SOF);
}if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_SOF)) { ... }
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT))
{
interrupt = USB_HC_ReadInterrupt(hhcd->Instance);
for (i = 0U; i < hhcd->Init.Host_channels; i++)
{
if ((interrupt & (1UL << (i & 0xFU))) != 0U)
{
if ((USBx_HC(i)->HCCHAR & USB_OTG_HCCHAR_EPDIR) == USB_OTG_HCCHAR_EPDIR)
{
HCD_HC_IN_IRQHandler(hhcd, (uint8_t)i);
}if ((USBx_HC(i)->HCCHAR & USB_OTG_HCCHAR_EPDIR) == USB_OTG_HCCHAR_EPDIR) { ... }
else
{
HCD_HC_OUT_IRQHandler(hhcd, (uint8_t)i);
}else { ... }
}if ((interrupt & (1UL << (i & 0xFU))) != 0U) { ... }
}for (i = 0U; i < hhcd->Init.Host_channels; i++) { ... }
__HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_HCINT);
}if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT)) { ... }
if ((__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_RXFLVL)) != 0U)
{
USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
HCD_RXQLVL_IRQHandler(hhcd);
USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
}if ((__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_RXFLVL)) != 0U) { ... }
}if (USB_GetMode(hhcd->Instance) == USB_OTG_MODE_HOST) { ... }
}{ ... }
/* ... */
void HAL_HCD_WKUP_IRQHandler(HCD_HandleTypeDef *hhcd)
{
UNUSED(hhcd);
}{ ... }
/* ... */
__weak void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd)
{
UNUSED(hhcd);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd)
{
UNUSED(hhcd);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd)
{
UNUSED(hhcd);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd)
{
UNUSED(hhcd);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd)
{
UNUSED(hhcd);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
{
UNUSED(hhcd);
UNUSED(chnum);
UNUSED(urb_state);
/* ... */
}{ ... }
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
/* ... */
HAL_StatusTypeDef HAL_HCD_RegisterCallback(HCD_HandleTypeDef *hhcd,
HAL_HCD_CallbackIDTypeDef CallbackID,
pHCD_CallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
if (pCallback == NULL)
{
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
return HAL_ERROR;
}if (pCallback == NULL) { ... }
__HAL_LOCK(hhcd);
if (hhcd->State == HAL_HCD_STATE_READY)
{
switch (CallbackID)
{
case HAL_HCD_SOF_CB_ID :
hhcd->SOFCallback = pCallback;
break;
case HAL_HCD_SOF_CB_ID :
case HAL_HCD_CONNECT_CB_ID :
hhcd->ConnectCallback = pCallback;
break;
case HAL_HCD_CONNECT_CB_ID :
case HAL_HCD_DISCONNECT_CB_ID :
hhcd->DisconnectCallback = pCallback;
break;
case HAL_HCD_DISCONNECT_CB_ID :
case HAL_HCD_PORT_ENABLED_CB_ID :
hhcd->PortEnabledCallback = pCallback;
break;
case HAL_HCD_PORT_ENABLED_CB_ID :
case HAL_HCD_PORT_DISABLED_CB_ID :
hhcd->PortDisabledCallback = pCallback;
break;
case HAL_HCD_PORT_DISABLED_CB_ID :
case HAL_HCD_MSPINIT_CB_ID :
hhcd->MspInitCallback = pCallback;
break;
case HAL_HCD_MSPINIT_CB_ID :
case HAL_HCD_MSPDEINIT_CB_ID :
hhcd->MspDeInitCallback = pCallback;
break;
case HAL_HCD_MSPDEINIT_CB_ID :
default :
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (hhcd->State == HAL_HCD_STATE_READY) { ... }
else if (hhcd->State == HAL_HCD_STATE_RESET)
{
switch (CallbackID)
{
case HAL_HCD_MSPINIT_CB_ID :
hhcd->MspInitCallback = pCallback;
break;
case HAL_HCD_MSPINIT_CB_ID :
case HAL_HCD_MSPDEINIT_CB_ID :
hhcd->MspDeInitCallback = pCallback;
break;
case HAL_HCD_MSPDEINIT_CB_ID :
default :
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (hhcd->State == HAL_HCD_STATE_RESET) { ... }
else
{
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(hhcd);
return status;
}HAL_HCD_RegisterCallback (HCD_HandleTypeDef *hhcd, HAL_HCD_CallbackIDTypeDef CallbackID, pHCD_CallbackTypeDef pCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_UnRegisterCallback(HCD_HandleTypeDef *hhcd, HAL_HCD_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
__HAL_LOCK(hhcd);
if (hhcd->State == HAL_HCD_STATE_READY)
{
switch (CallbackID)
{
case HAL_HCD_SOF_CB_ID :
hhcd->SOFCallback = HAL_HCD_SOF_Callback;
break;
case HAL_HCD_SOF_CB_ID :
case HAL_HCD_CONNECT_CB_ID :
hhcd->ConnectCallback = HAL_HCD_Connect_Callback;
break;
case HAL_HCD_CONNECT_CB_ID :
case HAL_HCD_DISCONNECT_CB_ID :
hhcd->DisconnectCallback = HAL_HCD_Disconnect_Callback;
break;
case HAL_HCD_DISCONNECT_CB_ID :
case HAL_HCD_PORT_ENABLED_CB_ID :
hhcd->PortEnabledCallback = HAL_HCD_PortEnabled_Callback;
break;
case HAL_HCD_PORT_ENABLED_CB_ID :
case HAL_HCD_PORT_DISABLED_CB_ID :
hhcd->PortDisabledCallback = HAL_HCD_PortDisabled_Callback;
break;
case HAL_HCD_PORT_DISABLED_CB_ID :
case HAL_HCD_MSPINIT_CB_ID :
hhcd->MspInitCallback = HAL_HCD_MspInit;
break;
case HAL_HCD_MSPINIT_CB_ID :
case HAL_HCD_MSPDEINIT_CB_ID :
hhcd->MspDeInitCallback = HAL_HCD_MspDeInit;
break;
case HAL_HCD_MSPDEINIT_CB_ID :
default :
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (hhcd->State == HAL_HCD_STATE_READY) { ... }
else if (hhcd->State == HAL_HCD_STATE_RESET)
{
switch (CallbackID)
{
case HAL_HCD_MSPINIT_CB_ID :
hhcd->MspInitCallback = HAL_HCD_MspInit;
break;
case HAL_HCD_MSPINIT_CB_ID :
case HAL_HCD_MSPDEINIT_CB_ID :
hhcd->MspDeInitCallback = HAL_HCD_MspDeInit;
break;
case HAL_HCD_MSPDEINIT_CB_ID :
default :
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (hhcd->State == HAL_HCD_STATE_RESET) { ... }
else
{
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(hhcd);
return status;
}HAL_HCD_UnRegisterCallback (HCD_HandleTypeDef *hhcd, HAL_HCD_CallbackIDTypeDef CallbackID) { ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_RegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd,
pHCD_HC_NotifyURBChangeCallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
if (pCallback == NULL)
{
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
return HAL_ERROR;
}if (pCallback == NULL) { ... }
__HAL_LOCK(hhcd);
if (hhcd->State == HAL_HCD_STATE_READY)
{
hhcd->HC_NotifyURBChangeCallback = pCallback;
}if (hhcd->State == HAL_HCD_STATE_READY) { ... }
else
{
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(hhcd);
return status;
}HAL_HCD_RegisterHC_NotifyURBChangeCallback (HCD_HandleTypeDef *hhcd, pHCD_HC_NotifyURBChangeCallbackTypeDef pCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_UnRegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd)
{
HAL_StatusTypeDef status = HAL_OK;
__HAL_LOCK(hhcd);
if (hhcd->State == HAL_HCD_STATE_READY)
{
hhcd->HC_NotifyURBChangeCallback = HAL_HCD_HC_NotifyURBChange_Callback;
}if (hhcd->State == HAL_HCD_STATE_READY) { ... }
else
{
hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(hhcd);
return status;
}HAL_HCD_UnRegisterHC_NotifyURBChangeCallback (HCD_HandleTypeDef *hhcd) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HCD_Start(HCD_HandleTypeDef *hhcd)
{
__HAL_LOCK(hhcd);
(void)USB_DriveVbus(hhcd->Instance, 1U);
__HAL_HCD_ENABLE(hhcd);
__HAL_UNLOCK(hhcd);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd)
{
__HAL_LOCK(hhcd);
(void)USB_StopHost(hhcd->Instance);
__HAL_UNLOCK(hhcd);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_ResetPort(HCD_HandleTypeDef *hhcd)
{
return (USB_ResetPort(hhcd->Instance));
}{ ... }
/* ... */
/* ... */
/* ... */
HCD_StateTypeDef HAL_HCD_GetState(HCD_HandleTypeDef const *hhcd)
{
return hhcd->State;
}{ ... }
/* ... */
HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef const *hhcd, uint8_t chnum)
{
return hhcd->hc[chnum].urb_state;
}{ ... }
/* ... */
uint32_t HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef const *hhcd, uint8_t chnum)
{
return hhcd->hc[chnum].xfer_count;
}{ ... }
/* ... */
HCD_HCStateTypeDef HAL_HCD_HC_GetState(HCD_HandleTypeDef const *hhcd, uint8_t chnum)
{
return hhcd->hc[chnum].state;
}{ ... }
/* ... */
uint32_t HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd)
{
return (USB_GetCurrentFrame(hhcd->Instance));
}{ ... }
/* ... */
uint32_t HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd)
{
return (USB_GetHostSpeed(hhcd->Instance));
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_HC_SetHubInfo(HCD_HandleTypeDef *hhcd, uint8_t ch_num,
uint8_t addr, uint8_t PortNbr)
{
uint32_t HostCoreSpeed = USB_GetHostSpeed(hhcd->Instance);
if ((hhcd->hc[ch_num].speed != HCD_DEVICE_SPEED_HIGH) && (HostCoreSpeed == HPRT0_PRTSPD_HIGH_SPEED))
{
hhcd->hc[ch_num].do_ssplit = 1U;
if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) && (hhcd->hc[ch_num].ep_is_in != 0U))
{
hhcd->hc[ch_num].toggle_in = 1U;
}if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) && (hhcd->hc[ch_num].ep_is_in != 0U)) { ... }
}if ((hhcd->hc[ch_num].speed != HCD_DEVICE_SPEED_HIGH) && (HostCoreSpeed == HPRT0_PRTSPD_HIGH_SPEED)) { ... }
hhcd->hc[ch_num].hub_addr = addr;
hhcd->hc[ch_num].hub_port_nbr = PortNbr;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HCD_HC_ClearHubInfo(HCD_HandleTypeDef *hhcd, uint8_t ch_num)
{
hhcd->hc[ch_num].do_ssplit = 0U;
hhcd->hc[ch_num].do_csplit = 0U;
hhcd->hc[ch_num].hub_addr = 0U;
hhcd->hc[ch_num].hub_port_nbr = 0U;
return HAL_OK;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */
static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
{
const USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
uint32_t USBx_BASE = (uint32_t)USBx;
uint32_t tmpreg;
if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_AHBERR))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
hhcd->hc[chnum].state = HC_XACTERR;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_AHBERR)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_BBERR))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_BBERR);
hhcd->hc[chnum].state = HC_BBLERR;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_BBERR)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_STALL))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
hhcd->hc[chnum].state = HC_STALL;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_STALL)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_DTERR))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
hhcd->hc[chnum].state = HC_DATATGLERR;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_DTERR)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_TXERR))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
hhcd->hc[chnum].state = HC_XACTERR;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_TXERR)) { ... }
else
{
}else { ... }
if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_FRMOR))
{
(void)USB_HC_Halt(hhcd->Instance, chnum);
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
}if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_FRMOR)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_XFRC))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
if (hhcd->hc[chnum].do_csplit == 1U)
{
hhcd->hc[chnum].do_csplit = 0U;
__HAL_HCD_CLEAR_HC_CSPLT(chnum);
}if (hhcd->hc[chnum].do_csplit == 1U) { ... }
if (hhcd->Init.dma_enable != 0U)
{
hhcd->hc[chnum].xfer_count = hhcd->hc[chnum].XferSize - (USBx_HC(chnum)->HCTSIZ & USB_OTG_HCTSIZ_XFRSIZ);
}if (hhcd->Init.dma_enable != 0U) { ... }
hhcd->hc[chnum].state = HC_XFRC;
hhcd->hc[chnum].ErrCnt = 0U;
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
(hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
{
(void)USB_HC_Halt(hhcd->Instance, chnum);
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
}if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) || (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)) { ... }
else if ((hhcd->hc[chnum].ep_type == EP_TYPE_INTR) ||
(hhcd->hc[chnum].ep_type == EP_TYPE_ISOC))
{
USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM;
hhcd->hc[chnum].urb_state = URB_DONE;
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->HC_NotifyURBChangeCallback(hhcd, chnum, hhcd->hc[chnum].urb_state);
#else
HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
#endif
}else if ((hhcd->hc[chnum].ep_type == EP_TYPE_INTR) || (hhcd->hc[chnum].ep_type == EP_TYPE_ISOC)) { ... }
else
{
}else { ... }
if (hhcd->Init.dma_enable == 1U)
{
if ((((hhcd->hc[chnum].xfer_count + hhcd->hc[chnum].max_packet - 1U) / hhcd->hc[chnum].max_packet) & 1U) != 0U)
{
hhcd->hc[chnum].toggle_in ^= 1U;
}if ((((hhcd->hc[chnum].xfer_count + hhcd->hc[chnum].max_packet - 1U) / hhcd->hc[chnum].max_packet) & 1U) != 0U) { ... }
}if (hhcd->Init.dma_enable == 1U) { ... }
else
{
hhcd->hc[chnum].toggle_in ^= 1U;
}else { ... }
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_XFRC)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_ACK))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
if (hhcd->hc[chnum].do_ssplit == 1U)
{
hhcd->hc[chnum].do_csplit = 1U;
hhcd->hc[chnum].state = HC_ACK;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}if (hhcd->hc[chnum].do_ssplit == 1U) { ... }
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_ACK)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_CHH))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
if (hhcd->hc[chnum].state == HC_XFRC)
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].urb_state = URB_DONE;
}if (hhcd->hc[chnum].state == HC_XFRC) { ... }
else if (hhcd->hc[chnum].state == HC_STALL)
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].urb_state = URB_STALL;
}else if (hhcd->hc[chnum].state == HC_STALL) { ... }
else if ((hhcd->hc[chnum].state == HC_XACTERR) ||
(hhcd->hc[chnum].state == HC_DATATGLERR))
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].ErrCnt++;
if (hhcd->hc[chnum].ErrCnt > 2U)
{
hhcd->hc[chnum].ErrCnt = 0U;
if (hhcd->hc[chnum].do_ssplit == 1U)
{
hhcd->hc[chnum].do_csplit = 0U;
hhcd->hc[chnum].ep_ss_schedule = 0U;
__HAL_HCD_CLEAR_HC_CSPLT(chnum);
}if (hhcd->hc[chnum].do_ssplit == 1U) { ... }
hhcd->hc[chnum].urb_state = URB_ERROR;
}if (hhcd->hc[chnum].ErrCnt > 2U) { ... }
else
{
hhcd->hc[chnum].urb_state = URB_NOTREADY;
if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
(hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
{
tmpreg = USBx_HC(chnum)->HCCHAR;
tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
tmpreg |= USB_OTG_HCCHAR_CHENA;
USBx_HC(chnum)->HCCHAR = tmpreg;
}if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) || (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)) { ... }
}else { ... }
}else if ((hhcd->hc[chnum].state == HC_XACTERR) || (hhcd->hc[chnum].state == HC_DATATGLERR)) { ... }
else if (hhcd->hc[chnum].state == HC_NYET)
{
hhcd->hc[chnum].state = HC_HALTED;
if (hhcd->hc[chnum].do_csplit == 1U)
{
if (hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
{
hhcd->hc[chnum].NyetErrCnt++;
if (hhcd->hc[chnum].NyetErrCnt > 2U)
{
hhcd->hc[chnum].NyetErrCnt = 0U;
hhcd->hc[chnum].do_csplit = 0U;
if (hhcd->hc[chnum].ErrCnt < 3U)
{
hhcd->hc[chnum].ep_ss_schedule = 1U;
}if (hhcd->hc[chnum].ErrCnt < 3U) { ... }
__HAL_HCD_CLEAR_HC_CSPLT(chnum);
hhcd->hc[chnum].urb_state = URB_ERROR;
}if (hhcd->hc[chnum].NyetErrCnt > 2U) { ... }
else
{
hhcd->hc[chnum].urb_state = URB_NOTREADY;
}else { ... }
}if (hhcd->hc[chnum].ep_type == EP_TYPE_INTR) { ... }
else
{
hhcd->hc[chnum].urb_state = URB_NOTREADY;
}else { ... }
if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
(hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
{
tmpreg = USBx_HC(chnum)->HCCHAR;
tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
tmpreg |= USB_OTG_HCCHAR_CHENA;
USBx_HC(chnum)->HCCHAR = tmpreg;
}if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) || (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)) { ... }
}if (hhcd->hc[chnum].do_csplit == 1U) { ... }
}else if (hhcd->hc[chnum].state == HC_NYET) { ... }
else if (hhcd->hc[chnum].state == HC_ACK)
{
hhcd->hc[chnum].state = HC_HALTED;
if (hhcd->hc[chnum].do_csplit == 1U)
{
hhcd->hc[chnum].urb_state = URB_NOTREADY;
USBx_HC(chnum)->HCSPLT |= USB_OTG_HCSPLT_COMPLSPLT;
USBx_HC(chnum)->HCINTMSK |= USB_OTG_HCINTMSK_NYET;
USBx_HC(chnum)->HCINTMSK &= ~USB_OTG_HCINT_ACK;
if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
(hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
{
tmpreg = USBx_HC(chnum)->HCCHAR;
tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
tmpreg |= USB_OTG_HCCHAR_CHENA;
USBx_HC(chnum)->HCCHAR = tmpreg;
}if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) || (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)) { ... }
}if (hhcd->hc[chnum].do_csplit == 1U) { ... }
}else if (hhcd->hc[chnum].state == HC_ACK) { ... }
else if (hhcd->hc[chnum].state == HC_NAK)
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].urb_state = URB_NOTREADY;
if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
(hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
{
tmpreg = USBx_HC(chnum)->HCCHAR;
tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
tmpreg |= USB_OTG_HCCHAR_CHENA;
USBx_HC(chnum)->HCCHAR = tmpreg;
}if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) || (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)) { ... }
}else if (hhcd->hc[chnum].state == HC_NAK) { ... }
else if (hhcd->hc[chnum].state == HC_BBLERR)
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].ErrCnt++;
hhcd->hc[chnum].urb_state = URB_ERROR;
}else if (hhcd->hc[chnum].state == HC_BBLERR) { ... }
else
{
if (hhcd->hc[chnum].state == HC_HALTED)
{
return;
}if (hhcd->hc[chnum].state == HC_HALTED) { ... }
}else { ... }
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->HC_NotifyURBChangeCallback(hhcd, chnum, hhcd->hc[chnum].urb_state);
#else
HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
#endif
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_CHH)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NYET))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NYET);
hhcd->hc[chnum].state = HC_NYET;
if (hhcd->hc[chnum].do_ssplit == 0U)
{
hhcd->hc[chnum].ErrCnt = 0U;
}if (hhcd->hc[chnum].do_ssplit == 0U) { ... }
(void)USB_HC_Halt(hhcd->Instance, chnum);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NYET)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NAK))
{
if (hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
{
hhcd->hc[chnum].ErrCnt = 0U;
hhcd->hc[chnum].state = HC_NAK;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}if (hhcd->hc[chnum].ep_type == EP_TYPE_INTR) { ... }
else if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) ||
(hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
{
hhcd->hc[chnum].ErrCnt = 0U;
if ((hhcd->Init.dma_enable == 0U) || (hhcd->hc[chnum].do_csplit == 1U))
{
hhcd->hc[chnum].state = HC_NAK;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}if ((hhcd->Init.dma_enable == 0U) || (hhcd->hc[chnum].do_csplit == 1U)) { ... }
}else if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL) || (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)) { ... }
else
{
}else { ... }
if (hhcd->hc[chnum].do_csplit == 1U)
{
hhcd->hc[chnum].do_csplit = 0U;
__HAL_HCD_CLEAR_HC_CSPLT(chnum);
__HAL_HCD_UNMASK_ACK_HC_INT(chnum);
}if (hhcd->hc[chnum].do_csplit == 1U) { ... }
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NAK)) { ... }
else
{
}else { ... }
}{ ... }
/* ... */
static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
{
const USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
uint32_t USBx_BASE = (uint32_t)USBx;
uint32_t tmpreg;
uint32_t num_packets;
if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_AHBERR))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
hhcd->hc[chnum].state = HC_XACTERR;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_AHBERR)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_ACK))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
if (hhcd->hc[chnum].do_ping == 1U)
{
hhcd->hc[chnum].do_ping = 0U;
hhcd->hc[chnum].urb_state = URB_NOTREADY;
hhcd->hc[chnum].state = HC_ACK;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}if (hhcd->hc[chnum].do_ping == 1U) { ... }
if ((hhcd->hc[chnum].do_ssplit == 1U) && (hhcd->hc[chnum].do_csplit == 0U))
{
if (hhcd->hc[chnum].ep_type != EP_TYPE_ISOC)
{
hhcd->hc[chnum].do_csplit = 1U;
}if (hhcd->hc[chnum].ep_type != EP_TYPE_ISOC) { ... }
hhcd->hc[chnum].state = HC_ACK;
(void)USB_HC_Halt(hhcd->Instance, chnum);
hhcd->hc[chnum].ErrCnt = 0U;
}if ((hhcd->hc[chnum].do_ssplit == 1U) && (hhcd->hc[chnum].do_csplit == 0U)) { ... }
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_ACK)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_FRMOR))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
(void)USB_HC_Halt(hhcd->Instance, chnum);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_FRMOR)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_XFRC))
{
hhcd->hc[chnum].ErrCnt = 0U;
if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NYET))
{
hhcd->hc[chnum].do_ping = 1U;
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NYET);
}if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NYET)) { ... }
if (hhcd->hc[chnum].do_csplit != 0U)
{
hhcd->hc[chnum].do_csplit = 0U;
__HAL_HCD_CLEAR_HC_CSPLT(chnum);
}if (hhcd->hc[chnum].do_csplit != 0U) { ... }
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
hhcd->hc[chnum].state = HC_XFRC;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_XFRC)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NYET))
{
hhcd->hc[chnum].state = HC_NYET;
if (hhcd->hc[chnum].do_ssplit == 0U)
{
hhcd->hc[chnum].do_ping = 1U;
}if (hhcd->hc[chnum].do_ssplit == 0U) { ... }
hhcd->hc[chnum].ErrCnt = 0U;
(void)USB_HC_Halt(hhcd->Instance, chnum);
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NYET);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NYET)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_STALL))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
hhcd->hc[chnum].state = HC_STALL;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_STALL)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NAK))
{
hhcd->hc[chnum].ErrCnt = 0U;
hhcd->hc[chnum].state = HC_NAK;
if (hhcd->hc[chnum].do_ping == 0U)
{
if (hhcd->hc[chnum].speed == HCD_DEVICE_SPEED_HIGH)
{
hhcd->hc[chnum].do_ping = 1U;
}if (hhcd->hc[chnum].speed == HCD_DEVICE_SPEED_HIGH) { ... }
}if (hhcd->hc[chnum].do_ping == 0U) { ... }
(void)USB_HC_Halt(hhcd->Instance, chnum);
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_NAK)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_TXERR))
{
if (hhcd->Init.dma_enable == 0U)
{
hhcd->hc[chnum].state = HC_XACTERR;
(void)USB_HC_Halt(hhcd->Instance, chnum);
}if (hhcd->Init.dma_enable == 0U) { ... }
else
{
hhcd->hc[chnum].ErrCnt++;
if (hhcd->hc[chnum].ErrCnt > 2U)
{
hhcd->hc[chnum].ErrCnt = 0U;
hhcd->hc[chnum].urb_state = URB_ERROR;
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->HC_NotifyURBChangeCallback(hhcd, chnum, hhcd->hc[chnum].urb_state);
#else
HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
#endif
}if (hhcd->hc[chnum].ErrCnt > 2U) { ... }
else
{
hhcd->hc[chnum].urb_state = URB_NOTREADY;
}else { ... }
}else { ... }
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_TXERR)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_DTERR))
{
hhcd->hc[chnum].state = HC_DATATGLERR;
(void)USB_HC_Halt(hhcd->Instance, chnum);
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_DTERR)) { ... }
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_CHH))
{
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
if (hhcd->hc[chnum].state == HC_XFRC)
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].urb_state = URB_DONE;
if ((hhcd->hc[chnum].ep_type == EP_TYPE_BULK) ||
(hhcd->hc[chnum].ep_type == EP_TYPE_INTR))
{
if (hhcd->Init.dma_enable == 0U)
{
hhcd->hc[chnum].toggle_out ^= 1U;
}if (hhcd->Init.dma_enable == 0U) { ... }
if ((hhcd->Init.dma_enable == 1U) && (hhcd->hc[chnum].xfer_len > 0U))
{
num_packets = (hhcd->hc[chnum].xfer_len + hhcd->hc[chnum].max_packet - 1U) / hhcd->hc[chnum].max_packet;
if ((num_packets & 1U) != 0U)
{
hhcd->hc[chnum].toggle_out ^= 1U;
}if ((num_packets & 1U) != 0U) { ... }
}if ((hhcd->Init.dma_enable == 1U) && (hhcd->hc[chnum].xfer_len > 0U)) { ... }
}if ((hhcd->hc[chnum].ep_type == EP_TYPE_BULK) || (hhcd->hc[chnum].ep_type == EP_TYPE_INTR)) { ... }
}if (hhcd->hc[chnum].state == HC_XFRC) { ... }
else if (hhcd->hc[chnum].state == HC_ACK)
{
hhcd->hc[chnum].state = HC_HALTED;
if (hhcd->hc[chnum].do_csplit == 1U)
{
hhcd->hc[chnum].urb_state = URB_NOTREADY;
}if (hhcd->hc[chnum].do_csplit == 1U) { ... }
}else if (hhcd->hc[chnum].state == HC_ACK) { ... }
else if (hhcd->hc[chnum].state == HC_NAK)
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].urb_state = URB_NOTREADY;
if (hhcd->hc[chnum].do_csplit == 1U)
{
hhcd->hc[chnum].do_csplit = 0U;
__HAL_HCD_CLEAR_HC_CSPLT(chnum);
}if (hhcd->hc[chnum].do_csplit == 1U) { ... }
}else if (hhcd->hc[chnum].state == HC_NAK) { ... }
else if (hhcd->hc[chnum].state == HC_NYET)
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].urb_state = URB_NOTREADY;
}else if (hhcd->hc[chnum].state == HC_NYET) { ... }
else if (hhcd->hc[chnum].state == HC_STALL)
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].urb_state = URB_STALL;
}else if (hhcd->hc[chnum].state == HC_STALL) { ... }
else if ((hhcd->hc[chnum].state == HC_XACTERR) ||
(hhcd->hc[chnum].state == HC_DATATGLERR))
{
hhcd->hc[chnum].state = HC_HALTED;
hhcd->hc[chnum].ErrCnt++;
if (hhcd->hc[chnum].ErrCnt > 2U)
{
hhcd->hc[chnum].ErrCnt = 0U;
hhcd->hc[chnum].urb_state = URB_ERROR;
}if (hhcd->hc[chnum].ErrCnt > 2U) { ... }
else
{
hhcd->hc[chnum].urb_state = URB_NOTREADY;
tmpreg = USBx_HC(chnum)->HCCHAR;
tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
tmpreg |= USB_OTG_HCCHAR_CHENA;
USBx_HC(chnum)->HCCHAR = tmpreg;
}else { ... }
}else if ((hhcd->hc[chnum].state == HC_XACTERR) || (hhcd->hc[chnum].state == HC_DATATGLERR)) { ... }
else
{
return;
}else { ... }
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->HC_NotifyURBChangeCallback(hhcd, chnum, hhcd->hc[chnum].urb_state);
#else
HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
#endif
}else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_CHH)) { ... }
else
{
return;
}else { ... }
}{ ... }
/* ... */
static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd)
{
const USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
uint32_t USBx_BASE = (uint32_t)USBx;
uint32_t pktsts;
uint32_t pktcnt;
uint32_t GrxstspReg;
uint32_t xferSizePktCnt;
uint32_t tmpreg;
uint32_t chnum;
GrxstspReg = hhcd->Instance->GRXSTSP;
chnum = GrxstspReg & USB_OTG_GRXSTSP_EPNUM;
pktsts = (GrxstspReg & USB_OTG_GRXSTSP_PKTSTS) >> 17;
pktcnt = (GrxstspReg & USB_OTG_GRXSTSP_BCNT) >> 4;
switch (pktsts)
{
case GRXSTS_PKTSTS_IN:
if ((pktcnt > 0U) && (hhcd->hc[chnum].xfer_buff != (void *)0))
{
if ((hhcd->hc[chnum].xfer_count + pktcnt) <= hhcd->hc[chnum].xfer_len)
{
(void)USB_ReadPacket(hhcd->Instance,
hhcd->hc[chnum].xfer_buff, (uint16_t)pktcnt);
hhcd->hc[chnum].xfer_buff += pktcnt;
hhcd->hc[chnum].xfer_count += pktcnt;
xferSizePktCnt = (USBx_HC(chnum)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) >> 19;
if ((hhcd->hc[chnum].max_packet == pktcnt) && (xferSizePktCnt > 0U))
{
tmpreg = USBx_HC(chnum)->HCCHAR;
tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
tmpreg |= USB_OTG_HCCHAR_CHENA;
USBx_HC(chnum)->HCCHAR = tmpreg;
hhcd->hc[chnum].toggle_in ^= 1U;
}if ((hhcd->hc[chnum].max_packet == pktcnt) && (xferSizePktCnt > 0U)) { ... }
}if ((hhcd->hc[chnum].xfer_count + pktcnt) <= hhcd->hc[chnum].xfer_len) { ... }
else
{
hhcd->hc[chnum].urb_state = URB_ERROR;
}else { ... }
}if ((pktcnt > 0U) && (hhcd->hc[chnum].xfer_buff != (void *)0)) { ... }
break;
case GRXSTS_PKTSTS_IN:
case GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
break;
case GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
case GRXSTS_PKTSTS_IN_XFER_COMP:
case GRXSTS_PKTSTS_CH_HALTED:
default:
break;default
}switch (pktsts) { ... }
}{ ... }
/* ... */
static void HCD_Port_IRQHandler(HCD_HandleTypeDef *hhcd)
{
const USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
uint32_t USBx_BASE = (uint32_t)USBx;
__IO uint32_t hprt0;
__IO uint32_t hprt0_dup;
hprt0 = USBx_HPRT0;
hprt0_dup = USBx_HPRT0;
hprt0_dup &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET | \
USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG);
if ((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET)
{
if ((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS)
{
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->ConnectCallback(hhcd);
#else
HAL_HCD_Connect_Callback(hhcd);
#endif
}if ((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS) { ... }
hprt0_dup |= USB_OTG_HPRT_PCDET;
}if ((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET) { ... }
if ((hprt0 & USB_OTG_HPRT_PENCHNG) == USB_OTG_HPRT_PENCHNG)
{
hprt0_dup |= USB_OTG_HPRT_PENCHNG;
if ((hprt0 & USB_OTG_HPRT_PENA) == USB_OTG_HPRT_PENA)
{
if (hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY)
{
if ((hprt0 & USB_OTG_HPRT_PSPD) == (HPRT0_PRTSPD_LOW_SPEED << 17))
{
(void)USB_InitFSLSPClkSel(hhcd->Instance, HCFG_6_MHZ);
}if ((hprt0 & USB_OTG_HPRT_PSPD) == (HPRT0_PRTSPD_LOW_SPEED << 17)) { ... }
else
{
(void)USB_InitFSLSPClkSel(hhcd->Instance, HCFG_48_MHZ);
}else { ... }
}if (hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY) { ... }
else
{
if (hhcd->Init.speed == HCD_SPEED_FULL)
{
USBx_HOST->HFIR = HFIR_60_MHZ;
}if (hhcd->Init.speed == HCD_SPEED_FULL) { ... }
}else { ... }
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->PortEnabledCallback(hhcd);
#else
HAL_HCD_PortEnabled_Callback(hhcd);
#endif
}if ((hprt0 & USB_OTG_HPRT_PENA) == USB_OTG_HPRT_PENA) { ... }
else
{
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
hhcd->PortDisabledCallback(hhcd);
#else
HAL_HCD_PortDisabled_Callback(hhcd);
#endif
}else { ... }
}if ((hprt0 & USB_OTG_HPRT_PENCHNG) == USB_OTG_HPRT_PENCHNG) { ... }
if ((hprt0 & USB_OTG_HPRT_POCCHNG) == USB_OTG_HPRT_POCCHNG)
{
hprt0_dup |= USB_OTG_HPRT_POCCHNG;
}if ((hprt0 & USB_OTG_HPRT_POCCHNG) == USB_OTG_HPRT_POCCHNG) { ... }
USBx_HPRT0 = hprt0_dup;
}{ ... }
/* ... */
/* ... */
/* ... */
#endif /* ... */
#endif
/* ... */
/* ... */