APM:Libraries
usbd_cdc_core.c
Go to the documentation of this file.
1 
66 /* Includes ------------------------------------------------------------------*/
67 #include "usbd_cdc_core.h"
68 #include "usbd_desc.h"
69 #include "usbd_req.h"
70 #include "ring_buff.h"
71 #include "min_max.h"
72 
111 /*********************************************
112  CDC Device library callbacks
113  *********************************************/
114 static uint8_t usbd_cdc_Init (void *pdev, uint8_t cfgidx);
115 static uint8_t usbd_cdc_DeInit (void *pdev, uint8_t cfgidx);
116 static uint8_t usbd_cdc_Setup (void *pdev, USB_SETUP_REQ *req);
117 static uint8_t usbd_cdc_EP0_RxReady (void *pdev);
118 static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum);
119 static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum);
120 static uint8_t usbd_cdc_SOF (void *pdev);
121 
122 /*********************************************
123  CDC specific management functions
124  *********************************************/
125 static uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length);
126 #ifdef USE_USB_OTG_HS
127 static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length);
128 #endif
129 
137 extern const uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC];
138 
139 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
140  #if defined ( __ICCARM__ )
141  #pragma data_alignment=4
142  #endif
143 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
144 __ALIGN_BEGIN uint8_t const usbd_cdc_CfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ;
145 
146 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
147  #if defined ( __ICCARM__ )
148  #pragma data_alignment=4
149  #endif
150 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
151 __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ;
152 
153 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
154  #if defined ( __ICCARM__ )
155  #pragma data_alignment=4
156  #endif
157 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
158 __ALIGN_BEGIN static __IO uint32_t usbd_cdc_AltSet __ALIGN_END = 0;
159 
160 /* OUT ring buffer */
161 
162 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
163  #if defined ( __ICCARM__ )
164  #pragma data_alignment=4
165  #endif
166 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
168 
169 uint32_t USB_Rx_buff_head = 0;
170 uint32_t USB_Rx_buff_tail = 0;
172 uint32_t USB_Rx_total_bytes = 0;
173 
174 /* IN ring buffer */
175 
176 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
177  #if defined ( __ICCARM__ )
178  #pragma data_alignment=4
179  #endif
180 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
182 
183 uint32_t USB_Tx_buff_head = 0;
184 uint32_t USB_Tx_buff_tail = 0;
185 uint32_t USB_Tx_total_bytes = 0;
186 
187 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
188  #if defined ( __ICCARM__ )
189  #pragma data_alignment=4
190  #endif
191 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
193 
194 uint8_t USB_Tx_Active = 0; /* IN endpoint is transmitting */
195 uint8_t USB_Rx_Active = 0; /* OUT endpoint is receiving */
196 
197 static uint32_t cdcCmd = 0xFF;
198 static uint32_t cdcLen = 0;
199 
200 /* CDC interface class callbacks structure */
202 {
206  NULL, /* EP0_TxSent, */
210  usbd_cdc_SOF,
211  NULL,
212  NULL,
214 #ifdef USE_USB_OTG_HS
215  USBD_cdc_GetOtherCfgDesc, /* use same config as per FS */
216 #endif /* USE_USB_OTG_HS */
217 };
218 
219 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
220  #if defined ( __ICCARM__ )
221  #pragma data_alignment=4
222  #endif
223 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
224 /* USB CDC device Configuration Descriptor */
225 __ALIGN_BEGIN uint8_t const usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
226 {
227  /*Configuration Descriptor*/
228  0x09, /* bLength: Configuration Descriptor size */
229  USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
230  USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
231  0x00,
232  0x02, /* bNumInterfaces: 2 interface */
233  0x01, /* bConfigurationValue: Configuration value */
234  0x00, /* iConfiguration: Index of string descriptor describing the configuration */
235  0xC0, /* bmAttributes: self powered */
236  0x32, /* MaxPower 0 mA */
237 
238  /*---------------------------------------------------------------------------*/
239 
240  /*Interface Descriptor */
241  0x09, /* bLength: Interface Descriptor size */
242  USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
243  /* Interface descriptor type */
244  0x00, /* bInterfaceNumber: Number of Interface */
245  0x00, /* bAlternateSetting: Alternate setting */
246  0x01, /* bNumEndpoints: One endpoints used */
247  0x02, /* bInterfaceClass: Communication Interface Class */
248  0x02, /* bInterfaceSubClass: Abstract Control Model */
249  0x01, /* bInterfaceProtocol: Common AT commands */
250  0x00, /* iInterface: */
251 
252  /*Header Functional Descriptor*/
253  0x05, /* bLength: Endpoint Descriptor size */
254  0x24, /* bDescriptorType: CS_INTERFACE */
255  0x00, /* bDescriptorSubtype: Header Func Desc */
256  0x10, /* bcdCDC: spec release number */
257  0x01,
258 
259  /*Call Management Functional Descriptor*/
260  0x05, /* bFunctionLength */
261  0x24, /* bDescriptorType: CS_INTERFACE */
262  0x01, /* bDescriptorSubtype: Call Management Func Desc */
263  0x00, /* bmCapabilities: D0+D1 */
264  0x01, /* bDataInterface: 1 */
265 
266  /*ACM Functional Descriptor*/
267  0x04, /* bFunctionLength */
268  0x24, /* bDescriptorType: CS_INTERFACE */
269  0x02, /* bDescriptorSubtype: Abstract Control Management desc */
270  0x02, /* bmCapabilities */
271 
272  /*Union Functional Descriptor*/
273  0x05, /* bFunctionLength */
274  0x24, /* bDescriptorType: CS_INTERFACE */
275  0x06, /* bDescriptorSubtype: Union func desc */
276  0x00, /* bMasterInterface: Communication class interface */
277  0x01, /* bSlaveInterface0: Data Class Interface */
278 
279  /*Endpoint 2 Descriptor*/
280  0x07, /* bLength: Endpoint Descriptor size */
281  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
282  CDC_CMD_EP, /* bEndpointAddress */
283  0x03, /* bmAttributes: Interrupt */
284  LOBYTE(CDC_CMD_PACKET_SZE), /* wMaxPacketSize: */
286 #ifdef USE_USB_OTG_HS
287  0x10, /* bInterval: */
288 #else
289  0xFF, /* bInterval: */
290 #endif /* USE_USB_OTG_HS */
291 
292  /*---------------------------------------------------------------------------*/
293 
294  /*Data class interface descriptor*/
295  0x09, /* bLength: Endpoint Descriptor size */
296  USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
297  0x01, /* bInterfaceNumber: Number of Interface */
298  0x00, /* bAlternateSetting: Alternate setting */
299  0x02, /* bNumEndpoints: Two endpoints used */
300  0x0A, /* bInterfaceClass: CDC */
301  0x00, /* bInterfaceSubClass: */
302  0x00, /* bInterfaceProtocol: */
303  0x00, /* iInterface: */
304 
305  /*Endpoint OUT Descriptor*/
306  0x07, /* bLength: Endpoint Descriptor size */
307  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
308  CDC_OUT_EP, /* bEndpointAddress */
309  0x02, /* bmAttributes: Bulk */
310  LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */
312  0x00, /* bInterval: ignore for Bulk transfer */
313 
314  /*Endpoint IN Descriptor*/
315  0x07, /* bLength: Endpoint Descriptor size */
316  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
317  CDC_IN_EP, /* bEndpointAddress */
318  0x02, /* bmAttributes: Bulk */
319  LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */
321  0x00 /* bInterval: ignore for Bulk transfer */
322 } ;
323 
324 #ifdef USE_USB_OTG_HS
325 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
326  #if defined ( __ICCARM__ )
327  #pragma data_alignment=4
328  #endif
329 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
330 __ALIGN_BEGIN uint8_t const usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
331 {
332  0x09, /* bLength: Configuation Descriptor size */
335  0x00,
336  0x02, /* bNumInterfaces: 2 interfaces */
337  0x01, /* bConfigurationValue: */
338  0x04, /* iConfiguration: */
339  0xC0, /* bmAttributes: */
340  0x32, /* MaxPower 100 mA */
341 
342  /*Interface Descriptor */
343  0x09, /* bLength: Interface Descriptor size */
344  USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
345  /* Interface descriptor type */
346  0x00, /* bInterfaceNumber: Number of Interface */
347  0x00, /* bAlternateSetting: Alternate setting */
348  0x01, /* bNumEndpoints: One endpoints used */
349  0x02, /* bInterfaceClass: Communication Interface Class */
350  0x02, /* bInterfaceSubClass: Abstract Control Model */
351  0x01, /* bInterfaceProtocol: Common AT commands */
352  0x00, /* iInterface: */
353 
354  /*Header Functional Descriptor*/
355  0x05, /* bLength: Endpoint Descriptor size */
356  0x24, /* bDescriptorType: CS_INTERFACE */
357  0x00, /* bDescriptorSubtype: Header Func Desc */
358  0x10, /* bcdCDC: spec release number */
359  0x01,
360 
361  /*Call Management Functional Descriptor*/
362  0x05, /* bFunctionLength */
363  0x24, /* bDescriptorType: CS_INTERFACE */
364  0x01, /* bDescriptorSubtype: Call Management Func Desc */
365  0x00, /* bmCapabilities: D0+D1 */
366  0x01, /* bDataInterface: 1 */
367 
368  /*ACM Functional Descriptor*/
369  0x04, /* bFunctionLength */
370  0x24, /* bDescriptorType: CS_INTERFACE */
371  0x02, /* bDescriptorSubtype: Abstract Control Management desc */
372  0x02, /* bmCapabilities */
373 
374  /*Union Functional Descriptor*/
375  0x05, /* bFunctionLength */
376  0x24, /* bDescriptorType: CS_INTERFACE */
377  0x06, /* bDescriptorSubtype: Union func desc */
378  0x00, /* bMasterInterface: Communication class interface */
379  0x01, /* bSlaveInterface0: Data Class Interface */
380 
381  /*Endpoint 2 Descriptor*/
382  0x07, /* bLength: Endpoint Descriptor size */
383  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
384  CDC_CMD_EP, /* bEndpointAddress */
385  0x03, /* bmAttributes: Interrupt */
386  LOBYTE(CDC_CMD_PACKET_SZE), /* wMaxPacketSize: */
388  0xFF, /* bInterval: */
389 
390  /*---------------------------------------------------------------------------*/
391 
392  /*Data class interface descriptor*/
393  0x09, /* bLength: Endpoint Descriptor size */
394  USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
395  0x01, /* bInterfaceNumber: Number of Interface */
396  0x00, /* bAlternateSetting: Alternate setting */
397  0x02, /* bNumEndpoints: Two endpoints used */
398  0x0A, /* bInterfaceClass: CDC */
399  0x00, /* bInterfaceSubClass: */
400  0x00, /* bInterfaceProtocol: */
401  0x00, /* iInterface: */
402 
403  /*Endpoint OUT Descriptor*/
404  0x07, /* bLength: Endpoint Descriptor size */
405  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
406  CDC_OUT_EP, /* bEndpointAddress */
407  0x02, /* bmAttributes: Bulk */
408  0x40, /* wMaxPacketSize: */
409  0x00,
410  0x00, /* bInterval: ignore for Bulk transfer */
411 
412  /*Endpoint IN Descriptor*/
413  0x07, /* bLength: Endpoint Descriptor size */
414  USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
415  CDC_IN_EP, /* bEndpointAddress */
416  0x02, /* bmAttributes: Bulk */
417  0x40, /* wMaxPacketSize: */
418  0x00,
419  0x00 /* bInterval */
420 };
421 #endif /* USE_USB_OTG_HS */
422 
438 static uint8_t usbd_cdc_Init (void *pdev,
439  uint8_t cfgidx)
440 {
441  uint8_t *pbuf;
442 
443  /* Open EP IN */
444  DCD_EP_Open(pdev,
445  CDC_IN_EP,
448 
449  /* Open EP OUT */
450  DCD_EP_Open(pdev,
451  CDC_OUT_EP,
454 
455  /* Open Command IN EP */
456  DCD_EP_Open(pdev,
457  CDC_CMD_EP,
460 
461  pbuf = (uint8_t *)USBD_DeviceDesc;
462  pbuf[4] = DEVICE_CLASS_CDC;
463  pbuf[5] = DEVICE_SUBCLASS_CDC;
464 
465  /* Initialize the Interface physical components */
466  APP_FOPS.pIf_Init();
467 
468  USB_Rx_Active = 1;
469 
470  /* Prepare Out endpoint to receive next packet */
471  DCD_EP_PrepareRx(pdev,
472  CDC_OUT_EP,
475 
476  return USBD_OK;
477 }
478 
486 static uint8_t usbd_cdc_DeInit (void *pdev,
487  uint8_t cfgidx)
488 {
489  /* Open EP IN */
490  DCD_EP_Close(pdev,
491  CDC_IN_EP);
492 
493  /* Open EP OUT */
494  DCD_EP_Close(pdev,
495  CDC_OUT_EP);
496 
497  /* Open Command IN EP */
498  DCD_EP_Close(pdev,
499  CDC_CMD_EP);
500 
501  /* Restore default state of the Interface physical components */
502  APP_FOPS.pIf_DeInit();
503 
504  return USBD_OK;
505 }
506 
514 static uint8_t usbd_cdc_Setup (void *pdev,
515  USB_SETUP_REQ *req)
516 {
517  uint16_t len=USB_CDC_DESC_SIZ;
518  uint8_t const *pbuf=usbd_cdc_CfgDesc + 9;
519 
520  switch (req->bmRequest & USB_REQ_TYPE_MASK)
521  {
522  /* CDC Class Requests -------------------------------*/
523  case USB_REQ_TYPE_CLASS :
524  /* Check if the request is a data setup packet */
525  if (req->wLength)
526  {
527  /* Check if the request is Device-to-Host */
528  if (req->bmRequest & 0x80)
529  {
530  /* Get the data to be sent to Host from interface layer */
531  APP_FOPS.pIf_Ctrl(req->bRequest, CmdBuff, req->wLength);
532 
533  /* Send the data to the host */
534  USBD_CtlSendData (pdev,
535  CmdBuff,
536  req->wLength);
537  }
538  else /* Host-to-Device requeset */
539  {
540  /* Set the value of the current command to be processed */
541  cdcCmd = req->bRequest;
542  cdcLen = req->wLength;
543 
544  /* Prepare the reception of the buffer over EP0
545  Next step: the received data will be managed in usbd_cdc_EP0_TxSent()
546  function. */
547  USBD_CtlPrepareRx (pdev,
548  CmdBuff,
549  req->wLength);
550  }
551  }
552  else /* No Data request */
553  {
554  /* Transfer the command to the interface layer */
555  APP_FOPS.pIf_Ctrl(req->bRequest, NULL, 0);
556  }
557 
558  return USBD_OK;
559 
560  default:
561  USBD_CtlError (pdev, req);
562  return USBD_FAIL;
563 
564 
565 
566  /* Standard Requests -------------------------------*/
568  switch (req->bRequest)
569  {
571  if( (req->wValue >> 8) == CDC_DESCRIPTOR_TYPE)
572  {
573 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
574  pbuf = usbd_cdc_Desc;
575 #else
576  pbuf = usbd_cdc_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM);
577 #endif
578  len = MIN(USB_CDC_DESC_SIZ , req->wLength);
579  }
580 
581  USBD_CtlSendData (pdev,
582  pbuf,
583  len);
584  break;
585 
586  case USB_REQ_GET_INTERFACE :
587  USBD_CtlSendData (pdev,
588  (uint8_t *)&usbd_cdc_AltSet,
589  1);
590  break;
591 
592  case USB_REQ_SET_INTERFACE :
593  if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM)
594  {
595  usbd_cdc_AltSet = (uint8_t)(req->wValue);
596  }
597  else
598  {
599  /* Call the error management function (command will be nacked */
600  USBD_CtlError (pdev, req);
601  }
602  break;
603  }
604  }
605  return USBD_OK;
606 }
607 
614 static uint8_t usbd_cdc_EP0_RxReady (void *pdev)
615 {
616  if (cdcCmd != NO_CMD)
617  {
618  /* Process the data */
619  APP_FOPS.pIf_Ctrl(cdcCmd, CmdBuff, cdcLen);
620 
621  /* Reset the command variable to default value */
622  cdcCmd = NO_CMD;
623  }
624 
625  return USBD_OK;
626 }
627 
628 static inline uint32_t last_tx_packet_size(void *pdev, uint8_t epnum)
629 {
630  return ((USB_OTG_CORE_HANDLE*)pdev)->dev.in_ep[epnum].xfer_len;
631 }
632 
633 static inline uint32_t last_rx_data_size(void *pdev, uint8_t epnum)
634 {
635  return ((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].xfer_count;
636 }
637 
645 static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum)
646 {
647  uint16_t USB_Tx_length;
648  if (!USB_Tx_Active)
649  return USBD_OK;
650 
652  if (USB_Tx_length) {
653  USB_Tx_length = MIN_(USB_Tx_length, CDC_DATA_IN_PACKET_SIZE);
654  } else if (last_tx_packet_size(pdev, epnum) != CDC_DATA_IN_PACKET_SIZE) {
655  USB_Tx_Active = 0;
656  return USBD_OK;
657  }
658  /* Send the available data buffer on IN endpoint or ZLP to indicate the end of data stream */
659  DCD_EP_Tx(
660  pdev,
661  CDC_IN_EP,
662  (uint8_t*)&USB_Tx_Buffer[USB_Tx_buff_tail],
663  USB_Tx_length
664  );
665  USB_Tx_buff_tail = ring_wrap(USB_TX_BUFF_SIZE, USB_Tx_buff_tail + USB_Tx_length);
666  USB_Tx_total_bytes += USB_Tx_length;
667  return USBD_OK;
668 }
669 
670 static inline int try_start_rx(void *pdev)
671 {
672  uint32_t space_avail;
675 
677  if (space_avail < CDC_DATA_OUT_PACKET_SIZE) {
679  if (space_avail < CDC_DATA_OUT_PACKET_SIZE) {
680  if (USB_Rx_Active) {
681  USB_Rx_Active = 0;
683  }
684  return 0;
685  }
687  USB_Rx_buff_head = 0;
689  USB_Rx_buff_tail = 0;
690  }
691  if (!USB_Rx_Active) {
692  USB_Rx_Active = 1;
694  }
695  /* Prepare Out endpoint to receive next packet */
697  pdev,
698  CDC_OUT_EP,
701  );
702  return 1;
703 }
704 
712 static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum)
713 {
714  uint32_t USB_Rx_Cnt = last_rx_data_size(pdev, epnum);
716  USB_Rx_total_bytes += USB_Rx_Cnt;
717  try_start_rx(pdev);
718  return USBD_OK;
719 }
720 
721 static void schedule_cdc_out(void *pdev)
722 {
723  if (!USB_Rx_Active)
724  try_start_rx(pdev);
725 }
726 
727 static void schedule_cdc_in(void *pdev)
728 {
729  uint16_t USB_Tx_length;
730  if (USB_Tx_Active)
731  return;
732 
734  if (!USB_Tx_length)
735  return;
736 
737  USB_Tx_Active = 1;
738  USB_Tx_length = MIN_(USB_Tx_length, CDC_DATA_IN_PACKET_SIZE);
739  /* Send the available data buffer on IN endpoint */
740  DCD_EP_Tx(
741  pdev,
742  CDC_IN_EP,
743  (uint8_t*)&USB_Tx_Buffer[USB_Tx_buff_tail],
744  USB_Tx_length
745  );
746  USB_Tx_buff_tail = ring_wrap(USB_TX_BUFF_SIZE, USB_Tx_buff_tail + USB_Tx_length);
747  USB_Tx_total_bytes += USB_Tx_length;
748 }
749 
757 static uint8_t usbd_cdc_SOF (void *pdev)
758 {
759  static uint32_t FrameCount = 0;
760 
761  if (FrameCount++ == CDC_IN_FRAME_INTERVAL)
762  {
763  /* Reset the frame counter */
764  FrameCount = 0;
765  /* Check the data to be sent through IN pipe */
766  schedule_cdc_in(pdev);
767  /* Check we can start receiving through OUT pipe */
768  schedule_cdc_out(pdev);
769  }
770 
771  return USBD_OK;
772 }
773 
781 static uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length)
782 {
783  *length = sizeof (usbd_cdc_CfgDesc);
784  return usbd_cdc_CfgDesc;
785 }
786 
794 #ifdef USE_USB_OTG_HS
795 static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length)
796 {
797  *length = sizeof (usbd_cdc_OtherCfgDesc);
798  return usbd_cdc_OtherCfgDesc;
799 }
800 #endif
801 
813 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define DEVICE_SUBCLASS_CDC
Definition: usbd_cdc_core.h:54
#define USB_RX_BUFF_SIZE
#define USB_REQ_TYPE_STANDARD
Definition: usbd_def.h:67
static uint32_t last_tx_packet_size(void *pdev, uint8_t epnum)
header file for the usbd_req.c file
uint8_t USB_Tx_Buffer[]
uint16_t(* pIf_DeInit)(void)
Definition: usbd_cdc_core.h:98
#define CDC_DESCRIPTOR_TYPE
Definition: usbd_cdc_core.h:51
USBD_Status USBD_CtlSendData(USB_OTG_CORE_HANDLE *pdev, const uint8_t *pbuf, uint16_t len)
USBD_CtlSendData send data on the ctl pipe.
Definition: usbd_ioreq.c:95
#define CDC_IN_EP
Definition: usbd_conf.h:48
#define USB_REQ_TYPE_CLASS
Definition: usbd_def.h:68
#define USB_REQ_SET_INTERFACE
Definition: usbd_def.h:86
#define USB_REQ_GET_INTERFACE
Definition: usbd_def.h:85
#define USB_OTG_EP_INT
Definition: usb_dcd.h:52
static unsigned ring_space_contig(unsigned size, unsigned head, unsigned tail)
Definition: ring_buff.h:38
static uint8_t usbd_cdc_Setup(void *pdev, USB_SETUP_REQ *req)
usbd_cdc_Setup Handle the CDC specific requests
USBD_Class_cb_TypeDef const USBD_CDC_cb
uint32_t DCD_EP_Tx(USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len)
Transmit data over USB.
Definition: usb_dcd.c:261
#define USBD_ITF_MAX_NUM
Definition: usbd_conf.h:39
static uint32_t cdcCmd
uint8_t USB_Tx_Active
static unsigned ring_wrap(unsigned size, unsigned idx)
Definition: ring_buff.h:8
static uint8_t usbd_cdc_SOF(void *pdev)
usbd_audio_SOF Start Of Frame event management
static void schedule_cdc_out(void *pdev)
uint32_t USB_Rx_total_bytes
uint32_t USB_Rx_buff_size
#define MIN_(a, b)
Definition: min_max.h:3
#define CDC_IN_FRAME_INTERVAL
Definition: usbd_conf.h:64
static uint8_t * USBD_cdc_GetCfgDesc(uint8_t speed, uint16_t *length)
USBD_cdc_GetCfgDesc Return configuration descriptor.
static uint32_t last_rx_data_size(void *pdev, uint8_t epnum)
#define MIN(a, b)
Definition: usb_conf.h:215
uint8_t USB_Rx_Buffer[]
header file for the usbd_cdc_core.c file.
uint32_t USB_Tx_total_bytes
uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type)
Configure an EP.
Definition: usb_dcd.c:155
#define CDC_DATA_OUT_PACKET_SIZE
Definition: usbd_cdc_core.h:67
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usbd_cdc_core.h:58
uint32_t DCD_EP_Close(USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr)
called when an EP is disabled
Definition: usb_dcd.c:194
static unsigned ring_space_wrapped(unsigned size, unsigned head, unsigned tail)
Definition: ring_buff.h:47
#define CDC_CMD_EP
Definition: usbd_conf.h:50
static uint8_t usbd_cdc_DeInit(void *pdev, uint8_t cfgidx)
usbd_cdc_Init DeInitialize the CDC layer
#define CDC_DATA_MAX_PACKET_SIZE
Definition: usbd_conf.h:61
#define USB_CDC_CONFIG_DESC_SIZ
Definition: usbd_cdc_core.h:48
#define USB_CDC_DESC_SIZ
Definition: usbd_cdc_core.h:49
uint16_t(* pIf_Ctrl)(uint32_t Cmd, uint8_t *Buf, uint32_t Len)
Definition: usbd_cdc_core.h:99
#define __ALIGN_BEGIN
Definition: usb_conf.h:198
CDC_IF_Prop_TypeDef APP_FOPS
static uint8_t usbd_cdc_DataIn(void *pdev, uint8_t epnum)
usbd_audio_DataIn Data sent on non-control IN endpoint
static uint32_t cdcLen
USBD_Status USBD_CtlPrepareRx(USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len)
USBD_CtlPrepareRx receive data on the ctl pipe.
Definition: usbd_ioreq.c:138
#define USB_SIZ_DEVICE_DESC
Definition: usbd_desc.h:53
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usbd_cdc_core.h:60
void DCD_SetEPStatus(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum, uint32_t Status)
Set the EP Status.
Definition: usb_dcd.c:450
#define USB_REQ_GET_DESCRIPTOR
Definition: usbd_def.h:81
static uint8_t usbd_cdc_EP0_RxReady(void *pdev)
usbd_cdc_EP0_RxReady Data received on control endpoint
uint8_t bmRequest
Definition: usb_core.h:182
__ALIGN_BEGIN uint8_t const usbd_cdc_CfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END
#define USB_OTG_EP_TX_NAK
Definition: usb_core.h:62
#define CDC_OUT_EP
Definition: usbd_conf.h:49
#define USB_OTG_EP_BULK
Definition: usb_dcd.h:51
static int try_start_rx(void *pdev)
#define USB_OTG_EP_TX_VALID
Definition: usb_core.h:63
#define CDC_DATA_IN_PACKET_SIZE
Definition: usbd_cdc_core.h:65
void USBD_CtlError(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req)
USBD_CtlError Handle USB low level Error.
Definition: usbd_req.c:801
uint32_t USB_Rx_buff_tail
#define NULL
Definition: hal_types.h:59
const uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC]
Definition: usb.c:129
static uint8_t usbd_cdc_Init(void *pdev, uint8_t cfgidx)
usbd_cdc_Init Initilaize the CDC interface
#define DEVICE_CLASS_CDC
Definition: usbd_cdc_core.h:53
uint32_t USB_Tx_buff_tail
#define USB_TX_BUFF_SIZE
uint8_t USB_Rx_Active
#define CDC_CMD_PACKET_SZE
Definition: usbd_conf.h:62
uint16_t wLength
Definition: usb_core.h:186
uint8_t bRequest
Definition: usb_core.h:183
static uint8_t usbd_cdc_DataOut(void *pdev, uint8_t epnum)
usbd_cdc_DataOut Data received on non-control Out endpoint
static void schedule_cdc_in(void *pdev)
#define HIBYTE(x)
Definition: usbd_def.h:126
#define LOBYTE(x)
Definition: usbd_def.h:125
#define USB_ENDPOINT_DESCRIPTOR_TYPE
Definition: usbd_cdc_core.h:61
uint32_t USB_Rx_buff_head
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION
Definition: usbd_def.h:95
static unsigned ring_data_contig(unsigned size, unsigned head, unsigned tail)
Definition: ring_buff.h:29
#define NO_CMD
Definition: usbd_cdc_core.h:85
#define USB_REQ_TYPE_MASK
Definition: usbd_def.h:70
uint16_t(* pIf_Init)(void)
Definition: usbd_cdc_core.h:97
uint32_t DCD_EP_PrepareRx(USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t buf_len)
DCD_EP_PrepareRx.
Definition: usb_dcd.c:221
uint16_t wValue
Definition: usb_core.h:184
header file for the usbd_desc.c file
uint32_t USB_Tx_buff_head