-
Notifications
You must be signed in to change notification settings - Fork 56
/
ux_device_descriptors.c
774 lines (632 loc) · 26.1 KB
/
ux_device_descriptors.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file ux_device_descriptors.c
* @author MCD Application Team
* @brief USBX Device descriptor header file
******************************************************************************
* @attention
*
* Copyright (c) 2020-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "ux_device_descriptors.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
USBD_DevClassHandleTypeDef USBD_Device_FS, USBD_Device_HS;
uint8_t UserClassInstance[USBD_MAX_CLASS_INTERFACES] = {
CLASS_TYPE_CDC_ECM,
};
/* The generic device descriptor buffer that will be filled by builder
Size of the buffer is the maximum possible device FS descriptor size. */
#if defined ( __ICCARM__ ) /* IAR Compiler */
#pragma data_alignment=4
#endif /* defined ( __ICCARM__ ) */
__ALIGN_BEGIN static uint8_t DevFrameWorkDesc_FS[USBD_FRAMEWORK_MAX_DESC_SZ] __ALIGN_END = {0};
/* The generic device descriptor buffer that will be filled by builder
Size of the buffer is the maximum possible device HS descriptor size. */
#if defined ( __ICCARM__ ) /* IAR Compiler */
#pragma data_alignment=4
#endif /* defined ( __ICCARM__ ) */
__ALIGN_BEGIN static uint8_t DevFrameWorkDesc_HS[USBD_FRAMEWORK_MAX_DESC_SZ] __ALIGN_END = {0};
static uint8_t *pDevFrameWorkDesc_FS = DevFrameWorkDesc_FS;
static uint8_t *pDevFrameWorkDesc_HS = DevFrameWorkDesc_HS;
/* USER CODE BEGIN PV0 */
/* USER CODE END PV0 */
/* String Device Framework :
Byte 0 and 1 : Word containing the language ID : 0x0904 for US
Byte 2 : Byte containing the index of the descriptor
Byte 3 : Byte containing the length of the descriptor string
*/
#if defined ( __ICCARM__ ) /* IAR Compiler */
#pragma data_alignment=4
#endif /* defined ( __ICCARM__ ) */
__ALIGN_BEGIN UCHAR USBD_string_framework[USBD_STRING_FRAMEWORK_MAX_LENGTH]
__ALIGN_END = {0};
/* Multiple languages are supported on the device, to add
a language besides English, the Unicode language code must
be appended to the language_id_framework array and the length
adjusted accordingly. */
#if defined ( __ICCARM__ ) /* IAR Compiler */
#pragma data_alignment=4
#endif /* defined ( __ICCARM__ ) */
__ALIGN_BEGIN UCHAR USBD_language_id_framework[LANGUAGE_ID_MAX_LENGTH]
__ALIGN_END = {0};
/* USER CODE BEGIN PV1 */
/* USER CODE END PV1 */
/* Private function prototypes -----------------------------------------------*/
static void USBD_Desc_GetString(uint8_t *desc, uint8_t *Buffer, uint16_t *len);
static uint8_t USBD_Desc_GetLen(uint8_t *buf);
static uint8_t *USBD_Device_Framework_Builder(USBD_DevClassHandleTypeDef *pdev,
uint8_t *pDevFrameWorkDesc,
uint8_t *UserClassInstance,
uint8_t Speed);
static uint8_t USBD_FrameWork_AddToConfDesc(USBD_DevClassHandleTypeDef *pdev,
uint8_t Speed,
uint8_t *pCmpstConfDesc);
static uint8_t USBD_FrameWork_AddClass(USBD_DevClassHandleTypeDef *pdev,
USBD_CompositeClassTypeDef class,
uint8_t cfgidx, uint8_t Speed,
uint8_t *pCmpstConfDesc);
static uint8_t USBD_FrameWork_FindFreeIFNbr(USBD_DevClassHandleTypeDef *pdev);
static void USBD_FrameWork_AddConfDesc(uint32_t Conf, uint32_t *pSze);
static void USBD_FrameWork_AssignEp(USBD_DevClassHandleTypeDef *pdev, uint8_t Add,
uint8_t Type, uint32_t Sze);
#if USBD_CDC_ECM_CLASS_ACTIVATED == 1U
static void USBD_FrameWork_CDCECMDesc(USBD_DevClassHandleTypeDef *pdev,
uint32_t pConf, uint32_t *Sze);
#endif /* USBD_CDC_ECM_CLASS_ACTIVATED == 1U */
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief USBD_Get_Device_Framework_Speed
* Return the device speed descriptor
* @param Speed : HIGH or FULL SPEED flag
* @param length : length of HIGH or FULL SPEED array
* @retval Pointer to descriptor buffer
*/
uint8_t *USBD_Get_Device_Framework_Speed(uint8_t Speed, ULONG *Length)
{
uint8_t *pFrameWork = NULL;
/* USER CODE BEGIN Device_Framework0 */
/* USER CODE END Device_Framework0 */
if (USBD_FULL_SPEED == Speed)
{
USBD_Device_Framework_Builder(&USBD_Device_FS, pDevFrameWorkDesc_FS,
UserClassInstance, Speed);
/* Get the length of USBD_device_framework_full_speed */
*Length = (ULONG)(USBD_Device_FS.CurrDevDescSz + USBD_Device_FS.CurrConfDescSz);
pFrameWork = pDevFrameWorkDesc_FS;
}
else
{
USBD_Device_Framework_Builder(&USBD_Device_HS, pDevFrameWorkDesc_HS,
UserClassInstance, Speed);
/* Get the length of USBD_device_framework_high_speed */
*Length = (ULONG)(USBD_Device_HS.CurrDevDescSz + USBD_Device_HS.CurrConfDescSz);
pFrameWork = pDevFrameWorkDesc_HS;
}
/* USER CODE BEGIN Device_Framework1 */
/* USER CODE END Device_Framework1 */
return pFrameWork;
}
/**
* @brief USBD_Get_String_Framework
* Return the language_id_framework
* @param Length : Length of String_Framework
* @retval Pointer to language_id_framework buffer
*/
uint8_t *USBD_Get_String_Framework(ULONG *Length)
{
uint16_t len = 0U;
uint8_t count = 0U;
/* USER CODE BEGIN String_Framework0 */
/* USER CODE END String_Framework0 */
/* Set the Manufacturer language Id and index in USBD_string_framework */
USBD_string_framework[count++] = USBD_LANGID_STRING & 0xFF;
USBD_string_framework[count++] = USBD_LANGID_STRING >> 8;
USBD_string_framework[count++] = USBD_IDX_MFC_STR;
/* Set the Manufacturer string in string_framework */
USBD_Desc_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_string_framework + count, &len);
/* Set the Product language Id and index in USBD_string_framework */
count += len + 1;
USBD_string_framework[count++] = USBD_LANGID_STRING & 0xFF;
USBD_string_framework[count++] = USBD_LANGID_STRING >> 8;
USBD_string_framework[count++] = USBD_IDX_PRODUCT_STR;
/* Set the Product string in USBD_string_framework */
USBD_Desc_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_string_framework + count, &len);
/* Set Serial language Id and index in string_framework */
count += len + 1;
USBD_string_framework[count++] = USBD_LANGID_STRING & 0xFF;
USBD_string_framework[count++] = USBD_LANGID_STRING >> 8;
USBD_string_framework[count++] = USBD_IDX_SERIAL_STR;
/* Set the Serial number in USBD_string_framework */
USBD_Desc_GetString((uint8_t *)USBD_SERIAL_NUMBER, USBD_string_framework + count, &len);
#if USBD_CDC_ECM_CLASS_ACTIVATED == 1
/* Set MAC_STRING_INDEX and MAC_STRING in string_framework */
count += len + 1;
USBD_string_framework[count++] = USBD_LANGID_STRING & 0xFF;
USBD_string_framework[count++] = USBD_LANGID_STRING >> 8;
USBD_string_framework[count++] = CDC_ECM_MAC_STRING_INDEX;
/* Set the Mac address in USBD_string_framework */
USBD_Desc_GetString((uint8_t *)CDC_ECM_LOCAL_MAC_STR_DESC, USBD_string_framework + count, &len);
#endif /* USBD_CDC_ECM_CLASS_ACTIVATED */
/* USER CODE BEGIN String_Framework1 */
/* USER CODE END String_Framework1 */
/* Get the length of USBD_string_framework */
*Length = strlen((const char *)USBD_string_framework);
return USBD_string_framework;
}
/**
* @brief USBD_Get_Language_Id_Framework
* Return the language_id_framework
* @param Length : Length of Language_Id_Framework
* @retval Pointer to language_id_framework buffer
*/
uint8_t *USBD_Get_Language_Id_Framework(ULONG *Length)
{
uint8_t count = 0U;
/* Set the language Id in USBD_language_id_framework */
USBD_language_id_framework[count++] = USBD_LANGID_STRING & 0xFF;
USBD_language_id_framework[count++] = USBD_LANGID_STRING >> 8;
/* Get the length of USBD_language_id_framework */
*Length = strlen((const char *)USBD_language_id_framework);
return USBD_language_id_framework;
}
/**
* @brief USBD_Get_Interface_Number
* Return interface number
* @param class_type : Device class type
* @param interface_type : Device interface type
* @retval interface number
*/
uint16_t USBD_Get_Interface_Number(uint8_t class_type, uint8_t interface_type)
{
uint8_t itf_num = 0U;
uint8_t idx = 0U;
/* USER CODE BEGIN USBD_Get_Interface_Number0 */
/* USER CODE END USBD_Get_Interface_Number0 */
for(idx = 0; idx < USBD_MAX_SUPPORTED_CLASS; idx++)
{
if ((USBD_Device_FS.tclasslist[idx].ClassType == class_type) &&
(USBD_Device_FS.tclasslist[idx].InterfaceType == interface_type))
{
itf_num = USBD_Device_FS.tclasslist[idx].Ifs[0];
}
}
/* USER CODE BEGIN USBD_Get_Interface_Number1 */
/* USER CODE END USBD_Get_Interface_Number1 */
return itf_num;
}
/**
* @brief USBD_Get_Configuration_Number
* Return configuration number
* @param class_type : Device class type
* @param interface_type : Device interface type
* @retval configuration number
*/
uint16_t USBD_Get_Configuration_Number(uint8_t class_type, uint8_t interface_type)
{
uint8_t cfg_num = 1U;
/* USER CODE BEGIN USBD_Get_CONFIGURATION_Number0 */
/* USER CODE END USBD_Get_CONFIGURATION_Number0 */
/* USER CODE BEGIN USBD_Get_CONFIGURATION_Number1 */
/* USER CODE END USBD_Get_CONFIGURATION_Number1 */
return cfg_num;
}
/**
* @brief USBD_Desc_GetString
* Convert ASCII string into Unicode one
* @param desc : descriptor buffer
* @param Unicode : Formatted string buffer (Unicode)
* @param len : descriptor length
* @retval None
*/
static void USBD_Desc_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
{
uint8_t idx = 0U;
uint8_t *pdesc;
if (desc == NULL)
{
return;
}
pdesc = desc;
*len = (uint16_t)USBD_Desc_GetLen(pdesc);
unicode[idx++] = *(uint8_t *)len;
while (*pdesc != (uint8_t)'\0')
{
unicode[idx++] = *pdesc;
pdesc++;
}
}
/**
* @brief USBD_Desc_GetLen
* return the string length
* @param buf : pointer to the ASCII string buffer
* @retval string length
*/
static uint8_t USBD_Desc_GetLen(uint8_t *buf)
{
uint8_t len = 0U;
uint8_t *pbuff = buf;
while (*pbuff != (uint8_t)'\0')
{
len++;
pbuff++;
}
return len;
}
/**
* @brief USBD_Device_Framework_Builder
* Device Framework builder
* @param pdev: device instance
* @param pDevFrameWorkDesc: Pointer to the device framework descriptor
* @param UserClassInstance: type of the class to be added
* @param Speed: Speed parameter HS or FS
* @retval status
*/
static uint8_t *USBD_Device_Framework_Builder(USBD_DevClassHandleTypeDef *pdev,
uint8_t *pDevFrameWorkDesc,
uint8_t *UserClassInstance,
uint8_t Speed)
{
static USBD_DeviceDescTypedef *pDevDesc;
static USBD_DevQualiDescTypedef *pDevQualDesc;
uint8_t Idx_Instance = 0U;
/* Set Dev and conf descriptors size to 0 */
pdev->CurrConfDescSz = 0U;
pdev->CurrDevDescSz = 0U;
/* Set the pointer to the device descriptor area*/
pDevDesc = (USBD_DeviceDescTypedef *)pDevFrameWorkDesc;
/* Start building the generic device descriptor common part */
pDevDesc->bLength = (uint8_t)sizeof(USBD_DeviceDescTypedef);
pDevDesc->bDescriptorType = UX_DEVICE_DESCRIPTOR_ITEM;
pDevDesc->bcdUSB = USB_BCDUSB;
pDevDesc->bDeviceClass = 0x00;
pDevDesc->bDeviceSubClass = 0x00;
pDevDesc->bDeviceProtocol = 0x00;
pDevDesc->bMaxPacketSize = USBD_MAX_EP0_SIZE;
pDevDesc->idVendor = USBD_VID;
pDevDesc->idProduct = USBD_PID;
pDevDesc->bcdDevice = 0x0200;
pDevDesc->iManufacturer = USBD_IDX_MFC_STR;
pDevDesc->iProduct = USBD_IDX_PRODUCT_STR;
pDevDesc->iSerialNumber = USBD_IDX_SERIAL_STR;
pDevDesc->bNumConfigurations = USBD_MAX_NUM_CONFIGURATION;
pdev->CurrDevDescSz += (uint32_t)sizeof(USBD_DeviceDescTypedef);
/* Check if USBx is in high speed mode to add qualifier descriptor */
if (Speed == USBD_HIGH_SPEED)
{
pDevQualDesc = (USBD_DevQualiDescTypedef *)(pDevFrameWorkDesc + pdev->CurrDevDescSz);
pDevQualDesc->bLength = (uint8_t)sizeof(USBD_DevQualiDescTypedef);
pDevQualDesc->bDescriptorType = UX_DEVICE_QUALIFIER_DESCRIPTOR_ITEM;
pDevQualDesc->bcdDevice = 0x0200;
pDevQualDesc->Class = 0x00;
pDevQualDesc->SubClass = 0x00;
pDevQualDesc->Protocol = 0x00;
pDevQualDesc->bMaxPacketSize = 0x40;
pDevQualDesc->bNumConfigurations = 0x01;
pDevQualDesc->bReserved = 0x00;
pdev->CurrDevDescSz += (uint32_t)sizeof(USBD_DevQualiDescTypedef);
}
/* Build the device framework */
while (Idx_Instance < USBD_MAX_SUPPORTED_CLASS)
{
if ((pdev->classId < USBD_MAX_SUPPORTED_CLASS) &&
(pdev->NumClasses < USBD_MAX_SUPPORTED_CLASS) &&
(UserClassInstance[Idx_Instance] != CLASS_TYPE_NONE))
{
/* Call the composite class builder */
(void)USBD_FrameWork_AddClass(pdev,
(USBD_CompositeClassTypeDef)UserClassInstance[Idx_Instance],
0, Speed,
(pDevFrameWorkDesc + pdev->CurrDevDescSz));
/* Increment the ClassId for the next occurrence */
pdev->classId ++;
pdev->NumClasses ++;
}
Idx_Instance++;
}
/* Check if there is a composite class and update device class */
if (pdev->NumClasses > 1)
{
pDevDesc->bDeviceClass = 0xEF;
pDevDesc->bDeviceSubClass = 0x02;
pDevDesc->bDeviceProtocol = 0x01;
}
else
{
/* Check if the CDC ACM class is set and update device class */
if (UserClassInstance[0] == CLASS_TYPE_CDC_ACM)
{
pDevDesc->bDeviceClass = 0x02;
pDevDesc->bDeviceSubClass = 0x02;
pDevDesc->bDeviceProtocol = 0x00;
}
}
return pDevFrameWorkDesc;
}
/**
* @brief USBD_FrameWork_AddClass
* Register a class in the class builder
* @param pdev: device instance
* @param class: type of the class to be added (from USBD_CompositeClassTypeDef)
* @param cfgidx: configuration index
* @param speed: device speed
* @param pCmpstConfDesc: to composite device configuration descriptor
* @retval status
*/
uint8_t USBD_FrameWork_AddClass(USBD_DevClassHandleTypeDef *pdev,
USBD_CompositeClassTypeDef class,
uint8_t cfgidx, uint8_t Speed,
uint8_t *pCmpstConfDesc)
{
if ((pdev->classId < USBD_MAX_SUPPORTED_CLASS) &&
(pdev->tclasslist[pdev->classId].Active == 0U))
{
/* Store the class parameters in the global tab */
pdev->tclasslist[pdev->classId].ClassId = pdev->classId;
pdev->tclasslist[pdev->classId].Active = 1U;
pdev->tclasslist[pdev->classId].ClassType = class;
/* Call configuration descriptor builder and endpoint configuration builder */
if (USBD_FrameWork_AddToConfDesc(pdev, Speed, pCmpstConfDesc) != UX_SUCCESS)
{
return UX_ERROR;
}
}
UNUSED(cfgidx);
return UX_SUCCESS;
}
/**
* @brief USBD_FrameWork_AddToConfDesc
* Add a new class to the configuration descriptor
* @param pdev: device instance
* @param Speed: device speed
* @param pCmpstConfDesc: to composite device configuration descriptor
* @retval status
*/
uint8_t USBD_FrameWork_AddToConfDesc(USBD_DevClassHandleTypeDef *pdev, uint8_t Speed,
uint8_t *pCmpstConfDesc)
{
uint8_t interface = 0U;
/* USER CODE BEGIN FrameWork_AddToConfDesc_0 */
/* USER CODE END FrameWork_AddToConfDesc_0 */
/* The USB drivers do not set the speed value, so set it here before starting */
pdev->Speed = Speed;
/* start building the config descriptor common part */
if (pdev->classId == 0U)
{
/* Add configuration and IAD descriptors */
USBD_FrameWork_AddConfDesc((uint32_t)pCmpstConfDesc, &pdev->CurrConfDescSz);
}
switch (pdev->tclasslist[pdev->classId].ClassType)
{
#if USBD_CDC_ECM_CLASS_ACTIVATED == 1
case CLASS_TYPE_CDC_ECM:
/* Find the first available interface slot and Assign number of interfaces */
interface = USBD_FrameWork_FindFreeIFNbr(pdev);
pdev->tclasslist[pdev->classId].NumIf = 2U;
pdev->tclasslist[pdev->classId].Ifs[0] = interface;
pdev->tclasslist[pdev->classId].Ifs[1] = (uint8_t)(interface + 1U);
/* Assign endpoint numbers */
pdev->tclasslist[pdev->classId].NumEps = 3U; /* EP_IN, EP_OUT, CMD_EP */
/* Check the current speed to assign endpoints */
if (Speed == USBD_HIGH_SPEED)
{
/* Assign OUT Endpoint */
USBD_FrameWork_AssignEp(pdev, USBD_CDCECM_EPOUT_ADDR,
USBD_EP_TYPE_BULK, USBD_CDCECM_EPOUT_HS_MPS);
/* Assign IN Endpoint */
USBD_FrameWork_AssignEp(pdev, USBD_CDCECM_EPIN_ADDR,
USBD_EP_TYPE_BULK, USBD_CDCECM_EPIN_HS_MPS);
/* Assign CMD Endpoint */
USBD_FrameWork_AssignEp(pdev, USBD_CDCECM_EPINCMD_ADDR,
USBD_EP_TYPE_INTR, USBD_CDCECM_EPINCMD_HS_MPS);
}
else
{
/* Assign OUT Endpoint */
USBD_FrameWork_AssignEp(pdev, USBD_CDCECM_EPOUT_ADDR,
USBD_EP_TYPE_BULK, USBD_CDCECM_EPOUT_FS_MPS);
/* Assign IN Endpoint */
USBD_FrameWork_AssignEp(pdev, USBD_CDCECM_EPIN_ADDR,
USBD_EP_TYPE_BULK, USBD_CDCECM_EPIN_FS_MPS);
/* Assign CMD Endpoint */
USBD_FrameWork_AssignEp(pdev, USBD_CDCECM_EPINCMD_ADDR,
USBD_EP_TYPE_INTR, USBD_CDCECM_EPINCMD_FS_MPS);
}
/* Configure and Append the Descriptor */
USBD_FrameWork_CDCECMDesc(pdev, (uint32_t)pCmpstConfDesc, &pdev->CurrConfDescSz);
break;
#endif /* USBD_CDC_ECM_CLASS_ACTIVATED */
/* USER CODE BEGIN FrameWork_AddToConfDesc_1 */
/* USER CODE END FrameWork_AddToConfDesc_1 */
default:
/* USER CODE BEGIN FrameWork_AddToConfDesc_2 */
/* USER CODE END FrameWork_AddToConfDesc_2 */
break;
}
return UX_SUCCESS;
}
/**
* @brief USBD_FrameWork_FindFreeIFNbr
* Find the first interface available slot
* @param pdev: device instance
* @retval The interface number to be used
*/
static uint8_t USBD_FrameWork_FindFreeIFNbr(USBD_DevClassHandleTypeDef *pdev)
{
uint32_t idx = 0U;
/* Unroll all already activated classes */
for (uint32_t i = 0U; i < pdev->NumClasses; i++)
{
/* Unroll each class interfaces */
for (uint32_t j = 0U; j < pdev->tclasslist[i].NumIf; j++)
{
/* Increment the interface counter index */
idx++;
}
}
/* Return the first available interface slot */
return (uint8_t)idx;
}
/**
* @brief USBD_FrameWork_AddConfDesc
* Add a new class to the configuration descriptor
* @param Conf: configuration descriptor
* @param pSze: pointer to the configuration descriptor size
* @retval none
*/
static void USBD_FrameWork_AddConfDesc(uint32_t Conf, uint32_t *pSze)
{
/* Intermediate variable to comply with MISRA-C Rule 11.3 */
USBD_ConfigDescTypedef *ptr = (USBD_ConfigDescTypedef *)Conf;
ptr->bLength = (uint8_t)sizeof(USBD_ConfigDescTypedef);
ptr->bDescriptorType = USB_DESC_TYPE_CONFIGURATION;
ptr->wDescriptorLength = 0U;
ptr->bNumInterfaces = 0U;
ptr->bConfigurationValue = 1U;
ptr->iConfiguration = USBD_CONFIG_STR_DESC_IDX;
ptr->bmAttributes = USBD_CONFIG_BMATTRIBUTES;
ptr->bMaxPower = USBD_CONFIG_MAXPOWER;
*pSze += sizeof(USBD_ConfigDescTypedef);
}
/**
* @brief USBD_FrameWork_AssignEp
* Assign and endpoint
* @param pdev: device instance
* @param Add: Endpoint address
* @param Type: Endpoint type
* @param Sze: Endpoint max packet size
* @retval none
*/
static void USBD_FrameWork_AssignEp(USBD_DevClassHandleTypeDef *pdev,
uint8_t Add, uint8_t Type, uint32_t Sze)
{
uint32_t idx = 0U;
/* Find the first available endpoint slot */
while (((idx < (pdev->tclasslist[pdev->classId]).NumEps) && \
((pdev->tclasslist[pdev->classId].Eps[idx].is_used) != 0U)))
{
/* Increment the index */
idx++;
}
/* Configure the endpoint */
pdev->tclasslist[pdev->classId].Eps[idx].add = Add;
pdev->tclasslist[pdev->classId].Eps[idx].type = Type;
pdev->tclasslist[pdev->classId].Eps[idx].size = (uint16_t) Sze;
pdev->tclasslist[pdev->classId].Eps[idx].is_used = 1U;
}
#if USBD_CDC_ECM_CLASS_ACTIVATED
/**
* @brief USBD_FrameWork_CDCECMDesc
* Configure and Append the CDC_ECM Descriptor
* @param pdev: device instance
* @param pConf: Configuration descriptor pointer
* @param Sze: pointer to the current configuration descriptor size
* @retval None
*/
static void USBD_FrameWork_CDCECMDesc(USBD_DevClassHandleTypeDef *pdev,
uint32_t pConf, uint32_t *Sze)
{
static USBD_IfDescTypedef *pIfDesc;
static USBD_EpDescTypedef *pEpDesc;
static USBD_ECMFuncDescTypedef *pFuncDesc;
static USBD_CDCHeaderFuncDescTypedef *pHeadDesc;
static USBD_CDCUnionFuncDescTypedef *pUnionDesc;
#if USBD_COMPOSITE_USE_IAD == 1
static USBD_IadDescTypedef *pIadDesc;
#endif /* USBD_COMPOSITE_USE_IAD == 1 */
#if USBD_COMPOSITE_USE_IAD == 1
/* IAD descriptor */
pIadDesc = ((USBD_IadDescTypedef *)(pConf + *Sze));
pIadDesc->bLength = (uint8_t)sizeof(USBD_IadDescTypedef);
pIadDesc->bDescriptorType = USB_DESC_TYPE_IAD;
pIadDesc->bFirstInterface = pdev->tclasslist[pdev->classId].Ifs[0];
pIadDesc->bInterfaceCount = 2U; /* 2 interfaces */
pIadDesc->bFunctionClass = 0x02U;
pIadDesc->bFunctionSubClass = 0x06U;
pIadDesc->bFunctionProtocol = 0x00U;
pIadDesc->iFunction = 0U; /* String Index */
*Sze += (uint32_t)sizeof(USBD_IadDescTypedef);
#endif /* USBD_COMPOSITE_USE_IAD == 1 */
/* Append ECM Interface descriptor */
__USBD_FRAMEWORK_SET_IF(pdev->tclasslist[pdev->classId].Ifs[0], 0U, 1U, 0x02U,
0x06U, 0U, 0U);
/* Append ECM header functional descriptor to Configuration descriptor */
pHeadDesc = ((USBD_CDCHeaderFuncDescTypedef *)(pConf + *Sze));
pHeadDesc->bLength = (uint8_t)sizeof(USBD_CDCHeaderFuncDescTypedef);
pHeadDesc->bDescriptorType = 0x24U;
pHeadDesc->bDescriptorSubtype = 0x00U;
pHeadDesc->bcdCDC = USBD_DESC_ECM_BCD;
*Sze += (uint32_t)sizeof(USBD_CDCHeaderFuncDescTypedef);
/* Append ECM functional descriptor to Configuration descriptor */
pFuncDesc = ((USBD_ECMFuncDescTypedef *)(pConf + *Sze));
pFuncDesc->bFunctionLength = (uint8_t)sizeof(USBD_ECMFuncDescTypedef);
pFuncDesc->bDescriptorType = 0x24U;
pFuncDesc->bDescriptorSubType = USBD_DESC_SUBTYPE_ACM;
pFuncDesc->iMacAddress = CDC_ECM_MAC_STRING_INDEX;
pFuncDesc->bEthernetStatistics3 = CDC_ECM_ETH_STATS_BYTE3;
pFuncDesc->bEthernetStatistics2 = CDC_ECM_ETH_STATS_BYTE2;
pFuncDesc->bEthernetStatistics1 = CDC_ECM_ETH_STATS_BYTE1;
pFuncDesc->bEthernetStatistics0 = CDC_ECM_ETH_STATS_BYTE0;
pFuncDesc->wMaxSegmentSize = CDC_ECM_ETH_MAX_SEGSZE;
pFuncDesc->bNumberMCFiltes = CDC_ECM_ETH_NBR_MACFILTERS;
pFuncDesc->bNumberPowerFiltes = CDC_ECM_ETH_NBR_PWRFILTERS;
*Sze += (uint32_t)sizeof(USBD_ECMFuncDescTypedef);
/* Append ECM Union functional descriptor to Configuration descriptor */
pUnionDesc = ((USBD_CDCUnionFuncDescTypedef *)((uint32_t)pConf + *Sze));
pUnionDesc->bLength = (uint8_t)sizeof(USBD_CDCUnionFuncDescTypedef);
pUnionDesc->bDescriptorType = 0x24U;
pUnionDesc->bDescriptorSubtype = 0x06U;
pUnionDesc->bMasterInterface = pdev->tclasslist[pdev->classId].Ifs[0];
pUnionDesc->bSlaveInterface = pdev->tclasslist[pdev->classId].Ifs[1];
*Sze += (uint32_t)sizeof(USBD_CDCUnionFuncDescTypedef);
/* Append ECM Communication IN Endpoint Descriptor to Configuration descriptor */
__USBD_FRAMEWORK_SET_EP(pdev->tclasslist[pdev->classId].Eps[2].add,
USBD_EP_TYPE_INTR,
(uint16_t)pdev->tclasslist[pdev->classId].Eps[2].size,
USBD_CDCECM_EPINCMD_HS_BINTERVAL,
USBD_CDCECM_EPINCMD_FS_BINTERVAL);
/* Append ECM Data class interface descriptor to Configuration descriptor */
__USBD_FRAMEWORK_SET_IF(pdev->tclasslist[pdev->classId].Ifs[1], 0U, 2U, 0x0AU, 0U,
0U, 0U);
/* Append ECM OUT Endpoint Descriptor to Configuration descriptor */
__USBD_FRAMEWORK_SET_EP((pdev->tclasslist[pdev->classId].Eps[0].add),
(USBD_EP_TYPE_BULK),
(uint16_t)(pdev->tclasslist[pdev->classId].Eps[0].size),
(0x00U), (0x00U));
/* Append ECM IN Endpoint Descriptor to Configuration descriptor */
__USBD_FRAMEWORK_SET_EP((pdev->tclasslist[pdev->classId].Eps[1].add),
(USBD_EP_TYPE_BULK),
(uint16_t)(pdev->tclasslist[pdev->classId].Eps[1].size),
(0x00U), (0x00U));
/* Update Config Descriptor and IAD descriptor */
((USBD_ConfigDescTypedef*)pConf)->bNumInterfaces += 2U;
((USBD_ConfigDescTypedef*)pConf)->wDescriptorLength = *Sze;
}
#endif /* USBD_CDC_ECM_CLASS_ACTIVATED */
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */