2 ******************************************************************************
3 * @file usbd_cdc_core.c
4 * @author MCD Application Team
7 * @brief This file provides the high layer firmware functions to manage the
8 * following functionalities of the USB CDC Class:
9 * - Initialization and Configuration of high and low layer
10 * - Enumeration as CDC Device (and enumeration for each implemented memory interface)
11 * - OUT/IN data transfer
12 * - Command IN transfer (class requests management)
17 * ===================================================================
18 * CDC Class Driver Description
19 * ===================================================================
20 * This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
21 * Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
22 * Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
23 * This driver implements the following aspects of the specification:
24 * - Device descriptor management
25 * - Configuration descriptor management
26 * - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
27 * - Requests management (as described in section 6.2 in specification)
28 * - Abstract Control Model compliant
29 * - Union Functional collection (using 1 IN endpoint for control)
30 * - Data interface class
33 * For the Abstract Control Model, this core allows only transmitting the requests to
34 * lower layer dispatcher (ie. usbd_cdc_vcp.c/.h) which should manage each request and
35 * perform relative actions.
37 * These aspects may be enriched or modified for a specific user application.
39 * This driver doesn't implement the following aspects of the specification
40 * (but it is possible to manage these features with some modifications on this driver):
41 * - Any class-specific aspect relative to communication classes should be managed by user application.
42 * - All communication classes other than PSTN are not managed
46 ******************************************************************************
49 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
50 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
51 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
52 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
53 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
54 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
56 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
57 ******************************************************************************
60 /* Includes ------------------------------------------------------------------*/
61 #include "usbd_cdc_core.h"
62 #include "usbd_desc.h"
66 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
71 /** @defgroup usbd_cdc
72 * @brief usbd core module
76 /** @defgroup usbd_cdc_Private_TypesDefinitions
84 /** @defgroup usbd_cdc_Private_Defines
92 /** @defgroup usbd_cdc_Private_Macros
100 /** @defgroup usbd_cdc_Private_FunctionPrototypes
104 /*********************************************
105 CDC Device library callbacks
106 *********************************************/
107 static uint8_t usbd_cdc_Init (void *pdev, uint8_t cfgidx);
108 static uint8_t usbd_cdc_DeInit (void *pdev, uint8_t cfgidx);
109 static uint8_t usbd_cdc_Setup (void *pdev, USB_SETUP_REQ *req);
110 static uint8_t usbd_cdc_EP0_RxReady (void *pdev);
111 static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum);
112 static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum);
113 static uint8_t usbd_cdc_SOF (void *pdev);
115 /*********************************************
116 CDC specific management functions
117 *********************************************/
118 static void Handle_USBAsynchXfer (void *pdev);
119 static uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length);
120 #ifdef USE_USB_OTG_HS
121 static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length);
127 /** @defgroup usbd_cdc_Private_Variables
130 extern CDC_IF_Prop_TypeDef APP_FOPS;
131 extern uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC];
133 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
134 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
135 #pragma data_alignment=4
137 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
138 __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ;
140 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
141 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
142 #pragma data_alignment=4
144 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
145 __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ;
147 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
148 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
149 #pragma data_alignment=4
151 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
152 __ALIGN_BEGIN static __IO uint32_t usbd_cdc_AltSet __ALIGN_END = 0;
154 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
155 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
156 #pragma data_alignment=4
158 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
159 __ALIGN_BEGIN uint8_t USB_Rx_Buffer [CDC_DATA_MAX_PACKET_SIZE] __ALIGN_END ;
161 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
162 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
163 #pragma data_alignment=4
165 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
166 __ALIGN_BEGIN uint8_t APP_Rx_Buffer [APP_RX_DATA_SIZE] __ALIGN_END ;
169 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
170 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
171 #pragma data_alignment=4
173 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
174 __ALIGN_BEGIN uint8_t CmdBuff[CDC_CMD_PACKET_SZE] __ALIGN_END ;
176 uint32_t APP_Rx_ptr_in = 0;
177 uint32_t APP_Rx_ptr_out = 0;
178 uint32_t APP_Rx_length = 0;
180 uint8_t USB_Tx_State = 0;
182 static uint32_t cdcCmd = 0xFF;
183 static uint32_t cdcLen = 0;
185 /* CDC interface class callbacks structure */
186 USBD_Class_cb_TypeDef USBD_CDC_cb =
191 NULL, /* EP0_TxSent, */
192 usbd_cdc_EP0_RxReady,
199 #ifdef USE_USB_OTG_HS
200 USBD_cdc_GetOtherCfgDesc, /* use same cobfig as per FS */
201 #endif /* USE_USB_OTG_HS */
204 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
205 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
206 #pragma data_alignment=4
208 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
209 /* USB CDC device Configuration Descriptor */
210 __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
212 /*Configuration Descriptor*/
213 0x09, /* bLength: Configuration Descriptor size */
214 USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
215 USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
217 0x02, /* bNumInterfaces: 2 interface */
218 0x01, /* bConfigurationValue: Configuration value */
219 0x00, /* iConfiguration: Index of string descriptor describing the configuration */
220 0xC0, /* bmAttributes: self powered */
221 0x32, /* MaxPower 0 mA */
223 /*---------------------------------------------------------------------------*/
225 /*Interface Descriptor */
226 0x09, /* bLength: Interface Descriptor size */
227 USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
228 /* Interface descriptor type */
229 0x00, /* bInterfaceNumber: Number of Interface */
230 0x00, /* bAlternateSetting: Alternate setting */
231 0x01, /* bNumEndpoints: One endpoints used */
232 0x02, /* bInterfaceClass: Communication Interface Class */
233 0x02, /* bInterfaceSubClass: Abstract Control Model */
234 0x01, /* bInterfaceProtocol: Common AT commands */
235 0x00, /* iInterface: */
237 /*Header Functional Descriptor*/
238 0x05, /* bLength: Endpoint Descriptor size */
239 0x24, /* bDescriptorType: CS_INTERFACE */
240 0x00, /* bDescriptorSubtype: Header Func Desc */
241 0x10, /* bcdCDC: spec release number */
244 /*Call Management Functional Descriptor*/
245 0x05, /* bFunctionLength */
246 0x24, /* bDescriptorType: CS_INTERFACE */
247 0x01, /* bDescriptorSubtype: Call Management Func Desc */
248 0x00, /* bmCapabilities: D0+D1 */
249 0x01, /* bDataInterface: 1 */
251 /*ACM Functional Descriptor*/
252 0x04, /* bFunctionLength */
253 0x24, /* bDescriptorType: CS_INTERFACE */
254 0x02, /* bDescriptorSubtype: Abstract Control Management desc */
255 0x02, /* bmCapabilities */
257 /*Union Functional Descriptor*/
258 0x05, /* bFunctionLength */
259 0x24, /* bDescriptorType: CS_INTERFACE */
260 0x06, /* bDescriptorSubtype: Union func desc */
261 0x00, /* bMasterInterface: Communication class interface */
262 0x01, /* bSlaveInterface0: Data Class Interface */
264 /*Endpoint 2 Descriptor*/
265 0x07, /* bLength: Endpoint Descriptor size */
266 USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
267 CDC_CMD_EP, /* bEndpointAddress */
268 0x03, /* bmAttributes: Interrupt */
269 LOBYTE(CDC_CMD_PACKET_SZE), /* wMaxPacketSize: */
270 HIBYTE(CDC_CMD_PACKET_SZE),
271 #ifdef USE_USB_OTG_HS
272 0x10, /* bInterval: */
274 0xFF, /* bInterval: */
275 #endif /* USE_USB_OTG_HS */
277 /*---------------------------------------------------------------------------*/
279 /*Data class interface descriptor*/
280 0x09, /* bLength: Endpoint Descriptor size */
281 USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
282 0x01, /* bInterfaceNumber: Number of Interface */
283 0x00, /* bAlternateSetting: Alternate setting */
284 0x02, /* bNumEndpoints: Two endpoints used */
285 0x0A, /* bInterfaceClass: CDC */
286 0x00, /* bInterfaceSubClass: */
287 0x00, /* bInterfaceProtocol: */
288 0x00, /* iInterface: */
290 /*Endpoint OUT Descriptor*/
291 0x07, /* bLength: Endpoint Descriptor size */
292 USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
293 CDC_OUT_EP, /* bEndpointAddress */
294 0x02, /* bmAttributes: Bulk */
295 LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */
296 HIBYTE(CDC_DATA_MAX_PACKET_SIZE),
297 0x00, /* bInterval: ignore for Bulk transfer */
299 /*Endpoint IN Descriptor*/
300 0x07, /* bLength: Endpoint Descriptor size */
301 USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
302 CDC_IN_EP, /* bEndpointAddress */
303 0x02, /* bmAttributes: Bulk */
304 LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */
305 HIBYTE(CDC_DATA_MAX_PACKET_SIZE),
306 0x00 /* bInterval: ignore for Bulk transfer */
309 #ifdef USE_USB_OTG_HS
310 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
311 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
312 #pragma data_alignment=4
314 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
315 __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
317 0x09, /* bLength: Configuation Descriptor size */
318 USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
319 USB_CDC_CONFIG_DESC_SIZ,
321 0x02, /* bNumInterfaces: 2 interfaces */
322 0x01, /* bConfigurationValue: */
323 0x04, /* iConfiguration: */
324 0xC0, /* bmAttributes: */
325 0x32, /* MaxPower 100 mA */
327 /*Interface Descriptor */
328 0x09, /* bLength: Interface Descriptor size */
329 USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
330 /* Interface descriptor type */
331 0x00, /* bInterfaceNumber: Number of Interface */
332 0x00, /* bAlternateSetting: Alternate setting */
333 0x01, /* bNumEndpoints: One endpoints used */
334 0x02, /* bInterfaceClass: Communication Interface Class */
335 0x02, /* bInterfaceSubClass: Abstract Control Model */
336 0x01, /* bInterfaceProtocol: Common AT commands */
337 0x00, /* iInterface: */
339 /*Header Functional Descriptor*/
340 0x05, /* bLength: Endpoint Descriptor size */
341 0x24, /* bDescriptorType: CS_INTERFACE */
342 0x00, /* bDescriptorSubtype: Header Func Desc */
343 0x10, /* bcdCDC: spec release number */
346 /*Call Management Functional Descriptor*/
347 0x05, /* bFunctionLength */
348 0x24, /* bDescriptorType: CS_INTERFACE */
349 0x01, /* bDescriptorSubtype: Call Management Func Desc */
350 0x00, /* bmCapabilities: D0+D1 */
351 0x01, /* bDataInterface: 1 */
353 /*ACM Functional Descriptor*/
354 0x04, /* bFunctionLength */
355 0x24, /* bDescriptorType: CS_INTERFACE */
356 0x02, /* bDescriptorSubtype: Abstract Control Management desc */
357 0x02, /* bmCapabilities */
359 /*Union Functional Descriptor*/
360 0x05, /* bFunctionLength */
361 0x24, /* bDescriptorType: CS_INTERFACE */
362 0x06, /* bDescriptorSubtype: Union func desc */
363 0x00, /* bMasterInterface: Communication class interface */
364 0x01, /* bSlaveInterface0: Data Class Interface */
366 /*Endpoint 2 Descriptor*/
367 0x07, /* bLength: Endpoint Descriptor size */
368 USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
369 CDC_CMD_EP, /* bEndpointAddress */
370 0x03, /* bmAttributes: Interrupt */
371 LOBYTE(CDC_CMD_PACKET_SZE), /* wMaxPacketSize: */
372 HIBYTE(CDC_CMD_PACKET_SZE),
373 0xFF, /* bInterval: */
375 /*---------------------------------------------------------------------------*/
377 /*Data class interface descriptor*/
378 0x09, /* bLength: Endpoint Descriptor size */
379 USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
380 0x01, /* bInterfaceNumber: Number of Interface */
381 0x00, /* bAlternateSetting: Alternate setting */
382 0x02, /* bNumEndpoints: Two endpoints used */
383 0x0A, /* bInterfaceClass: CDC */
384 0x00, /* bInterfaceSubClass: */
385 0x00, /* bInterfaceProtocol: */
386 0x00, /* iInterface: */
388 /*Endpoint OUT Descriptor*/
389 0x07, /* bLength: Endpoint Descriptor size */
390 USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
391 CDC_OUT_EP, /* bEndpointAddress */
392 0x02, /* bmAttributes: Bulk */
393 0x40, /* wMaxPacketSize: */
395 0x00, /* bInterval: ignore for Bulk transfer */
397 /*Endpoint IN Descriptor*/
398 0x07, /* bLength: Endpoint Descriptor size */
399 USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
400 CDC_IN_EP, /* bEndpointAddress */
401 0x02, /* bmAttributes: Bulk */
402 0x40, /* wMaxPacketSize: */
406 #endif /* USE_USB_OTG_HS */
412 /** @defgroup usbd_cdc_Private_Functions
417 * @brief usbd_cdc_Init
418 * Initilaize the CDC interface
419 * @param pdev: device instance
420 * @param cfgidx: Configuration index
423 static uint8_t usbd_cdc_Init (void *pdev,
431 CDC_DATA_IN_PACKET_SIZE,
437 CDC_DATA_OUT_PACKET_SIZE,
440 /* Open Command IN EP */
446 pbuf = (uint8_t *)USBD_DeviceDesc;
447 pbuf[4] = DEVICE_CLASS_CDC;
448 pbuf[5] = DEVICE_SUBCLASS_CDC;
450 /* Initialize the Interface physical components */
453 /* Prepare Out endpoint to receive next packet */
454 DCD_EP_PrepareRx(pdev,
456 (uint8_t*)(USB_Rx_Buffer),
457 CDC_DATA_OUT_PACKET_SIZE);
463 * @brief usbd_cdc_Init
464 * DeInitialize the CDC layer
465 * @param pdev: device instance
466 * @param cfgidx: Configuration index
469 static uint8_t usbd_cdc_DeInit (void *pdev,
480 /* Open Command IN EP */
484 /* Restore default state of the Interface physical components */
485 APP_FOPS.pIf_DeInit();
491 * @brief usbd_cdc_Setup
492 * Handle the CDC specific requests
493 * @param pdev: instance
494 * @param req: usb requests
497 static uint8_t usbd_cdc_Setup (void *pdev,
503 switch (req->bmRequest & USB_REQ_TYPE_MASK)
505 /* CDC Class Requests -------------------------------*/
506 case USB_REQ_TYPE_CLASS :
507 /* Check if the request is a data setup packet */
510 /* Check if the request is Device-to-Host */
511 if (req->bmRequest & 0x80)
513 /* Get the data to be sent to Host from interface layer */
514 APP_FOPS.pIf_Ctrl(req->bRequest, CmdBuff, req->wLength);
516 /* Send the data to the host */
517 USBD_CtlSendData (pdev,
521 else /* Host-to-Device requeset */
523 /* Set the value of the current command to be processed */
524 cdcCmd = req->bRequest;
525 cdcLen = req->wLength;
527 /* Prepare the reception of the buffer over EP0
528 Next step: the received data will be managed in usbd_cdc_EP0_TxSent()
530 USBD_CtlPrepareRx (pdev,
535 else /* No Data request */
537 /* Transfer the command to the interface layer */
538 APP_FOPS.pIf_Ctrl(req->bRequest, NULL, 0);
544 USBD_CtlError (pdev, req);
549 /* Standard Requests -------------------------------*/
550 case USB_REQ_TYPE_STANDARD:
551 switch (req->bRequest)
553 case USB_REQ_GET_DESCRIPTOR:
554 if( (req->wValue >> 8) == CDC_DESCRIPTOR_TYPE)
556 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
557 pbuf = usbd_cdc_Desc;
559 pbuf = usbd_cdc_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM);
561 len = MIN(USB_CDC_DESC_SIZ , req->wLength);
564 USBD_CtlSendData (pdev,
569 case USB_REQ_GET_INTERFACE :
570 USBD_CtlSendData (pdev,
571 (uint8_t *)&usbd_cdc_AltSet,
575 case USB_REQ_SET_INTERFACE :
576 if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM)
578 usbd_cdc_AltSet = (uint8_t)(req->wValue);
582 /* Call the error management function (command will be nacked */
583 USBD_CtlError (pdev, req);
592 * @brief usbd_cdc_EP0_RxReady
593 * Data received on control endpoint
594 * @param pdev: device device instance
597 static uint8_t usbd_cdc_EP0_RxReady (void *pdev)
599 if (cdcCmd != NO_CMD)
601 /* Process the data */
602 APP_FOPS.pIf_Ctrl(cdcCmd, CmdBuff, cdcLen);
604 /* Reset the command variable to default value */
612 * @brief usbd_audio_DataIn
613 * Data sent on non-control IN endpoint
614 * @param pdev: device instance
615 * @param epnum: endpoint number
618 static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum)
621 uint16_t USB_Tx_length;
623 if (USB_Tx_State == 1)
625 if (APP_Rx_length == 0)
631 if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE){
632 USB_Tx_ptr = APP_Rx_ptr_out;
633 USB_Tx_length = CDC_DATA_IN_PACKET_SIZE;
635 APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE;
636 APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE;
640 USB_Tx_ptr = APP_Rx_ptr_out;
641 USB_Tx_length = APP_Rx_length;
643 APP_Rx_ptr_out += APP_Rx_length;
647 /* Prepare the available data buffer to be sent on IN endpoint */
650 (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr],
659 * @brief usbd_audio_DataOut
660 * Data received on non-control Out endpoint
661 * @param pdev: device instance
662 * @param epnum: endpoint number
665 static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum)
669 /* Get the received data buffer and update the counter */
670 USB_Rx_Cnt = ((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].xfer_count;
672 /* USB data will be immediately processed, this allow next USB traffic being
673 NAKed till the end of the application Xfer */
674 APP_FOPS.pIf_DataRx(USB_Rx_Buffer, USB_Rx_Cnt);
676 /* Prepare Out endpoint to receive next packet */
677 DCD_EP_PrepareRx(pdev,
679 (uint8_t*)(USB_Rx_Buffer),
680 CDC_DATA_OUT_PACKET_SIZE);
686 * @brief usbd_audio_SOF
687 * Start Of Frame event management
688 * @param pdev: instance
689 * @param epnum: endpoint number
692 static uint8_t usbd_cdc_SOF (void *pdev)
694 static uint32_t FrameCount = 0;
696 if (FrameCount++ == CDC_IN_FRAME_INTERVAL)
698 /* Reset the frame counter */
701 /* Check the data to be sent through IN pipe */
702 Handle_USBAsynchXfer(pdev);
709 * @brief Handle_USBAsynchXfer
711 * @param pdev: instance
714 static void Handle_USBAsynchXfer (void *pdev)
717 uint16_t USB_Tx_length;
719 if(USB_Tx_State != 1)
721 if (APP_Rx_ptr_out == APP_RX_DATA_SIZE)
726 if(APP_Rx_ptr_out == APP_Rx_ptr_in)
732 if(APP_Rx_ptr_out > APP_Rx_ptr_in) /* rollback */
734 APP_Rx_length = APP_RX_DATA_SIZE - APP_Rx_ptr_out;
739 APP_Rx_length = APP_Rx_ptr_in - APP_Rx_ptr_out;
742 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
743 APP_Rx_length &= ~0x03;
744 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
746 if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE)
748 USB_Tx_ptr = APP_Rx_ptr_out;
749 USB_Tx_length = CDC_DATA_IN_PACKET_SIZE;
751 APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE;
752 APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE;
756 USB_Tx_ptr = APP_Rx_ptr_out;
757 USB_Tx_length = APP_Rx_length;
759 APP_Rx_ptr_out += APP_Rx_length;
766 (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr],
773 * @brief USBD_cdc_GetCfgDesc
774 * Return configuration descriptor
775 * @param speed : current device speed
776 * @param length : pointer data length
777 * @retval pointer to descriptor buffer
779 static uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length)
781 *length = sizeof (usbd_cdc_CfgDesc);
782 return usbd_cdc_CfgDesc;
786 * @brief USBD_cdc_GetCfgDesc
787 * Return configuration descriptor
788 * @param speed : current device speed
789 * @param length : pointer data length
790 * @retval pointer to descriptor buffer
792 #ifdef USE_USB_OTG_HS
793 static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length)
795 *length = sizeof (usbd_cdc_OtherCfgDesc);
796 return usbd_cdc_OtherCfgDesc;
811 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/