Rev 18 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 18 | Rev 19 | ||
|---|---|---|---|
| Line 19... | Line 19... | ||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | /* Virtual serial port over USB.*/ |
21 | /* Virtual serial port over USB.*/ |
| 22 | SerialUSBDriver SDU1; |
22 | SerialUSBDriver SDU1; |
| 23 | 23 | ||
| 24 | #if HAL_USE_SERIAL_USB == TRUE |
24 | #if HAL_USE_USB_DUAL_CDC == TRUE |
| 25 | SerialUSBDriver SDU2; |
25 | SerialUSBDriver SDU2; |
| 26 | #endif |
26 | #endif |
| 27 | 27 | ||
| 28 | 28 | ||
| - | 29 | ||
| - | 30 | #if HAL_USE_USB_DUAL_CDC==TRUE |
|
| - | 31 | #define USB_EP_BULK_DATASIZE 0x0020 |
|
| - | 32 | #define USB_EP_INTR_DATASIZE 0x0010 |
|
| - | 33 | #define USB_MAX_PACKETSIZE 0x0008 |
|
| - | 34 | #else |
|
| - | 35 | #define USB_EP_BULK_DATASIZE 0x0040 |
|
| - | 36 | #define USB_EP_INTR_DATASIZE 0x0010 |
|
| - | 37 | #define USB_MAX_PACKETSIZE 0x0040 |
|
| - | 38 | #endif |
|
| - | 39 | ||
| - | 40 | ||
| 29 | /* |
41 | /* |
| 30 | * Endpoints to be used for USBD1/SDU1. |
42 | * Endpoints to be used for USBD1/SDU1. |
| 31 | */ |
43 | */ |
| 32 | #define USBD1_DATA_REQUEST_EP 1 |
44 | #define USBD1_DATA_REQUEST_EP 1 |
| 33 | #define USBD1_DATA_AVAILABLE_EP 1 |
45 | #define USBD1_DATA_AVAILABLE_EP 1 |
| Line 47... | Line 59... | ||
| 47 | static const uint8_t vcom_device_descriptor_data[18] = { |
59 | static const uint8_t vcom_device_descriptor_data[18] = { |
| 48 | USB_DESC_DEVICE (0x0110, /* bcdUSB (1.1). */ |
60 | USB_DESC_DEVICE (0x0110, /* bcdUSB (1.1). */ |
| 49 | 0x02, /* bDeviceClass (CDC). */ |
61 | 0x02, /* bDeviceClass (CDC). */ |
| 50 | 0x00, /* bDeviceSubClass. */ |
62 | 0x00, /* bDeviceSubClass. */ |
| 51 | 0x00, /* bDeviceProtocol. */ |
63 | 0x00, /* bDeviceProtocol. */ |
| 52 | 0x40, /* bMaxPacketSize. */ |
64 | USB_MAX_PACKETSIZE, /* bMaxPacketSize. */ |
| 53 | 0x0483, /* idVendor (ST). */ |
65 | 0x0483, /* idVendor (ST). */ |
| 54 | 0x5740, /* idProduct. */ |
66 | 0x5740, /* idProduct. */ |
| 55 | 0x0200, /* bcdDevice. */ |
67 | 0x0200, /* bcdDevice. */ |
| 56 | 1, /* iManufacturer. */ |
68 | 1, /* iManufacturer. */ |
| 57 | 2, /* iProduct. */ |
69 | 2, /* iProduct. */ |
| 58 | 3, /* iSerialNumber. */ |
70 | 4, /* iSerialNumber. */ |
| 59 | 1) /* bNumConfigurations. */ |
71 | 1) /* bNumConfigurations. */ |
| 60 | }; |
72 | }; |
| 61 | 73 | ||
| 62 | /* |
74 | /* |
| 63 | * Device Descriptor wrapper. |
75 | * Device Descriptor wrapper. |
| Line 66... | Line 78... | ||
| 66 | sizeof vcom_device_descriptor_data, |
78 | sizeof vcom_device_descriptor_data, |
| 67 | vcom_device_descriptor_data |
79 | vcom_device_descriptor_data |
| 68 | }; |
80 | }; |
| 69 | 81 | ||
| 70 | 82 | ||
| - | 83 | ||
| - | 84 | ||
| - | 85 | ||
| 71 | /* Configuration Descriptor tree for a CDC.*/ |
86 | /* Configuration Descriptor tree for a CDC.*/ |
| 72 | 87 | ||
| 73 | static const uint8_t vcom_configuration_descriptor_data[] = { |
88 | static const uint8_t vcom_configuration_descriptor_data[] = { |
| 74 | /* Configuration Descriptor.*/ |
89 | /* Configuration Descriptor.*/ |
| 75 | #if HAL_USE_USB_DUAL_CDC == FALSE |
90 | #if HAL_USE_USB_DUAL_CDC == FALSE |
| 76 | /* the header is 9 bytes long, total has 2 EPs in use = 67 bytes */ |
91 | /* the header is 9 bytes long, total has 2 EPs in use = 67 bytes */ |
| 77 | USB_DESC_CONFIGURATION(67, /* wTotalLength. */ |
92 | USB_DESC_CONFIGURATION(67, /* wTotalLength. */ |
| 78 | 0x02, /* bNumInterfaces. */ |
93 | 0x02, /* bNumInterfaces. */ |
| 79 | 0x01, /* bConfigurationValue. */ |
94 | 0x01, /* bConfigurationValue. */ |
| 80 | 0, /* iConfiguration. */ |
95 | 0, /* iConfiguration. */ |
| 81 | 0xC0, /* bmAttributes (self powered). */ |
96 | 0x80, /* bmAttributes (bus powered). */ |
| 82 | 50), /* bMaxPower (100mA). */ |
97 | 50), /* bMaxPower (100mA). */ |
| 83 | #else |
98 | #else |
| 84 | /* the header is 9 bytes long, total has 4 EP in use = 67 * 2 -9 bytes */ |
99 | /* the header is 9 bytes long, total has 4 EP in use = 67 * 2 -9 bytes */ |
| 85 | USB_DESC_CONFIGURATION(125, /* wTotalLength. */ |
100 | USB_DESC_CONFIGURATION(125, /* wTotalLength. */ |
| 86 | 0x04, /* bNumInterfaces. */ |
101 | 0x04, /* bNumInterfaces. */ |
| 87 | 0x01, /* bConfigurationValue. */ |
102 | 0x01, /* bConfigurationValue. */ |
| 88 | 0, /* iConfiguration. */ |
103 | 0, /* iConfiguration. */ |
| 89 | 0xC0, /* bmAttributes (self powered). */ |
104 | 0x80, /* bmAttributes (bus powered). */ |
| 90 | 50), /* bMaxPower (100mA). */ |
105 | 50), /* bMaxPower (100mA). */ |
| 91 | #endif |
106 | #endif |
| 92 | /* Interface Descriptor.*/ |
107 | /* Interface Descriptor.*/ |
| 93 | USB_DESC_INTERFACE (0x00, /* bInterfaceNumber. */ |
108 | USB_DESC_INTERFACE (0x00, /* bInterfaceNumber. */ |
| 94 | 0x00, /* bAlternateSetting. */ |
109 | 0x00, /* bAlternateSetting. */ |
| Line 147... | Line 162... | ||
| 147 | 4.7). */ |
162 | 4.7). */ |
| 148 | 0x00), /* iInterface. */ |
163 | 0x00), /* iInterface. */ |
| 149 | /* Endpoint 3 Descriptor.*/ |
164 | /* Endpoint 3 Descriptor.*/ |
| 150 | USB_DESC_ENDPOINT (USBD1_DATA_AVAILABLE_EP, /* bEndpointAddress.*/ |
165 | USB_DESC_ENDPOINT (USBD1_DATA_AVAILABLE_EP, /* bEndpointAddress.*/ |
| 151 | 0x02, /* bmAttributes (Bulk). */ |
166 | 0x02, /* bmAttributes (Bulk). */ |
| 152 | 0x0040, /* wMaxPacketSize. */ |
167 | 0x0040, /* wMaxPacketSize. */ |
| 153 | 0x00), /* bInterval. */ |
168 | 0x00), /* bInterval. */ |
| 154 | /* Endpoint 1 Descriptor.*/ |
169 | /* Endpoint 1 Descriptor.*/ |
| 155 | USB_DESC_ENDPOINT (USBD1_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/ |
170 | USB_DESC_ENDPOINT (USBD1_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/ |
| 156 | 0x02, /* bmAttributes (Bulk). */ |
171 | 0x02, /* bmAttributes (Bulk). */ |
| 157 | 0x0040, /* wMaxPacketSize. */ |
172 | 0x0040, /* wMaxPacketSize. */ |
| Line 224... | Line 239... | ||
| 224 | 0x02, /* bmAttributes (Bulk). */ |
239 | 0x02, /* bmAttributes (Bulk). */ |
| 225 | 0x0040, /* wMaxPacketSize. */ |
240 | 0x0040, /* wMaxPacketSize. */ |
| 226 | 0x00) /* bInterval. */ |
241 | 0x00) /* bInterval. */ |
| 227 | #endif |
242 | #endif |
| 228 | }; |
243 | }; |
| - | 244 | ||
| - | 245 | ||
| 229 | /* |
246 | /* |
| 230 | * Configuration Descriptor wrapper. |
247 | * Configuration Descriptor wrapper. |
| 231 | */ |
248 | */ |
| 232 | static const USBDescriptor vcom_configuration_descriptor = { |
249 | static const USBDescriptor vcom_configuration_descriptor = { |
| 233 | sizeof vcom_configuration_descriptor_data, |
250 | sizeof vcom_configuration_descriptor_data, |
| Line 321... | Line 338... | ||
| 321 | static USBOutEndpointState ep1outstate; |
338 | static USBOutEndpointState ep1outstate; |
| 322 | 339 | ||
| 323 | /** |
340 | /** |
| 324 | * @brief EP1 initialization structure (both IN and OUT). |
341 | * @brief EP1 initialization structure (both IN and OUT). |
| 325 | */ |
342 | */ |
| - | 343 | ||
| 326 | static const USBEndpointConfig ep1config = { |
344 | static const USBEndpointConfig ep1config = { |
| 327 | USB_EP_MODE_TYPE_BULK, |
345 | USB_EP_MODE_TYPE_BULK, |
| 328 | NULL, |
346 | NULL, |
| 329 | sduDataTransmitted, |
347 | sduDataTransmitted, |
| 330 | sduDataReceived, |
348 | sduDataReceived, |
| 331 | 0x0040, |
349 | USB_EP_BULK_DATASIZE, |
| 332 | 0x0040, |
350 | USB_EP_BULK_DATASIZE, |
| 333 | &ep1instate, |
351 | &ep1instate, |
| 334 | &ep1outstate, |
352 | &ep1outstate, |
| 335 | 2, |
353 | 2, |
| 336 | NULL |
354 | NULL |
| 337 | }; |
355 | }; |
| Line 347... | Line 365... | ||
| 347 | static const USBEndpointConfig ep2config = { |
365 | static const USBEndpointConfig ep2config = { |
| 348 | USB_EP_MODE_TYPE_INTR, |
366 | USB_EP_MODE_TYPE_INTR, |
| 349 | NULL, |
367 | NULL, |
| 350 | sduInterruptTransmitted, |
368 | sduInterruptTransmitted, |
| 351 | NULL, |
369 | NULL, |
| 352 | 0x0010, |
370 | USB_EP_INTR_DATASIZE, |
| 353 | 0x0000, |
371 | 0x0000, |
| 354 | &ep2instate, |
372 | &ep2instate, |
| 355 | NULL, |
373 | NULL, |
| 356 | 1, |
374 | 1, |
| 357 | NULL |
375 | NULL |
| 358 | }; |
376 | }; |
| 359 | 377 | ||
| 360 | 378 | ||
| 361 | #if DUAL_CDC_EP ==TRUE |
379 | #if HAL_USE_USB_DUAL_CDC==TRUE |
| 362 | /** |
380 | /** |
| 363 | * @brief IN EP3 state. |
381 | * @brief IN EP3 state. |
| 364 | */ |
382 | */ |
| 365 | static USBInEndpointState ep3instate; |
383 | static USBInEndpointState ep3instate; |
| 366 | 384 | ||
| Line 375... | Line 393... | ||
| 375 | static const USBEndpointConfig ep3config = { |
393 | static const USBEndpointConfig ep3config = { |
| 376 | USB_EP_MODE_TYPE_BULK, |
394 | USB_EP_MODE_TYPE_BULK, |
| 377 | NULL, |
395 | NULL, |
| 378 | sduDataTransmitted, |
396 | sduDataTransmitted, |
| 379 | sduDataReceived, |
397 | sduDataReceived, |
| 380 | 0x0040, |
398 | USB_EP_BULK_DATASIZE, |
| 381 | 0x0040, |
399 | USB_EP_BULK_DATASIZE, |
| 382 | &ep3instate, |
400 | &ep3instate, |
| 383 | &ep3outstate, |
401 | &ep3outstate, |
| 384 | 2, |
402 | 2, |
| 385 | NULL |
403 | NULL |
| 386 | }; |
404 | }; |
| Line 396... | Line 414... | ||
| 396 | static const USBEndpointConfig ep4config = { |
414 | static const USBEndpointConfig ep4config = { |
| 397 | USB_EP_MODE_TYPE_INTR, |
415 | USB_EP_MODE_TYPE_INTR, |
| 398 | NULL, |
416 | NULL, |
| 399 | sduInterruptTransmitted, |
417 | sduInterruptTransmitted, |
| 400 | NULL, |
418 | NULL, |
| 401 | 0x0010, |
419 | USB_EP_INTR_DATASIZE, |
| 402 | 0x0000, |
420 | 0x0000, |
| 403 | &ep4instate, |
421 | &ep4instate, |
| 404 | NULL, |
422 | NULL, |
| 405 | 1, |
423 | 1, |
| 406 | NULL |
424 | NULL |
| Line 423... | Line 441... | ||
| 423 | /* Enables the endpoints specified into the configuration. |
441 | /* Enables the endpoints specified into the configuration. |
| 424 | Note, this callback is invoked from an ISR so I-Class functions |
442 | Note, this callback is invoked from an ISR so I-Class functions |
| 425 | must be used.*/ |
443 | must be used.*/ |
| 426 | usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP, &ep1config); |
444 | usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP, &ep1config); |
| 427 | usbInitEndpointI(usbp, USBD1_INTERRUPT_REQUEST_EP, &ep2config); |
445 | usbInitEndpointI(usbp, USBD1_INTERRUPT_REQUEST_EP, &ep2config); |
| 428 | #if DUAL_CDC_EP == TRUE |
446 | #if HAL_USE_USB_DUAL_CDC == TRUE |
| 429 | usbInitEndpointI(usbp, USBD1_DATA2_REQUEST_EP, &ep3config); |
447 | usbInitEndpointI(usbp, USBD1_DATA2_REQUEST_EP, &ep3config); |
| 430 | usbInitEndpointI(usbp, USBD1_INTERRUPT2_REQUEST_EP, &ep4config); |
448 | usbInitEndpointI(usbp, USBD1_INTERRUPT2_REQUEST_EP, &ep4config); |
| 431 | #endif |
449 | #endif |
| 432 | /* Resetting the state of the CDC subsystem.*/ |
450 | /* Resetting the state of the CDC subsystem.*/ |
| 433 | sduConfigureHookI(&SDU1); |
451 | sduConfigureHookI(&SDU1); |