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
54
55
56
57
58
59
60
63
64
65
69
70
73
76
77
78
81
82
85
86
87
90
91
94
95
96
99
100
101
102
103
104
105
106
107
108
110
111
112
113
115
116
117
118
119
120
121
122
123
124
125
126
127
130
131
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
152
153
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
175
176
177
178
179
180
181
182
183
187
192
197
202
207
208
209
210
211
212
213
214
215
216
217
218
225
226
227
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
255
256
259
260
267
268
269
270
271
272
273
274
275
276
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
305
306
307
308
309
316
317
318
319
320
321
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
350
351
352
353
354
355
356
357
358
362
363
364
365
366
367
368
372
376
380
384
388
392
396
400
401
402
403
404
405
406
418
436
448
469
472
476
477
478
479
483
484
485
486
487
488
489
490
491
492
493
494
495
501
502
503
509
515
521
522
523
524
525
526
527
528
529
530
531
532
536
537
538
539
540
541
542
543
544
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
713
717
718
719
720
726
732
733
734
735
736
737
738
739
740
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
768
774
775
776
777
783
784
785
786
790
791
792
793
794
795
796
799
806
807
808
809
810
811
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
841
846
847
848
855
856
857
858
859
860
862
863
864
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
925
926
927
928
935
936
937
938
939
940
941
942
943
947
948
949
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
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
1091
1092
1093
1094
1095
1096
1097
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1118
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1161
1162
1163
1164
1165
1166
1167
1173
1174
1175
1176
1177
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1211
1212
1213
1214
1215
1219
1220
1221
1222
1223
1224
1230
1231
1232
1233
1234
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1302
1303
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1340
1341
1342
1343
1346
1347
1348
1351
1352
1353
1356
/* ... */
/* ... */
#include "usbd_dfu.h"
#include "usbd_ctlreq.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev);
static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev);
static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev);
#ifndef USE_USBD_COMPOSITE
static uint8_t *USBD_DFU_GetCfgDesc(uint16_t *length);
static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length);/* ... */
#endif
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev,
uint8_t index, uint16_t *length);/* ... */
#endif
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
static void DFU_GetStatus(USBD_HandleTypeDef *pdev);
static void DFU_ClearStatus(USBD_HandleTypeDef *pdev);
static void DFU_GetState(USBD_HandleTypeDef *pdev);
static void DFU_Abort(USBD_HandleTypeDef *pdev);
static void DFU_Leave(USBD_HandleTypeDef *pdev);
static void *USBD_DFU_GetDfuFuncDesc(uint8_t *pConfDesc);
/* ... */
/* ... */
USBD_ClassTypeDef USBD_DFU =
{
USBD_DFU_Init,
USBD_DFU_DeInit,
USBD_DFU_Setup,
USBD_DFU_EP0_TxReady,
USBD_DFU_EP0_RxReady,
NULL,
NULL,
USBD_DFU_SOF,
NULL,
NULL,
#ifdef USE_USBD_COMPOSITE
NULL,
NULL,
NULL,
NULL,/* ... */
#else
USBD_DFU_GetCfgDesc,
USBD_DFU_GetCfgDesc,
USBD_DFU_GetCfgDesc,
USBD_DFU_GetDeviceQualifierDesc,/* ... */
#endif
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
USBD_DFU_GetUsrStringDesc
#endif
...};
#ifndef USE_USBD_COMPOSITE
__ALIGN_BEGIN static uint8_t USBD_DFU_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END =
{
0x09,
USB_DESC_TYPE_CONFIGURATION,
USB_DFU_CONFIG_DESC_SIZ,
0x00,
0x01,
0x01,
0x02,
/* ... */
#if (USBD_SELF_POWERED == 1U)
0xC0,
#else
0x80,
#endif
USBD_MAX_POWER,
USBD_DFU_IF_DESC(0U),
#if (USBD_DFU_MAX_ITF_NUM > 1U) Descriptor of DFU interface 0 Alternate setting 0
USBD_DFU_IF_DESC(1),/* ... */
#endif
#if (USBD_DFU_MAX_ITF_NUM > 2U) Descriptor of DFU interface 0 Alternate setting 1
USBD_DFU_IF_DESC(2),/* ... */
#endif
#if (USBD_DFU_MAX_ITF_NUM > 3U) Descriptor of DFU interface 0 Alternate setting 2
USBD_DFU_IF_DESC(3),/* ... */
#endif
#if (USBD_DFU_MAX_ITF_NUM > 4U) Descriptor of DFU interface 0 Alternate setting 3
USBD_DFU_IF_DESC(4),/* ... */
#endif
#if (USBD_DFU_MAX_ITF_NUM > 5U) Descriptor of DFU interface 0 Alternate setting 4
USBD_DFU_IF_DESC(5),/* ... */
#endif
#if (USBD_DFU_MAX_ITF_NUM > 6U)
#error "ERROR: usbd_dfu_core.c: Modify the file to support more descriptors!"
#endif
Descriptor of DFU interface 0 Alternate setting 5
0x09,
DFU_DESCRIPTOR_TYPE,
0x0B,
/* ... */
0xFF,
0x00,
/* ... */
TRANSFER_SIZE_BYTES(USBD_DFU_XFER_SIZE),
0x1A,
0x01 DFU Functional Descriptor
...};
__ALIGN_BEGIN static uint8_t USBD_DFU_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
{
USB_LEN_DEV_QUALIFIER_DESC,
USB_DESC_TYPE_DEVICE_QUALIFIER,
0x00,
0x02,
0x00,
0x00,
0x00,
0x40,
0x01,
0x00,
...};/* ... */
#endif
/* ... */
/* ... */
/* ... */
static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
UNUSED(cfgidx);
USBD_DFU_HandleTypeDef *hdfu;
hdfu = (USBD_DFU_HandleTypeDef *)USBD_malloc(sizeof(USBD_DFU_HandleTypeDef));
if (hdfu == NULL)
{
pdev->pClassDataCmsit[pdev->classId] = NULL;
return (uint8_t)USBD_EMEM;
}if (hdfu == NULL) { ... }
pdev->pClassDataCmsit[pdev->classId] = (void *)hdfu;
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
hdfu->alt_setting = 0U;
hdfu->data_ptr = USBD_DFU_APP_DEFAULT_ADD;
hdfu->wblock_num = 0U;
hdfu->wlength = 0U;
hdfu->manif_state = DFU_MANIFEST_COMPLETE;
hdfu->dev_state = DFU_STATE_IDLE;
hdfu->dev_status[0] = DFU_ERROR_NONE;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = DFU_STATE_IDLE;
hdfu->dev_status[5] = 0U;
if (((USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId])->Init() != USBD_OK)
{
return (uint8_t)USBD_FAIL;
}if (((USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId])->Init() != USBD_OK) { ... }
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
UNUSED(cfgidx);
USBD_DFU_HandleTypeDef *hdfu;
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
{
return (uint8_t)USBD_EMEM;
}if (pdev->pClassDataCmsit[pdev->classId] == NULL) { ... }
hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
hdfu->wblock_num = 0U;
hdfu->wlength = 0U;
hdfu->dev_state = DFU_STATE_IDLE;
hdfu->dev_status[0] = DFU_ERROR_NONE;
hdfu->dev_status[4] = DFU_STATE_IDLE;
((USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
USBD_free(pdev->pClassDataCmsit[pdev->classId]);
pdev->pClassDataCmsit[pdev->classId] = NULL;
pdev->pClassData = NULL;
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_StatusTypeDef ret = USBD_OK;
uint8_t *pbuf;
uint16_t len;
uint16_t status_info = 0U;
if (hdfu == NULL)
{
return (uint8_t)USBD_FAIL;
}if (hdfu == NULL) { ... }
switch (req->bmRequest & USB_REQ_TYPE_MASK)
{
case USB_REQ_TYPE_CLASS:
switch (req->bRequest)
{
case DFU_DNLOAD:
DFU_Download(pdev, req);
break;
case DFU_DNLOAD:
case DFU_UPLOAD:
DFU_Upload(pdev, req);
break;
case DFU_UPLOAD:
case DFU_GETSTATUS:
DFU_GetStatus(pdev);
break;
case DFU_GETSTATUS:
case DFU_CLRSTATUS:
DFU_ClearStatus(pdev);
break;
case DFU_CLRSTATUS:
case DFU_GETSTATE:
DFU_GetState(pdev);
break;
case DFU_GETSTATE:
case DFU_ABORT:
DFU_Abort(pdev);
break;
case DFU_ABORT:
case DFU_DETACH:
DFU_Detach(pdev, req);
break;
case DFU_DETACH:
default:
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
break;default
}switch (req->bRequest) { ... }
break;
case USB_REQ_TYPE_CLASS:
case USB_REQ_TYPE_STANDARD:
switch (req->bRequest)
{
case USB_REQ_GET_STATUS:
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
}if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... }
else
{
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
}else { ... }
break;
case USB_REQ_GET_STATUS:
case USB_REQ_GET_DESCRIPTOR:
if ((req->wValue >> 8) == DFU_DESCRIPTOR_TYPE)
{
pbuf = (uint8_t *)USBD_DFU_GetDfuFuncDesc(pdev->pConfDesc);
if (pbuf != NULL)
{
len = MIN(USB_DFU_DESC_SIZ, req->wLength);
(void)USBD_CtlSendData(pdev, pbuf, len);
}if (pbuf != NULL) { ... }
else
{
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
}else { ... }
}if ((req->wValue >> 8) == DFU_DESCRIPTOR_TYPE) { ... }
break;
case USB_REQ_GET_DESCRIPTOR:
case USB_REQ_GET_INTERFACE:
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
(void)USBD_CtlSendData(pdev, (uint8_t *)&hdfu->alt_setting, 1U);
}if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... }
else
{
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
}else { ... }
break;
case USB_REQ_GET_INTERFACE:
case USB_REQ_SET_INTERFACE:
if ((uint8_t)(req->wValue) < USBD_DFU_MAX_ITF_NUM)
{
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
hdfu->alt_setting = (uint8_t)(req->wValue);
}if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... }
else
{
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
}else { ... }
}if ((uint8_t)(req->wValue) < USBD_DFU_MAX_ITF_NUM) { ... }
else
{
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
}else { ... }
break;
case USB_REQ_SET_INTERFACE:
case USB_REQ_CLEAR_FEATURE:
break;
case USB_REQ_CLEAR_FEATURE:
default:
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
break;default
}switch (req->bRequest) { ... }
break;
case USB_REQ_TYPE_STANDARD:
default:
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
break;default
}switch (req->bmRequest & USB_REQ_TYPE_MASK) { ... }
return (uint8_t)ret;
}{ ... }
#ifndef USE_USBD_COMPOSITE
/* ... */
static uint8_t *USBD_DFU_GetCfgDesc(uint16_t *length)
{
*length = (uint16_t)sizeof(USBD_DFU_CfgDesc);
return USBD_DFU_CfgDesc;
}{ ... }
#endif/* ... */
/* ... */
static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev)
{
UNUSED(pdev);
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
{
USBD_SetupReqTypedef req;
uint32_t app_addr_ptr;
uint32_t addr;
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
uint32_t VendorStatus = 0U;
#endif
if (hdfu == NULL)
{
return (uint8_t)USBD_FAIL;
}if (hdfu == NULL) { ... }
if (hdfu->dev_state == DFU_STATE_DNLOAD_BUSY)
{
if (hdfu->wblock_num == 0U)
{
if (hdfu->wlength == 1U)
{
if (hdfu->buffer.d8[0] == DFU_CMD_GETCOMMANDS)
{
}if (hdfu->buffer.d8[0] == DFU_CMD_GETCOMMANDS) { ... }
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
else
{
if (DfuInterface->VendorDownloadCMD(hdfu->buffer.d8, hdfu->wblock_num,
hdfu->wlength, &VendorStatus) != USBD_OK)
{
hdfu->dev_state = DFU_STATE_ERROR;
hdfu->dev_status[0] = (uint8_t)VendorStatus;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
return (uint8_t)USBD_FAIL;
}if (DfuInterface->VendorDownloadCMD(hdfu->buffer.d8, hdfu->wblock_num, hdfu->wlength, &VendorStatus) != USBD_OK) { ... }
}else { ... }
/* ... */#endif
}if (hdfu->wlength == 1U) { ... }
else if (hdfu->wlength == 5U)
{
if (hdfu->buffer.d8[0] == DFU_CMD_SETADDRESSPOINTER)
{
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_SETADDRESSPOINTER, &VendorStatus) != USBD_OK)
{
hdfu->dev_state = DFU_STATE_ERROR;
hdfu->dev_status[0] = (uint8_t)VendorStatus;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
return (uint8_t)USBD_FAIL;
}if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_SETADDRESSPOINTER, &VendorStatus) != USBD_OK) { ... }
/* ... */#endif
hdfu->data_ptr = hdfu->buffer.d8[1];
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[2] << 8;
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[3] << 16;
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[4] << 24;
}if (hdfu->buffer.d8[0] == DFU_CMD_SETADDRESSPOINTER) { ... }
else if (hdfu->buffer.d8[0] == DFU_CMD_ERASE)
{
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_DOWNLOAD, &VendorStatus) != USBD_OK)
{
hdfu->dev_state = DFU_STATE_ERROR;
hdfu->dev_status[0] = (uint8_t)VendorStatus;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
return (uint8_t)USBD_FAIL;
}if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_DOWNLOAD, &VendorStatus) != USBD_OK) { ... }
/* ... */#endif
app_addr_ptr = hdfu->buffer.d8[1];
app_addr_ptr += (uint32_t)hdfu->buffer.d8[2] << 8;
app_addr_ptr += (uint32_t)hdfu->buffer.d8[3] << 16;
app_addr_ptr += (uint32_t)hdfu->buffer.d8[4] << 24;
if (DfuInterface->Erase(app_addr_ptr) != USBD_OK)
{
hdfu->dev_state = DFU_STATE_ERROR;
hdfu->dev_status[0] = DFU_ERROR_VENDOR;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
return (uint8_t)USBD_FAIL;
}if (DfuInterface->Erase(app_addr_ptr) != USBD_OK) { ... }
}else if (hdfu->buffer.d8[0] == DFU_CMD_ERASE) { ... }
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
else
{
if (DfuInterface->VendorDownloadCMD(hdfu->buffer.d8, hdfu->wblock_num,
hdfu->wlength, &VendorStatus) != USBD_OK)
{
hdfu->dev_state = DFU_STATE_ERROR;
hdfu->dev_status[0] = (uint8_t)VendorStatus;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
return (uint8_t)USBD_FAIL;
}if (DfuInterface->VendorDownloadCMD(hdfu->buffer.d8, hdfu->wblock_num, hdfu->wlength, &VendorStatus) != USBD_OK) { ... }
}else { ... }
/* ... */#else
else
{
return (uint8_t)USBD_FAIL;
}else { ... }
/* ... */#endif
}else if (hdfu->wlength == 5U) { ... }
else
{
hdfu->wlength = 0U;
hdfu->wblock_num = 0U;
req.bmRequest = 0U;
req.wLength = 1U;
USBD_CtlError(pdev, &req);
}else { ... }
}if (hdfu->wblock_num == 0U) { ... }
else
{
if (hdfu->wblock_num > 1U)
{
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_DOWNLOAD, &VendorStatus) != USBD_OK)
{
hdfu->dev_state = DFU_STATE_ERROR;
hdfu->dev_status[0] = (uint8_t)VendorStatus;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
return (uint8_t)USBD_FAIL;
}if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_DOWNLOAD, &VendorStatus) != USBD_OK) { ... }
/* ... */#endif
addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr;
if (DfuInterface->Write(hdfu->buffer.d8, (uint8_t *)addr, hdfu->wlength) != USBD_OK)
{
hdfu->dev_state = DFU_STATE_ERROR;
hdfu->dev_status[0] = DFU_ERROR_VENDOR;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
return (uint8_t)USBD_FAIL;
}if (DfuInterface->Write(hdfu->buffer.d8, (uint8_t *)addr, hdfu->wlength) != USBD_OK) { ... }
}if (hdfu->wblock_num > 1U) { ... }
}else { ... }
hdfu->wlength = 0U;
hdfu->wblock_num = 0U;
hdfu->dev_state = DFU_STATE_DNLOAD_SYNC;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
}if (hdfu->dev_state == DFU_STATE_DNLOAD_BUSY) { ... }
else if (hdfu->dev_state == DFU_STATE_MANIFEST)
{
DFU_Leave(pdev);
...}
else
{
return (uint8_t)USBD_FAIL;
}else { ... }
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev)
{
UNUSED(pdev);
return (uint8_t)USBD_OK;
}{ ... }
#ifndef USE_USBD_COMPOSITE
/* ... */
static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length)
{
*length = (uint16_t)sizeof(USBD_DFU_DeviceQualifierDesc);
return USBD_DFU_DeviceQualifierDesc;
}{ ... }
#endif/* ... */
/* ... */
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length)
{
static uint8_t USBD_StrDesc[255];
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
if (index <= (USBD_IDX_INTERFACE_STR + USBD_DFU_MAX_ITF_NUM))
{
USBD_GetString((uint8_t *)DfuInterface->pStrDesc, USBD_StrDesc, length);
return USBD_StrDesc;
}if (index <= (USBD_IDX_INTERFACE_STR + USBD_DFU_MAX_ITF_NUM)) { ... }
else
{
*length = 0U;
return NULL;
}else { ... }
}{ ... }
/* ... */#endif
/* ... */
uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
USBD_DFU_MediaTypeDef *fops)
{
if (fops == NULL)
{
return (uint8_t)USBD_FAIL;
}if (fops == NULL) { ... }
pdev->pUserData[pdev->classId] = fops;
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
/* ... */
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_DFUFuncDescTypeDef *pDfuFunc = (USBD_DFUFuncDescTypeDef *)USBD_DFU_GetDfuFuncDesc(pdev->pConfDesc);
if ((hdfu == NULL) || (pDfuFunc == NULL))
{
return;
}if ((hdfu == NULL) || (pDfuFunc == NULL)) { ... }
if ((hdfu->dev_state == DFU_STATE_IDLE) ||
(hdfu->dev_state == DFU_STATE_DNLOAD_SYNC) ||
(hdfu->dev_state == DFU_STATE_DNLOAD_IDLE) ||
(hdfu->dev_state == DFU_STATE_MANIFEST_SYNC) ||
(hdfu->dev_state == DFU_STATE_UPLOAD_IDLE))
{
hdfu->dev_state = DFU_STATE_IDLE;
hdfu->dev_status[0] = DFU_ERROR_NONE;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
hdfu->dev_status[5] = 0U;
hdfu->wblock_num = 0U;
hdfu->wlength = 0U;
}if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_DNLOAD_SYNC) || (hdfu->dev_state == DFU_STATE_DNLOAD_IDLE) || (hdfu->dev_state == DFU_STATE_MANIFEST_SYNC) || (hdfu->dev_state == DFU_STATE_UPLOAD_IDLE)) { ... }
if ((pDfuFunc->bmAttributes & DFU_DETACH_MASK) != 0U)
{
(void)USBD_Stop(pdev);
(void)USBD_Start(pdev);
}if ((pDfuFunc->bmAttributes & DFU_DETACH_MASK) != 0U) { ... }
else
{
USBD_Delay((uint32_t)req->wValue);
}else { ... }
}{ ... }
/* ... */
static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
uint32_t VendorStatus = 0U;/* ... */
#endif
if (hdfu == NULL)
{
return;
}if (hdfu == NULL) { ... }
if (req->wLength > 0U)
{
if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_DNLOAD_IDLE))
{
hdfu->wblock_num = req->wValue;
hdfu->wlength = MIN(req->wLength, USBD_DFU_XFER_SIZE);
hdfu->dev_state = DFU_STATE_DNLOAD_SYNC;
hdfu->dev_status[4] = hdfu->dev_state;
(void)USBD_CtlPrepareRx(pdev, (uint8_t *)hdfu->buffer.d8, hdfu->wlength);
}if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_DNLOAD_IDLE)) { ... }
else
{
USBD_CtlError(pdev, req);
}else { ... }
}if (req->wLength > 0U) { ... }
else
{
if ((hdfu->dev_state == DFU_STATE_DNLOAD_IDLE) || (hdfu->dev_state == DFU_STATE_IDLE))
{
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_SETADDRESSPOINTER, &VendorStatus) != USBD_OK)
{
hdfu->dev_state = DFU_STATE_ERROR;
hdfu->dev_status[0] = (uint8_t)VendorStatus;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
}if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_SETADDRESSPOINTER, &VendorStatus) != USBD_OK) { ... }
else
#endif
{
hdfu->manif_state = DFU_MANIFEST_IN_PROGRESS;
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
}else { ... }
}if ((hdfu->dev_state == DFU_STATE_DNLOAD_IDLE) || (hdfu->dev_state == DFU_STATE_IDLE)) { ... }
else
{
USBD_CtlError(pdev, req);
}else { ... }
}else { ... }
}{ ... }
/* ... */
static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
uint8_t *phaddr;
uint32_t addr;
uint32_t CmdLength;
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
uint32_t VendorStatus = 0U;
uint8_t VendorCmdLength = 0U;
uint8_t VendorCmdBuffer[DFU_VENDOR_CMD_MAX];
uint8_t idx;/* ... */
#endif
if (hdfu == NULL)
{
return;
}if (hdfu == NULL) { ... }
if (req->wLength > 0U)
{
if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_UPLOAD_IDLE))
{
hdfu->wblock_num = req->wValue;
hdfu->wlength = MIN(req->wLength, USBD_DFU_XFER_SIZE);
if (hdfu->wblock_num == 0U)
{
hdfu->dev_state = (hdfu->wlength > 3U) ? DFU_STATE_IDLE : DFU_STATE_UPLOAD_IDLE;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
hdfu->buffer.d8[0] = DFU_CMD_GETCOMMANDS;
hdfu->buffer.d8[1] = DFU_CMD_SETADDRESSPOINTER;
hdfu->buffer.d8[2] = DFU_CMD_ERASE;
CmdLength = 3U;
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
if (DfuInterface->GetVendorCMD != NULL)
{
(void)DfuInterface->GetVendorCMD(VendorCmdBuffer, (uint8_t *)&VendorCmdLength);
for (idx = 0U; idx < MIN(VendorCmdLength, DFU_VENDOR_CMD_MAX); idx++)
{
hdfu->buffer.d8[idx + 3U] = VendorCmdBuffer[idx];
}for (idx = 0U; idx < MIN(VendorCmdLength, DFU_VENDOR_CMD_MAX); idx++) { ... }
CmdLength += MIN(VendorCmdLength, DFU_VENDOR_CMD_MAX);
}if (DfuInterface->GetVendorCMD != NULL) { ... }
/* ... */#endif
(void)USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->buffer.d8[0])), CmdLength);
}if (hdfu->wblock_num == 0U) { ... }
else if (hdfu->wblock_num > 1U)
{
hdfu->dev_state = DFU_STATE_UPLOAD_IDLE;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
if (DfuInterface->VendorUploadCMD(hdfu->data_ptr, hdfu->wblock_num, &VendorStatus) != USBD_OK)
{
hdfu->dev_state = DFU_ERROR_STALLEDPKT;
hdfu->dev_status[0] = (uint8_t)VendorStatus;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
USBD_CtlError(pdev, req);
}if (DfuInterface->VendorUploadCMD(hdfu->data_ptr, hdfu->wblock_num, &VendorStatus) != USBD_OK) { ... }
if (VendorStatus == IS_DFU_PHY_ADDRESS)/* ... */
#endif
{
addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr;
phaddr = DfuInterface->Read((uint8_t *)addr, hdfu->buffer.d8, hdfu->wlength);
if (phaddr == NULL)
{
hdfu->dev_state = DFU_ERROR_STALLEDPKT;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
USBD_CtlError(pdev, req);
}if (phaddr == NULL) { ... }
else
{
(void)USBD_CtlSendData(pdev, phaddr, hdfu->wlength);
}else { ... }
...}
}else if (hdfu->wblock_num > 1U) { ... }
else
{
hdfu->dev_state = DFU_ERROR_STALLEDPKT;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
USBD_CtlError(pdev, req);
}else { ... }
}if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_UPLOAD_IDLE)) { ... }
else
{
hdfu->wlength = 0U;
hdfu->wblock_num = 0U;
USBD_CtlError(pdev, req);
}else { ... }
}if (req->wLength > 0U) { ... }
else
{
hdfu->dev_state = DFU_STATE_IDLE;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
}else { ... }
}{ ... }
/* ... */
static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
{
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
USBD_DFUFuncDescTypeDef *pDfuFunc = (USBD_DFUFuncDescTypeDef *)USBD_DFU_GetDfuFuncDesc(pdev->pConfDesc);
if ((hdfu == NULL) || (DfuInterface == NULL) || (pDfuFunc == NULL))
{
return;
}if ((hdfu == NULL) || (DfuInterface == NULL) || (pDfuFunc == NULL)) { ... }
switch (hdfu->dev_state)
{
case DFU_STATE_DNLOAD_SYNC:
if (hdfu->wlength != 0U)
{
hdfu->dev_state = DFU_STATE_DNLOAD_BUSY;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
if ((hdfu->wblock_num == 0U) && (hdfu->buffer.d8[0] == DFU_CMD_ERASE))
{
DfuInterface->GetStatus(hdfu->data_ptr, DFU_MEDIA_ERASE, hdfu->dev_status);
}if ((hdfu->wblock_num == 0U) && (hdfu->buffer.d8[0] == DFU_CMD_ERASE)) { ... }
else
{
DfuInterface->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status);
}else { ... }
}if (hdfu->wlength != 0U) { ... }
else
{
hdfu->dev_state = DFU_STATE_DNLOAD_IDLE;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
}else { ... }
break;
case DFU_STATE_DNLOAD_SYNC:
case DFU_STATE_MANIFEST_SYNC:
if (hdfu->manif_state == DFU_MANIFEST_IN_PROGRESS)
{
hdfu->dev_state = DFU_STATE_MANIFEST;
hdfu->dev_status[1] = 1U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
}if (hdfu->manif_state == DFU_MANIFEST_IN_PROGRESS) { ... }
else
{
if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) &&
((pDfuFunc->bmAttributes & DFU_MANIFEST_MASK) != 0U))
{
hdfu->dev_state = DFU_STATE_IDLE;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
}if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) && ((pDfuFunc->bmAttributes & DFU_MANIFEST_MASK) != 0U)) { ... }
}else { ... }
break;
case DFU_STATE_MANIFEST_SYNC:
default:
break;default
}switch (hdfu->dev_state) { ... }
(void)USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->dev_status[0])), 6U);
}{ ... }
/* ... */
static void DFU_ClearStatus(USBD_HandleTypeDef *pdev)
{
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
if (hdfu == NULL)
{
return;
}if (hdfu == NULL) { ... }
if (hdfu->dev_state == DFU_STATE_ERROR)
{
hdfu->dev_state = DFU_STATE_IDLE;
hdfu->dev_status[0] = DFU_ERROR_NONE;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
hdfu->dev_status[5] = 0U;
}if (hdfu->dev_state == DFU_STATE_ERROR) { ... }
else
{
hdfu->dev_state = DFU_STATE_ERROR;
hdfu->dev_status[0] = DFU_ERROR_UNKNOWN;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
hdfu->dev_status[5] = 0U;
}else { ... }
}{ ... }
/* ... */
static void DFU_GetState(USBD_HandleTypeDef *pdev)
{
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
if (hdfu == NULL)
{
return;
}if (hdfu == NULL) { ... }
(void)USBD_CtlSendData(pdev, &hdfu->dev_state, 1U);
}{ ... }
/* ... */
static void DFU_Abort(USBD_HandleTypeDef *pdev)
{
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
if (hdfu == NULL)
{
return;
}if (hdfu == NULL) { ... }
if ((hdfu->dev_state == DFU_STATE_IDLE) ||
(hdfu->dev_state == DFU_STATE_DNLOAD_SYNC) ||
(hdfu->dev_state == DFU_STATE_DNLOAD_IDLE) ||
(hdfu->dev_state == DFU_STATE_MANIFEST_SYNC) ||
(hdfu->dev_state == DFU_STATE_UPLOAD_IDLE))
{
hdfu->dev_state = DFU_STATE_IDLE;
hdfu->dev_status[0] = DFU_ERROR_NONE;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
hdfu->dev_status[5] = 0U;
hdfu->wblock_num = 0U;
hdfu->wlength = 0U;
}if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_DNLOAD_SYNC) || (hdfu->dev_state == DFU_STATE_DNLOAD_IDLE) || (hdfu->dev_state == DFU_STATE_MANIFEST_SYNC) || (hdfu->dev_state == DFU_STATE_UPLOAD_IDLE)) { ... }
}{ ... }
/* ... */
static void DFU_Leave(USBD_HandleTypeDef *pdev)
{
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
USBD_DFUFuncDescTypeDef *pDfuFunc = (USBD_DFUFuncDescTypeDef *)USBD_DFU_GetDfuFuncDesc(pdev->pConfDesc);
if ((hdfu == NULL) || (DfuInterface == NULL) || (pDfuFunc == NULL))
{
return;
}if ((hdfu == NULL) || (DfuInterface == NULL) || (pDfuFunc == NULL)) { ... }
hdfu->manif_state = DFU_MANIFEST_COMPLETE;
if ((pDfuFunc->bmAttributes & DFU_MANIFEST_MASK) != 0U)
{
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
return;
}if ((pDfuFunc->bmAttributes & DFU_MANIFEST_MASK) != 0U) { ... }
else
{
hdfu->dev_state = DFU_STATE_MANIFEST_WAIT_RESET;
hdfu->dev_status[1] = 0U;
hdfu->dev_status[2] = 0U;
hdfu->dev_status[3] = 0U;
hdfu->dev_status[4] = hdfu->dev_state;
(void)USBD_Stop(pdev);
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
DfuInterface->LeaveDFU(hdfu->data_ptr);/* ... */
#else
NVIC_SystemReset();/* ... */
#endif
}else { ... }
}{ ... }
/* ... */
static void *USBD_DFU_GetDfuFuncDesc(uint8_t *pConfDesc)
{
USBD_ConfigDescTypeDef *desc = (USBD_ConfigDescTypeDef *)(void *)pConfDesc;
USBD_DescHeaderTypeDef *pdesc = (USBD_DescHeaderTypeDef *)(void *)pConfDesc;
uint8_t *pDfuDesc = NULL;
uint16_t ptr;
if (desc->wTotalLength > desc->bLength)
{
ptr = desc->bLength;
while (ptr < desc->wTotalLength)
{
pdesc = USBD_GetNextDesc((uint8_t *)pdesc, &ptr);
if (pdesc->bDescriptorType == DFU_DESCRIPTOR_TYPE)
{
pDfuDesc = (uint8_t *)pdesc;
break;
}if (pdesc->bDescriptorType == DFU_DESCRIPTOR_TYPE) { ... }
}while (ptr < desc->wTotalLength) { ... }
}if (desc->wTotalLength > desc->bLength) { ... }
return pDfuDesc;
}{ ... }
/* ... */
/* ... */
/* ... */
Includes