Rev 7 | Rev 19 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7 | Rev 18 | ||
---|---|---|---|
Line 14... | Line 14... | ||
14 | limitations under the License. |
14 | limitations under the License. |
15 | */ |
15 | */ |
16 | 16 | ||
17 | #include "hal.h" |
17 | #include "hal.h" |
18 | 18 | ||
- | 19 | ||
- | 20 | ||
19 | /* Virtual serial port over USB.*/ |
21 | /* Virtual serial port over USB.*/ |
20 | SerialUSBDriver SDU1; |
22 | SerialUSBDriver SDU1; |
21 | 23 | ||
- | 24 | #if HAL_USE_SERIAL_USB == TRUE |
|
- | 25 | SerialUSBDriver SDU2; |
|
- | 26 | #endif |
|
- | 27 | ||
- | 28 | ||
22 | /* |
29 | /* |
23 | * Endpoints to be used for USBD1. |
30 | * Endpoints to be used for USBD1/SDU1. |
24 | */ |
31 | */ |
25 | #define USBD1_DATA_REQUEST_EP 1 |
32 | #define USBD1_DATA_REQUEST_EP 1 |
26 | #define USBD1_DATA_AVAILABLE_EP 1 |
33 | #define USBD1_DATA_AVAILABLE_EP 1 |
27 | #define USBD1_INTERRUPT_REQUEST_EP 2 |
34 | #define USBD1_INTERRUPT_REQUEST_EP 2 |
28 | 35 | ||
29 | /* |
36 | /* |
- | 37 | * Endpoints to be used for USBD1/SDU2 |
|
- | 38 | */ |
|
- | 39 | #if HAL_USE_USB_DUAL_CDC == TRUE |
|
- | 40 | #define USBD1_DATA2_REQUEST_EP 3 |
|
- | 41 | #define USBD1_DATA2_AVAILABLE_EP 3 |
|
- | 42 | #define USBD1_INTERRUPT2_REQUEST_EP 4 |
|
- | 43 | #endif |
|
- | 44 | /* |
|
30 | * USB Device Descriptor. |
45 | * USB Device Descriptor. |
31 | */ |
46 | */ |
32 | static const uint8_t vcom_device_descriptor_data[18] = { |
47 | static const uint8_t vcom_device_descriptor_data[18] = { |
33 | USB_DESC_DEVICE (0x0110, /* bcdUSB (1.1). */ |
48 | USB_DESC_DEVICE (0x0110, /* bcdUSB (1.1). */ |
34 | 0x02, /* bDeviceClass (CDC). */ |
49 | 0x02, /* bDeviceClass (CDC). */ |
Line 38... | Line 53... | ||
38 | 0x0483, /* idVendor (ST). */ |
53 | 0x0483, /* idVendor (ST). */ |
39 | 0x5740, /* idProduct. */ |
54 | 0x5740, /* idProduct. */ |
40 | 0x0200, /* bcdDevice. */ |
55 | 0x0200, /* bcdDevice. */ |
41 | 1, /* iManufacturer. */ |
56 | 1, /* iManufacturer. */ |
42 | 2, /* iProduct. */ |
57 | 2, /* iProduct. */ |
43 | 3, /* iSerialNumber. */ |
58 | 3, /* iSerialNumber. */ |
44 | 1) /* bNumConfigurations. */ |
59 | 1) /* bNumConfigurations. */ |
45 | }; |
60 | }; |
46 | 61 | ||
47 | /* |
62 | /* |
48 | * Device Descriptor wrapper. |
63 | * Device Descriptor wrapper. |
Line 50... | Line 65... | ||
50 | static const USBDescriptor vcom_device_descriptor = { |
65 | static const USBDescriptor vcom_device_descriptor = { |
51 | sizeof vcom_device_descriptor_data, |
66 | sizeof vcom_device_descriptor_data, |
52 | vcom_device_descriptor_data |
67 | vcom_device_descriptor_data |
53 | }; |
68 | }; |
54 | 69 | ||
- | 70 | ||
55 | /* Configuration Descriptor tree for a CDC.*/ |
71 | /* Configuration Descriptor tree for a CDC.*/ |
- | 72 | ||
56 | static const uint8_t vcom_configuration_descriptor_data[67] = { |
73 | static const uint8_t vcom_configuration_descriptor_data[] = { |
57 | /* Configuration Descriptor.*/ |
74 | /* Configuration Descriptor.*/ |
- | 75 | #if HAL_USE_USB_DUAL_CDC == FALSE |
|
- | 76 | /* the header is 9 bytes long, total has 2 EPs in use = 67 bytes */ |
|
58 | USB_DESC_CONFIGURATION(67, /* wTotalLength. */ |
77 | USB_DESC_CONFIGURATION(67, /* wTotalLength. */ |
59 | 0x02, /* bNumInterfaces. */ |
78 | 0x02, /* bNumInterfaces. */ |
60 | 0x01, /* bConfigurationValue. */ |
79 | 0x01, /* bConfigurationValue. */ |
61 | 0, /* iConfiguration. */ |
80 | 0, /* iConfiguration. */ |
62 | 0xC0, /* bmAttributes (self powered). */ |
81 | 0xC0, /* bmAttributes (self powered). */ |
63 | 50), /* bMaxPower (100mA). */ |
82 | 50), /* bMaxPower (100mA). */ |
- | 83 | #else |
|
- | 84 | /* the header is 9 bytes long, total has 4 EP in use = 67 * 2 -9 bytes */ |
|
- | 85 | USB_DESC_CONFIGURATION(125, /* wTotalLength. */ |
|
- | 86 | 0x04, /* bNumInterfaces. */ |
|
- | 87 | 0x01, /* bConfigurationValue. */ |
|
- | 88 | 0, /* iConfiguration. */ |
|
- | 89 | 0xC0, /* bmAttributes (self powered). */ |
|
- | 90 | 50), /* bMaxPower (100mA). */ |
|
- | 91 | #endif |
|
64 | /* Interface Descriptor.*/ |
92 | /* Interface Descriptor.*/ |
65 | USB_DESC_INTERFACE (0x00, /* bInterfaceNumber. */ |
93 | USB_DESC_INTERFACE (0x00, /* bInterfaceNumber. */ |
66 | 0x00, /* bAlternateSetting. */ |
94 | 0x00, /* bAlternateSetting. */ |
67 | 0x01, /* bNumEndpoints. */ |
95 | 0x01, /* bNumEndpoints. */ |
68 | 0x02, /* bInterfaceClass (Communications |
96 | 0x02, /* bInterfaceClass (Communications |
69 | Interface Class, CDC section |
97 | Interface Class, CDC section |
Line 71... | Line 99... | ||
71 | 0x02, /* bInterfaceSubClass (Abstract |
99 | 0x02, /* bInterfaceSubClass (Abstract |
72 | Control Model, CDC section 4.3). */ |
100 | Control Model, CDC section 4.3). */ |
73 | 0x01, /* bInterfaceProtocol (AT commands, |
101 | 0x01, /* bInterfaceProtocol (AT commands, |
74 | CDC section 4.4). */ |
102 | CDC section 4.4). */ |
75 | 0), /* iInterface. */ |
103 | 0), /* iInterface. */ |
- | 104 | ||
76 | /* Header Functional Descriptor (CDC section 5.2.3).*/ |
105 | /* Header Functional Descriptor (CDC section 5.2.3).*/ |
77 | USB_DESC_BYTE (5), /* bLength. */ |
106 | USB_DESC_BYTE (5), /* bLength. */ |
78 | USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */ |
107 | USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */ |
79 | USB_DESC_BYTE (0x00), /* bDescriptorSubtype (Header |
108 | USB_DESC_BYTE (0x00), /* bDescriptorSubtype (Header |
80 | Functional Descriptor. */ |
109 | Functional Descriptor. */ |
81 | USB_DESC_BCD (0x0110), /* bcdCDC. */ |
110 | USB_DESC_BCD (0x0110), /* bcdCDC. */ |
Line 124... | Line 153... | ||
124 | 0x00), /* bInterval. */ |
153 | 0x00), /* bInterval. */ |
125 | /* Endpoint 1 Descriptor.*/ |
154 | /* Endpoint 1 Descriptor.*/ |
126 | USB_DESC_ENDPOINT (USBD1_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/ |
155 | USB_DESC_ENDPOINT (USBD1_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/ |
127 | 0x02, /* bmAttributes (Bulk). */ |
156 | 0x02, /* bmAttributes (Bulk). */ |
128 | 0x0040, /* wMaxPacketSize. */ |
157 | 0x0040, /* wMaxPacketSize. */ |
129 | 0x00) /* bInterval. */ |
158 | 0x00), /* bInterval. */ |
- | 159 | #if HAL_USE_USB_DUAL_CDC ==TRUE |
|
- | 160 | /* Configuration Descriptor tree for a CDC.*/ |
|
- | 161 | USB_DESC_INTERFACE (0x02, /* bInterfaceNumber. */ |
|
- | 162 | 0x00, /* bAlternateSetting. */ |
|
- | 163 | 0x01, /* bNumEndpoints. */ |
|
- | 164 | 0x02, /* bInterfaceClass (Communications |
|
- | 165 | Interface Class, CDC section |
|
- | 166 | 4.2). */ |
|
- | 167 | 0x02, /* bInterfaceSubClass (Abstract |
|
- | 168 | Control Model, CDC section 4.3). */ |
|
- | 169 | 0x01, /* bInterfaceProtocol (AT commands, |
|
- | 170 | CDC section 4.4). */ |
|
- | 171 | 0), /* iInterface. */ |
|
- | 172 | ||
- | 173 | /* Header Functional Descriptor (CDC section 5.2.3).*/ |
|
- | 174 | USB_DESC_BYTE (5), /* bLength. */ |
|
- | 175 | USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */ |
|
- | 176 | USB_DESC_BYTE (0x00), /* bDescriptorSubtype (Header |
|
- | 177 | Functional Descriptor. */ |
|
- | 178 | USB_DESC_BCD (0x0110), /* bcdCDC. */ |
|
- | 179 | /* Call Management Functional Descriptor. */ |
|
- | 180 | USB_DESC_BYTE (5), /* bFunctionLength. */ |
|
- | 181 | USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */ |
|
- | 182 | USB_DESC_BYTE (0x01), /* bDescriptorSubtype (Call Management |
|
- | 183 | Functional Descriptor). */ |
|
- | 184 | USB_DESC_BYTE (0x00), /* bmCapabilities (D0+D1). */ |
|
- | 185 | USB_DESC_BYTE (0x01), /* bDataInterface. */ |
|
- | 186 | /* ACM Functional Descriptor.*/ |
|
- | 187 | USB_DESC_BYTE (4), /* bFunctionLength. */ |
|
- | 188 | USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */ |
|
- | 189 | USB_DESC_BYTE (0x02), /* bDescriptorSubtype (Abstract |
|
- | 190 | Control Management Descriptor). */ |
|
- | 191 | USB_DESC_BYTE (0x02), /* bmCapabilities. */ |
|
- | 192 | /* Union Functional Descriptor.*/ |
|
- | 193 | USB_DESC_BYTE (5), /* bFunctionLength. */ |
|
- | 194 | USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */ |
|
- | 195 | USB_DESC_BYTE (0x06), /* bDescriptorSubtype (Union |
|
- | 196 | Functional Descriptor). */ |
|
- | 197 | USB_DESC_BYTE (0x00), /* bMasterInterface (Communication |
|
- | 198 | Class Interface). */ |
|
- | 199 | USB_DESC_BYTE (0x01), /* bSlaveInterface0 (Data Class |
|
- | 200 | Interface). */ |
|
- | 201 | /* Endpoint 2 Descriptor.*/ |
|
- | 202 | USB_DESC_ENDPOINT (USBD1_INTERRUPT2_REQUEST_EP|0x80, |
|
- | 203 | 0x03, /* bmAttributes (Interrupt). */ |
|
- | 204 | 0x0008, /* wMaxPacketSize. */ |
|
- | 205 | 0xFF), /* bInterval. */ |
|
- | 206 | /* Interface Descriptor.*/ |
|
- | 207 | USB_DESC_INTERFACE (0x03, /* bInterfaceNumber. */ |
|
- | 208 | 0x00, /* bAlternateSetting. */ |
|
- | 209 | 0x02, /* bNumEndpoints. */ |
|
- | 210 | 0x0A, /* bInterfaceClass (Data Class |
|
- | 211 | Interface, CDC section 4.5). */ |
|
- | 212 | 0x00, /* bInterfaceSubClass (CDC section |
|
- | 213 | 4.6). */ |
|
- | 214 | 0x00, /* bInterfaceProtocol (CDC section |
|
- | 215 | 4.7). */ |
|
- | 216 | 0x00), /* iInterface. */ |
|
- | 217 | /* Endpoint 3 Descriptor.*/ |
|
- | 218 | USB_DESC_ENDPOINT (USBD1_DATA2_AVAILABLE_EP, /* bEndpointAddress.*/ |
|
- | 219 | 0x02, /* bmAttributes (Bulk). */ |
|
- | 220 | 0x0040, /* wMaxPacketSize. */ |
|
- | 221 | 0x00), /* bInterval. */ |
|
- | 222 | /* Endpoint 1 Descriptor.*/ |
|
- | 223 | USB_DESC_ENDPOINT (USBD1_DATA2_REQUEST_EP|0x80, /* bEndpointAddress.*/ |
|
- | 224 | 0x02, /* bmAttributes (Bulk). */ |
|
- | 225 | 0x0040, /* wMaxPacketSize. */ |
|
- | 226 | 0x00) /* bInterval. */ |
|
- | 227 | #endif |
|
130 | }; |
228 | }; |
131 | - | ||
132 | /* |
229 | /* |
133 | * Configuration Descriptor wrapper. |
230 | * Configuration Descriptor wrapper. |
134 | */ |
231 | */ |
135 | static const USBDescriptor vcom_configuration_descriptor = { |
232 | static const USBDescriptor vcom_configuration_descriptor = { |
136 | sizeof vcom_configuration_descriptor_data, |
233 | sizeof vcom_configuration_descriptor_data, |
Line 258... | Line 355... | ||
258 | NULL, |
355 | NULL, |
259 | 1, |
356 | 1, |
260 | NULL |
357 | NULL |
261 | }; |
358 | }; |
262 | 359 | ||
- | 360 | ||
- | 361 | #if DUAL_CDC_EP ==TRUE |
|
- | 362 | /** |
|
- | 363 | * @brief IN EP3 state. |
|
- | 364 | */ |
|
- | 365 | static USBInEndpointState ep3instate; |
|
- | 366 | ||
- | 367 | /** |
|
- | 368 | * @brief OUT EP3 state. |
|
- | 369 | */ |
|
- | 370 | static USBOutEndpointState ep3outstate; |
|
- | 371 | ||
- | 372 | /** |
|
- | 373 | * @brief EP3 initialization structure (both IN and OUT). |
|
- | 374 | */ |
|
- | 375 | static const USBEndpointConfig ep3config = { |
|
- | 376 | USB_EP_MODE_TYPE_BULK, |
|
- | 377 | NULL, |
|
- | 378 | sduDataTransmitted, |
|
- | 379 | sduDataReceived, |
|
- | 380 | 0x0040, |
|
- | 381 | 0x0040, |
|
- | 382 | &ep3instate, |
|
- | 383 | &ep3outstate, |
|
- | 384 | 2, |
|
- | 385 | NULL |
|
- | 386 | }; |
|
- | 387 | ||
- | 388 | /** |
|
- | 389 | * @brief IN EP4 state. |
|
- | 390 | */ |
|
- | 391 | static USBInEndpointState ep4instate; |
|
- | 392 | ||
- | 393 | /** |
|
- | 394 | * @brief EP4 initialization structure (IN only). |
|
- | 395 | */ |
|
- | 396 | static const USBEndpointConfig ep4config = { |
|
- | 397 | USB_EP_MODE_TYPE_INTR, |
|
- | 398 | NULL, |
|
- | 399 | sduInterruptTransmitted, |
|
- | 400 | NULL, |
|
- | 401 | 0x0010, |
|
- | 402 | 0x0000, |
|
- | 403 | &ep4instate, |
|
- | 404 | NULL, |
|
- | 405 | 1, |
|
- | 406 | NULL |
|
- | 407 | }; |
|
- | 408 | ||
- | 409 | ||
- | 410 | #endif |
|
263 | /* |
411 | /* |
264 | * Handles the USB driver global events. |
412 | * Handles the USB driver global events. |
265 | */ |
413 | */ |
266 | static void usb_event(USBDriver *usbp, usbevent_t event) { |
414 | static void usb_event(USBDriver *usbp, usbevent_t event) { |
267 | extern SerialUSBDriver SDU1; |
415 | extern SerialUSBDriver SDU1; |
Line 275... | Line 423... | ||
275 | /* Enables the endpoints specified into the configuration. |
423 | /* Enables the endpoints specified into the configuration. |
276 | Note, this callback is invoked from an ISR so I-Class functions |
424 | Note, this callback is invoked from an ISR so I-Class functions |
277 | must be used.*/ |
425 | must be used.*/ |
278 | usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP, &ep1config); |
426 | usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP, &ep1config); |
279 | usbInitEndpointI(usbp, USBD1_INTERRUPT_REQUEST_EP, &ep2config); |
427 | usbInitEndpointI(usbp, USBD1_INTERRUPT_REQUEST_EP, &ep2config); |
- | 428 | #if DUAL_CDC_EP == TRUE |
|
- | 429 | usbInitEndpointI(usbp, USBD1_DATA2_REQUEST_EP, &ep3config); |
|
- | 430 | usbInitEndpointI(usbp, USBD1_INTERRUPT2_REQUEST_EP, &ep4config); |
|
280 | 431 | #endif |
|
281 | /* Resetting the state of the CDC subsystem.*/ |
432 | /* Resetting the state of the CDC subsystem.*/ |
282 | sduConfigureHookI(&SDU1); |
433 | sduConfigureHookI(&SDU1); |
283 | 434 | ||
284 | chSysUnlockFromISR(); |
435 | chSysUnlockFromISR(); |
285 | return; |
436 | return; |
Line 338... | Line 489... | ||
338 | &USBD1, |
489 | &USBD1, |
339 | USBD1_DATA_REQUEST_EP, |
490 | USBD1_DATA_REQUEST_EP, |
340 | USBD1_DATA_AVAILABLE_EP, |
491 | USBD1_DATA_AVAILABLE_EP, |
341 | USBD1_INTERRUPT_REQUEST_EP |
492 | USBD1_INTERRUPT_REQUEST_EP |
342 | }; |
493 | }; |
- | 494 | ||
- | 495 | #if HAL_USE_USB_DUAL_CDC == TRUE |
|
- | 496 | const SerialUSBConfig serusbcfg2 = { |
|
- | 497 | &USBD1, |
|
- | 498 | USBD1_DATA2_REQUEST_EP, |
|
- | 499 | USBD1_DATA2_AVAILABLE_EP, |
|
- | 500 | USBD1_INTERRUPT2_REQUEST_EP |
|
- | 501 | }; |
|
- | 502 | #endif |