Index: libraries/SCPU_USB_Device_Library/class/CDC/usbd_cdc_core.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/CDC/usbd_cdc_core.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/CDC/usbd_cdc_core.c	(working copy)
@@ -4,21 +4,21 @@
   * @author  MCD Application Team
   * @version V1.1.0
   * @date    19-March-2012
-  * @brief   This file provides the high layer firmware functions to manage the 
+  * @brief   This file provides the high layer firmware functions to manage the
   *          following functionalities of the USB CDC Class:
   *           - Initialization and Configuration of high and low layer
   *           - Enumeration as CDC Device (and enumeration for each implemented memory interface)
   *           - OUT/IN data transfer
   *           - Command IN transfer (class requests management)
   *           - Error management
-  *           
+  *
   *  @verbatim
-  *      
-  *          ===================================================================      
+  *
+  *          ===================================================================
   *                                CDC Class Driver Description
-  *          =================================================================== 
+  *          ===================================================================
   *           This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
-  *           Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus 
+  *           Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
   *           Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
   *           This driver implements the following aspects of the specification:
   *             - Device descriptor management
@@ -33,16 +33,16 @@
   *             For the Abstract Control Model, this core allows only transmitting the requests to
   *             lower layer dispatcher (ie. usbd_cdc_vcp.c/.h) which should manage each request and
   *             perform relative actions.
-  * 
+  *
   *           These aspects may be enriched or modified for a specific user application.
-  *          
-  *            This driver doesn't implement the following aspects of the specification 
+  *
+  *            This driver doesn't implement the following aspects of the specification
   *            (but it is possible to manage these features with some modifications on this driver):
   *             - Any class-specific aspect relative to communication classes should be managed by user application.
   *             - All communication classes other than PSTN are not managed
-  *      
+  *
   *  @endverbatim
-  *                                  
+  *
   ******************************************************************************
   * @attention
   *
@@ -54,14 +54,14 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   ******************************************************************************
-  */ 
+  */
 
 /* Includes ------------------------------------------------------------------*/
 #include "usbd_cdc_core.h"
@@ -74,33 +74,33 @@
   */
 
 
-/** @defgroup usbd_cdc 
+/** @defgroup usbd_cdc
   * @brief usbd core module
   * @{
-  */ 
+  */
 
 /** @defgroup usbd_cdc_Private_TypesDefinitions
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup usbd_cdc_Private_Defines
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup usbd_cdc_Private_Macros
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup usbd_cdc_Private_FunctionPrototypes
@@ -123,63 +123,63 @@
  *********************************************/
 static void Handle_USBAsynchXfer  (void *pdev);
 static uint8_t  *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length);
-#ifdef USE_USB_OTG_HS  
+#ifdef USE_USB_OTG_HS
 static uint8_t  *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length);
 #endif
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup usbd_cdc_Private_Variables
   * @{
-  */ 
+  */
 extern CDC_IF_Prop_TypeDef  APP_FOPS;
 extern uint8_t USBD_DeviceDesc   [USB_SIZ_DEVICE_DESC];
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc  [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ;
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc  [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ;
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 __ALIGN_BEGIN static uint32_t  usbd_cdc_AltSet  __ALIGN_END = 0;
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 __ALIGN_BEGIN uint8_t USB_Rx_Buffer   [CDC_DATA_MAX_PACKET_SIZE] __ALIGN_END ;
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 
 #ifdef USER_SPECIFIED_DATA_SOURCE
 uint8_t *APP_Rx_Buffer = NULL;
 #else
-//__ALIGN_BEGIN uint8_t APP_Rx_Buffer   [APP_RX_DATA_SIZE] __ALIGN_END ; 
-struct APP_DATA_STRUCT_DEF APP_Gdata_param; 
+//__ALIGN_BEGIN uint8_t APP_Rx_Buffer   [APP_RX_DATA_SIZE] __ALIGN_END ;
+struct APP_DATA_STRUCT_DEF APP_Gdata_param;
 #endif
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 __ALIGN_BEGIN uint8_t CmdBuff[CDC_CMD_PACKET_SZE] __ALIGN_END ;
@@ -194,7 +194,7 @@
 static uint32_t cdcLen = 0;
 
 /* CDC interface class callbacks structure */
-USBD_Class_cb_TypeDef  USBD_CDC_cb = 
+USBD_Class_cb_TypeDef  USBD_CDC_cb =
 {
   usbd_cdc_Init,
   usbd_cdc_DeInit,
@@ -205,16 +205,16 @@
   usbd_cdc_DataOut,
   usbd_cdc_SOF,
   NULL,
-  NULL,     
+  NULL,
   USBD_cdc_GetCfgDesc,
-#ifdef USE_USB_OTG_HS   
+#ifdef USE_USB_OTG_HS
   USBD_cdc_GetOtherCfgDesc, /* use same cobfig as per FS */
 #endif /* USE_USB_OTG_HS  */
 };
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 /* USB CDC device Configuration Descriptor */
@@ -230,9 +230,9 @@
   0x00,   /* iConfiguration: Index of string descriptor describing the configuration */
   0xC0,   /* bmAttributes: self powered */
   0x32,   /* MaxPower 0 mA */
-  
+
   /*---------------------------------------------------------------------------*/
-  
+
   /*Interface Descriptor */
   0x09,   /* bLength: Interface Descriptor size */
   USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: Interface */
@@ -244,14 +244,14 @@
   0x02,   /* bInterfaceSubClass: Abstract Control Model */
   0x01,   /* bInterfaceProtocol: Common AT commands */
   0x00,   /* iInterface: */
-  
+
   /*Header Functional Descriptor*/
   0x05,   /* bLength: Endpoint Descriptor size */
   0x24,   /* bDescriptorType: CS_INTERFACE */
   0x00,   /* bDescriptorSubtype: Header Func Desc */
   0x10,   /* bcdCDC: spec release number */
   0x01,
-  
+
   /*Call Management Functional Descriptor*/
   0x05,   /* bFunctionLength */
   0x24,   /* bDescriptorType: CS_INTERFACE */
@@ -259,20 +259,20 @@
   0x00,   /* bmCapabilities: D0+D1 */
   0x00,   /* bDataInterface: 0 */
 //  0x01,   /* bDataInterface: 1 */
-  
+
   /*ACM Functional Descriptor*/
   0x04,   /* bFunctionLength */
   0x24,   /* bDescriptorType: CS_INTERFACE */
   0x02,   /* bDescriptorSubtype: Abstract Control Management desc */
   0x02,   /* bmCapabilities */
-  
+
   /*Union Functional Descriptor*/
   0x05,   /* bFunctionLength */
   0x24,   /* bDescriptorType: CS_INTERFACE */
   0x06,   /* bDescriptorSubtype: Union func desc */
   0x00,   /* bMasterInterface: Communication class interface */
   0x01,   /* bSlaveInterface0: Data Class Interface */
-  
+
   /*Endpoint 2 Descriptor*/
   0x07,                           /* bLength: Endpoint Descriptor size */
   USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
@@ -283,11 +283,11 @@
 #ifdef USE_USB_OTG_HS
   0x10,                           /* bInterval: */
 #else
-  0xFF,                           /* bInterval: */
+  0x01,                           /* bInterval: */
 #endif /* USE_USB_OTG_HS */
-  
+
   /*---------------------------------------------------------------------------*/
-  
+
   /*Data class interface descriptor*/
   0x09,   /* bLength: Endpoint Descriptor size */
   USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: */
@@ -298,7 +298,7 @@
   0x00,   /* bInterfaceSubClass: */
   0x00,   /* bInterfaceProtocol: */
   0x00,   /* iInterface: */
-  
+
   /*Endpoint OUT Descriptor*/
   0x07,   /* bLength: Endpoint Descriptor size */
   USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType: Endpoint */
@@ -307,7 +307,7 @@
   LOBYTE(CDC_DATA_MAX_PACKET_SIZE),  /* wMaxPacketSize: */
   HIBYTE(CDC_DATA_MAX_PACKET_SIZE),
   0x00,                              /* bInterval: ignore for Bulk transfer */
-  
+
   /*Endpoint IN Descriptor*/
   0x07,   /* bLength: Endpoint Descriptor size */
   USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType: Endpoint */
@@ -321,21 +321,21 @@
 #ifdef USE_USB_OTG_HS
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
-#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ 
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ]  __ALIGN_END =
-{ 
+{
   0x09,   /* bLength: Configuation Descriptor size */
-  USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,   
+  USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
   USB_CDC_CONFIG_DESC_SIZ,
   0x00,
   0x02,   /* bNumInterfaces: 2 interfaces */
   0x01,   /* bConfigurationValue: */
   0x04,   /* iConfiguration: */
   0xC0,   /* bmAttributes: */
-  0x32,   /* MaxPower 100 mA */  
-  
+  0x32,   /* MaxPower 100 mA */
+
   /*Interface Descriptor */
   0x09,   /* bLength: Interface Descriptor size */
   USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: Interface */
@@ -347,34 +347,34 @@
   0x02,   /* bInterfaceSubClass: Abstract Control Model */
   0x01,   /* bInterfaceProtocol: Common AT commands */
   0x00,   /* iInterface: */
-  
+
   /*Header Functional Descriptor*/
   0x05,   /* bLength: Endpoint Descriptor size */
   0x24,   /* bDescriptorType: CS_INTERFACE */
   0x00,   /* bDescriptorSubtype: Header Func Desc */
   0x10,   /* bcdCDC: spec release number */
   0x01,
-  
+
   /*Call Management Functional Descriptor*/
   0x05,   /* bFunctionLength */
   0x24,   /* bDescriptorType: CS_INTERFACE */
   0x01,   /* bDescriptorSubtype: Call Management Func Desc */
   0x00,   /* bmCapabilities: D0+D1 */
   0x01,   /* bDataInterface: 1 */
-  
+
   /*ACM Functional Descriptor*/
   0x04,   /* bFunctionLength */
   0x24,   /* bDescriptorType: CS_INTERFACE */
   0x02,   /* bDescriptorSubtype: Abstract Control Management desc */
   0x02,   /* bmCapabilities */
-  
+
   /*Union Functional Descriptor*/
   0x05,   /* bFunctionLength */
   0x24,   /* bDescriptorType: CS_INTERFACE */
   0x06,   /* bDescriptorSubtype: Union func desc */
   0x00,   /* bMasterInterface: Communication class interface */
   0x01,   /* bSlaveInterface0: Data Class Interface */
-  
+
   /*Endpoint 2 Descriptor*/
   0x07,                           /* bLength: Endpoint Descriptor size */
   USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
@@ -383,9 +383,9 @@
   LOBYTE(CDC_CMD_PACKET_SZE),     /* wMaxPacketSize: */
   HIBYTE(CDC_CMD_PACKET_SZE),
   0xFF,                           /* bInterval: */
-  
+
   /*---------------------------------------------------------------------------*/
-  
+
   /*Data class interface descriptor*/
   0x09,   /* bLength: Endpoint Descriptor size */
   USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: */
@@ -396,7 +396,7 @@
   0x00,   /* bInterfaceSubClass: */
   0x00,   /* bInterfaceProtocol: */
   0x00,   /* iInterface: */
-  
+
   /*Endpoint OUT Descriptor*/
   0x07,   /* bLength: Endpoint Descriptor size */
   USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType: Endpoint */
@@ -405,7 +405,7 @@
   0x40,                              /* wMaxPacketSize: */
   0x00,
   0x00,                              /* bInterval: ignore for Bulk transfer */
-  
+
   /*Endpoint IN Descriptor*/
   0x07,   /* bLength: Endpoint Descriptor size */
   USB_ENDPOINT_DESCRIPTOR_TYPE,     /* bDescriptorType: Endpoint */
@@ -419,11 +419,11 @@
 
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup usbd_cdc_Private_Functions
   * @{
-  */ 
+  */
 
 /**
   * @brief  usbd_cdc_Init
@@ -432,7 +432,7 @@
   * @param  cfgidx: Configuration index
   * @retval status
   */
-static uint8_t  usbd_cdc_Init (void  *pdev, 
+static uint8_t  usbd_cdc_Init (void  *pdev,
                                uint8_t cfgidx)
 {
   uint8_t *pbuf;
@@ -442,23 +442,23 @@
               CDC_IN_EP,
               CDC_DATA_IN_PACKET_SIZE,
               USB_OTG_EP_BULK);
-  
+
   /* Open EP OUT */
   DCD_EP_Open(pdev,
               CDC_OUT_EP,
               CDC_DATA_OUT_PACKET_SIZE,
               USB_OTG_EP_BULK);
-  
+
   /* Open Command IN EP */
   DCD_EP_Open(pdev,
               CDC_CMD_EP,
               CDC_CMD_PACKET_SZE,
               USB_OTG_EP_INT);
-  
+
   pbuf = (uint8_t *)USBD_DeviceDesc;
   pbuf[4] = DEVICE_CLASS_CDC;
   pbuf[5] = DEVICE_SUBCLASS_CDC;
-  
+
   /* Initialize the Interface physical components */
   APP_FOPS.pIf_Init();
 
@@ -467,7 +467,7 @@
                    CDC_OUT_EP,
                    (uint8_t*)(USB_Rx_Buffer),
                    CDC_DATA_OUT_PACKET_SIZE);
-  
+
   return USBD_OK;
 }
 
@@ -478,24 +478,24 @@
   * @param  cfgidx: Configuration index
   * @retval status
   */
-static uint8_t  usbd_cdc_DeInit (void  *pdev, 
+static uint8_t  usbd_cdc_DeInit (void  *pdev,
                                  uint8_t cfgidx)
 {
   /* Open EP IN */
   DCD_EP_Close(pdev,
               CDC_IN_EP);
-  
+
   /* Open EP OUT */
   DCD_EP_Close(pdev,
               CDC_OUT_EP);
-  
+
   /* Open Command IN EP */
   DCD_EP_Close(pdev,
               CDC_CMD_EP);
 
   /* Restore default state of the Interface physical components */
   APP_FOPS.pIf_DeInit();
-  
+
   return USBD_OK;
 }
 
@@ -506,12 +506,12 @@
   * @param  req: usb requests
   * @retval status
   */
-static uint8_t  usbd_cdc_Setup (void  *pdev, 
+static uint8_t  usbd_cdc_Setup (void  *pdev,
                                 USB_SETUP_REQ *req)
 {
   uint16_t len=USB_CDC_DESC_SIZ;
   uint8_t  *pbuf=usbd_cdc_CfgDesc + 9;
-  
+
   switch (req->bmRequest & USB_REQ_TYPE_MASK)
   {
     /* CDC Class Requests -------------------------------*/
@@ -524,25 +524,27 @@
         {
           /* Get the data to be sent to Host from interface layer */
           APP_FOPS.pIf_Ctrl(req->bRequest, CmdBuff, req->wLength);
-          
+
           /* Send the data to the host */
-          USBD_CtlSendData (pdev, 
+          USBD_CtlSendData (pdev,
                             CmdBuff,
-                            req->wLength);          
+                            req->wLength);
         }
         else /* Host-to-Device requeset */
         {
           /* Set the value of the current command to be processed */
           cdcCmd = req->bRequest;
           cdcLen = req->wLength;
-          
+
           /* Prepare the reception of the buffer over EP0
-          Next step: the received data will be managed in usbd_cdc_EP0_TxSent() 
+          Next step: the received data will be managed in usbd_cdc_EP0_TxSent()
           function. */
      //     MyPrintf("cdc class \n\r");
+          delay_ms(1);
+          while(USB_OTG_READ_REG8(((USB_OTG_CORE_HANDLE*)pdev)->regs.LENREGS[0])<cdcLen);
           USBD_CtlPrepareRx (pdev,
                              CmdBuff,
-                             req->wLength);    
+                             req->wLength);
           APP_FOPS.pIf_Ctrl(req->bRequest, CmdBuff, req->wLength);
           if(req->wLength != 0)
           {
@@ -555,41 +557,41 @@
             /* Transfer the command to the interface layer */
             APP_FOPS.pIf_Ctrl(req->bRequest, NULL, 0);
       }
-      
+
       return USBD_OK;
-      
+
     default:
       USBD_CtlError (pdev, req);
       return USBD_FAIL;
-    
-      
-      
+
+
+
     /* Standard Requests -------------------------------*/
   case USB_REQ_TYPE_STANDARD:
     switch (req->bRequest)
     {
-    case USB_REQ_GET_DESCRIPTOR: 
+    case USB_REQ_GET_DESCRIPTOR:
       if( (req->wValue >> 8) == CDC_DESCRIPTOR_TYPE)
       {
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
-        pbuf = usbd_cdc_Desc;   
+        pbuf = usbd_cdc_Desc;
 #else
         pbuf = usbd_cdc_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM);
-#endif 
+#endif
         len = MIN(USB_CDC_DESC_SIZ , req->wLength);
       }
-      
-      USBD_CtlSendData (pdev, 
+
+      USBD_CtlSendData (pdev,
                         pbuf,
                         len);
       break;
-      
+
     case USB_REQ_GET_INTERFACE :
       USBD_CtlSendData (pdev,
                         (uint8_t *)&usbd_cdc_AltSet,
                         1);
       break;
-      
+
     case USB_REQ_SET_INTERFACE :
       if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM)
       {
@@ -613,16 +615,16 @@
   * @retval status
   */
 static uint8_t  usbd_cdc_EP0_RxReady (void  *pdev)
-{ 
+{
   if (cdcCmd != NO_CMD)
   {
     /* Process the data */
     APP_FOPS.pIf_Ctrl(cdcCmd, CmdBuff, cdcLen);
-    
+
     /* Reset the command variable to default value */
     cdcCmd = NO_CMD;
   }
-  
+
   return USBD_OK;
 }
 
@@ -640,11 +642,11 @@
 
   if (USB_Tx_State == 1)
   {
-    if (APP_Rx_length == 0) 
+    if (APP_Rx_length == 0)
     {
       USB_Tx_State = 0;
     }
-    else 
+    else
     {
         if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE)
         {
@@ -652,12 +654,12 @@
             if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out + CDC_DATA_IN_PACKET_SIZE >= APP_RX_DATA_SIZE)
             {
                 USB_Tx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
-                APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;	
+                APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;
                 APP_Rx_length -= USB_Tx_length;
                 APP_Gdata_param.rx_structure.Rx_counter -= USB_Tx_length;
             }else{
                 USB_Tx_length = CDC_DATA_IN_PACKET_SIZE;
-                APP_Gdata_param.rx_structure.APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE;	
+                APP_Gdata_param.rx_structure.APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE;
                 APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE;
                 APP_Gdata_param.rx_structure.Rx_counter -= CDC_DATA_IN_PACKET_SIZE;
             }
@@ -668,7 +670,7 @@
             if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out + APP_Rx_length >= APP_RX_DATA_SIZE)
             {
                 USB_Tx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
-                APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;	
+                APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;
                 APP_Rx_length -= USB_Tx_length;
                 APP_Gdata_param.rx_structure.Rx_counter -= USB_Tx_length;
             }else{
@@ -684,8 +686,8 @@
 			  CDC_IN_EP,
 			  (uint8_t*)&APP_Gdata_param.rx_structure.APP_Rx_Buffer[USB_Tx_ptr],
 			  USB_Tx_length);
-  }  
-  
+  }
+
   return USBD_OK;
 }
 
@@ -696,42 +698,37 @@
   * @param  epnum: endpoint number
   * @retval status
   */
-#define CDC_DATA_TIMEOUT	(CPU_MHZ/100)	//10ms
-uint32_t cdc_wait_data_times; 
-uint32_t cdc_wait_data_time; 
-uint8_t CDC_Recv_Flag;
+#define wAIT_TIMES  20  //wAIT_TIMES*50us
+extern uint8_t usbFlowCtrl;
 static uint8_t  usbd_cdc_DataOut (void *pdev, uint8_t epnum)
-{      
+{
   uint16_t USB_Rx_Cnt;
-  
+
   /* Get the received data buffer and update the counter */
- 
-  /* USB data will be immediately processed, this allow next USB traffic being 
+
+  /* USB data will be immediately processed, this allow next USB traffic being
      NAKed till the end of the application Xfer */
   /* Prepare Out endpoint to receive next packet */
   DCD_EP_PrepareRx(pdev,
                    CDC_OUT_EP,
                    (uint8_t*)(USB_Rx_Buffer),
                    CDC_DATA_OUT_PACKET_SIZE);
-   USB_Rx_Cnt = ((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].xfer_count;
-  APP_FOPS.pIf_DataRx(USB_Rx_Buffer, USB_Rx_Cnt);
-   if(USB_Rx_Cnt == CDC_DATA_OUT_PACKET_SIZE)
-   {
-	//my_delay_ms(1);
-	cdc_wait_data_times=CDC_DATA_TIMEOUT;//直接用宏定义的话，因为每次算除法，时间变大1000倍
-	cdc_wait_data_time=0;
-	while(cdc_wait_data_time<cdc_wait_data_times)
-	{
-		if(USB_OTG_READ_REG8(((USB_OTG_CORE_HANDLE*)pdev)->regs.LENREGS[CDC_OUT_EP])>=CDC_DATA_OUT_PACKET_SIZE)
-		{
-			break;
-		}
-		cdc_wait_data_time++;
-	}
-	
-	usbd_cdc_DataOut(pdev,epnum);
-   }
-   CDC_Recv_Flag =1;
+    USB_Rx_Cnt = ((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].xfer_count;
+    APP_FOPS.pIf_DataRx(USB_Rx_Buffer, USB_Rx_Cnt);
+    if(USB_Rx_Cnt==((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].maxpacket && usbFlowCtrl==0)
+    {
+        int wait_times=0;
+        while(wait_times<wAIT_TIMES)
+        {
+            if(USB_OTG_READ_REG8(((USB_OTG_CORE_HANDLE*)pdev)->regs.LENREGS[epnum])>=((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].maxpacket)
+            {
+                break;
+            }
+            delay_us(50);
+            wait_times++;
+        }
+        usbd_cdc_DataOut(pdev,epnum);
+    }
   return USBD_OK;
 }
 
@@ -743,18 +740,18 @@
   * @retval status
   */
 static uint8_t  usbd_cdc_SOF (void *pdev)
-{      
+{
   static uint32_t FrameCount = 0;
-  
+
   if (FrameCount++ == CDC_IN_FRAME_INTERVAL)
   {
     /* Reset the frame counter */
     FrameCount = 0;
-    
+
     /* Check the data to be sent through IN pipe */
     Handle_USBAsynchXfer(pdev);
   }
-  
+
   return USBD_OK;
 }
 
@@ -768,7 +765,7 @@
 {
   uint16_t USB_Tx_ptr;
   uint16_t USB_Tx_length;
-  
+
   if(USB_Tx_State != 1)
   {
     if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out == CDC_APP_RX_DATA_SIZE)
@@ -794,17 +791,17 @@
 //    APP_Rx_length = APP_Gdata_param.rx_structure.Rx_counter;
 //	APP_Rx_length = APP_Gdata_param.rx_structure.APP_Rx_ptr_in - \
 //					APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
-//    if(APP_Gdata_param.rx_structure.APP_Rx_ptr_out == APP_Gdata_param.rx_structure.APP_Rx_ptr_in) 
+//    if(APP_Gdata_param.rx_structure.APP_Rx_ptr_out == APP_Gdata_param.rx_structure.APP_Rx_ptr_in)
 //    {
 //      USB_Tx_State = 0;
 //      return;
 //    }
-    
+
     if(APP_Gdata_param.rx_structure.APP_Rx_ptr_out > APP_Gdata_param.rx_structure.APP_Rx_ptr_in) /* rollback */
-    { 
+    {
       APP_Rx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
     }
-    else 
+    else
     {
       APP_Rx_length = APP_Gdata_param.rx_structure.APP_Rx_ptr_in - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
     }
@@ -812,19 +809,19 @@
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
      APP_Rx_length &= ~0x03;
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
-    
+
     if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE)
     {
         USB_Tx_ptr = APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
         if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out + CDC_DATA_IN_PACKET_SIZE >= CDC_APP_RX_DATA_SIZE)
         {
             USB_Tx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
-            APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;	
+            APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;
             APP_Rx_length -= USB_Tx_length;
             APP_Gdata_param.rx_structure.Rx_counter = APP_Rx_length;
         }else{
             USB_Tx_length = CDC_DATA_IN_PACKET_SIZE;
-            APP_Gdata_param.rx_structure.APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE;	
+            APP_Gdata_param.rx_structure.APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE;
             APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE;
             APP_Gdata_param.rx_structure.Rx_counter = APP_Rx_length;
         }
@@ -835,7 +832,7 @@
         if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out + APP_Rx_length >= CDC_APP_RX_DATA_SIZE)
         {
             USB_Tx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
-            APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;	
+            APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;
             APP_Rx_length -= USB_Tx_length;
             APP_Gdata_param.rx_structure.Rx_counter = APP_Rx_length;
         }else{
@@ -845,18 +842,18 @@
             APP_Gdata_param.rx_structure.Rx_counter = APP_Rx_length;
         }
     }
-    USB_Tx_State = 1; 
+    USB_Tx_State = 1;
 
     DCD_EP_Tx (pdev,
                CDC_IN_EP,
                (uint8_t*)&APP_Gdata_param.rx_structure.APP_Rx_Buffer[USB_Tx_ptr],
                USB_Tx_length);
-  }  
-  
+  }
+
 }
 
 /**
-  * @brief  USBD_cdc_GetCfgDesc 
+  * @brief  USBD_cdc_GetCfgDesc
   *         Return configuration descriptor
   * @param  speed : current device speed
   * @param  length : pointer data length
@@ -869,13 +866,13 @@
 }
 
 /**
-  * @brief  USBD_cdc_GetCfgDesc 
+  * @brief  USBD_cdc_GetCfgDesc
   *         Return configuration descriptor
   * @param  speed : current device speed
   * @param  length : pointer data length
   * @retval pointer to descriptor buffer
   */
-#ifdef USE_USB_OTG_HS 
+#ifdef USE_USB_OTG_HS
 static uint8_t  *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length)
 {
   *length = sizeof (usbd_cdc_OtherCfgDesc);
@@ -884,14 +881,14 @@
 #endif
 /**
   * @}
-  */ 
+  */
 
 /**
   * @}
-  */ 
+  */
 
 /**
   * @}
-  */ 
+  */
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Index: libraries/SCPU_USB_Device_Library/class/PRINTER/usbd_printer_core.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/PRINTER/usbd_printer_core.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/PRINTER/usbd_printer_core.h	(working copy)
@@ -0,0 +1,164 @@
+/**
+  ******************************************************************************
+  * @file    usbd_printer_core.h
+  * @author  MCD Application Team
+  * @version V1.1.0
+  * @date    19-March-2012
+  * @brief   header file for the usbd_printer_core.c file.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+
+#ifndef __USB_PRINTER_CORE_H_
+#define __USB_PRINTER_CORE_H_
+
+#include  "usbd_ioreq.h"
+
+/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
+  * @{
+  */
+
+/** @defgroup usbd_printer
+  * @brief This file is the Header file for USBD_printer.c
+  * @{
+  */
+
+
+/** @defgroup usbd_printer_Exported_Defines
+  * @{
+  */
+#define USB_PRINTER_CONFIG_DESC_SIZ                (32)
+#define USB_PRINTER_DESC_SIZ                       (USB_PRINTER_CONFIG_DESC_SIZ-9)
+
+#define PRINTER_DESCRIPTOR_TYPE                     0x21
+
+#define DEVICE_CLASS_PRINTER                        0x02
+#define DEVICE_SUBCLASS_PRINTER                     0x00
+
+
+#define USB_DEVICE_DESCRIPTOR_TYPE              0x01
+#define USB_CONFIGURATION_DESCRIPTOR_TYPE       0x02
+#define USB_STRING_DESCRIPTOR_TYPE              0x03
+#define USB_INTERFACE_DESCRIPTOR_TYPE           0x04
+#define USB_ENDPOINT_DESCRIPTOR_TYPE            0x05
+
+#define STANDARD_ENDPOINT_DESC_SIZE             0x09
+
+#define PRINTER_DATA_IN_PACKET_SIZE                PRINTER_DATA_MAX_PACKET_SIZE
+
+#define PRINTER_DATA_OUT_PACKET_SIZE               PRINTER_DATA_MAX_PACKET_SIZE
+
+#define PRINTER_APP_RX_DATA_SIZE				   APP_RX_DATA_SIZE
+
+#define PRINTER_APP_TX_DATA_SIZE				   APP_TX_DATA_SIZE
+
+/*---------------------------------------------------------------------*/
+/*  PRINTER definitions                                                    */
+/*---------------------------------------------------------------------*/
+
+/**************************************************/
+/* PRINTER Requests                                   */
+/**************************************************/
+#define SEND_ENCAPSULATED_COMMAND               0x00
+#define GET_ENCAPSULATED_RESPONSE               0x01
+#define SET_COMM_FEATURE                        0x02
+#define GET_COMM_FEATURE                        0x03
+#define CLEAR_COMM_FEATURE                      0x04
+#define SET_LINE_CODING                         0x20
+#define GET_LINE_CODING                         0x21
+#define SET_CONTROL_LINE_STATE                  0x22
+#define SEND_BREAK                              0x23
+#define NO_CMD                                  0xFF
+
+/**
+  * @}
+  */
+
+
+/** @defgroup USBD_CORE_Exported_TypesDefinitions
+  * @{
+  */
+typedef struct _PRINTER_IF_PROP
+{
+  uint16_t (*pIf_Init)     (void);
+  uint16_t (*pIf_DeInit)   (void);
+  uint16_t (*pIf_Ctrl)     (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
+  uint16_t (*pIf_DataTx)   (uint8_t* Buf, uint32_t Len);
+  uint16_t (*pIf_DataRx)   (uint8_t* Buf, uint32_t Len);
+}
+PRINTER_IF_Prop_TypeDef;
+/**
+  * @}
+  */
+struct APP_DATA_STRUCT_DEF
+{
+    /* 閫氳繃PC鎺ユ敹鏁版嵁(灏嗕細閫氳繃涓插彛鍙戝嚭鐨勬暟鎹)淇℃伅 */
+    struct {
+        uint8_t APP_Tx_Buffer[PRINTER_APP_TX_DATA_SIZE];     // 鎺ユ敹鏁版嵁缂撳瓨
+        volatile uint32_t APP_Tx_ptr_in;            // 缂撳瓨鎺ユ敹鏁版嵁璧峰鍋忕Щ鍦板潃
+        volatile uint32_t APP_Tx_ptr_out;           // 缂撳瓨璇诲彇鏁版嵁璧峰鍋忕Щ鍦板潃
+        volatile uint32_t Tx_counter;               // 鍙戦佺紦瀛樼瓑寰呰璇诲彇鐨勬暟鎹釜鏁
+    } tx_structure;
+    /* 閫氳繃涓插彛鎺ユ敹鏁版嵁(灏嗕細閫氳繃USB鍙戦佺粰PC鐨勬暟鎹)淇℃伅 */
+    struct{
+        uint8_t APP_Rx_Buffer[PRINTER_APP_RX_DATA_SIZE];    // 鎺ユ敹鏁版嵁缂撳瓨
+        volatile uint32_t APP_Rx_ptr_in;            // 缂撳瓨鎺ユ敹鏁版嵁璧峰鍋忕Щ鍦板潃
+        volatile uint32_t APP_Rx_ptr_out;           // 缂撳瓨璇诲彇鏁版嵁璧峰鍋忕Щ鍦板潃
+        volatile uint32_t Rx_counter;               // 鎺ユ敹缂撳瓨绛夊緟琚鍙栫殑鏁版嵁涓暟
+    } rx_structure;
+    uint8_t COM_config_cmp; //涓插彛鐘舵(1:涓插彛澶勪簬杩炴帴鐘舵侊紱0锛氫覆鍙ｅ浜庢柇寮鐘舵)
+} ;
+
+
+/** @defgroup USBD_CORE_Exported_Macros
+  * @{
+  */
+
+/**
+  * @}
+  */
+
+/** @defgroup USBD_CORE_Exported_Variables
+  * @{
+  */
+
+extern USBD_Class_cb_TypeDef  USBD_PRINTER_cb;
+/**
+  * @}
+  */
+
+/** @defgroup USB_CORE_Exported_Functions
+  * @{
+  */
+/**
+  * @}
+  */
+
+#endif  // __USB_PRINTER_CORE_H_
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Index: libraries/SCPU_USB_Device_Library/class/PRINTER/usbd_printer_core.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/PRINTER/usbd_printer_core.c	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/PRINTER/usbd_printer_core.c	(working copy)
@@ -0,0 +1,765 @@
+/**
+  ******************************************************************************
+  * @file    usbd_printer_core.c
+  * @author  MCD Application Team
+  * @version V1.1.0
+  * @date    19-March-2012
+  * @brief   This file provides the high layer firmware functions to manage the
+  *          following functionalities of the USB PRINTER Class:
+  *           - Initialization and Configuration of high and low layer
+  *           - Enumeration as PRINTER Device (and enumeration for each implemented memory interface)
+  *           - OUT/IN data transfer
+  *           - Command IN transfer (class requests management)
+  *           - Error management
+  *
+  *  @verbatim
+  *
+  *          ===================================================================
+  *                                PRINTER Class Driver Description
+  *          ===================================================================
+  *           This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
+  *           Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
+  *           Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
+  *           This driver implements the following aspects of the specification:
+  *             - Device descriptor management
+  *             - Configuration descriptor management
+  *             - Enumeration as PRINTER device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
+  *             - Requests management (as described in section 6.2 in specification)
+  *             - Abstract Control Model compliant
+  *             - Union Functional collection (using 1 IN endpoint for control)
+  *             - Data interface class
+
+  *           @note
+  *             For the Abstract Control Model, this core allows only transmitting the requests to
+  *             lower layer dispatcher (ie. usbd_printer_vcp.c/.h) which should manage each request and
+  *             perform relative actions.
+  *
+  *           These aspects may be enriched or modified for a specific user application.
+  *
+  *            This driver doesn't implement the following aspects of the specification
+  *            (but it is possible to manage these features with some modifications on this driver):
+  *             - Any class-specific aspect relative to communication classes should be managed by user application.
+  *             - All communication classes other than PSTN are not managed
+  *
+  *  @endverbatim
+  *
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbd_printer_core.h"
+#include "usbd_desc.h"
+#include "usbd_req.h"
+#include "usbd_usr.h"
+#include "yc_timer.h"
+
+/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
+  * @{
+  */
+
+
+/** @defgroup usbd_printer
+  * @brief usbd core module
+  * @{
+  */
+
+/** @defgroup usbd_printer_Private_TypesDefinitions
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+/** @defgroup usbd_printer_Private_Defines
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+/** @defgroup usbd_printer_Private_Macros
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+/** @defgroup usbd_printer_Private_FunctionPrototypes
+  * @{
+  */
+
+/*********************************************
+   PRINTER Device library callbacks
+ *********************************************/
+static uint8_t  usbd_printer_Init        (void  *pdev, uint8_t cfgidx);
+static uint8_t  usbd_printer_DeInit      (void  *pdev, uint8_t cfgidx);
+static uint8_t  usbd_printer_Setup       (void  *pdev, USB_SETUP_REQ *req);
+static uint8_t  usbd_printer_EP0_RxReady  (void *pdev);
+static uint8_t  usbd_printer_DataIn      (void *pdev, uint8_t epnum);
+static uint8_t  usbd_printer_DataOut     (void *pdev, uint8_t epnum);
+static uint8_t  usbd_printer_SOF         (void *pdev);
+
+/*********************************************
+   PRINTER specific management functions
+ *********************************************/
+static void Handle_USBAsynchXfer  (void *pdev);
+static uint8_t  *USBD_printer_GetCfgDesc (uint8_t speed, uint16_t *length);
+#ifdef USE_USB_OTG_HS
+static uint8_t  *USBD_printer_GetOtherCfgDesc (uint8_t speed, uint16_t *length);
+#endif
+/**
+  * @}
+  */
+
+/** @defgroup usbd_printer_Private_Variables
+  * @{
+  */
+extern PRINTER_IF_Prop_TypeDef  APP_FOPS;
+extern uint8_t USBD_DeviceDesc   [USB_SIZ_DEVICE_DESC];
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+__ALIGN_BEGIN uint8_t usbd_printer_CfgDesc  [USB_PRINTER_CONFIG_DESC_SIZ] __ALIGN_END ;
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+__ALIGN_BEGIN uint8_t usbd_printer_OtherCfgDesc  [USB_PRINTER_CONFIG_DESC_SIZ] __ALIGN_END ;
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+__ALIGN_BEGIN static uint32_t  usbd_printer_AltSet  __ALIGN_END = 0;
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+__ALIGN_BEGIN uint8_t USB_Rx_Buffer   [PRINTER_DATA_MAX_PACKET_SIZE] __ALIGN_END ;
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+
+#ifdef USER_SPECIFIED_DATA_SOURCE
+uint8_t *APP_Rx_Buffer = NULL;
+#else
+//__ALIGN_BEGIN uint8_t APP_Rx_Buffer   [APP_RX_DATA_SIZE] __ALIGN_END ;
+struct APP_DATA_STRUCT_DEF APP_Gdata_param;
+#endif
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+__ALIGN_BEGIN uint8_t CmdBuff[PRINTER_CMD_PACKET_SZE] __ALIGN_END ;
+
+//volatile uint32_t APP_Rx_ptr_in  = 0;
+//volatile uint32_t APP_Rx_ptr_out = 0;
+uint32_t APP_Rx_length  = 0;
+
+uint8_t  USB_Tx_State = 0;
+
+static uint32_t printerCmd = 0xFF;
+static uint32_t printerLen = 0;
+
+/* PRINTER interface class callbacks structure */
+USBD_Class_cb_TypeDef  USBD_PRINTER_cb =
+{
+  usbd_printer_Init,
+  usbd_printer_DeInit,
+  usbd_printer_Setup,
+  NULL,                 /* EP0_TxSent, */
+  usbd_printer_EP0_RxReady,
+  usbd_printer_DataIn,
+  usbd_printer_DataOut,
+  usbd_printer_SOF,
+  NULL,
+  NULL,
+  USBD_printer_GetCfgDesc,
+#ifdef USE_USB_OTG_HS
+  USBD_printer_GetOtherCfgDesc, /* use same cobfig as per FS */
+#endif /* USE_USB_OTG_HS  */
+};
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+/* USB PRINTER device Configuration Descriptor */
+__ALIGN_BEGIN uint8_t usbd_printer_CfgDesc[USB_PRINTER_CONFIG_DESC_SIZ]  __ALIGN_END =
+{
+    /*Configuation Descriptor*/
+    0x09,   /* bLength: Configuation Descriptor size */
+    USB_CONFIGURATION_DESCRIPTOR_TYPE,      /* bDescriptorType: Configuration */
+    USB_PRINTER_CONFIG_DESC_SIZ,       /* wTotalLength:no of returned bytes */
+    0x00,
+
+    0x01,   /* bNumInterfaces: 1 interface */
+
+    0x01,   /* bConfigurationValue: Configuration value */
+    0x00,   /* iConfiguration: Index of string descriptor describing the configuration */
+    0xc0,   /* bmAttributes: self powered */
+    0x32,   /* MaxPower 0 mA */
+    /*Interface Descriptor*/
+    0x09,   /* bLength: Interface Descriptor size */
+    USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: Interface */
+    /* Interface descriptor type */
+    0x00,   /* bInterfaceNumber: Number of Interface */
+    0x00,   /* bAlternateSetting: Alternate setting */
+    0x02,   /* bNumEndpoints: One endpoints used */
+
+    0x07,  //basic class for printer
+    0x01,  //printer calll device
+
+    0x02, // bi-directional interface.
+    0x04,   /* iInterface: */
+
+    /*Endpoint 3 Descriptor*/
+    0x07,   /* bLength: Endpoint Descriptor size */
+    USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
+    PRINTER_OUT_EP,   /* bEndpointAddress: (OUT3) */
+    0x02,   /* bmAttributes: Bulk */
+    0x40,             /* wMaxPacketSize: */
+    0x00,
+    0x00,   /* bInterval: ignore for Bulk transfer */
+    /*Endpoint 1 Descriptor*/
+    0x07,   /* bLength: Endpoint Descriptor size */
+    USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
+    PRINTER_IN_EP,   /* bEndpointAddress: (IN1) */
+    0x02,   /* bmAttributes: Bulk */
+    0x40,             /* wMaxPacketSize: */
+    0x00,
+    0x00    /* bInterval */
+};
+
+/* USB PRINTER device id Descriptor */
+__ALIGN_BEGIN uint8_t print_id_descriptor[] __ALIGN_END =
+{
+0x00,
+0x00,
+'M','A','N','U','F','A','C','T','U','R','E','R',':','Y','I','C','H','I','P',';',
+'C','O','M','M','A','N','D',' ','S','E','T',':','E','S','C','/','P','O','S',';',
+'M','O','D','E','L',':','-','P','r','i','n','t','e','r',' ','d','e','m','o',';',
+'C','O','M','M','E','N','T',':','t','e','s','t',' ','P','r','i','n','t','e','r',';',
+'A','C','T','I','V','E',' ','C','O','M','M','A','N','D',':','E','S','C','/','P','O','S',';'
+};
+
+#ifdef USE_USB_OTG_HS
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+__ALIGN_BEGIN uint8_t usbd_printer_OtherCfgDesc[USB_PRINTER_CONFIG_DESC_SIZ]  __ALIGN_END =
+{
+};
+#endif /* USE_USB_OTG_HS  */
+
+/**
+  * @}
+  */
+
+/** @defgroup usbd_printer_Private_Functions
+  * @{
+  */
+
+/**
+  * @brief  usbd_printer_Init
+  *         Initilaize the PRINTER interface
+  * @param  pdev: device instance
+  * @param  cfgidx: Configuration index
+  * @retval status
+  */
+static uint8_t  usbd_printer_Init (void  *pdev,
+                               uint8_t cfgidx)
+{
+//  uint8_t *pbuf;
+
+  /* Open EP IN */
+  DCD_EP_Open(pdev,
+              PRINTER_IN_EP,
+              PRINTER_DATA_IN_PACKET_SIZE,
+              USB_OTG_EP_BULK);
+
+  /* Open EP OUT */
+  DCD_EP_Open(pdev,
+              PRINTER_OUT_EP,
+              PRINTER_DATA_OUT_PACKET_SIZE,
+              USB_OTG_EP_BULK);
+
+  /* Open Command IN EP */
+  DCD_EP_Open(pdev,
+              PRINTER_CMD_EP,
+              PRINTER_CMD_PACKET_SZE,
+              USB_OTG_EP_INT);
+
+//  pbuf = (uint8_t *)USBD_DeviceDesc;
+//  pbuf[4] = DEVICE_CLASS_PRINTER;
+//  pbuf[5] = DEVICE_SUBCLASS_PRINTER;
+
+  /* Initialize the Interface physical components */
+  APP_FOPS.pIf_Init();
+
+  /* Prepare Out endpoint to receive next packet */
+  DCD_EP_PrepareRx(pdev,
+                   PRINTER_OUT_EP,
+                   (uint8_t*)(USB_Rx_Buffer),
+                   PRINTER_DATA_OUT_PACKET_SIZE);
+
+  return USBD_OK;
+}
+
+/**
+  * @brief  usbd_printer_Init
+  *         DeInitialize the PRINTER layer
+  * @param  pdev: device instance
+  * @param  cfgidx: Configuration index
+  * @retval status
+  */
+static uint8_t  usbd_printer_DeInit (void  *pdev,
+                                 uint8_t cfgidx)
+{
+  /* Open EP IN */
+  DCD_EP_Close(pdev,
+              PRINTER_IN_EP);
+
+  /* Open EP OUT */
+  DCD_EP_Close(pdev,
+              PRINTER_OUT_EP);
+
+  /* Open Command IN EP */
+  DCD_EP_Close(pdev,
+              PRINTER_CMD_EP);
+
+  /* Restore default state of the Interface physical components */
+  APP_FOPS.pIf_DeInit();
+
+  return USBD_OK;
+}
+
+/**
+  * @brief  usbd_printer_Setup
+  *         Handle the PRINTER specific requests
+  * @param  pdev: instance
+  * @param  req: usb requests
+  * @retval status
+  */
+static uint8_t  usbd_printer_Setup (void  *pdev,
+                                USB_SETUP_REQ *req)
+{
+  uint16_t len=USB_PRINTER_DESC_SIZ;
+  uint8_t  *pbuf=usbd_printer_CfgDesc + 9;
+
+  switch (req->bmRequest & USB_REQ_TYPE_MASK)
+  {
+    /* PRINTER Class Requests -------------------------------*/
+  case USB_REQ_TYPE_CLASS :
+      /* Check if the request is a data setup packet */
+      if (req->wLength)
+      {
+        /* Check if the request is Device-to-Host */
+        if (req->bmRequest & 0x80)
+        {
+          /* Get the data to be sent to Host from interface layer */
+          //APP_FOPS.pIf_Ctrl(req->bRequest, CmdBuff, req->wLength);
+
+          /* Send the data to the host */
+          print_id_descriptor[0]=sizeof(print_id_descriptor)>>8;
+          print_id_descriptor[1]=sizeof(print_id_descriptor);
+          USBD_CtlSendData (pdev,
+                            print_id_descriptor,
+                            sizeof(print_id_descriptor));
+        }
+        else /* Host-to-Device requeset */
+        {
+          /* Set the value of the current command to be processed */
+          printerCmd = req->bRequest;
+          printerLen = req->wLength;
+
+          /* Prepare the reception of the buffer over EP0
+          Next step: the received data will be managed in usbd_printer_EP0_TxSent()
+          function. */
+     //     MyPrintf("printer class \n\r");
+          USBD_CtlPrepareRx (pdev,
+                             CmdBuff,
+                             req->wLength);
+          APP_FOPS.pIf_Ctrl(req->bRequest, CmdBuff, req->wLength);
+          if(req->wLength != 0)
+          {
+          	USBD_CtlSendStatus(pdev);
+          }
+        }
+      }
+      else /* No Data request */
+      {
+            /* Transfer the command to the interface layer */
+            APP_FOPS.pIf_Ctrl(req->bRequest, NULL, 0);
+      }
+
+      return USBD_OK;
+
+    default:
+      USBD_CtlError (pdev, req);
+      return USBD_FAIL;
+
+
+
+    /* Standard Requests -------------------------------*/
+  case USB_REQ_TYPE_STANDARD:
+    switch (req->bRequest)
+    {
+    case USB_REQ_GET_DESCRIPTOR:
+      if( (req->wValue >> 8) == PRINTER_DESCRIPTOR_TYPE)
+      {
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+        pbuf = usbd_printer_Desc;
+#else
+        pbuf = usbd_printer_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM);
+#endif
+        len = MIN(USB_PRINTER_DESC_SIZ , req->wLength);
+      }
+
+      USBD_CtlSendData (pdev,
+                        pbuf,
+                        len);
+      break;
+
+    case USB_REQ_GET_INTERFACE :
+      USBD_CtlSendData (pdev,
+                        (uint8_t *)&usbd_printer_AltSet,
+                        1);
+      break;
+
+    case USB_REQ_SET_INTERFACE :
+      if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM)
+      {
+        usbd_printer_AltSet = (uint8_t)(req->wValue);
+      }
+      else
+      {
+        /* Call the error management function (command will be nacked */
+        USBD_CtlError (pdev, req);
+      }
+      break;
+    }
+  }
+  return USBD_OK;
+}
+
+/**
+  * @brief  usbd_printer_EP0_RxReady
+  *         Data received on control endpoint
+  * @param  pdev: device device instance
+  * @retval status
+  */
+static uint8_t  usbd_printer_EP0_RxReady (void  *pdev)
+{
+  if (printerCmd != NO_CMD)
+  {
+    /* Process the data */
+    APP_FOPS.pIf_Ctrl(printerCmd, CmdBuff, printerLen);
+
+    /* Reset the command variable to default value */
+    printerCmd = NO_CMD;
+  }
+
+  return USBD_OK;
+}
+
+/**
+  * @brief  usbd_audio_DataIn
+  *         Data sent on non-control IN endpoint
+  * @param  pdev: device instance
+  * @param  epnum: endpoint number
+  * @retval status
+  */
+static uint8_t  usbd_printer_DataIn (void *pdev, uint8_t epnum)
+{
+  uint16_t USB_Tx_ptr;
+  uint16_t USB_Tx_length = 0;
+
+  if (USB_Tx_State == 1)
+  {
+    if (APP_Rx_length == 0)
+    {
+      USB_Tx_State = 0;
+    }
+    else
+    {
+        if (APP_Rx_length > PRINTER_DATA_IN_PACKET_SIZE)
+        {
+            USB_Tx_ptr = APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+            if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out + PRINTER_DATA_IN_PACKET_SIZE >= APP_RX_DATA_SIZE)
+            {
+                USB_Tx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+                APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;
+                APP_Rx_length -= USB_Tx_length;
+                APP_Gdata_param.rx_structure.Rx_counter -= USB_Tx_length;
+            }else{
+                USB_Tx_length = PRINTER_DATA_IN_PACKET_SIZE;
+                APP_Gdata_param.rx_structure.APP_Rx_ptr_out += PRINTER_DATA_IN_PACKET_SIZE;
+                APP_Rx_length -= PRINTER_DATA_IN_PACKET_SIZE;
+                APP_Gdata_param.rx_structure.Rx_counter -= PRINTER_DATA_IN_PACKET_SIZE;
+            }
+        }
+        else
+        {
+            USB_Tx_ptr = APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+            if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out + APP_Rx_length >= APP_RX_DATA_SIZE)
+            {
+                USB_Tx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+                APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;
+                APP_Rx_length -= USB_Tx_length;
+                APP_Gdata_param.rx_structure.Rx_counter -= USB_Tx_length;
+            }else{
+                USB_Tx_length = APP_Rx_length;
+                APP_Gdata_param.rx_structure.APP_Rx_ptr_out += APP_Rx_length;
+				APP_Gdata_param.rx_structure.Rx_counter -= APP_Rx_length;
+                APP_Rx_length = 0;
+            }
+        }
+	}
+	/* Prepare the available data buffer to be sent on IN endpoint */
+
+	DCD_EP_Tx(pdev,
+			  PRINTER_IN_EP,
+			  (uint8_t*)&APP_Gdata_param.rx_structure.APP_Rx_Buffer[USB_Tx_ptr],
+			  USB_Tx_length);
+  }
+
+  return USBD_OK;
+}
+
+/**
+  * @brief  usbd_printer_DataOut
+  *         Data received on non-control Out endpoint
+  * @param  pdev: device instance
+  * @param  epnum: endpoint number
+  * @retval status
+  */
+#define wAIT_TIMES  20  //wAIT_TIMES*50us
+extern uint8_t usbFlowCtrl;
+static uint8_t  usbd_printer_DataOut (void *pdev, uint8_t epnum)
+{
+  uint16_t USB_Rx_Cnt;
+
+  /* Get the received data buffer and update the counter */
+
+  /* USB data will be immediately processed, this allow next USB traffic being
+     NAKed till the end of the application Xfer */
+  /* Prepare Out endpoint to receive next packet */
+  DCD_EP_PrepareRx(pdev,
+                   PRINTER_OUT_EP,
+                   (uint8_t*)(USB_Rx_Buffer),
+                   PRINTER_DATA_OUT_PACKET_SIZE);
+    USB_Rx_Cnt = ((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].xfer_count;
+    APP_FOPS.pIf_DataRx(USB_Rx_Buffer, USB_Rx_Cnt);
+    if(USB_Rx_Cnt==((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].maxpacket && usbFlowCtrl==0)
+    {
+        int wait_times=0;
+        while(wait_times<wAIT_TIMES)
+        {
+            if(USB_OTG_READ_REG8(((USB_OTG_CORE_HANDLE*)pdev)->regs.LENREGS[epnum])>=((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].maxpacket)
+            {
+                break;
+            }
+            delay_us(50);
+            wait_times++;
+        }
+        usbd_printer_DataOut(pdev,epnum);
+    }
+	return USBD_OK;
+}
+
+/**
+  * @brief  usbd_audio_SOF
+  *         Start Of Frame event management
+  * @param  pdev: instance
+  * @param  epnum: endpoint number
+  * @retval status
+  */
+static uint8_t  usbd_printer_SOF (void *pdev)
+{
+  static uint32_t FrameCount = 0;
+
+  if (FrameCount++ == PRINTER_IN_FRAME_INTERVAL)
+  {
+    /* Reset the frame counter */
+    FrameCount = 0;
+
+    /* Check the data to be sent through IN pipe */
+    Handle_USBAsynchXfer(pdev);
+  }
+
+  return USBD_OK;
+}
+
+/**
+  * @brief  Handle_USBAsynchXfer
+  *         Send data to USB
+  * @param  pdev: instance
+  * @retval None
+  */
+static void Handle_USBAsynchXfer (void *pdev)
+{
+  uint16_t USB_Tx_ptr;
+  uint16_t USB_Tx_length;
+
+  if(USB_Tx_State != 1)
+  {
+    if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out == PRINTER_APP_RX_DATA_SIZE)
+    {
+      APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;
+    }
+	#if 1
+	if (!APP_Gdata_param.rx_structure.Rx_counter)
+	{
+		USB_Tx_State = 0;
+        return;
+	}
+	APP_Rx_length = APP_Gdata_param.rx_structure.Rx_counter;
+	#else
+    /* */
+//    if (!APP_Gdata_param.rx_structure.Rx_counter)
+	if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out == \
+		APP_Gdata_param.rx_structure.APP_Rx_ptr_in)
+    {
+        USB_Tx_State = 0;
+        return;
+    }
+//    APP_Rx_length = APP_Gdata_param.rx_structure.Rx_counter;
+//	APP_Rx_length = APP_Gdata_param.rx_structure.APP_Rx_ptr_in - \
+//					APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+//    if(APP_Gdata_param.rx_structure.APP_Rx_ptr_out == APP_Gdata_param.rx_structure.APP_Rx_ptr_in)
+//    {
+//      USB_Tx_State = 0;
+//      return;
+//    }
+
+    if(APP_Gdata_param.rx_structure.APP_Rx_ptr_out > APP_Gdata_param.rx_structure.APP_Rx_ptr_in) /* rollback */
+    {
+      APP_Rx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+    }
+    else
+    {
+      APP_Rx_length = APP_Gdata_param.rx_structure.APP_Rx_ptr_in - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+    }
+	#endif
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+     APP_Rx_length &= ~0x03;
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+
+    if (APP_Rx_length > PRINTER_DATA_IN_PACKET_SIZE)
+    {
+        USB_Tx_ptr = APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+        if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out + PRINTER_DATA_IN_PACKET_SIZE >= PRINTER_APP_RX_DATA_SIZE)
+        {
+            USB_Tx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+            APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;
+            APP_Rx_length -= USB_Tx_length;
+            APP_Gdata_param.rx_structure.Rx_counter = APP_Rx_length;
+        }else{
+            USB_Tx_length = PRINTER_DATA_IN_PACKET_SIZE;
+            APP_Gdata_param.rx_structure.APP_Rx_ptr_out += PRINTER_DATA_IN_PACKET_SIZE;
+            APP_Rx_length -= PRINTER_DATA_IN_PACKET_SIZE;
+            APP_Gdata_param.rx_structure.Rx_counter = APP_Rx_length;
+        }
+    }
+    else
+    {
+        USB_Tx_ptr = APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+        if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out + APP_Rx_length >= PRINTER_APP_RX_DATA_SIZE)
+        {
+            USB_Tx_length = APP_RX_DATA_SIZE - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+            APP_Gdata_param.rx_structure.APP_Rx_ptr_out = 0;
+            APP_Rx_length -= USB_Tx_length;
+            APP_Gdata_param.rx_structure.Rx_counter = APP_Rx_length;
+        }else{
+            USB_Tx_length = APP_Rx_length;
+            APP_Gdata_param.rx_structure.APP_Rx_ptr_out += APP_Rx_length;
+            APP_Rx_length = 0;
+            APP_Gdata_param.rx_structure.Rx_counter = APP_Rx_length;
+        }
+    }
+    USB_Tx_State = 1;
+
+    DCD_EP_Tx (pdev,
+               PRINTER_IN_EP,
+               (uint8_t*)&APP_Gdata_param.rx_structure.APP_Rx_Buffer[USB_Tx_ptr],
+               USB_Tx_length);
+  }
+}
+
+/**
+  * @brief  USBD_printer_GetCfgDesc
+  *         Return configuration descriptor
+  * @param  speed : current device speed
+  * @param  length : pointer data length
+  * @retval pointer to descriptor buffer
+  */
+static uint8_t  *USBD_printer_GetCfgDesc (uint8_t speed, uint16_t *length)
+{
+  *length = sizeof (usbd_printer_CfgDesc);
+  return usbd_printer_CfgDesc;
+}
+
+/**
+  * @brief  USBD_printer_GetCfgDesc
+  *         Return configuration descriptor
+  * @param  speed : current device speed
+  * @param  length : pointer data length
+  * @retval pointer to descriptor buffer
+  */
+#ifdef USE_USB_OTG_HS
+static uint8_t  *USBD_printer_GetOtherCfgDesc (uint8_t speed, uint16_t *length)
+{
+  *length = sizeof (usbd_printer_OtherCfgDesc);
+  return usbd_printer_OtherCfgDesc;
+}
+#endif
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Index: libraries/SCPU_USB_Device_Library/class/ccid/usbd_ccid_core.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/ccid/usbd_ccid_core.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/ccid/usbd_ccid_core.c	(working copy)
@@ -7,15 +7,15 @@
   * @brief   This file provides all the CCID core functions.
   *
   * @verbatim
-  *      
-  *          ===================================================================      
+  *
+  *          ===================================================================
   *                                CCID Class  Description
-  *          =================================================================== 
-  *           This module manages the Specification for Integrated Circuit(s) 
+  *          ===================================================================
+  *           This module manages the Specification for Integrated Circuit(s)
   *             Cards Interface Revision 1.1
   *           This driver implements the following aspects of the specification:
-  *             - Bulk Transfers 
-  *      
+  *             - Bulk Transfers
+  *
   *  @endverbatim
   *
   ******************************************************************************
@@ -29,8 +29,8 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
@@ -120,29 +120,29 @@
                                       04h 1.8V*/
 
     0x01, 0x00, 0x00, 0x00,  /* dwProtocols: 0001h = Protocol T=0 */
-    0x10, 0x0E, 0x00, 0x00,  /* dwDefaultClock: 3.6Mhz = 3600kHz = 0x0E10, 
-                                  for 4 Mhz the value is (0x00000FA0) : 
+    0x10, 0x0E, 0x00, 0x00,  /* dwDefaultClock: 3.6Mhz = 3600kHz = 0x0E10,
+                                  for 4 Mhz the value is (0x00000FA0) :
                                  This is used in ETU and waiting time calculations*/
-    0x10, 0x0E, 0x00, 0x00,  /* dwMaximumClock: Maximum supported ICC clock frequency 
-                                  in KHz. So, 3.6Mhz = 3600kHz = 0x0E10, 
+    0x10, 0x0E, 0x00, 0x00,  /* dwMaximumClock: Maximum supported ICC clock frequency
+                                  in KHz. So, 3.6Mhz = 3600kHz = 0x0E10,
                                                 4 Mhz (0x00000FA0) : */
-    0x00,         /* bNumClockSupported : no setting from PC 
-                               If the value is 00h, the 
-                              supported clock frequencies are assumed to be the 
-                              default clock frequency defined by dwDefaultClock 
-                              and the maximum clock frequency defined by 
+    0x00,         /* bNumClockSupported : no setting from PC
+                               If the value is 00h, the
+                              supported clock frequencies are assumed to be the
+                              default clock frequency defined by dwDefaultClock
+                              and the maximum clock frequency defined by
                               dwMaximumClock */
 
     0xCD, 0x25, 0x00, 0x00,  /* dwDataRate: Default ICC I/O data rate in bps
-                                 9677 bps = 0x25CD 
+                                 9677 bps = 0x25CD
                                  for example 10752 bps (0x00002A00) */
 
-    0xCD, 0x25, 0x00, 0x00,  /* dwMaxDataRate: Maximum supported ICC I/O data 
+    0xCD, 0x25, 0x00, 0x00,  /* dwMaxDataRate: Maximum supported ICC I/O data
                                  rate in bps */
     0x00,                 /* bNumDataRatesSupported :
                            The number of data rates that are supported by the CCID
-                           If the value is 00h, all data rates between the default 
-                           data rate dwDataRate and the maximum data rate 
+                           If the value is 00h, all data rates between the default
+                           data rate dwDataRate and the maximum data rate
                            dwMaxDataRate are supported.
                            Dont support GET_CLOCK_FREQUENCIES
                           */
@@ -153,18 +153,18 @@
 
     0x38, 0x00, EXCHANGE_LEVEL_FEATURE, 0x00,
     /* dwFeatures: clk, baud rate, voltage : automatic */
-    /* 00000008h Automatic ICC voltage selection 
+    /* 00000008h Automatic ICC voltage selection
     00000010h Automatic ICC clock frequency change
-    00000020h Automatic baud rate change according to 
-    active parameters provided by the Host or self 
-    determined 00000100h CCID can set 
-    ICC in clock stop mode      
-    
-    Only one of the following values may be present to 
+    00000020h Automatic baud rate change according to
+    active parameters provided by the Host or self
+    determined 00000100h CCID can set
+    ICC in clock stop mode
+
+    Only one of the following values may be present to
     select a level of exchange:
     00010000h TPDU level exchanges with CCID
     00020000h Short APDU level exchange with CCID
-    00040000h Short and Extended APDU level exchange 
+    00040000h Short and Extended APDU level exchange
     If none of those values : character level of exchange*/
     0x0F, 0x01, 0x00, 0x00,  /* dwMaxCCIDMessageLength: Maximum block size + header*/
     /* 261 + 10   */
@@ -206,7 +206,7 @@
 
 /**
   * @brief  USBD_CCID_Init
-  *         Initialize  the USB CCID Interface 
+  *         Initialize  the USB CCID Interface
   * @param  pdev: device instance
   * @param  cfgidx: configuration index
   * @retval status
@@ -289,13 +289,13 @@
                 ((req->bmRequest & 0x80) != 0x80))
             { /* Check bmRequest : No Data-In stage. 0x80 is Data Direction */
 
-                /* The wValue field contains the slot number (bSlot) in the low byte 
+                /* The wValue field contains the slot number (bSlot) in the low byte
                 and the sequence number (bSeq) in the high byte.*/
                 slot_nb = (uint8_t)((req->wValue) & 0x00ff);
                 seq_nb = (uint8_t)(((req->wValue) & 0xff00) >> 8);
 
                 if (CCID_CmdAbort(slot_nb, seq_nb) != 0)
-                { /* If error is returned by lower layer : 
+                { /* If error is returned by lower layer :
                        Generally Slot# may not have matched */
                     USBD_CtlError(pdev, req);
                     return USBD_FAIL;
@@ -443,7 +443,7 @@
                                  uint8_t epnum)
 {
 
-			MyPrintf("333333\n");
+//			MyPrintf("333333\n");
 
     DCD_EP_PrepareRx(pdev,
                                      CCID_BULK_OUT_EP,
@@ -454,7 +454,7 @@
 }
 
 /**
-  * @brief  USBD_CCID_GetCfgDesc 
+  * @brief  USBD_CCID_GetCfgDesc
   *         return configuration descriptor
   * @param  speed : current device speed
   * @param  length : pointer data length
Index: libraries/SCPU_USB_Device_Library/class/ccid/usbd_ccid_if.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/ccid/usbd_ccid_if.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/class/ccid/usbd_ccid_if.c	(working copy)
@@ -4,7 +4,7 @@
   * @author  MCD Application Team
   * @version V1.0.1
   * @date    31-January-2014
-  * @brief   This file provides all the functions for USB Interface for CCID 
+  * @brief   This file provides all the functions for USB Interface for CCID
   ******************************************************************************
   * @attention
   *
@@ -16,8 +16,8 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
@@ -96,7 +96,7 @@
 
 /**
   * @brief  CCID_Message_In
-  *         Handle Bulk IN & Intr IN data stage 
+  *         Handle Bulk IN & Intr IN data stage
   * @param  pdev: device instance
   * @param  uint8_t epnum: endpoint index
   * @retval None
@@ -138,22 +138,21 @@
 }
 
 
-#define CCID_DATA_TIMEOUT	(CPU_MHZ/100)	//10ms
-uint32_t ccid_wait_data_times; 
-uint32_t ccid_wait_data_time; 
+#define CCID_DATA_TIMEOUT	(20)	//CCID_DATA_TIMEOUT*50us
+uint32_t ccid_wait_data_time;
 uint32_t ccid_wait_data_len;
 void CCID_wait_next_packet(USB_OTG_CORE_HANDLE *pdev,uint8_t epnum)
 {
-	ccid_wait_data_times=CCID_DATA_TIMEOUT;//直接用宏定义的话，因为每次算除法，时间变大1000倍
-	ccid_wait_data_time=0;	
-	while(ccid_wait_data_time<ccid_wait_data_times)
+	ccid_wait_data_time=0;
+	while(ccid_wait_data_time<CCID_DATA_TIMEOUT)
 	{
-		ccid_wait_data_len = USB_OTG_READ_REG8(pdev->regs.LENREGS[epnum]); 
+		ccid_wait_data_len = USB_OTG_READ_REG8(pdev->regs.LENREGS[epnum]);
 		if(ccid_wait_data_len>=CCID_BULK_EPOUT_SIZE ||\
 			 ((UsbMessageLength+ccid_wait_data_len) == (Ccid_bulkout_data.dwLength + CCID_CMD_HEADER_SIZE)))
 		{
 			break;
 		}
+        ((void(*)(int))(FUNC_DELAY_US_ADDR))(50);
 		ccid_wait_data_time++;
 	}
 }
@@ -170,11 +169,9 @@
 void CCID_BulkMessage_Out(USB_OTG_CORE_HANDLE *pdev,
                           uint8_t epnum)
 {
-		
-    uint16_t dataLen;			
+
+    uint16_t dataLen;
     dataLen = USBD_GetRxCount(pdev, CCID_BULK_OUT_EP);
-    MyPrintf("Len = %d\r\n", dataLen);
-    MyPrintf("state = %d\r\n", Ccid_BulkState);
     switch (Ccid_BulkState)
     {
     case CCID_STATE_IDLE:
@@ -195,8 +192,8 @@
 
             /*
             Refer : 6 CCID Messages
-            The response messages always contain the exact same slot number, 
-            and sequence number fields from the header that was contained in 
+            The response messages always contain the exact same slot number,
+            and sequence number fields from the header that was contained in
             the Bulk-OUT command message.
             */
             Ccid_bulkin_data.bSlot = Ccid_bulkout_data.bSlot;
@@ -204,7 +201,7 @@
 
             if (dataLen < CCID_BULK_EPOUT_SIZE)
             { /* Short message, less than the EP Out Size, execute the command,
-               if parameter like dwLength is too big, the appropriate command will 
+               if parameter like dwLength is too big, the appropriate command will
                give an error */
                 //MyPrintf("> Enter CCID_CmdDecode\r\n");
                 CCID_CmdDecode(pdev);
@@ -233,7 +230,7 @@
 
 									//delay_us(300);
 									CCID_wait_next_packet(pdev,CCID_BULK_OUT_EP);
-									
+
 									USBD_CCID_DataOut(pdev,epnum);
 
                 } /* if (dataLen == CCID_BULK_EPOUT_SIZE) ends */
@@ -244,21 +241,21 @@
     case CCID_STATE_RECEIVE_DATA:
 
         UsbMessageLength += dataLen;
-        
+
         if (dataLen < CCID_BULK_EPOUT_SIZE)
         { /* Short message, less than the EP Out Size, execute the command,
-             if parameter like dwLength is too big, the appropriate command will 
+             if parameter like dwLength is too big, the appropriate command will
              give an error */
 
             /* Full command is received, process the Command */
-            
+
             CCID_ReceiveCmdHeader(pUsbMessageBuffer, dataLen);
             CCID_CmdDecode(pdev);
             Ccid_BulkState = CCID_STATE_IDLE;
         }
         else if (dataLen == CCID_BULK_EPOUT_SIZE)
         {
-            
+
             if (UsbMessageLength < (Ccid_bulkout_data.dwLength + CCID_CMD_HEADER_SIZE))
             {
                 CCID_ReceiveCmdHeader(pUsbMessageBuffer, dataLen); /* Copy data */
@@ -272,7 +269,7 @@
 //                                 CCID_BULK_EPOUT_SIZE);
 								//delay_us(300);
 								CCID_wait_next_packet(pdev,CCID_BULK_OUT_EP);
-								
+
 								USBD_CCID_DataOut(pdev,epnum);
             }
             else if (UsbMessageLength == (Ccid_bulkout_data.dwLength + CCID_CMD_HEADER_SIZE))
@@ -419,7 +416,7 @@
 
 /**
   * @brief  CCID_Response_SendData
-  *         Send the data on bulk-in EP 
+  *         Send the data on bulk-in EP
   * @param  pdev: device instance
   * @param  uint8_t* buf: pointer to data buffer
   * @param  uint16_t len: Data Length
@@ -455,7 +452,7 @@
 
 /**
   * @brief  CCID_ReceiveCmdHeader
-  *         Receive the Data from USB BulkOut Buffer to Pointer 
+  *         Receive the Data from USB BulkOut Buffer to Pointer
   * @param  uint8_t* pDst: destination address to copy the buffer
   * @param  uint8_t u8length: length of data to copy
   * @retval None
@@ -474,7 +471,7 @@
 /**
   * @brief  CCID_IsIntrTransferComplete
   *         Provides the status of previous Interrupt transfer status
-  * @param  None 
+  * @param  None
   * @retval uint8_t PrevXferComplete_IntrIn: Value of the previous transfer status
   */
 uint8_t CCID_IsIntrTransferComplete(void)
@@ -484,9 +481,9 @@
 
 /**
   * @brief  CCID_IsIntrTransferComplete
-  *         Set the value of the Interrupt transfer status 
+  *         Set the value of the Interrupt transfer status
   * @param  uint8_t xfer_Status: Value of the Interrupt transfer status to set
-  * @retval None 
+  * @retval None
   */
 void CCID_SetIntrTransferStatus(uint8_t xfer_Status)
 {
Index: libraries/SCPU_USB_Device_Library/core/usbd_core.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/core/usbd_core.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/core/usbd_core.c	(working copy)
@@ -5,7 +5,7 @@
  * Date                 : 21-May-2019
  * Description          : Peripheral Device Interface low layer.
  *****************************************************************************/
- 
+
 /* Include ------------------------------------------------------------------*/
 #include "usbd_core.h"
 #include "usbd_req.h"
@@ -13,10 +13,10 @@
 #include "usb_dcd_int.h"
 #include "usb_bsp.h"
 /* Private typedef ----------------------------------------------------------*/
-/* Private define -----------------------------------------------------------*/	
-/* Private macro ------------------------------------------------------------*/	
-/* Private variables --------------------------------------------------------*/	
-/* Ptivate function prototypes ----------------------------------------------*/	
+/* Private define -----------------------------------------------------------*/
+/* Private macro ------------------------------------------------------------*/
+/* Private variables --------------------------------------------------------*/
+/* Ptivate function prototypes ----------------------------------------------*/
 
 /******************************************************************************
 * Function Name  :
@@ -31,7 +31,7 @@
 
 /** @defgroup USBD_CORE_Private_FunctionPrototypes
 * @{
-*/ 
+*/
 static uint8_t USBD_SetupStage(USB_OTG_CORE_HANDLE *pdev);
 static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum);
 static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum);
@@ -48,11 +48,11 @@
 static uint8_t  USBD_RunTestMode (USB_OTG_CORE_HANDLE  *pdev) ;
 /**
 * @}
-*/ 
+*/
 
 
 
-USBD_DCD_INT_cb_TypeDef USBD_DCD_INT_cb = 
+USBD_DCD_INT_cb_TypeDef USBD_DCD_INT_cb =
 {
     USBD_DataOutStage,
     USBD_DataInStage,
@@ -64,16 +64,16 @@
     USBD_IsoINIncomplete,
     USBD_IsoOUTIncomplete,
 #ifdef VBUS_SENSING_ENABLED
-    USBD_DevConnected, 
-    USBD_DevDisconnected,    
-#endif  
+    USBD_DevConnected,
+    USBD_DevDisconnected,
+#endif
 };
 
 USBD_DCD_INT_cb_TypeDef  *USBD_DCD_INT_fops = &USBD_DCD_INT_cb;
 
 
 /**
-* @brief  USBD_SetupStage 
+* @brief  USBD_SetupStage
 *         Handle the setup stage
 * @param  pdev: device instance
 * @retval status
@@ -84,10 +84,10 @@
 //    USB_OTG_CSR0L_IN_PERIPHERAL_TypeDef csr0l;
 //    csr0l.d8 = USB_OTG_READ_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L);
     USBD_ParseSetupRequest(pdev , &req);
- 
-    switch (req.bmRequest & 0x1F) 
+
+    switch (req.bmRequest & 0x1F)
     {
-    case USB_REQ_RECIPIENT_DEVICE:	
+    case USB_REQ_RECIPIENT_DEVICE:
         USBD_StdDevReq(pdev, &req);
         break;
 
@@ -95,17 +95,17 @@
         USBD_StdItfReq(pdev, &req);
         break;
 
-    case USB_REQ_RECIPIENT_ENDPOINT:  
-        USBD_StdEPReq(pdev, &req);   
+    case USB_REQ_RECIPIENT_ENDPOINT:
+        USBD_StdEPReq(pdev, &req);
         break;
 
-    default:      
+    default:
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        csr0l.b.data_end = 1;
 //        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
         DCD_EP_Stall(pdev , req.bmRequest & 0x80);
         break;
-    }  
+    }
     return USBD_OK;
 }
 
@@ -113,7 +113,7 @@
 
 
 /**
-* @brief  USBD_DataOutStage 
+* @brief  USBD_DataOutStage
 *         Handle data out stage
 * @param  pdev: device instance
 * @param  epnum: endpoint index
@@ -123,7 +123,7 @@
 {
     USB_OTG_EP *ep;
 
-    if(epnum == 0) 
+    if(epnum == 0)
     {
         ep = &pdev->dev.out_ep[0];
         if ( pdev->dev.device_state == USB_OTG_EP0_DATA_OUT)
@@ -135,9 +135,9 @@
                 if(pdev->cfg.dma_enable == 1)
                 {
                     /* in slave mode this, is handled by the RxSTSQLvl ISR */
-                    ep->xfer_buff += ep->maxpacket; 
-                }        
-                USBD_CtlContinueRx (pdev, 
+                    ep->xfer_buff += ep->maxpacket;
+                }
+                USBD_CtlContinueRx (pdev,
                                     ep->xfer_buff,
                                     MIN(ep->rem_data_len ,ep->maxpacket));
             }
@@ -146,7 +146,7 @@
                 if((pdev->dev.class_cb->EP0_RxReady != NULL)&&
                    (pdev->dev.device_status == USB_OTG_CONFIGURED))
                 {
-                    pdev->dev.class_cb->EP0_RxReady(pdev); 
+                    pdev->dev.class_cb->EP0_RxReady(pdev);
                 }
                 USBD_CtlSendStatus(pdev);
             }
@@ -155,15 +155,15 @@
     else if((pdev->dev.class_cb->DataOut != NULL)&&
             (pdev->dev.device_status == USB_OTG_CONFIGURED))
     {
-        
-        pdev->dev.class_cb->DataOut(pdev, epnum); 
-    }  
+
+        pdev->dev.class_cb->DataOut(pdev, epnum);
+    }
     return USBD_OK;
 }
 
 
 /**
-* @brief  USBD_DataInStage 
+* @brief  USBD_DataInStage
 *         Handle data in stage
 * @param  pdev: device instance
 * @param  epnum: endpoint index
@@ -173,7 +173,7 @@
 {
     USB_OTG_EP *ep;
 
-    if (epnum == 0) 
+    if (epnum == 0)
     {
 //        ep = &pdev->dev.in_ep[0];
 //        if ( pdev->dev.device_state == USB_OTG_EP0_DATA_IN)
@@ -186,8 +186,8 @@
 //                    /* in slave mode this, is handled by the TxFifoEmpty ISR */
 //                    ep->xfer_buff += ep->maxpacket;
 //                }
-//                USBD_CtlContinueSendData (pdev, 
-//                                          ep->xfer_buff, 
+//                USBD_CtlContinueSendData (pdev,
+//                                          ep->xfer_buff,
 //                                          ep->rem_data_len);
 //            }
 //            else
@@ -205,23 +205,23 @@
 //                    if ((pdev->dev.class_cb->EP0_TxSent != NULL)&&
 //                        (pdev->dev.device_status == USB_OTG_CONFIGURED))
 //                    {
-//                        pdev->dev.class_cb->EP0_TxSent(pdev); 
-//                    }          
+//                        pdev->dev.class_cb->EP0_TxSent(pdev);
+//                    }
 //                    USBD_CtlReceiveStatus(pdev);
 //                }
 //            }
 //        }
 //        if (pdev->dev.test_mode == 1)
 //        {
-//            USBD_RunTestMode(pdev); 
+//            USBD_RunTestMode(pdev);
 //            pdev->dev.test_mode = 0;
 //        }
     }
-    else if ((pdev->dev.class_cb->DataIn != NULL)&& 
+    else if ((pdev->dev.class_cb->DataIn != NULL)&&
              (pdev->dev.device_status == USB_OTG_CONFIGURED))
     {
-        pdev->dev.class_cb->DataIn(pdev, epnum); 
-    }  
+        pdev->dev.class_cb->DataIn(pdev, epnum);
+    }
     return USBD_OK;
 }
 
@@ -229,8 +229,8 @@
 
 void USBD_Init(USB_OTG_CORE_HANDLE *pdev,
                USB_OTG_CORE_ID_TypeDef coreID,
-               USBD_DEVICE *pDevice,                  
-               USBD_Class_cb_TypeDef *class_cb, 
+               USBD_DEVICE *pDevice,
+               USBD_Class_cb_TypeDef *class_cb,
                USBD_Usr_cb_TypeDef *usr_cb)
 {
 
@@ -239,8 +239,8 @@
 
         /*Register class and user callbacks */
        pdev->dev.class_cb = class_cb;
-       pdev->dev.usr_cb = usr_cb;  
-       pdev->dev.usr_device = pDevice;    
+       pdev->dev.usr_cb = usr_cb;
+       pdev->dev.usr_device = pDevice;
 
        /* set USB OTG core params */
        DCD_Init(pdev, coreID);
@@ -255,7 +255,7 @@
 
 
 /**
-* @brief  USBD_DeInit 
+* @brief  USBD_DeInit
 *         Re-Initialize th device library
 * @param  pdev: device instance
 * @retval status: status
@@ -270,6 +270,7 @@
 
 static uint8_t USBD_Reset(USB_OTG_CORE_HANDLE  *pdev)
 {
+    #if 0
     /* Open EP0 OUT */
     DCD_EP_Open(pdev,
                 0x00,
@@ -281,7 +282,7 @@
                 0x80,
                 USB_OTG_MAX_EP0_SIZE,
                 EP_TYPE_CTRL);
-
+    #endif
     /* Upon Reset call usr call back */
     pdev->dev.device_status = USB_OTG_DEFAULT;
     pdev->dev.usr_cb->DeviceReset(pdev->cfg.speed);
@@ -290,7 +291,7 @@
 }
 
 /**
-* @brief  USBD_Resume 
+* @brief  USBD_Resume
 *         Handle Resume event
 * @param  pdev: device instance
 * @retval status
@@ -299,15 +300,15 @@
 static uint8_t USBD_Resume(USB_OTG_CORE_HANDLE  *pdev)
 {
     /* Upon Resume call usr call back */
-    pdev->dev.usr_cb->DeviceResumed(); 
-    pdev->dev.device_status = pdev->dev.device_old_status;  
-    pdev->dev.device_status = USB_OTG_CONFIGURED;  
+    pdev->dev.usr_cb->DeviceResumed();
+    pdev->dev.device_status = pdev->dev.device_old_status;
+    pdev->dev.device_status = USB_OTG_CONFIGURED;
     return USBD_OK;
 }
 
 
 /**
-* @brief  USBD_Suspend 
+* @brief  USBD_Suspend
 *         Handle Suspend event
 * @param  pdev: device instance
 * @retval status
@@ -318,13 +319,13 @@
     pdev->dev.device_old_status = pdev->dev.device_status;
     pdev->dev.device_status  = USB_OTG_SUSPENDED;
     /* Upon Resume call usr call back */
-    pdev->dev.usr_cb->DeviceSuspended(); 
+    pdev->dev.usr_cb->DeviceSuspended();
     return USBD_OK;
 }
 
 
 /**
-* @brief  USBD_SOF 
+* @brief  USBD_SOF
 *         Handle SOF event
 * @param  pdev: device instance
 * @retval status
@@ -334,12 +335,12 @@
 {
     if (pdev->dev.class_cb->SOF)
     {
-        pdev->dev.class_cb->SOF(pdev); 
+        pdev->dev.class_cb->SOF(pdev);
     }
     return USBD_OK;
 }
 /**
-* @brief  USBD_SetCfg 
+* @brief  USBD_SetCfg
 *        Configure device and start the interface
 * @param  pdev: device instance
 * @param  cfgidx: configuration index
@@ -348,15 +349,15 @@
 
 USBD_Status USBD_SetCfg(USB_OTG_CORE_HANDLE  *pdev, uint8_t cfgidx)
 {
-    pdev->dev.class_cb->Init(pdev, cfgidx); 
+    pdev->dev.class_cb->Init(pdev, cfgidx);
 
     /* Upon set config call usr call back */
     pdev->dev.usr_cb->DeviceConfigured();
-    return USBD_OK; 
+    return USBD_OK;
 }
 
 /**
-* @brief  USBD_ClrCfg 
+* @brief  USBD_ClrCfg
 *         Clear current configuration
 * @param  pdev: device instance
 * @param  cfgidx: configuration index
@@ -364,37 +365,37 @@
 */
 USBD_Status USBD_ClrCfg(USB_OTG_CORE_HANDLE  *pdev, uint8_t cfgidx)
 {
-    pdev->dev.class_cb->DeInit(pdev, cfgidx);   
+    pdev->dev.class_cb->DeInit(pdev, cfgidx);
     return USBD_OK;
 }
 
 /**
-* @brief  USBD_IsoINIncomplete 
+* @brief  USBD_IsoINIncomplete
 *         Handle iso in incomplete event
 * @param  pdev: device instance
 * @retval status
 */
 static uint8_t USBD_IsoINIncomplete(USB_OTG_CORE_HANDLE  *pdev)
 {
-    pdev->dev.class_cb->IsoINIncomplete(pdev);   
+    pdev->dev.class_cb->IsoINIncomplete(pdev);
     return USBD_OK;
 }
 
 /**
-* @brief  USBD_IsoOUTIncomplete 
+* @brief  USBD_IsoOUTIncomplete
 *         Handle iso out incomplete event
 * @param  pdev: device instance
 * @retval status
 */
 static uint8_t USBD_IsoOUTIncomplete(USB_OTG_CORE_HANDLE  *pdev)
 {
-    pdev->dev.class_cb->IsoOUTIncomplete(pdev);   
+    pdev->dev.class_cb->IsoOUTIncomplete(pdev);
     return USBD_OK;
 }
 
 #ifdef VBUS_SENSING_ENABLED
 /**
-* @brief  USBD_DevConnected 
+* @brief  USBD_DevConnected
 *         Handle device connection event
 * @param  pdev: device instance
 * @retval status
@@ -402,12 +403,12 @@
 static uint8_t USBD_DevConnected(USB_OTG_CORE_HANDLE  *pdev)
 {
     pdev->dev.usr_cb->DeviceConnected();
-    pdev->dev.connection_status = 1;  
+    pdev->dev.connection_status = 1;
     return USBD_OK;
 }
 
 /**
-* @brief  USBD_DevDisconnected 
+* @brief  USBD_DevDisconnected
 *         Handle device disconnection event
 * @param  pdev: device instance
 * @retval status
@@ -416,7 +417,7 @@
 {
     pdev->dev.usr_cb->DeviceDisconnected();
     pdev->dev.class_cb->DeInit(pdev, 0);
-    pdev->dev.connection_status = 0;    
+    pdev->dev.connection_status = 0;
     return USBD_OK;
 }
 
Index: libraries/SCPU_USB_Device_Library/core/usbd_ioreq.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/core/usbd_ioreq.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/core/usbd_ioreq.c	(working copy)
@@ -5,14 +5,14 @@
  * Date                 : 21-May-2019
  * Description          : This file provides the IO requests APIs for control endpoints.
  *****************************************************************************/
- 
+
 /* Include ------------------------------------------------------------------*/
 #include "usbd_ioreq.h"
 /* Private typedef ----------------------------------------------------------*/
-/* Private define -----------------------------------------------------------*/	
-/* Private macro ------------------------------------------------------------*/	
-/* Private variables --------------------------------------------------------*/	
-/* Ptivate function prototypes ----------------------------------------------*/	
+/* Private define -----------------------------------------------------------*/
+/* Private macro ------------------------------------------------------------*/
+/* Private variables --------------------------------------------------------*/
+/* Ptivate function prototypes ----------------------------------------------*/
 
 /******************************************************************************
 * Function Name  :
@@ -26,56 +26,56 @@
   */
 
 
-/** @defgroup USBD_IOREQ 
+/** @defgroup USBD_IOREQ
   * @brief control I/O requests module
   * @{
-  */ 
+  */
 
 /** @defgroup USBD_IOREQ_Private_TypesDefinitions
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_IOREQ_Private_Defines
   * @{
-  */ 
+  */
 
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_IOREQ_Private_Macros
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_IOREQ_Private_Variables
   * @{
-  */ 
+  */
 
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_IOREQ_Private_FunctionPrototypes
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_IOREQ_Private_Functions
   * @{
-  */ 
+  */
 
 /**
 * @brief  USBD_CtlSendData
@@ -85,7 +85,7 @@
 * @param  len: length of data to be sent
 * @retval status
 */
-USBD_Status  USBD_CtlSendData (USB_OTG_CORE_HANDLE  *pdev, 
+USBD_Status  USBD_CtlSendData (USB_OTG_CORE_HANDLE  *pdev,
                                uint8_t *pbuf,
                                uint16_t len)
 {
@@ -108,7 +108,7 @@
 * @param  len: length of data to be sent
 * @retval status
 */
-USBD_Status  USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE  *pdev, 
+USBD_Status  USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE  *pdev,
                                        uint8_t *pbuf,
                                        uint16_t len)
 {
@@ -129,7 +129,7 @@
 * @retval status
 */
 USBD_Status  USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE  *pdev,
-                                  uint8_t *pbuf,                                  
+                                  uint8_t *pbuf,
                                   uint16_t len)
 {
     USBD_Status ret = USBD_OK;
@@ -155,15 +155,15 @@
 * @param  len: length of data to be received
 * @retval status
 */
-USBD_Status  USBD_CtlContinueRx (USB_OTG_CORE_HANDLE  *pdev, 
-                                          uint8_t *pbuf,                                          
+USBD_Status  USBD_CtlContinueRx (USB_OTG_CORE_HANDLE  *pdev,
+                                          uint8_t *pbuf,
                                           uint16_t len)
 {
     USBD_Status ret = USBD_OK;
 
     DCD_EP_PrepareRx (pdev,
-                      0,                     
-                      pbuf,                         
+                      0,
+                      pbuf,
                       len);
     return ret;
 }
@@ -177,12 +177,13 @@
 {
     USBD_Status ret = USBD_OK;
     pdev->dev.device_state = USB_OTG_EP0_STATUS_IN;
-    DCD_EP_Tx (pdev,
-               0,
-               NULL, 
-               0); 
+//    DCD_EP_Tx (pdev,
+//               0,
+//               NULL,
+//               0);
+    USB_OTG_EPReply_Zerolen(pdev,0);
 
-//    USB_OTG_EP0_OutStart(pdev);  
+//    USB_OTG_EP0_OutStart(pdev);
 
     return ret;
 }
@@ -196,11 +197,11 @@
 USBD_Status  USBD_CtlReceiveStatus (USB_OTG_CORE_HANDLE  *pdev)
 {
     USBD_Status ret = USBD_OK;
-    pdev->dev.device_state = USB_OTG_EP0_STATUS_OUT;  
+    pdev->dev.device_state = USB_OTG_EP0_STATUS_OUT;
     DCD_EP_PrepareRx ( pdev,
                        0,
                        NULL,
-                       0);  
+                       0);
 
 //    USB_OTG_EP0_OutStart(pdev);
 
@@ -222,15 +223,15 @@
 
 /**
   * @}
-  */ 
+  */
 
 
 /**
   * @}
-  */ 
+  */
 
 
 /**
   * @}
-  */ 
+  */
 /************************ (C) COPYRIGHT 2014 YICHIP ****END OF FILE****/
Index: libraries/SCPU_USB_Device_Library/core/usbd_req.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/core/usbd_req.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/SCPU_USB_Device_Library/core/usbd_req.c	(working copy)
@@ -5,16 +5,16 @@
  * Date                 : 21-May-2019
  * Description          : This file provides the standard USB requests following chapter 9.
  *****************************************************************************/
- 
+
 /* Include ------------------------------------------------------------------*/
 #include "usbd_req.h"
 #include "usbd_ioreq.h"
 #include "usbd_desc.h"
 /* Private typedef ----------------------------------------------------------*/
-/* Private define -----------------------------------------------------------*/	
-/* Private macro ------------------------------------------------------------*/	
-/* Private variables --------------------------------------------------------*/	
-/* Ptivate function prototypes ----------------------------------------------*/	
+/* Private define -----------------------------------------------------------*/
+/* Private macro ------------------------------------------------------------*/
+/* Private variables --------------------------------------------------------*/
+/* Ptivate function prototypes ----------------------------------------------*/
 
 /******************************************************************************
 * Function Name  :
@@ -28,106 +28,106 @@
   */
 
 
-/** @defgroup USBD_REQ 
+/** @defgroup USBD_REQ
   * @brief USB standard requests module
   * @{
-  */ 
+  */
 
 /** @defgroup USBD_REQ_Private_TypesDefinitions
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_REQ_Private_Defines
   * @{
-  */ 
+  */
 
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_REQ_Private_Macros
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_REQ_Private_Variables
   * @{
-  */ 
+  */
 
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
     #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-        #pragma data_alignment=4   
+        #pragma data_alignment=4
     #endif
-#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */  
-__ALIGN_BEGIN uint32_t USBD_ep_status __ALIGN_END  = 0; 
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+__ALIGN_BEGIN uint32_t USBD_ep_status __ALIGN_END  = 0;
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
     #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-        #pragma data_alignment=4   
+        #pragma data_alignment=4
     #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 __ALIGN_BEGIN uint32_t  USBD_default_cfg __ALIGN_END  = 0;
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
     #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-        #pragma data_alignment=4   
+        #pragma data_alignment=4
     #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
-__ALIGN_BEGIN uint32_t  USBD_cfg_status __ALIGN_END  = 0;  
+__ALIGN_BEGIN uint32_t  USBD_cfg_status __ALIGN_END  = 0;
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
     #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-        #pragma data_alignment=4   
+        #pragma data_alignment=4
     #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 __ALIGN_BEGIN uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ] __ALIGN_END ;
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_REQ_Private_FunctionPrototypes
   * @{
-  */ 
-static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE  *pdev, 
+  */
+static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE  *pdev,
                                USB_SETUP_REQ *req);
 
-static void USBD_SetAddress(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_SetAddress(USB_OTG_CORE_HANDLE  *pdev,
                             USB_SETUP_REQ *req);
 
-static void USBD_SetConfig(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_SetConfig(USB_OTG_CORE_HANDLE  *pdev,
                            USB_SETUP_REQ *req);
 
-static void USBD_GetConfig(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_GetConfig(USB_OTG_CORE_HANDLE  *pdev,
                            USB_SETUP_REQ *req);
 
-static void USBD_GetStatus(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_GetStatus(USB_OTG_CORE_HANDLE  *pdev,
                            USB_SETUP_REQ *req);
 
-static void USBD_SetFeature(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_SetFeature(USB_OTG_CORE_HANDLE  *pdev,
                             USB_SETUP_REQ *req);
 
-static void USBD_ClrFeature(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_ClrFeature(USB_OTG_CORE_HANDLE  *pdev,
                             USB_SETUP_REQ *req);
 
 static uint8_t USBD_GetLen(uint8_t *buf);
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_REQ_Private_Functions
   * @{
-  */ 
+  */
 
 
 /**
@@ -141,19 +141,19 @@
 extern uint8_t Address_Value;
 USBD_Status  USBD_StdDevReq (USB_OTG_CORE_HANDLE  *pdev, USB_SETUP_REQ  *req)
 {
-    USBD_Status ret = USBD_OK;  
+    USBD_Status ret = USBD_OK;
 //    USB_OTG_CSR0L_IN_PERIPHERAL_TypeDef csr0l;
 //    csr0l.d8 = USB_OTG_READ_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L);
 
-    switch (req->bRequest) 
+    switch (req->bRequest)
     {
-    case USB_REQ_GET_DESCRIPTOR:	
+    case USB_REQ_GET_DESCRIPTOR:
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
         USBD_GetDescriptor (pdev, req);
         break;
 
-    case USB_REQ_SET_ADDRESS: 
+    case USB_REQ_SET_ADDRESS:
         SetAddress_Flag = 1;
         Address_Value = (uint8_t)(req->wValue) & 0x7F;
 //        csr0l.b.serviced_rxpktrdy = 1;
@@ -162,44 +162,44 @@
         USBD_SetAddress(pdev, req);
         break;
 
-    case USB_REQ_SET_CONFIGURATION:	
+    case USB_REQ_SET_CONFIGURATION:
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        csr0l.b.data_end = 1;
-//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);        
+//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
         USBD_SetConfig (pdev , req);
         break;
 
-    case USB_REQ_GET_CONFIGURATION:  
+    case USB_REQ_GET_CONFIGURATION:
 //        csr0l.b.serviced_rxpktrdy = 1;
-//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);        
+//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
         USBD_GetConfig (pdev , req);
         break;
 
-    case USB_REQ_GET_STATUS:	
+    case USB_REQ_GET_STATUS:
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
         USBD_GetStatus (pdev , req);
         break;
 
 
-    case USB_REQ_SET_FEATURE:  
+    case USB_REQ_SET_FEATURE:
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        csr0l.b.data_end = 1;
 //        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
-        USBD_SetFeature (pdev , req);    
+        USBD_SetFeature (pdev , req);
         break;
 
-    case USB_REQ_CLEAR_FEATURE: 
+    case USB_REQ_CLEAR_FEATURE:
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        csr0l.b.data_end = 1;
-//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);        
+//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
         USBD_ClrFeature (pdev , req);
         break;
     case USB_REQ_SET_DESCRIPTOR:
 //        csr0l.b.serviced_rxpktrdy = 1;
-//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);   
+//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
         break;
-    default:  
+    default:
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        csr0l.b.data_end = 1;
 //        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
@@ -219,18 +219,18 @@
 */
 USBD_Status  USBD_StdItfReq (USB_OTG_CORE_HANDLE  *pdev, USB_SETUP_REQ  *req)
 {
-    USBD_Status ret = USBD_OK; 
+    USBD_Status ret = USBD_OK;
 //    USB_OTG_CSR0L_IN_PERIPHERAL_TypeDef csr0l;
 //    csr0l.d8 = USB_OTG_READ_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L);
-    switch (pdev->dev.device_status) 
+    switch (pdev->dev.device_status)
     {
     case USB_OTG_CONFIGURED:
 
-        if (LOBYTE(req->wIndex) <= USBD_ITF_MAX_NUM) 
+        if (LOBYTE(req->wIndex) <= USBD_ITF_MAX_NUM)
         {
 //            csr0l.b.serviced_rxpktrdy = 1;
 //            USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
-            pdev->dev.class_cb->Setup(pdev, req); 
+            pdev->dev.class_cb->Setup(pdev, req);
 //            if (pdev->dev.out_ep[0].xfer_buff != pdev->dev.setup_packet)
 //            {
 ////                req->wLength = 0;
@@ -242,9 +242,9 @@
             {
                 USBD_CtlSendStatus(pdev);
             }
-        } 
-        else 
-        {                                               
+        }
+        else
+        {
 //            csr0l.b.serviced_rxpktrdy = 1;
 //            csr0l.b.data_end = 1;
 //            USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
@@ -271,45 +271,45 @@
 */
 USBD_Status  USBD_StdEPReq (USB_OTG_CORE_HANDLE  *pdev, USB_SETUP_REQ  *req)
 {
-  
+
     uint8_t   ep_addr;
-    USBD_Status ret = USBD_OK; 
+    USBD_Status ret = USBD_OK;
 //    USB_OTG_CSR0L_IN_PERIPHERAL_TypeDef csr0l;
 //    csr0l.d8 = USB_OTG_READ_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L);
-    ep_addr  = LOBYTE(req->wIndex);   
+    ep_addr  = LOBYTE(req->wIndex);
 
-    switch (req->bRequest) 
+    switch (req->bRequest)
     {
     case USB_REQ_SET_FEATURE :
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        csr0l.b.data_end = 1;
 //        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
-        switch (pdev->dev.device_status) 
+        switch (pdev->dev.device_status)
         {
-        case USB_OTG_ADDRESSED:          
-            if ((ep_addr != 0x00) && (ep_addr != 0x80)) 
+        case USB_OTG_ADDRESSED:
+            if ((ep_addr != 0x00) && (ep_addr != 0x80))
             {
                 DCD_EP_Stall(pdev , ep_addr);
             }
-            break;	
+            break;
 
-        case USB_OTG_CONFIGURED: 		
+        case USB_OTG_CONFIGURED:
             if (req->wValue == USB_FEATURE_EP_HALT)
             {
-                if ((ep_addr != 0x00) && (ep_addr != 0x80)) 
-                { 
+                if ((ep_addr != 0x00) && (ep_addr != 0x80))
+                {
                     DCD_EP_Stall(pdev , ep_addr);
 
                 }
             }
-            pdev->dev.class_cb->Setup (pdev, req);   
+            pdev->dev.class_cb->Setup (pdev, req);
             USBD_CtlSendStatus(pdev);
 
             break;
 
-        default:    	
+        default:
             USBD_CtlError(pdev , req);
-            break;    
+            break;
         }
         break;
 
@@ -317,20 +317,20 @@
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        csr0l.b.data_end = 1;
 //        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
-        switch (pdev->dev.device_status) 
+        switch (pdev->dev.device_status)
         {
-        case USB_OTG_ADDRESSED:          
-            if ((ep_addr != 0x00) && (ep_addr != 0x80)) 
+        case USB_OTG_ADDRESSED:
+            if ((ep_addr != 0x00) && (ep_addr != 0x80))
             {
                 DCD_EP_Stall(pdev , ep_addr);
             }
-            break;	
+            break;
 
-        case USB_OTG_CONFIGURED:   
+        case USB_OTG_CONFIGURED:
             if (req->wValue == USB_FEATURE_EP_HALT)
             {
-                if ((ep_addr != 0x00) && (ep_addr != 0x80)) 
-                {        
+                if ((ep_addr != 0x00) && (ep_addr != 0x80))
+                {
 //                    DCD_EP_ClrStall(pdev , ep_addr);
                     pdev->dev.class_cb->Setup (pdev, req);
                 }
@@ -338,57 +338,57 @@
             }
             break;
 
-        default:                         
+        default:
             USBD_CtlError(pdev , req);
-            break;    
+            break;
         }
         break;
 
-    case USB_REQ_GET_STATUS:		
+    case USB_REQ_GET_STATUS:
 //        csr0l.b.serviced_rxpktrdy = 1;
 //        csr0l.b.data_end = 1;
-//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);        
-        switch (pdev->dev.device_status) 
+//        USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
+        switch (pdev->dev.device_status)
         {
-        case USB_OTG_ADDRESSED:          
-            if ((ep_addr != 0x00) && (ep_addr != 0x80)) 
+        case USB_OTG_ADDRESSED:
+            if ((ep_addr != 0x00) && (ep_addr != 0x80))
             {
                 DCD_EP_Stall(pdev , ep_addr);
             }
-            break;	
+            break;
 
-        case USB_OTG_CONFIGURED:         
+        case USB_OTG_CONFIGURED:
 
 
             if ((ep_addr & 0x80)== 0x80)
             {
                 if(pdev->dev.in_ep[ep_addr & 0x7F].is_stall)
                 {
-                    USBD_ep_status = 0x0001;     
+                    USBD_ep_status = 0x0001;
                 }
                 else
                 {
-                    USBD_ep_status = 0x0000;  
+                    USBD_ep_status = 0x0000;
                 }
             }
             else if ((ep_addr & 0x80)== 0x00)
             {
                 if(pdev->dev.out_ep[ep_addr].is_stall)
                 {
-                    USBD_ep_status = 0x0001;     
+                    USBD_ep_status = 0x0001;
                 }
 
-                else 
+                else
                 {
-                    USBD_ep_status = 0x0000;     
-                }      
+                    USBD_ep_status = 0x0000;
+                }
             }
             USBD_CtlSendData (pdev,
                     (uint8_t *)&USBD_ep_status,
                     2);
             break;
 
-        default:                         
+        default:
             USBD_CtlError(pdev , req);
             break;
         }
@@ -409,7 +409,7 @@
 * @param  req: usb request
 * @retval status
 */
-static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE  *pdev,
                                USB_SETUP_REQ *req)
 {
     uint16_t len;
@@ -421,13 +421,14 @@
     {
     case USB_DESC_TYPE_DEVICE:
         pbuf = pdev->dev.usr_device->GetDeviceDescriptor(pdev->cfg.speed, &len);
-//        if ((req->wLength == 64) ||( pdev->dev.device_status == USB_OTG_DEFAULT))  
-//        {                  
+//        if ((req->wLength == 64) ||( pdev->dev.device_status == USB_OTG_DEFAULT))
+//        {
 //            len = 8;
 //        };
         break;
 
     case USB_DESC_TYPE_CONFIGURATION:
+        delay_ms(1);
         pbuf   = (uint8_t *)pdev->dev.class_cb->GetConfigDescriptor(pdev->cfg.speed, &len);
         #ifdef USB_OTG_HS_CORE
             if((pdev->cfg.speed == USB_OTG_SPEED_FULL )&&
@@ -435,16 +436,16 @@
             {
                 pbuf   = (uint8_t *)pdev->dev.class_cb->GetOtherConfigDescriptor(pdev->cfg.speed, &len);
             }
-        #endif  
+        #endif
             pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
-            pdev->dev.pConfig_descriptor = pbuf;    
+            pdev->dev.pConfig_descriptor = pbuf;
         break;
 
     case USB_DESC_TYPE_STRING:
         switch ((uint8_t)(req->wValue))
         {
         case USBD_IDX_LANGID_STR:
-            pbuf = pdev->dev.usr_device->GetLangIDStrDescriptor(pdev->cfg.speed, &len);        
+            pbuf = pdev->dev.usr_device->GetLangIDStrDescriptor(pdev->cfg.speed, &len);
             break;
 
         case USBD_IDX_MFC_STR:
@@ -473,15 +474,15 @@
             #ifdef USB_SUPPORT_USER_STRING_DESC
                 pbuf = pdev->dev.class_cb->GetUsrStrDescriptor(pdev->cfg.speed, (req->wValue) , &len);
                 break;
-            #else      
+            #else
                 USBD_CtlError(pdev , req);
                 return;
-            #endif /* USBD_CtlError(pdev , req); */      
+            #endif /* USBD_CtlError(pdev , req); */
         }
         break;
-    case USB_DESC_TYPE_DEVICE_QUALIFIER:                   
+    case USB_DESC_TYPE_DEVICE_QUALIFIER:
         #ifdef USB_OTG_HS_CORE
-        if(pdev->cfg.speed == USB_OTG_SPEED_HIGH  )   
+        if(pdev->cfg.speed == USB_OTG_SPEED_HIGH  )
         {
 
             pbuf   = (uint8_t *)pdev->dev.class_cb->GetConfigDescriptor(pdev->cfg.speed, &len);
@@ -502,16 +503,16 @@
         #else
             USBD_CtlError(pdev , req);
             return;
-        #endif    
+        #endif
 
     case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION:
-        #ifdef USB_OTG_HS_CORE   
+        #ifdef USB_OTG_HS_CORE
 
-        if(pdev->cfg.speed == USB_OTG_SPEED_HIGH  )   
+        if(pdev->cfg.speed == USB_OTG_SPEED_HIGH  )
         {
             pbuf   = (uint8_t *)pdev->dev.class_cb->GetOtherConfigDescriptor(pdev->cfg.speed, &len);
             pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION;
-            break; 
+            break;
         }
         else
         {
@@ -521,10 +522,10 @@
         #else
             USBD_CtlError(pdev , req);
             return;
-        #endif     
+        #endif
 
 
-    default: 
+    default:
         USBD_CtlError(pdev , req);
         return;
     }
@@ -534,12 +535,12 @@
 
         len = MIN(len , req->wLength);
 
-        USBD_CtlSendData (pdev, 
+        USBD_CtlSendData (pdev,
                           pbuf,
                           len);
-        
+
     }
-  
+
 }
 
 /**
@@ -549,43 +550,43 @@
 * @param  req: usb request
 * @retval status
 */
-static void USBD_SetAddress(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_SetAddress(USB_OTG_CORE_HANDLE  *pdev,
                             USB_SETUP_REQ *req)
 {
-  uint8_t  dev_addr; 
-  
-  if ((req->wIndex == 0) && (req->wLength == 0)) 
+  uint8_t  dev_addr;
+
+  if ((req->wIndex == 0) && (req->wLength == 0))
   {
-    dev_addr = (uint8_t)(req->wValue) & 0x7F;     
-    
-    if (pdev->dev.device_status == USB_OTG_CONFIGURED) 
+    dev_addr = (uint8_t)(req->wValue) & 0x7F;
+
+    if (pdev->dev.device_status == USB_OTG_CONFIGURED)
     {
       USBD_CtlError(pdev , req);
-    } 
-    else 
+    }
+    else
     {
       pdev->dev.device_address = dev_addr;
-//      DCD_EP_SetAddress(pdev, dev_addr);               
-//      USBD_CtlSendStatus(pdev); 
+//      DCD_EP_SetAddress(pdev, dev_addr);
+//      USBD_CtlSendStatus(pdev);
       USB_OTG_WRITE_REG8(&pdev->regs.CTRLREGS->FADDR,Address_Value);
       USBD_CtlSendStatus(pdev);
-      
+
 //      MyPrintf("address = %x\n",Address_Value);
-      
-      if (dev_addr != 0) 
+
+      if (dev_addr != 0)
       {
         pdev->dev.device_status  = USB_OTG_ADDRESSED;
-      } 
-      else 
+      }
+      else
       {
-        pdev->dev.device_status  = USB_OTG_DEFAULT; 
+        pdev->dev.device_status  = USB_OTG_DEFAULT;
       }
     }
-  } 
-  else 
+  }
+  else
   {
-     USBD_CtlError(pdev , req);                        
-  } 
+     USBD_CtlError(pdev , req);
+  }
 }
 
 /**
@@ -595,46 +596,46 @@
 * @param  req: usb request
 * @retval status
 */
-static void USBD_SetConfig(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_SetConfig(USB_OTG_CORE_HANDLE  *pdev,
                            USB_SETUP_REQ *req)
 {
-  
+
     static uint8_t  cfgidx;
 
-    cfgidx = (uint8_t)(req->wValue);                 
+    cfgidx = (uint8_t)(req->wValue);
 
-    if (cfgidx > USBD_CFG_MAX_NUM ) 
-    {            
-        USBD_CtlError(pdev , req);                              
-    } 
-    else 
+    if (cfgidx > USBD_CFG_MAX_NUM )
     {
-        switch (pdev->dev.device_status) 
+        USBD_CtlError(pdev , req);
+    }
+    else
+    {
+        switch (pdev->dev.device_status)
         {
         case USB_OTG_ADDRESSED:
-            if (cfgidx) 
-            {                                			   							   							   				
+            if (cfgidx)
+            {
                 pdev->dev.device_config = cfgidx;
                 pdev->dev.device_status = USB_OTG_CONFIGURED;
                 USBD_SetCfg(pdev , cfgidx);
                 USBD_CtlSendStatus(pdev);
             }
-            else 
+            else
             {
                 USBD_CtlSendStatus(pdev);
             }
             break;
-          
+
         case USB_OTG_CONFIGURED:
-            if (cfgidx == 0) 
-            {                           
+            if (cfgidx == 0)
+            {
                 pdev->dev.device_status = USB_OTG_ADDRESSED;
-                pdev->dev.device_config = cfgidx;          
+                pdev->dev.device_config = cfgidx;
                 USBD_ClrCfg(pdev , cfgidx);
                 USBD_CtlSendStatus(pdev);
 
-            } 
-            else  if (cfgidx != pdev->dev.device_config) 
+            }
+            else  if (cfgidx != pdev->dev.device_config)
             {
                 /* Clear old configuration */
                 USBD_ClrCfg(pdev , pdev->dev.device_config);
@@ -649,9 +650,9 @@
                 USBD_CtlSendStatus(pdev);
             }
             break;
-          
-        default:					
-            USBD_CtlError(pdev , req);                     
+
+        default:
+            USBD_CtlError(pdev , req);
             break;
         }
     }
@@ -664,28 +665,28 @@
 * @param  req: usb request
 * @retval status
 */
-static void USBD_GetConfig(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_GetConfig(USB_OTG_CORE_HANDLE  *pdev,
                            USB_SETUP_REQ *req)
 {
- 
-    if (req->wLength != 1) 
-    {                   
+
+    if (req->wLength != 1)
+    {
         USBD_CtlError(pdev , req);
     }
-    else 
+    else
     {
-        switch (pdev->dev.device_status )  
+        switch (pdev->dev.device_status )
         {
-        case USB_OTG_ADDRESSED:                     
+        case USB_OTG_ADDRESSED:
 
-            USBD_CtlSendData (pdev, 
+            USBD_CtlSendData (pdev,
                              (uint8_t *)&USBD_default_cfg,
                               1);
             break;
 
-        case USB_OTG_CONFIGURED:                   
+        case USB_OTG_CONFIGURED:
 
-            USBD_CtlSendData (pdev, 
+            USBD_CtlSendData (pdev,
                               &pdev->dev.device_config,
                               1);
             break;
@@ -704,34 +705,34 @@
 * @param  req: usb request
 * @retval status
 */
-static void USBD_GetStatus(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_GetStatus(USB_OTG_CORE_HANDLE  *pdev,
                            USB_SETUP_REQ *req)
 {
-  
-    
-    switch (pdev->dev.device_status) 
+
+
+    switch (pdev->dev.device_status)
     {
     case USB_OTG_ADDRESSED:
     case USB_OTG_CONFIGURED:
 
         #ifdef USBD_SELF_POWERED
-            USBD_cfg_status = USB_CONFIG_SELF_POWERED;                                    
+            USBD_cfg_status = USB_CONFIG_SELF_POWERED;
         #else
-            USBD_cfg_status = 0x00;                                    
+            USBD_cfg_status = 0x00;
         #endif
-              
-        if (pdev->dev.DevRemoteWakeup) 
+
+        if (pdev->dev.DevRemoteWakeup)
         {
-            USBD_cfg_status |= USB_CONFIG_REMOTE_WAKEUP;                                
+            USBD_cfg_status |= USB_CONFIG_REMOTE_WAKEUP;
         }
 
-        USBD_CtlSendData (pdev, 
+        USBD_CtlSendData (pdev,
                          (uint8_t *)&USBD_cfg_status,
                           2);
         break;
 
     default :
-        USBD_CtlError(pdev , req);                        
+        USBD_CtlError(pdev , req);
         break;
     }
 }
@@ -744,7 +745,7 @@
 * @param  req: usb request
 * @retval status
 */
-static void USBD_SetFeature(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_SetFeature(USB_OTG_CORE_HANDLE  *pdev,
                             USB_SETUP_REQ *req)
 {
 
@@ -753,36 +754,36 @@
 
     if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
     {
-        pdev->dev.DevRemoteWakeup = 1;  
-        pdev->dev.class_cb->Setup (pdev, req);   
+        pdev->dev.DevRemoteWakeup = 1;
+        pdev->dev.class_cb->Setup (pdev, req);
         USBD_CtlSendStatus(pdev);
         USB_OTG_ActiveRemoteWakeup(pdev);
     }
 
-//    else if ((req->wValue == USB_FEATURE_TEST_MODE) && 
+//    else if ((req->wValue == USB_FEATURE_TEST_MODE) &&
 //           ((req->wIndex & 0xFF) == 0))
 //    {
  //       dctl.d8 = USB_OTG_READ_REG8(&pdev->regs.COMMREGS->TESTMODE);
 //        dctl.d8 = 0;
 //        test_mode = req->wIndex >> 8;
-//        switch (test_mode) 
+//        switch (test_mode)
 //        {
 //        case 1: // TEST_SE0_NAK
 //            dctl.b.test_SE0_NAK = 1;
 //            break;
-//          
-//        case 2: // TEST_J	
+//
+//        case 2: // TEST_J
 //            dctl.b.test_J = 1;
 //            break;
-//          
+//
 //        case 3: // TEST_K
 //            dctl.b.test_K = 1;
 //            break;
-//          
+//
 //        case 4: // TEST_PACKET
 //            dctl.b.test_packet = 1;
 //            break;
-//          
+//
 //        case 5: // TEST_FORCE_ENABLE
 //            dctl.b.force_FS = 1;
 //            dctl.b.force_host = 1;  /* Full-speed Host */
@@ -803,17 +804,17 @@
 * @param  req: usb request
 * @retval status
 */
-static void USBD_ClrFeature(USB_OTG_CORE_HANDLE  *pdev, 
+static void USBD_ClrFeature(USB_OTG_CORE_HANDLE  *pdev,
                             USB_SETUP_REQ *req)
 {
     switch (pdev->dev.device_status)
     {
     case USB_OTG_ADDRESSED:
     case USB_OTG_CONFIGURED:
-        if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) 
+        if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
         {
-            pdev->dev.DevRemoteWakeup = 0; 
-            pdev->dev.class_cb->Setup (pdev, req);   
+            pdev->dev.DevRemoteWakeup = 0;
+            pdev->dev.class_cb->Setup (pdev, req);
             USBD_CtlSendStatus(pdev);
         }
         break;
@@ -825,7 +826,7 @@
 }
 
 /**
-* @brief  USBD_ParseSetupRequest 
+* @brief  USBD_ParseSetupRequest
 *         Copy buffer into setup structure
 * @param  pdev: device instance
 * @param  req: usb request
@@ -847,7 +848,7 @@
 }
 
 /**
-* @brief  USBD_CtlError 
+* @brief  USBD_CtlError
 *         Handle USB low level Error
 * @param  pdev: device instance
 * @param  req: usb request
@@ -857,9 +858,9 @@
 void USBD_CtlError( USB_OTG_CORE_HANDLE  *pdev,
                             USB_SETUP_REQ *req)
 {
-  
+
 //    DCD_EP_Stall(pdev , 0x80);
-    DCD_EP_Stall(pdev , 0); 
+    DCD_EP_Stall(pdev , 0);
 }
 
 
@@ -875,18 +876,18 @@
 {
     uint8_t idx = 0;
 
-    if (desc != NULL) 
+    if (desc != NULL)
     {
-        *len =  USBD_GetLen(desc) * 2 + 2;    
+        *len =  USBD_GetLen(desc) * 2 + 2;
         unicode[idx++] = *len;
         unicode[idx++] =  USB_DESC_TYPE_STRING;
 
-        while (*desc != 0) 
+        while (*desc != 0)
         {
             unicode[idx++] = *desc++;
             unicode[idx++] =  0x00;
         }
-    } 
+    }
 }
 
 /**
@@ -899,7 +900,7 @@
 {
     uint8_t  len = 0;
 
-    while (*buf != 0) 
+    while (*buf != 0)
     {
         len++;
         buf++;
@@ -909,16 +910,16 @@
 }
 /**
   * @}
-  */ 
+  */
 
 
 /**
   * @}
-  */ 
+  */
 
 
 /**
   * @}
-  */ 
+  */
 
 /************************ (C) COPYRIGHT 2014 YICHIP ****END OF FILE****/
Index: libraries/harward_Der/Usb_dcd_init.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/Usb_dcd_init.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/Usb_dcd_init.c	(working copy)
@@ -5,7 +5,7 @@
  * Date                 : 21-May-2019
  * Description          : Peripheral Device interrupt subroutines.
  *****************************************************************************/
- 
+
 /* Include ------------------------------------------------------------------*/
 #include "usb_dcd_int.h"
 #include "usb_defines.h"
@@ -19,7 +19,7 @@
 * @{
 */
 
-/** @defgroup USB_DCD_INT 
+/** @defgroup USB_DCD_INT
 * @brief This file contains the interrupt subroutines for the Device mode.
 * @{
 */
@@ -27,15 +27,14 @@
 
 /** @defgroup USB_DCD_INT_Private_Defines
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 /* Interrupt Handlers */
 static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev, uint16_t ep_intr);
 static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev, uint16_t ep_intr);
-static uint32_t DCD_HandleUsbReset_ISR();
 
 void _delay_(uint32_t t)
 {
@@ -50,152 +49,94 @@
 */
 
 extern USBD_DCD_INT_cb_TypeDef USBD_DCD_INT_cb;
-uint8_t setup_cnt =0;
 uint8_t SetAddress_Flag = 0;
 uint8_t Address_Value = 0;
 uint8_t out0_data_len=0;
+uint8_t usbFlowCtrl=0;
 uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev)
 {
-   USB_OTG_IRQ1_TypeDef gintr_status;
-   USB_OTG_trig_TypeDef trig;
-   USB_OTG_IRQ2_TypeDef fifo_empty_irq;
-   
-   
+    USB_OTG_IRQ1_TypeDef gintr_status;
+    USB_OTG_trig_TypeDef trig;
+    USB_OTG_IRQ2_TypeDef fifo_empty_irq;
+
+
     uint32_t retval = 0;
     USB_OTG_EP *ep;
     uint8_t rx_DataLength = 0;
-      if (USB_OTG_IsDeviceMode(pdev)) /* ensure that we are in device mode */
-      {
-				gintr_status.d8 = USB_OTG_READ_REG8(&(pdev ->regs.STATUSEGS ->STATUS));
-				fifo_empty_irq.d8 = USB_OTG_READ_REG8(&pdev ->regs.STATUSEGS ->EMPTY);
-//	MyPrintf("\n%x",gintr_status.d8);
-//	MyPrintf("empty =%x\n",fifo_empty_irq.d8  );
-//	MyPrintf(" status =%x\n",(&(pdev ->regs.STATUSEGS ->STATUS)));
-			if(! gintr_status.d8)
-				return 0;
+    if (USB_OTG_IsDeviceMode(pdev)) /* ensure that we are in device mode */
+    {
+
+        gintr_status.d8 = USB_OTG_READ_REG8(&(pdev ->regs.STATUSEGS ->STATUS));
+        fifo_empty_irq.d8 = USB_OTG_READ_REG8(&pdev ->regs.STATUSEGS ->EMPTY);
+//        MyPrintf("\nstatus:%x\n",gintr_status.d8);
+//        MyPrintf("empty:%x\n",fifo_empty_irq.d8  );
+        if(! gintr_status.d8)
+        {
+            return 0;
+        }
 
 
-//	if (gintr_status.b.suspend)
+//        if (gintr_status.b.suspend)
 //        {
 //            retval |= DCD_HandleUSBSuspend_ISR(pdev);
 //        }
-//	if(gintr_status.b.nak)
-//	{
-//	  retval |= DCD_HandleSof_ISR(pdev);
-//	}
-	if(gintr_status.b.reset)
-	{
-	  retval |= DCD_HandleUsbReset_ISR(pdev);
-	}
-	USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->STATUS, 0xe0);
+//        if(gintr_status.b.nak)
+//        {
+//            retval |= DCD_HandleSof_ISR(pdev);
+//        }
+        if(gintr_status.b.reset)
+        {
+            retval |= USBD_DCD_INT_fops->Reset(pdev);
+        }
+        USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->STATUS, 0xe0);
 
-  if(gintr_status.d8 &0x0E)
-    {
-    //	MyPrintf("bulkout\r\n");
-	 retval |= DCD_HandleOutEP_ISR(pdev, gintr_status.d8 &0x0E);
-	 USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->STATUS, gintr_status.d8 &0x0E);
-    }
-    
-     if(gintr_status.b.outep0_irq)
-     {
-	  USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->STATUS, 0x11);
-	 if (SetAddress_Flag)
+        if(gintr_status.d8 &0x0E)
+        {
+//            MyPrintf("bulkout\r\n");
+            retval |= DCD_HandleOutEP_ISR(pdev, gintr_status.d8 &0x0E);
+            if(usbFlowCtrl==0)
+            {
+                USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->STATUS, gintr_status.d8 &0x0E);
+            }
+        }
+
+        if(gintr_status.b.outep0_irq)
+        {
+            USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->STATUS, 0x11);
+            if (SetAddress_Flag)
             {
-               USB_OTG_MODIFY_REG8(&pdev->regs.CTRLREGS->FADDR,0,0x80);
+                USB_OTG_MODIFY_REG8(&pdev->regs.CTRLREGS->FADDR,0,0x80);
                 SetAddress_Flag = 0;
 //                MyPrintf("set address \n");
-            }  
-          if(gintr_status.b.setup)
-          {
-          	   delay_ms(1);
-//               MyPrintf("cnt = %d\n",setup_cnt);
-//               MyPrintf("YICHIP SCPU USB CCID setup packet start .\n");
-//           USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->STATUS, 0x11);
-           rx_DataLength = USB_OTG_READ_REG8(pdev->regs.LENREGS[0]);
-//           MyPrintf("len =%d\n",rx_DataLength );
-                if ((rx_DataLength < pdev->dev.out_ep[0].maxpacket) || \
-                    (pdev->dev.out_ep[0].xfer_count + rx_DataLength == pdev->dev.out_ep[0].xfer_len))
-                {
-                    /* Copy the setup packet received in FIFO into the setup buffer in RAM */
-                    USB_OTG_ReadPacket(pdev , 
-                                       pdev->dev.out_ep[0].xfer_buff + pdev->dev.out_ep[0].xfer_count,
-                                       0, 
-                                       USB_SETUP_PACKET_LEN);
-                    pdev->dev.out_ep[0].xfer_count =0;
-                    if (pdev->dev.out_ep[0].xfer_buff != pdev->dev.setup_packet)
-                    {
-//                        if (pdev->dev.out_ep[0].xfer_len == 7)
-//                        {
-//                            csr0l.b.serviced_rxpktrdy = 1;
-//                            USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
-                            
-                            pdev->dev.out_ep[0].xfer_buff = pdev->dev.setup_packet;
-                            pdev->dev.out_ep[0].xfer_count = 0;
-                            pdev->dev.out_ep[0].xfer_len = 8;
-//                            /* RX COMPLETE */
-//                            USBD_DCD_INT_fops->DataOutStage(pdev , 0);
-//                            pdev->dev.device_state = USB_OTG_EP0_STATUS_IN;
-//                            DCD_EP_Tx (pdev,
-//                                       0,
-//                                       NULL, 
-//                                       0); 
-//                            /* RX COMPLETE */
-//                            USBD_DCD_INT_fops->DataOutStage(pdev , 0);
-//                        }
-                    }
-                    else{
-                        /* deal with receive setup packet */
-//                   MyPrintf("req ->bmRequest =%x\n",*(uint8_t *)  (pdev->dev.setup_packet));
-				if(rx_DataLength >USB_SETUP_PACKET_LEN)
-				{
-					out0_data_len = rx_DataLength -USB_SETUP_PACKET_LEN;
-				}
-               	    USBD_DCD_INT_fops->SetupStage(pdev);
-//               	      MyPrintf("setup packet receive.\n");
-                    }
-              }  
-	else{
-                    /* Copy the setup packet received in FIFO into the setup buffer in RAM */
-                    USB_OTG_ReadPacket(pdev , 
-//                                       pdev->dev.setup_packet + pdev->dev.out_ep[0].xfer_count, 
-                                       pdev->dev.out_ep[0].xfer_buff + pdev->dev.out_ep[0].xfer_count,
-                                       0, 
-                                       rx_DataLength);
-                    pdev->dev.out_ep[0].xfer_count += rx_DataLength;
-//                    USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L, csr0l.d8);
-                }
-          }
-
-          
-          //ep0 dispose
-
-     }
-
-//    if(gintr_status.d8 &0x0E)
-//    {
-//    	MyPrintf("bulkout\r\n");
-//	 retval |= DCD_HandleOutEP_ISR(pdev, gintr_status.d8 &0x0E);
-//	 USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->STATUS, gintr_status.d8 &0x0E);
-//    }
+            }
+            if(gintr_status.b.setup)
+            {
+                while(USB_OTG_READ_REG8(pdev->regs.LENREGS[0])<USB_SETUP_PACKET_LEN);
+                USB_OTG_ReadPacket(pdev ,pdev->dev.setup_packet,0,USB_SETUP_PACKET_LEN);
+                USBD_DCD_INT_fops->SetupStage(pdev);
+            }
+            else
+            {
+                //ep0 not setup packet
+                //MyPrintf("ep0 not setup packet\n");
+            }
+        }
 
-    //     tx
-    if(fifo_empty_irq.d8 &0x0F)
-    {
-    	  _delay_(300);
-	   retval |= DCD_HandleInEP_ISR(pdev, fifo_empty_irq.d8 &0x0F);
+        //tx
+        if(fifo_empty_irq.d8 &0x0F)//in empty
+        {
+            retval |= DCD_HandleInEP_ISR(pdev, fifo_empty_irq.d8 &0x0F);
             USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->EMPTY, fifo_empty_irq.d8 &0xFF);
             USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->FULL, 0xFF);
-            
-//             MyPrintf("fifo empty irq.\n");
+        }
+//        if(fifo_empty_irq.d8 &0xF0)//out empty
+//        {
+//            MyPrintf("outfifo empty irq.\n");
+//            retval |= DCD_HandleOutEP_ISR(pdev,fifo_empty_irq.d8 &0x20);
+//            USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->EMPTY, fifo_empty_irq.d8 &0xF0);
+//        }
     }
-// if(fifo_empty_irq.d8 &0xF0)
-// {
-//	 MyPrintf("outfifo empty irq.\n");
-//	retval |= DCD_HandleOutEP_ISR(pdev,fifo_empty_irq.d8 &0x20);
-//	USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->EMPTY, fifo_empty_irq.d8 &0xF0);
-// }
-      }
-      return retval;
+    return retval;
 }
 
 
@@ -209,22 +150,23 @@
 {
 	  USB_OTG_EP *ep;
 	  uint16_t epnum = 0;
- 
+
 	 while ( ep_intr )
     {
     	  ep = &pdev->dev.in_ep[epnum];
           /* Setup and start the Transfer */
           ep->is_in = 1;
-          ep->num = epnum;  
+          ep->num = epnum;
         if (ep_intr & 0x01) /* In ITR */
        {
 	if (pdev->dev.in_ep[epnum].rem_data_len == 0)
 	{
-			
-			if(pdev->dev.zero_replay_flag )
+
+			if(pdev->dev.in_ep[epnum].xfer_len!=0 && pdev->dev.in_ep[epnum].xfer_len%pdev->dev.in_ep[epnum].maxpacket==0)
 			{
 				USB_OTG_EPReply_Zerolen(pdev,ep);
-				pdev->dev.zero_replay_flag =0;
+                pdev->dev.in_ep[epnum].xfer_len=0;
+//				pdev->dev.zero_replay_flag =0;
 			}
 		return 0;
 	}
@@ -233,9 +175,9 @@
 		 if (pdev->dev.in_ep[epnum].xfer_len - pdev->dev.in_ep[epnum].xfer_count >= pdev->dev.in_ep[epnum].maxpacket)
                     {
 //                    	MyPrintf("tg\n\r");
-                        USB_OTG_WritePacket (pdev, 
+                        USB_OTG_WritePacket (pdev,
                                              pdev->dev.in_ep[epnum].xfer_buff + pdev->dev.in_ep[epnum].xfer_count,
-                                             epnum, 
+                                             epnum,
                                              pdev->dev.in_ep[epnum].maxpacket);
                          USB_OTG_TRIG(pdev ,ep );
                         pdev->dev.in_ep[epnum].xfer_count += pdev->dev.in_ep[epnum].maxpacket;
@@ -248,12 +190,12 @@
                     }
                     else
                     {
-//                       MyPrintf("tc\n\r");	
-                        USB_OTG_WritePacket (pdev, 
-                                             pdev->dev.in_ep[epnum].xfer_buff + pdev->dev.in_ep[epnum].xfer_count,  
+//                       MyPrintf("tc\n\r");
+                        USB_OTG_WritePacket (pdev,
+                                             pdev->dev.in_ep[epnum].xfer_buff + pdev->dev.in_ep[epnum].xfer_count,
                                              epnum,
                                              pdev->dev.in_ep[epnum].xfer_len - pdev->dev.in_ep[epnum].xfer_count);
-                            USB_OTG_TRIG(pdev ,ep );                 
+                            USB_OTG_TRIG(pdev ,ep );
                         pdev->dev.in_ep[epnum].xfer_count = pdev->dev.in_ep[epnum].xfer_len;
                         pdev->dev.in_ep[epnum].rem_data_len = 0;
 //                        txcsrl.b.tx_pkt_rdy = 1;
@@ -263,11 +205,11 @@
 												pdev->dev.zero_replay_flag =0;
 //                        USB_OTG_TRIG(pdev ,ep );
 //                       MyPrintf("tx xfer continue.\n\r");
-                        
+
                     }
         }
     }
-   
+
    epnum++;
    ep_intr >>= 1;
    }
@@ -297,11 +239,11 @@
              {
              	USBD_DCD_INT_fops->DataOutStage(pdev , epnum);
              }
-             
+
 //                {
-//                    USB_OTG_ReadPacket (pdev, 
+//                    USB_OTG_ReadPacket (pdev,
 //                                        pdev->dev.out_ep[epnum].xfer_buff + pdev->dev.out_ep[epnum].xfer_count,
-//                                        epnum, 
+//                                        epnum,
 //                                        pdev->dev.out_ep[epnum].maxpacket);
 //                    pdev->dev.out_ep[epnum].xfer_count += pdev->dev.out_ep[epnum].maxpacket;
  //                   rxcsrl.b.rx_pkt_rdy = 0;
@@ -315,9 +257,9 @@
 //                }
 //              else
 //                {
-//                    USB_OTG_ReadPacket (pdev, 
+//                    USB_OTG_ReadPacket (pdev,
 //                                        pdev->dev.out_ep[epnum].xfer_buff + pdev->dev.out_ep[epnum].xfer_count,
-//                                        epnum, 
+//                                        epnum,
 //                                        rx_count);
 //                    pdev->dev.out_ep[epnum].xfer_count += rx_count;
 //                    if (pdev->dev.out_ep[epnum].xfer_len >=  pdev->dev.out_ep[epnum].xfer_count)
@@ -333,7 +275,7 @@
 //                    /* RX COMPLETE */
 //                    USBD_DCD_INT_fops->DataOutStage(pdev , epnum);
 //                }
-	 
+
       }
                  /* Endpoint disable  */
          epnum++;
@@ -344,23 +286,6 @@
 
 
 
-/**
-* @brief  DCD_HandleUsbReset_ISR
-*         This interrupt occurs when a USB Reset is detected
-* @param  pdev: device instance
-* @retval status
-*/
-extern USB_OTG_CORE_HANDLE  USB_OTG_dev;
-static uint32_t DCD_HandleUsbReset_ISR()
-{
-	
-		 USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
-		 USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
-//	 MyPrintf("YICHIP SCPU USB CCID demo V1.0.  reset \n");
-	 return 1;
-}
-
-
 
 
 
Index: libraries/harward_Der/Usb_regs.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/Usb_regs.h	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/Usb_regs.h	(working copy)
@@ -6,8 +6,8 @@
  * Date                 : 21-May-2019
  * Description          : USB OTG IP hardware registers.
  *****************************************************************************/
- 
- 
+
+
 #ifndef __USB_OTG_REGS_H__
 #define __USB_OTG_REGS_H__
 
@@ -35,11 +35,11 @@
 
 
 
-#define USB_OTG_FS_BASE_ADDR               CORE_USB_CONFIG 
-#define NUM_EP_FIFO                                         4 
+#define USB_OTG_FS_BASE_ADDR               CORE_USB_CONFIG
+#define NUM_EP_FIFO                                         4
 #define USB_OTG_EP_FIFO_REG_OFFSET                          0x0001
 
-#define USB_OTG_MAX_TX_FIFOS                 15
+#define USB_OTG_MAX_TX_FIFOS                 4
 
 #define USB_OTG_HS_MAX_PACKET_SIZE           512
 #define USB_OTG_FS_MAX_PACKET_SIZE           64
@@ -55,16 +55,16 @@
     volatile uint8_t IRQ_MASK2;
     volatile uint8_t IRQ_MASK3;
     volatile uint8_t FADDR;
-   
+
 }USB_OTG_CTRLREGS;
 typedef struct _USB_OTG_XFERCTL
 {
    volatile uint8_t TRIG;
    volatile uint8_t STALL;
-   volatile uint8_t TOGGLE;   
+   volatile uint8_t TOGGLE;
 }USB_OTG_XFERCTL;
 
-typedef struct _USB_OTG_EPREGS 
+typedef struct _USB_OTG_EPREGS
 {
     volatile uint8_t EP0;
     volatile uint8_t EP1;
@@ -73,7 +73,7 @@
 
 }USB_OTG_EPREGS;
 
-typedef struct _USB_OTG_EP_LENREGS  
+typedef struct _USB_OTG_EP_LENREGS
 {
     volatile uint8_t EP0_LEN;
     volatile uint8_t EP1_LEN;
@@ -84,7 +84,7 @@
 
 typedef struct _USB_OTG_STATUSREGS
 {
-  volatile uint8_t STALL_STATUS;	
+  volatile uint8_t STALL_STATUS;
    volatile uint8_t STATUS;
    volatile uint8_t EMPTY;
    volatile uint8_t FULL;
@@ -101,7 +101,7 @@
   USB_OTG_XFERCTL		*xferctl;
   uint8_t          				*ep[NUM_EP_FIFO];
   uint8_t    					*LENREGS[NUM_EP_FIFO];
-  USB_OTG_STATUSREGS	*STATUSEGS;	
+  USB_OTG_STATUSREGS	*STATUSEGS;
 
 }USB_OTG_CORE_REGS, *PUSB_OTG_CORE_REGS;
 
Index: libraries/harward_Der/usb_core.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/usb_core.h	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/usb_core.h	(working copy)
@@ -5,38 +5,38 @@
  * Date                 : 21-May-2019
  * Description          : Specific api's relative to the used hardware platform.
  *****************************************************************************/
- 
- 
+
+
 #ifndef __USB_CORE_H__
 #define __USB_CORE_H__
- 
- 
+
+
 #ifdef __cplusplus
 extern "C" {
 #endif
-	
+
 /* Include ------------------------------------------------------------------*/
 #include "usb_regs.h"
 #include "usb_conf.h"
-#include "usb_defines.h"	
+#include "usb_defines.h"
 /* Exported types -----------------------------------------------------------*/
-/* Exported constants -------------------------------------------------------*/	
-/* Exported macro -----------------------------------------------------------*/	
-/* Exported functions -------------------------------------------------------*/	
-/* Exported variables -------------------------------------------------------*/	
+/* Exported constants -------------------------------------------------------*/
+/* Exported macro -----------------------------------------------------------*/
+/* Exported functions -------------------------------------------------------*/
+/* Exported variables -------------------------------------------------------*/
 /** @addtogroup USB_OTG_DRIVER
   * @{
   */
-  
+
 /** @defgroup USB_CORE
   * @brief usb otg driver core layer
   * @{
-  */ 
+  */
 
 
 /** @defgroup USB_CORE_Exported_Defines
   * @{
-  */ 
+  */
 
 #define USB_OTG_EP0_IDLE                          0
 #define USB_OTG_EP0_SETUP                         1
@@ -50,20 +50,20 @@
 #define USB_OTG_EP_TX_STALL                       0x0010
 #define USB_OTG_EP_TX_NAK                         0x0020
 #define USB_OTG_EP_TX_VALID                       0x0030
- 
+
 #define USB_OTG_EP_RX_DIS                         0x0000
 #define USB_OTG_EP_RX_STALL                       0x1000
 #define USB_OTG_EP_RX_NAK                         0x2000
 #define USB_OTG_EP_RX_VALID                       0x3000
 /**
   * @}
-  */ 
+  */
 #define MAX_DATA_LENGTH                           0x200
 
 
 /** @defgroup USB_CORE_Exported_Types
   * @{
-  */ 
+  */
 
 
 typedef enum {
@@ -78,9 +78,9 @@
     HC_NAK,
     HC_NYET,
     HC_STALL,
-    HC_XACTERR,  
-    HC_BBLERR,   
-    HC_DATATGLERR,  
+    HC_XACTERR,
+    HC_BBLERR,
+    HC_DATATGLERR,
 }HC_STATUS;
 
 typedef enum {
@@ -97,9 +97,9 @@
     CTRL_HALTED,
     CTRL_NAK,
     CTRL_STALL,
-    CTRL_XACTERR,  
-    CTRL_BBLERR,   
-    CTRL_DATATGLERR,  
+    CTRL_XACTERR,
+    CTRL_BBLERR,
+    CTRL_DATATGLERR,
     CTRL_FAIL
 }CTRL_STATUS;
 
@@ -110,16 +110,16 @@
     uint8_t       ep_num;
     uint8_t       ep_is_in;
     uint8_t       speed;
-    uint8_t       do_ping;  
+    uint8_t       do_ping;
     uint8_t       ep_type;
     uint16_t      max_packet;
     uint8_t       data_pid;
     uint8_t       *xfer_buff;
     uint32_t      xfer_len;
-    uint32_t      xfer_count;  
+    uint32_t      xfer_count;
     uint8_t       toggle_in;
     uint8_t       toggle_out;
-    uint32_t       dma_addr;  
+    uint32_t       dma_addr;
 }
 USB_OTG_HC , *PUSB_OTG_HC;
 
@@ -127,7 +127,7 @@
 {
     uint8_t        num;
     uint8_t        is_in;
-    uint8_t        is_stall;  
+    uint8_t        is_stall;
     uint8_t        type;
     uint8_t        data_pid_start;
     uint8_t        even_odd_frame;
@@ -135,15 +135,15 @@
     uint8_t       maxpacket;
     /* transaction level variables*/
     uint8_t        *xfer_buff;
-    uint32_t       dma_addr;  
+    uint32_t       dma_addr;
     uint32_t       xfer_len;
     uint32_t       xfer_count;
-    /* Transfer level variables*/  
+    /* Transfer level variables*/
     uint32_t       rem_data_len;
     uint32_t       total_data_len;
-    uint8_t       ctl_data_len;  
+    uint8_t       ctl_data_len;
 
-} 
+}
 USB_OTG_EP , *PUSB_OTG_EP;
 
 typedef struct USB_OTG_core_cfg
@@ -158,37 +158,37 @@
     uint8_t       Sof_output;
     uint8_t       low_power;
     uint8_t       coreID;
- 
+
 }
 USB_OTG_CORE_CFGS, *PUSB_OTG_CORE_CFGS;
 
 
 
 typedef  struct  usb_setup_req {
-    
-    uint8_t   bmRequest;                      
-    uint8_t   bRequest;                           
-    uint16_t  wValue;                             
-    uint16_t  wIndex;                             
-    uint16_t  wLength;                            
+
+    uint8_t   bmRequest;
+    uint8_t   bRequest;
+    uint16_t  wValue;
+    uint16_t  wIndex;
+    uint16_t  wLength;
 } USB_SETUP_REQ;
 
 typedef struct _Device_TypeDef
 {
-    uint8_t  *(*GetDeviceDescriptor)( uint8_t speed , uint16_t *length);  
-    uint8_t  *(*GetLangIDStrDescriptor)( uint8_t speed , uint16_t *length); 
-    uint8_t  *(*GetManufacturerStrDescriptor)( uint8_t speed , uint16_t *length);  
-    uint8_t  *(*GetProductStrDescriptor)( uint8_t speed , uint16_t *length);  
-    uint8_t  *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length);  
-    uint8_t  *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length);  
-    uint8_t  *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length);   
-    
+    uint8_t  *(*GetDeviceDescriptor)( uint8_t speed , uint16_t *length);
+    uint8_t  *(*GetLangIDStrDescriptor)( uint8_t speed , uint16_t *length);
+    uint8_t  *(*GetManufacturerStrDescriptor)( uint8_t speed , uint16_t *length);
+    uint8_t  *(*GetProductStrDescriptor)( uint8_t speed , uint16_t *length);
+    uint8_t  *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length);
+    uint8_t  *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length);
+    uint8_t  *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length);
+
 } USBD_DEVICE, *pUSBD_DEVICE;
 
 //typedef struct USB_OTG_hPort
 //{
 //  void (*Disconnect) (void *phost);
-//  void (*Connect) (void *phost); 
+//  void (*Connect) (void *phost);
 //  uint8_t ConnStatus;
 //  uint8_t DisconnStatus;
 //  uint8_t ConnHandled;
@@ -200,40 +200,40 @@
     uint8_t  (*Init)         (void *pdev , uint8_t cfgidx);
     uint8_t  (*DeInit)       (void *pdev , uint8_t cfgidx);
     /* Control Endpoints*/
-    uint8_t  (*Setup)        (void *pdev , USB_SETUP_REQ  *req);  
-    uint8_t  (*EP0_TxSent)   (void *pdev );    
-    uint8_t  (*EP0_RxReady)  (void *pdev );  
+    uint8_t  (*Setup)        (void *pdev , USB_SETUP_REQ  *req);
+    uint8_t  (*EP0_TxSent)   (void *pdev );
+    uint8_t  (*EP0_RxReady)  (void *pdev );
     /* Class Specific Endpoints*/
-    uint8_t  (*DataIn)       (void *pdev , uint8_t epnum);   
-    uint8_t  (*DataOut)      (void *pdev , uint8_t epnum); 
-    uint8_t  (*SOF)          (void *pdev); 
-    uint8_t  (*IsoINIncomplete)  (void *pdev); 
-    uint8_t  (*IsoOUTIncomplete)  (void *pdev);   
-
-    uint8_t  *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length); 
-#ifdef USB_OTG_HS_CORE 
-    uint8_t  *(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length);   
+    uint8_t  (*DataIn)       (void *pdev , uint8_t epnum);
+    uint8_t  (*DataOut)      (void *pdev , uint8_t epnum);
+    uint8_t  (*SOF)          (void *pdev);
+    uint8_t  (*IsoINIncomplete)  (void *pdev);
+    uint8_t  (*IsoOUTIncomplete)  (void *pdev);
+
+    uint8_t  *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length);
+#ifdef USB_OTG_HS_CORE
+    uint8_t  *(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length);
+#endif
+
+#ifdef USB_SUPPORT_USER_STRING_DESC
+    uint8_t  *(*GetUsrStrDescriptor)( uint8_t speed ,uint8_t index,  uint16_t *length);
 #endif
 
-#ifdef USB_SUPPORT_USER_STRING_DESC 
-    uint8_t  *(*GetUsrStrDescriptor)( uint8_t speed ,uint8_t index,  uint16_t *length);   
-#endif  
-  
 } USBD_Class_cb_TypeDef;
 
 
 
 typedef struct _USBD_USR_PROP
 {
-    void (*Init)(void);   
-    void (*DeviceReset)(uint8_t speed); 
+    void (*Init)(void);
+    void (*DeviceReset)(uint8_t speed);
     void (*DeviceConfigured)(void);
     void (*DeviceSuspended)(void);
-    void (*DeviceResumed)(void);  
+    void (*DeviceResumed)(void);
+
+    void (*DeviceConnected)(void);
+    void (*DeviceDisconnected)(void);
 
-    void (*DeviceConnected)(void);  
-    void (*DeviceDisconnected)(void);    
-  
 }
 USBD_Usr_cb_TypeDef;
 
@@ -243,17 +243,17 @@
     uint8_t        device_state;                    /* EP0 State */
     uint8_t        device_status;                   /* Define the connection,configuration and power status */
     uint8_t        device_status_new;
-    uint8_t        device_old_status;    
+    uint8_t        device_old_status;
     uint8_t        device_address;
-    uint8_t        connection_status;  
+    uint8_t        connection_status;
     uint8_t        test_mode;
     uint32_t       DevRemoteWakeup;
     USB_OTG_EP     in_ep   [USB_OTG_MAX_TX_FIFOS];
     USB_OTG_EP     out_ep  [USB_OTG_MAX_TX_FIFOS];
-    uint8_t        setup_packet [8*3];
+    uint8_t        setup_packet [8];
     USBD_Class_cb_TypeDef         *class_cb;
     USBD_Usr_cb_TypeDef           *usr_cb;
-    USBD_DEVICE                   *usr_device;  
+    USBD_DEVICE                   *usr_device;
     uint8_t        *pConfig_descriptor;
     uint8_t	      zero_replay_flag;
  }
@@ -262,15 +262,15 @@
 
 typedef struct _HCD
 {
-    uint8_t                  Rx_Buffer [MAX_DATA_LENGTH];  
+    uint8_t                  Rx_Buffer [MAX_DATA_LENGTH];
     volatile uint32_t            ConnSts;
     volatile uint32_t            ErrCnt[USB_OTG_MAX_TX_FIFOS];
     volatile uint32_t            XferCnt[USB_OTG_MAX_TX_FIFOS];
-    volatile HC_STATUS           HC_Status[USB_OTG_MAX_TX_FIFOS];  
+    volatile HC_STATUS           HC_Status[USB_OTG_MAX_TX_FIFOS];
     volatile URB_STATE           URB_State[USB_OTG_MAX_TX_FIFOS];
     USB_OTG_HC               hc [USB_OTG_MAX_TX_FIFOS];
     uint16_t                 channel [USB_OTG_MAX_TX_FIFOS];
-//  USB_OTG_hPort_TypeDef    *port_cb;  
+//  USB_OTG_hPort_TypeDef    *port_cb;
 }
 HCD_DEV , *USB_OTG_USBH_PDEV;
 
@@ -278,8 +278,8 @@
 typedef struct _OTG
 {
     uint8_t    OTG_State;
-    uint8_t    OTG_PrevState;  
-    uint8_t    OTG_Mode;    
+    uint8_t    OTG_PrevState;
+    uint8_t    OTG_Mode;
 }
 OTG_DEV , *USB_OTG_USBO_PDEV;
 
@@ -301,41 +301,41 @@
 
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USB_CORE_Exported_Macros
   * @{
-  */ 
+  */
 
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup USB_CORE_Exported_Variables
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup USB_CORE_Exported_FunctionsPrototype
   * @{
-  */ 
+  */
 USB_OTG_STS  USB_OTG_TRIG(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
 USB_OTG_STS USB_OTG_EPReply_Zerolen(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
 
 USB_OTG_STS  USB_OTG_CoreInit        (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS  USB_OTG_SelectCore      (USB_OTG_CORE_HANDLE *pdev, 
+USB_OTG_STS  USB_OTG_SelectCore      (USB_OTG_CORE_HANDLE *pdev,
                                       USB_OTG_CORE_ID_TypeDef coreID);
 USB_OTG_STS  USB_OTG_EnableGlobalInt (USB_OTG_CORE_HANDLE *pdev);
 USB_OTG_STS  USB_OTG_DisableGlobalInt(USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev, 
-                         uint8_t *dest, 
-                         uint8_t ch_ep_num, 
+void USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev,
+                         uint8_t *dest,
+                         uint8_t ch_ep_num,
                          uint8_t len);
 
-                         
+
 USB_OTG_STS  USB_OTG_WritePacket     (USB_OTG_CORE_HANDLE *pdev ,
     uint8_t *src,
     uint8_t ch_ep_num,
@@ -390,22 +390,22 @@
 void         USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev);
 void         USB_OTG_StopDevice(USB_OTG_CORE_HANDLE *pdev);
 void         USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t Status);
-uint32_t     USB_OTG_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,USB_OTG_EP *ep); 
+uint32_t     USB_OTG_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,USB_OTG_EP *ep);
 #endif
 
 
 /**
   * @}
-  */ 
+  */
 
 /**
   * @}
-  */ 
+  */
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 
 #ifdef __cplusplus
 }
-#endif	 
+#endif
 
 #endif	/* __USB_CORE_H__ */
 
Index: libraries/harward_Der/usb_core.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/usb_core.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/usb_core.c	(working copy)
@@ -5,7 +5,7 @@
  * Date                 : 21-May-2019
  * Description          : USB-OTG Core layer.
  *****************************************************************************/
- 
+
 /* Include ------------------------------------------------------------------*/
 #include "usb_core.h"
 #include "usb_bsp.h"
@@ -13,10 +13,10 @@
 #include "usbd_usr.h"
 
 /* Private typedef ----------------------------------------------------------*/
-/* Private define -----------------------------------------------------------*/	
-/* Private macro ------------------------------------------------------------*/	
-/* Private variables --------------------------------------------------------*/	
-/* Ptivate function prototypes ----------------------------------------------*/	
+/* Private define -----------------------------------------------------------*/
+/* Private macro ------------------------------------------------------------*/
+/* Private variables --------------------------------------------------------*/
+/* Ptivate function prototypes ----------------------------------------------*/
 
 /******************************************************************************
 * Function Name  :
@@ -29,7 +29,7 @@
 
 
 /*******************************************************************************
-* @brief  USB_OTG_WritePacket : Writes a packet into the Tx FIFO associated 
+* @brief  USB_OTG_WritePacket : Writes a packet into the Tx FIFO associated
 *         with the EP
 * @param  pdev : Selected device
 * @param  src : source pointer
@@ -38,16 +38,16 @@
 * @retval USB_OTG_STS : status
 */
 
-USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev, 
-                                uint8_t             *src, 
-                                uint8_t             ch_ep_num, 
+USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev,
+                                uint8_t             *src,
+                                uint8_t             ch_ep_num,
                                 uint8_t            len)
 {
     USB_OTG_STS status = USB_OTG_OK;
     uint8_t i= 0;
   //  MyPrintf("write_len%x\n\r",len);
 //	my_delay_ms(1);
- 
+
     #ifdef USB_HID_DEMO_TEST
     if(ch_ep_num == 1)
     {
@@ -68,8 +68,8 @@
        	//	MyPrintf("src = %02x\n", *src);
           	USB_OTG_WRITE_REG8(pdev->regs.ep[ch_ep_num],*src++);
         }
-//        USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->EMPTY, 1<<ch_ep_num);							
-    } 
+//        USB_OTG_WRITE_REG8(&pdev->regs.STATUSEGS ->EMPTY, 1<<ch_ep_num);
+    }
 
     return status;
 }
@@ -83,9 +83,9 @@
 * @param  bytes : No. of bytes
 * @retval None
 */
-void USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev, 
-                         uint8_t *dest, 
-                         uint8_t ch_ep_num, 
+void USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev,
+                         uint8_t *dest,
+                         uint8_t ch_ep_num,
                          uint8_t len)
 {
     uint8_t i=0;
@@ -96,12 +96,12 @@
     {
       //  *data_buff = USB_OTG_READ_REG8(pdev->regs.ep[ch_ep_num]);
 //				delay_ms(1);
-				*data_buff = USB_OTG_READ_REG8(CORE_USB_EP(ch_ep_num));	
+				*data_buff = USB_OTG_READ_REG8(CORE_USB_EP(ch_ep_num));
     }
 
-		
+
     /* Return the buffer pointer because if the transfer is composed of several
-     packets, the data of the next packet must be stored following the 
+     packets, the data of the next packet must be stored following the
      previous packet's data */
 //    return ;
 }
@@ -109,28 +109,28 @@
 
 
 /**
-* @brief  USB_OTG_SelectCore 
+* @brief  USB_OTG_SelectCore
 *         Initialize core registers address.
 * @param  pdev : Selected device
 * @param  coreID : USB OTG Core ID
 * @retval USB_OTG_STS : status
 */
-USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev, 
+USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev,
                                USB_OTG_CORE_ID_TypeDef coreID)
 {
        uint32_t i , baseAddress = 0;
        USB_OTG_STS status = USB_OTG_OK;
         #ifdef  USB_OTG_DMA_ENABLE
-        pdev->cfg.dma_enable       = 1; 
+        pdev->cfg.dma_enable       = 1;
         #else
         pdev->cfg.dma_enable       = 0;
         #endif
 
 	 /* at startup the core is in FS mode */
        pdev->cfg.speed            = USB_OTG_SPEED_FULL;
-       pdev->cfg.mps              = USB_OTG_FS_MAX_PACKET_SIZE ;    
+       pdev->cfg.mps              = USB_OTG_FS_MAX_PACKET_SIZE ;
+
 
-       
        /* initialize device cfg following its address */
     if (coreID == USB_OTG_FS_CORE_ID)
     {
@@ -139,43 +139,43 @@
 //        pdev->cfg.host_channels    = 8 ;
         pdev->cfg.dev_endpoints    = 4 ;
         pdev->cfg.TotalFifoSize    = 64; /* in 8-bits */
-        pdev->cfg.phy_itface       = USB_OTG_EMBEDDED_PHY;     
+        pdev->cfg.phy_itface       = USB_OTG_EMBEDDED_PHY;
+
+        #ifdef USB_OTG_FS_SOF_OUTPUT_ENABLED
+        pdev->cfg.Sof_output       = 1;
+        #endif
 
-        #ifdef USB_OTG_FS_SOF_OUTPUT_ENABLED    
-        pdev->cfg.Sof_output       = 1;    
-        #endif 
-
-        #ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT    
-        pdev->cfg.low_power        = 1;    
-        #endif     
+        #ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
+        pdev->cfg.low_power        = 1;
+        #endif
     }
     else if (coreID == USB_OTG_HS_CORE_ID)
     {
         baseAddress                = USB_OTG_FS_BASE_ADDR;
-        pdev->cfg.coreID           = USB_OTG_HS_CORE_ID;    
+        pdev->cfg.coreID           = USB_OTG_HS_CORE_ID;
         pdev->cfg.host_channels    = 8 ;
         pdev->cfg.dev_endpoints    = 4 ;
         pdev->cfg.TotalFifoSize    = 512;/* in 8-bits */
 
         #ifdef USB_OTG_ULPI_PHY_ENABLED
             pdev->cfg.phy_itface       = USB_OTG_ULPI_PHY;
-        #else    
+        #else
         #ifdef USB_OTG_EMBEDDED_PHY_ENABLED
             pdev->cfg.phy_itface       = USB_OTG_EMBEDDED_PHY;
-        #endif  
-        #endif      
+        #endif
+        #endif
 
-        #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED    
-            pdev->cfg.dma_enable       = 1;    
+        #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+            pdev->cfg.dma_enable       = 1;
         #endif
 
-        #ifdef USB_OTG_HS_SOF_OUTPUT_ENABLED    
-            pdev->cfg.Sof_output       = 1;    
-        #endif 
-
-        #ifdef USB_OTG_HS_LOW_PWR_MGMT_SUPPORT    
-            pdev->cfg.low_power        = 1;    
-        #endif 
+        #ifdef USB_OTG_HS_SOF_OUTPUT_ENABLED
+            pdev->cfg.Sof_output       = 1;
+        #endif
+
+        #ifdef USB_OTG_HS_LOW_PWR_MGMT_SUPPORT
+            pdev->cfg.low_power        = 1;
+        #endif
     }
 
 	/* Common USB Registers */
@@ -217,25 +217,25 @@
 //    usbcfg.d32 = 0;
 //    gccfg.d32 = 0;
 //    ahbcfg.d32 = 0;
-//  
-//    /* FS interface*/ 
+//
+//    /* FS interface*/
 //    /* Reset after a PHY select and set Host mode */
 //    USB_OTG_CoreReset(pdev);
 //    /* Deactivate the power down*/
 //    gccfg.d32 = 0;
 //    gccfg.b.pwdn = 1;
-//    
+//
 //    gccfg.b.vbussensingA = 1 ;
-//    gccfg.b.vbussensingB = 1 ;     
+//    gccfg.b.vbussensingB = 1 ;
 //#ifndef VBUS_SENSING_ENABLED
-//    gccfg.b.disablevbussensing = 1; 
-//#endif    
-//    
+//    gccfg.b.disablevbussensing = 1;
+//#endif
+//
 //    if(pdev->cfg.Sof_output)
 //    {
-//        gccfg.b.sofouten = 1;  
+//        gccfg.b.sofouten = 1;
 //    }
-//    
+//
 //    USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GCCFG, gccfg.d32);
 //    USB_OTG_BSP_mDelay(20);
 //    /* case the HS core is working in FS mode */
@@ -270,10 +270,10 @@
     USB_OTG_STS status = USB_OTG_OK;
 //    USB_OTG_POWER_TypeDef  power;
 //    USB_OTG_DEVCTL_TypeDef devctl;
-    
+
 //    power.d8 = 0;
 //    devctl.d8 = USB_OTG_READ_REG8(&pdev->regs.DYNFIFOREGS->DEVCTL);
-//    
+//
     if ( mode == HOST_MODE)
     {
 //        power.b.en_suspendM = 1;
@@ -298,7 +298,7 @@
 
 	delay_us(50);
    // USB_OTG_BSP_mDelay(50);
-	
+
     return status;
 }
 
@@ -324,7 +324,7 @@
 //        addr = &pdev->regs.COMMREGS->INTRRXE;
         intr_rxtxe.d8 = 1 << ep->num;
         USB_OTG_MODIFY_REG8(&pdev->regs.CTRLREGS ->IRQ_MASK1, intr_rxtxe.d8, 0);
-    }  
+    }
     return status;
 }
 
@@ -346,14 +346,14 @@
 //        addr = &pdev->regs.COMMREGS->INTRTXE;
 	 empty_rxtxe.d8 = 1 << ep->num;
         USB_OTG_MODIFY_REG8(&pdev->regs.CTRLREGS ->IRQ_MASK1, 0, empty_rxtxe.d8);
-      
+
     }
     else
     {
 //        addr = &pdev->regs.COMMREGS->INTRRXE;
         intr_rxtxe.d8 = 1 << ep->num;
         USB_OTG_MODIFY_REG8(&pdev->regs.CTRLREGS ->IRQ_MASK1, 0, intr_rxtxe.d8);
-     }  
+     }
     return status;
 }
 
@@ -381,7 +381,7 @@
 }
 
 /**
-* @brief  USB_OTG_EPStartXfer : Handle the setup for data xfer for an EP and 
+* @brief  USB_OTG_EPStartXfer : Handle the setup for data xfer for an EP and
 *         starts the xfer
 * @param  pdev : Selected device
 * @retval USB_OTG_STS : status
@@ -393,7 +393,7 @@
     USB_OTG_STS status = USB_OTG_OK;
     uint8_t  rx_count;
     /* IN endpoint */
-	
+
     if (ep->is_in == 1)
 		{
 					 if ((pdev->cfg.dma_enable == 0) || ((USB_OTG_DEV_DMA_EP_NUM & 0x07) != ep->num))
@@ -402,29 +402,29 @@
 									if(ep->rem_data_len == ep->maxpacket)
 									{
 //										MyPrintf("max\r\n");
-										USB_OTG_WritePacket(pdev, 
-																							ep->xfer_buff + ep->xfer_count, 
-																							ep->num, 
-																							ep->maxpacket); 
+										USB_OTG_WritePacket(pdev,
+																							ep->xfer_buff + ep->xfer_count,
+																							ep->num,
+																							ep->maxpacket);
 													ep->xfer_count += ep->maxpacket;
 //													USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,1 << ep ->num);
 //													USB_OTG_WRITE_REG8(CORE_USB_TRIG,1 << ep ->num);
 													USB_OTG_TRIG(pdev,ep);
-													ep->xfer_count = ep->xfer_len; 
+													ep->xfer_count = ep->xfer_len;
 													ep->rem_data_len = 0;
 													pdev->dev.zero_replay_flag =1;
-									
+
 									}
 									/* Zero Length Packet? */
 									else if (ep->rem_data_len == 0)
 									{
 //											MyPrintf("rem_zero\r\n");
-											USB_OTG_WritePacket(pdev, 
-																					ep->xfer_buff + ep->xfer_count, 
-																					ep->num, 
+											USB_OTG_WritePacket(pdev,
+																					ep->xfer_buff + ep->xfer_count,
+																					ep->num,
 																					0);
 											ep->xfer_count = ep->xfer_len;
-											ep->rem_data_len = 0; 
+											ep->rem_data_len = 0;
 			//								tx_csrl.b.tx_pkt_rdy = 1;
 				//							USB_OTG_WRITE_REG8(&pdev->regs.CSRREGS[ep->num]->TXCSRL,tx_csrl.d8);
 									}
@@ -433,36 +433,37 @@
 											if (ep->rem_data_len >ep->maxpacket)
 											{
 //													  GPIO_CONFIG(3) = GPCFG_OUTPUT_LOW;
-													USB_OTG_WritePacket(pdev, 
-																							ep->xfer_buff + ep->xfer_count, 
-																							ep->num, 
-																							ep->maxpacket); 
+													USB_OTG_WritePacket(pdev,
+																							ep->xfer_buff + ep->xfer_count,
+																							ep->num,
+																							ep->maxpacket);
 													USB_OTG_TRIG(pdev,ep);
 //													GPIO_CONFIG(3) = GPCFG_OUTPUT_HIGH;
 													ep->xfer_count += ep->maxpacket;
+                                                    ep->rem_data_len = ep->xfer_len - ep->xfer_count;
 //												MyPrintf("x\r\n");
-													if (ep->xfer_len >= ep->xfer_count)
-													{
-															ep->rem_data_len = ep->xfer_len - ep->xfer_count;
-													}		 
-													else		 
-													{
-															ep->rem_data_len = 0;
-															ep->xfer_count = ep->xfer_len;
-													}										
+//													if (ep->xfer_len >= ep->xfer_count)
+//													{
+//															ep->rem_data_len = ep->xfer_len - ep->xfer_count;
+//													}
+//													else
+//													{
+//															ep->rem_data_len = 0;
+//															ep->xfer_count = ep->xfer_len;
+//													}
 			//										tx_csrl.b.tx_pkt_rdy = 1;
 			//										USB_OTG_WRITE_REG8(&pdev->regs.CSRREGS[ep->num]->TXCSRL,tx_csrl.d8);
 											}
 											else
 											{
 //													MyPrintf("tx_len %x\n",ep->rem_data_len);
-													USB_OTG_WritePacket(pdev, 
-																							ep->xfer_buff + ep->xfer_count, 
-																							ep->num, 
-																							ep->rem_data_len); 
+													USB_OTG_WritePacket(pdev,
+																							ep->xfer_buff + ep->xfer_count,
+																							ep->num,
+																							ep->rem_data_len);
 													USB_OTG_TRIG(pdev,ep);
-													ep->xfer_count = ep->xfer_len; 
-													ep->rem_data_len = 0;								
+													ep->xfer_count = ep->xfer_len;
+													ep->rem_data_len = 0;
 			//										tx_csrl.b.tx_pkt_rdy = 1;
 			//										USB_OTG_WRITE_REG8(&pdev->regs.CSRREGS[ep->num]->TXCSRL,tx_csrl.d8);
 											}
@@ -471,11 +472,11 @@
 		}
 		else
 		{
-				/* OUT endpoint */					
-								rx_count = USB_OTG_READ_REG8(pdev->regs.LENREGS[ep ->num]); 
+				/* OUT endpoint */
+								rx_count = USB_OTG_READ_REG8(pdev->regs.LENREGS[ep ->num]);
 								data_len   = rx_count;
 //								MyPrintf("out_packetlen  %d\n",rx_count);
-								USB_OTG_ReadPacket(pdev, ep->xfer_buff + ep->xfer_count,ep->num, rx_count);																 
+								USB_OTG_ReadPacket(pdev, ep->xfer_buff + ep->xfer_count,ep->num, rx_count);
 								ep->xfer_count += rx_count;
 								if (ep->xfer_len <= ep->xfer_count)
 								{
@@ -497,7 +498,7 @@
 
 
 /**
-* @brief  USB_OTG_EP0StartXfer : Handle the setup for a data xfer for EP0 and 
+* @brief  USB_OTG_EP0StartXfer : Handle the setup for a data xfer for EP0 and
 *         starts the xfer
 * @param  pdev : Selected device
 * @retval USB_OTG_STS : status
@@ -513,14 +514,16 @@
     /* IN endpoint */
     if (ep->is_in == 1)
     {
-        ep->rem_data_len = ep->xfer_len - ep->xfer_count;
+//        ep->rem_data_len = ep->xfer_len - ep->xfer_count;
         /* Zero Length Packet? */
         if (ep->rem_data_len == 0)
         {
 //        	//	send zero packet
-           USB_OTG_EPReply_Zerolen(pdev,ep);
-            ep->xfer_count = ep->xfer_len;
-            ep->rem_data_len = 0;
+            if(ep->xfer_len!=0 && ep->xfer_len%ep->maxpacket==0)
+            {
+                USB_OTG_EPReply_Zerolen(pdev,ep);
+                ep->xfer_len=0;
+            }
 //            csr0l.b.tx_pkt_rdy = 1;
 //            csr0l.b.data_end = 1;
 //            USB_OTG_WRITE_REG8(&pdev->regs.INDEXREGS->CSRL.CSR0L,csr0l.d8);
@@ -529,10 +532,10 @@
         {
             if (ep->rem_data_len > ep->maxpacket)
             {
-                USB_OTG_WritePacket(pdev, 
-                                    ep->xfer_buff + ep->xfer_count, 
-                                    0, 
-                                    ep->maxpacket); 
+                USB_OTG_WritePacket(pdev,
+                                    ep->xfer_buff + ep->xfer_count,
+                                    0,
+                                    ep->maxpacket);
                 ep->xfer_count += ep->maxpacket;
                 ep->rem_data_len = ep->xfer_len - ep->xfer_count;
                 USB_OTG_TRIG(pdev , ep);
@@ -542,12 +545,12 @@
             else
             {
       //          MyPrintf("txbuf = %x\n", ep->xfer_buff);
-                USB_OTG_WritePacket(pdev, 
-                                    ep->xfer_buff + ep->xfer_count, 
-                                    0, 
-                                    ep->rem_data_len);  
-                ep->xfer_count = ep->xfer_len;    
-                ep->rem_data_len = 0;   
+                USB_OTG_WritePacket(pdev,
+                                    ep->xfer_buff + ep->xfer_count,
+                                    0,
+                                    ep->rem_data_len);
+                ep->xfer_count = ep->xfer_len;
+                ep->rem_data_len = 0;
                 USB_OTG_TRIG(pdev , ep);
 //                MyPrintf("usb0 tx\n");
 //                csr0l.b.tx_pkt_rdy = 1;
@@ -578,7 +581,7 @@
         }
         else
         {
-	//		rx_count = USB_OTG_READ_REG8(pdev->regs.LENREGS[0]); 
+	//		rx_count = USB_OTG_READ_REG8(pdev->regs.LENREGS[0]);
 			if(out0_data_len)
 			{
 								 rx_count = out0_data_len;
@@ -588,11 +591,11 @@
 				rx_count = USB_OTG_READ_REG8(pdev->regs.LENREGS[0]);
 			}
 //								MyPrintf("out_packetlen  %d\n",rx_count);
-								USB_OTG_ReadPacket(pdev, ep->xfer_buff + ep->xfer_count,ep->num, ep->xfer_len);	
+								USB_OTG_ReadPacket(pdev, ep->xfer_buff + ep->xfer_count,ep->num, ep->xfer_len);
 						        ep->xfer_count =0;
 							 ep->xfer_buff = pdev->dev.setup_packet;
-			
-				
+
+
         }
 
     }
@@ -651,7 +654,7 @@
 //        }
 //        else
 //        {
-//            
+//
 //            USB_OTG_WRITE_REG8(&pdev->regs.xferctl ->STALL, 0x01);
 //        }
 //    }
@@ -667,7 +670,7 @@
 //            USB_OTG_WRITE_REG8(&pdev->regs.xferctl ->STALL, 0x01);
 //        }
 //    }
-    
+
     return status;
 }
 
@@ -694,15 +697,15 @@
 void USB_OTG_ActiveRemoteWakeup(USB_OTG_CORE_HANDLE *pdev)
 {
     USB_OTG_CTL_TypeDef power;
-    /* Note: If CLK has been stopped,it will need be restarted before 
-     * this write can occur. 
+    /* Note: If CLK has been stopped,it will need be restarted before
+     * this write can occur.
      */
-    power.d8 = USB_OTG_READ_REG8(&pdev->regs.CTRLREGS ->USB_CTL); 
+    power.d8 = USB_OTG_READ_REG8(&pdev->regs.CTRLREGS ->USB_CTL);
     power.b.resume = 1;
     power.b.wakeup_enable = 1;
     USB_OTG_WRITE_REG8(&pdev->regs.CTRLREGS ->USB_CTL, power.d8);
     /* The software should leave then this bit set for approximately 10ms
-     * (minimum of 2ms, a maximum of 15ms) before resetting it to 0.    
+     * (minimum of 2ms, a maximum of 15ms) before resetting it to 0.
      */
    delay_ms(2);
    delay_us(500);
Index: libraries/harward_Der/usb_defines.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/usb_defines.h	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/libraries/harward_Der/usb_defines.h	(working copy)
@@ -5,46 +5,46 @@
  * Date                 : 21-May-2019
  * Description          : Header of the Core Layer.
  *****************************************************************************/
- 
- 
+
+
 #ifndef __USB_DEF_H__
 #define __USB_DEF_H__
- 
- 
+
+
 #ifdef __cplusplus
 extern "C" {
 #endif
-	
+
 /* Include ------------------------------------------------------------------*/
-#include "usb_conf.h"	
+#include "usb_conf.h"
 /* Exported types -----------------------------------------------------------*/
-/* Exported constants -------------------------------------------------------*/	
-/* Exported macro -----------------------------------------------------------*/	
-/* Exported functions -------------------------------------------------------*/	
-/* Exported variables -------------------------------------------------------*/	
+/* Exported constants -------------------------------------------------------*/
+/* Exported macro -----------------------------------------------------------*/
+/* Exported functions -------------------------------------------------------*/
+/* Exported variables -------------------------------------------------------*/
 /** @addtogroup USB_OTG_DRIVER
   * @{
   */
-  
+
 /** @defgroup USB_DEFINES
-  * @brief This file is the 
+  * @brief This file is the
   * @{
-  */ 
+  */
 
 
 /** @defgroup USB_DEFINES_Exported_Defines
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup _CORE_DEFINES_
   * @{
   */
-	
 
+#define USB_FLOWCTRL
 
 #define USB_STATUS_SETUP			0x10
 #define USB_STATUS_SUSPEND			0x20
@@ -186,7 +186,7 @@
 
 /** @defgroup USB_DEFINES_Exported_Types
   * @{
-  */ 
+  */
 
 typedef enum
 {
@@ -195,29 +195,29 @@
 }USB_OTG_CORE_ID_TypeDef;
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USB_DEFINES_Exported_Macros
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup USB_DEFINES_Exported_Variables
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup USB_DEFINES_Exported_FunctionsPrototype
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup Internal_Macro's
@@ -249,7 +249,7 @@
 };
 #ifdef __cplusplus
 }
-#endif	 
+#endif
 
 #endif	/* __USB_DEF_H__ */
 
Index: scpu_usb_CDC_Device_Demo/usb_conf.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usb_conf.h	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usb_conf.h	(working copy)
@@ -16,8 +16,8 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
@@ -31,22 +31,21 @@
 
 /* Includes ------------------------------------------------------------------*/
 #include "yc3121.h"
-//#include "mhscpu_eval.h" 
 
 
 
 /** @addtogroup USB_OTG_DRIVER
   * @{
   */
-  
+
 /** @defgroup USB_CONF
   * @brief USB low level driver configuration file
   * @{
-  */ 
+  */
 
 /** @defgroup USB_CONF_Exported_Defines
   * @{
-  */ 
+  */
 
 /* USB Core and PHY interface configuration.
    Tip: To avoid modifying these defines each time you need to change the USB
@@ -55,30 +54,30 @@
    */
 /****************** USB OTG FS PHY CONFIGURATION *******************************
 *  The USB OTG FS Core supports one on-chip Full Speed PHY.
-*  
-*  The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor 
+*
+*  The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor
 *  when FS core is used.
 *******************************************************************************/
 #ifndef USE_USB_OTG_FS
  //#define USE_USB_OTG_FS
 #endif /* USE_USB_OTG_FS */
 
-#ifdef USE_USB_OTG_FS 
+#ifdef USE_USB_OTG_FS
  #define USB_OTG_FS_CORE
 #endif
 
 /****************** USB OTG HS PHY CONFIGURATION *******************************
 *  The USB OTG HS Core supports two PHY interfaces:
-*   (i)  An ULPI interface for the external High Speed PHY: the USB HS Core will 
+*   (i)  An ULPI interface for the external High Speed PHY: the USB HS Core will
 *        operate in High speed mode
 *   (ii) An on-chip Full Speed PHY: the USB HS Core will operate in Full speed mode
 *
 *  You can select the PHY to be used using one of these two defines:
-*   (i)  USE_ULPI_PHY: if the USB OTG HS Core is to be used in High speed mode 
+*   (i)  USE_ULPI_PHY: if the USB OTG HS Core is to be used in High speed mode
 *   (ii) USE_EMBEDDED_PHY: if the USB OTG HS Core is to be used in Full speed mode
 *
-*  Notes: 
-*   - The USE_ULPI_PHY symbol is defined in the project compiler preprocessor as 
+*  Notes:
+*   - The USE_ULPI_PHY symbol is defined in the project compiler preprocessor as
 *     default PHY when HS core is used.
 *   - On STM322xG-EVAL and STM324xG-EVAL boards, only configuration(i) is available.
 *     Configuration (ii) need a different hardware, for more details refer to your
@@ -96,46 +95,46 @@
  //#define USE_EMBEDDED_PHY
 #endif /* USE_EMBEDDED_PHY */
 
-#ifdef USE_USB_OTG_HS 
+#ifdef USE_USB_OTG_HS
  #define USB_OTG_HS_CORE
 #endif
 
 /*******************************************************************************
 *                      FIFO Size Configuration in Device mode
-*  
-*  (i) Receive data FIFO size = RAM for setup packets + 
+*
+*  (i) Receive data FIFO size = RAM for setup packets +
 *                   OUT endpoint control information +
 *                   data OUT packets + miscellaneous
 *      Space = ONE 32-bits words
 *     --> RAM for setup packets = 10 spaces
-*        (n is the nbr of CTRL EPs the device core supports) 
+*        (n is the nbr of CTRL EPs the device core supports)
 *     --> OUT EP CTRL info      = 1 space
-*        (one space for status information written to the FIFO along with each 
+*        (one space for status information written to the FIFO along with each
 *        received packet)
-*     --> data OUT packets      = (Largest Packet Size / 4) + 1 spaces 
+*     --> data OUT packets      = (Largest Packet Size / 4) + 1 spaces
 *        (MINIMUM to receive packets)
-*     --> OR data OUT packets  = at least 2*(Largest Packet Size / 4) + 1 spaces 
+*     --> OR data OUT packets  = at least 2*(Largest Packet Size / 4) + 1 spaces
 *        (if high-bandwidth EP is enabled or multiple isochronous EPs)
 *     --> miscellaneous = 1 space per OUT EP
-*        (one space for transfer complete status information also pushed to the 
+*        (one space for transfer complete status information also pushed to the
 *        FIFO with each endpoint's last packet)
 *
-*  (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for 
+*  (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
 *       that particular IN EP. More space allocated in the IN EP Tx FIFO results
 *       in a better performance on the USB and can hide latencies on the AHB.
 *
 *  (iii) TXn min size = 16 words. (n  : Transmit FIFO index)
-*   (iv) When a TxFIFO is not used, the Configuration should be as follows: 
+*   (iv) When a TxFIFO is not used, the Configuration should be as follows:
 *       case 1 :  n > m    and Txn is not used    (n,m  : Transmit FIFO indexes)
 *       --> Txm can use the space allocated for Txn.
 *       case2  :  n < m    and Txn is not used    (n,m  : Transmit FIFO indexes)
 *       --> Txn should be configured with the minimum space of 16 words
-*  (v) The FIFO is used optimally when used TxFIFOs are allocated in the top 
+*  (v) The FIFO is used optimally when used TxFIFOs are allocated in the top
 *       of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
 *   (vi) In HS case12 FIFO locations should be reserved for internal DMA registers
-*        so total FIFO size should be 1012 Only instead of 1024       
+*        so total FIFO size should be 1012 Only instead of 1024
 *******************************************************************************/
- 
+
 /****************** USB OTG HS CONFIGURATION **********************************/
 #ifdef USB_OTG_HS_CORE
  #define RX_FIFO_HS_SIZE                          512
@@ -151,10 +150,10 @@
  #ifdef USE_ULPI_PHY
   #define USB_OTG_ULPI_PHY_ENABLED
  #endif
- #ifdef USE_EMBEDDED_PHY 
+ #ifdef USE_EMBEDDED_PHY
    #define USB_OTG_EMBEDDED_PHY_ENABLED
  #endif
- #define USB_OTG_HS_INTERNAL_DMA_ENABLED 
+ #define USB_OTG_HS_INTERNAL_DMA_ENABLED
  #define USB_OTG_HS_DEDICATED_EP1_ENABLED
  #define USB_OTG_HS_LOW_PWR_MGMT_SUPPORT
 #endif
@@ -188,7 +187,7 @@
                                      ((size) == 64)  || \
                                      ((size) == 128) || \
                                      ((size) == 256) || \
-                                     ((size) == 512)) 
+                                     ((size) == 512))
 //#define USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
 // #define USB_OTG_FS_SOF_OUTPUT_ENABLED
 
@@ -210,25 +209,25 @@
 
 /****************** C Compilers dependant keywords ****************************/
 /* In HS mode and when the DMA is used, all variables and data structures dealing
-   with the DMA during the transaction process should be 4-bytes aligned */    
+   with the DMA during the transaction process should be 4-bytes aligned */
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined   (__GNUC__)        /* GNU Compiler */
     #define __ALIGN_END    __attribute__ ((aligned (4)))
-    #define __ALIGN_BEGIN         
-  #else                           
+    #define __ALIGN_BEGIN
+  #else
     #define __ALIGN_END
     #if defined   (__CC_ARM)      /* ARM Compiler */
-      #define __ALIGN_BEGIN    __align(4)  
+      #define __ALIGN_BEGIN    __align(4)
     #elif defined (__ICCARM__)    /* IAR Compiler */
-      #define __ALIGN_BEGIN 
+      #define __ALIGN_BEGIN
     #elif defined  (__TASKING__)  /* TASKING Compiler */
-      #define __ALIGN_BEGIN    __align(4) 
-    #endif /* __CC_ARM */  
-  #endif /* __GNUC__ */ 
+      #define __ALIGN_BEGIN    __align(4)
+    #endif /* __CC_ARM */
+  #endif /* __GNUC__ */
 #else
-  //#define __ALIGN_BEGIN         __align(4) 
+  //#define __ALIGN_BEGIN         __align(4)
   #define __ALIGN_END    __attribute__ ((aligned (4)))
-  #define __ALIGN_BEGIN 
+  #define __ALIGN_BEGIN
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 
 /* __packed keyword used to decrease the data type alignment to 1-byte */
@@ -236,7 +235,7 @@
   #define __packed    __packed
 #elif defined (__ICCARM__)     /* IAR Compiler */
   #define __packed    __packed
-#elif defined   ( __GNUC__ )   /* GNU Compiler */                        
+#elif defined   ( __GNUC__ )   /* GNU Compiler */
 //  #define __packed    __attribute__ ((__packed__))
 #elif defined   (__TASKING__)  /* TASKING Compiler */
   #define __packed    __unaligned
@@ -244,37 +243,37 @@
 
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USB_CONF_Exported_Types
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USB_CONF_Exported_Macros
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup USB_CONF_Exported_Variables
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup USB_CONF_Exported_FunctionsPrototype
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 #endif //__USB_CONF__H__
@@ -282,11 +281,11 @@
 
 /**
   * @}
-  */ 
+  */
 
 /**
   * @}
-  */ 
+  */
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 
Index: scpu_usb_CDC_Device_Demo/usb_main.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usb_main.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usb_main.c	(working copy)
@@ -9,9 +9,9 @@
   * @attention
   *
   ******************************************************************************
-  */ 
+  */
 
-/* Includes ------------------------------------------------------------------*/ 
+/* Includes ------------------------------------------------------------------*/
 
 
 
@@ -23,107 +23,73 @@
 #include "usbd_usr.h"
 #include "usbd_desc.h"
 #include "misc.h"
+#include "usbd_cdc_vcp.h"
 
 
 USB_OTG_CORE_HANDLE  USB_OTG_dev;
-extern struct APP_DATA_STRUCT_DEF APP_Gdata_param; 
 extern CDC_IF_Prop_TypeDef  APP_FOPS;
 
 
-void usb_init()
+void usb_reg_init()
 {
-					USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x00);
-		//			my_delay_ms(1);
-					USB_OTG_WRITE_REG8(CORE_USB_TRIG,0xc0); 
-					 USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x3c);
-					 USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
-					 USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
-					 USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
-					 USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
-					 #ifdef USB_HID_DEMO_TEST
-					  USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf2);
-					  #else
-					 USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
-					 #endif
-					 USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
+    USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x00);
+    my_delay_ms(1);
+    USB_OTG_WRITE_REG8(CORE_USB_TRIG,0xc0);
+    USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x3c);
+    USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
+    USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
+    USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
 
 
 }
- extern uint8_t CDC_Recv_Flag;
 
 uint8_t Rxbuf[1024*2] = {0};
+uint32_t totalLen=0;
 void usb_main(void)
 {
   int rxlen = 0;
-	enable_clock(CLKCLS_BT);	
+	enable_clock(CLKCLS_BT);
 	BT_CLKPLL_EN = 0xff;
 	enable_clock(CLKCLS_USB);
 	SYSCTRL_HCLK_CON |= 1 << 11;
-	usb_init();
-	
-  enable_intr(INTR_USB); 
+	usb_reg_init();
+
   memset(&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
 
   USBD_Init(&USB_OTG_dev,
         #ifdef USE_USB_OTG_HS
               USB_OTG_HS_CORE_ID,
         #else
-              USB_OTG_FS_CORE_ID, 
+              USB_OTG_FS_CORE_ID,
         #endif
               &USR_desc,
-              &USBD_CDC_cb, 
+              &USBD_CDC_cb,
               &USRD_cb);
-	
-    MyPrintf("YICHIP SCPU USB VCP Demo V1.0.\n");
-	
+
+enable_intr(INTR_USB);
+
 	while(1)
 	{
-		uint16_t temp1,temp2,cnt;
-				temp2 = temp1;
-				temp1 = USB_OTG_READ_REG8(USB_SOFCNT)|( USB_OTG_READ_REG8(USB_SOFCNTHI)<<8); 
-				if((temp2 == temp1) && (temp1 !=0))
-				    cnt++;
-				else 
-					cnt = 0;
-				
-				if(cnt ==10000)
-				{
-					MyPrintf("reset ");
-					USB_OTG_dev.dev.zero_replay_flag =0;
-					memset(&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
-					USB_OTG_dev.dev.device_status = USB_OTG_DEFAULT;
-
-                              	 USBD_Init(&USB_OTG_dev,
-                                      #ifdef USE_USB_OTG_HS
-                                            USB_OTG_HS_CORE_ID,
-                                      #else
-                                            USB_OTG_FS_CORE_ID, 
-                                      #endif
-                                            &USR_desc,
-                                            &USBD_CDC_cb, 
-                                            &USRD_cb);
-					temp1=temp2=cnt=0;
-					USB_OTG_WRITE_REG8(CORE_USB_CLEAR,0x40);
-					USB_OTG_WRITE_REG8(USB_SOFCNT,0);
-					usb_init();
-				}
-		if (CDC_Recv_Flag)
-		{
-			rxlen = VCP_GetRxBuflen();
-			if(rxlen>0)
-			{
-				MyPrintf("rxlen =%d\n\r",rxlen);
-				for(int i=0; i<rxlen; i++)
-				{
-					Rxbuf[i] = VCP_GetRxChar();	
-				}
-
-				CDC_Recv_Flag = 0;
-				DCD_EP_Tx(&USB_OTG_dev,CDC_IN_EP,(uint8_t*)Rxbuf,rxlen);	
-			}
-		}
-	}
-  }  
+        rxlen = VCP_GetRxBuflen();
+        if(rxlen>0)
+        {
+            totalLen +=rxlen;
+            MyPrintf("totalLen=%d rxlen =%d\n\r",totalLen,rxlen);
+            for(int i=0; i<rxlen; i++)
+            {
+                Rxbuf[i] = VCP_GetRxChar();
+                MyPrintf("%02x ",Rxbuf[i]);
+            }
+            MyPrintf("\n");
+            #ifndef USB_FLOWCTRL
+            DCD_EP_Tx(&USB_OTG_dev,CDC_IN_EP,(uint8_t*)Rxbuf,rxlen);
+            #endif
+        }
+    }
+}
 
 
 
@@ -146,6 +112,6 @@
 
 
 
- 
+
 
 
Index: scpu_usb_CDC_Device_Demo/usbd_cdc_vcp.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usbd_cdc_vcp.h	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usbd_cdc_vcp.h	(working copy)
@@ -16,8 +16,8 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
@@ -41,7 +41,7 @@
 
 
 /* Exported typef ------------------------------------------------------------*/
-/* The following structures groups all needed parameters to be configured for the 
+/* The following structures groups all needed parameters to be configured for the
    ComPort. These parameters can modified on the fly by the host through CDC class
    command class requests. */
 typedef struct
@@ -57,8 +57,8 @@
 /* Exported constants --------------------------------------------------------*/
 /* The following define is used to route the USART IRQ handler to be used.
    The IRQ handler function is implemented in the usbd_cdc_vcp.c file. */
-          
-//#define EVAL_COM_IRQHandler            UART1_IRQHandler  
+
+//#define EVAL_COM_IRQHandler            UART1_IRQHandler
 
 #define DEFAULT_CONFIG                  0
 #define OTHER_CONFIG                    1
@@ -68,7 +68,7 @@
 uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len);
 uint32_t VCP_GetTxBuflen(void);
 uint32_t VCP_GetTxBufrsaddr(void);
-int32_t  VCP_GetRxChar(void);
+uint8_t  VCP_GetRxChar(void);
 uint32_t VCP_GetRxBuflen(void);
 int8_t * VCP_GetRxBufrsaddr(void);
 #endif /* __USBD_CDC_VCP_H */
Index: scpu_usb_CDC_Device_Demo/usbd_cdc_vcp.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usbd_cdc_vcp.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usbd_cdc_vcp.c	(working copy)
@@ -16,17 +16,17 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   ******************************************************************************
-  */ 
+  */
 
-#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED 
-#pragma     data_alignment = 4 
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+#pragma     data_alignment = 4
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 
 /* Includes ------------------------------------------------------------------*/
@@ -49,19 +49,19 @@
 
 UART_InitTypeDef USART_InitStructure;
 
-/* These are external variables imported from CDC core to be used for IN 
+/* These are external variables imported from CDC core to be used for IN
    transfer management. */
 
 #ifdef USER_SPECIFIED_DATA_SOURCE
-extern uint8_t  *APP_Rx_Buffer;   
+extern uint8_t  *APP_Rx_Buffer;
 uint8_t COM_Rx_data_buf[2048];
-#else  
-//extern uint8_t  APP_Rx_Buffer [];   
-extern struct APP_DATA_STRUCT_DEF APP_Gdata_param; 
+#else
+//extern uint8_t  APP_Rx_Buffer [];
+extern struct APP_DATA_STRUCT_DEF APP_Gdata_param;
 #endif                            /* Write CDC received data in this buffer.
                                      These data will be sent over USB IN endpoint
                                      in the CDC core functions. */
-//extern volatile uint32_t APP_Rx_ptr_in;    
+//extern volatile uint32_t APP_Rx_ptr_in;
                                   /* Increment this pointer or roll it back to
                                      start address when writing received data
                                      in the buffer APP_Rx_Buffer. */
@@ -75,7 +75,7 @@
 
 static uint16_t VCP_COMConfig(uint8_t Conf);
 
-CDC_IF_Prop_TypeDef VCP_fops = 
+CDC_IF_Prop_TypeDef VCP_fops =
 {
   VCP_Init,
   VCP_DeInit,
@@ -94,7 +94,7 @@
 static uint16_t VCP_Init(void)
 {
 //    NVIC_InitTypeDef NVIC_InitStructure;
-    
+
     /**/
     #ifdef USER_SPECIFIED_DATA_SOURCE
     APP_Rx_Buffer = COM_Rx_data_buf;
@@ -104,7 +104,7 @@
 	memset(&APP_Gdata_param, 0, sizeof(APP_Gdata_param));
     /* EVAL_COM1 default configuration */
     /* EVAL_COM1 configured as follow:
-        - BaudRate = 115200 baud  
+        - BaudRate = 115200 baud
         - Word Length = 8 Bits
         - One Stop Bit
         - Parity Odd
@@ -146,13 +146,13 @@
 /**
   * @brief  VCP_Ctrl
   *         Manage the CDC class requests
-  * @param  Cmd: Command code            
+  * @param  Cmd: Command code
   * @param  Buf: Buffer containing command data (request parameters)
   * @param  Len: Number of data to be sent (in bytes)
   * @retval Result of the opeartion (USBD_OK in all cases)
   */
 static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
-{ 
+{
   switch (Cmd)
   {
   case SEND_ENCAPSULATED_COMMAND:
@@ -181,8 +181,8 @@
     linecoding.paritytype = Buf[5];
     linecoding.datatype = Buf[6];
     APP_Gdata_param.COM_config_cmp = 1;
-    MyPrintf("cmp=%X\n",APP_Gdata_param.COM_config_cmp);
-     MyPrintf("SET_LINE_CODING \n\r");
+//    MyPrintf("cmp=%X\n",APP_Gdata_param.COM_config_cmp);
+//    MyPrintf("SET_LINE_CODING \n\r");
     /* Set the new configuration */
     VCP_COMConfig(OTHER_CONFIG);
     break;
@@ -194,7 +194,8 @@
     Buf[3] = (uint8_t)(linecoding.bitrate >> 24);
     Buf[4] = linecoding.format;
     Buf[5] = linecoding.paritytype;
-    Buf[6] = linecoding.datatype; 
+    Buf[6] = linecoding.datatype;
+//    MyPrintf("GET_LINE_CODING \n\r");
     break;
 
   case SET_CONTROL_LINE_STATE:
@@ -203,8 +204,8 @@
 
   case SEND_BREAK:
     /* Not  needed for this driver */
-    break;    
-    
+    break;
+
   default:
     break;
   }
@@ -222,7 +223,7 @@
 }
 /**
   * @brief  VCP_DataTx
-  *         CDC received data to be send over USB IN endpoint are managed in 
+  *         CDC received data to be send over USB IN endpoint are managed in
   *         this function.
   * @param  Buf: Buffer of data to be sent
   * @param  Len: Number of data to be sent (in bytes)
@@ -233,14 +234,14 @@
     #ifdef USER_SPECIFIED_DATA_SOURCE
     uint32_t i = 0;
     for (i = 0; i < Len; i++)
-    {   
+    {
         *(APP_Rx_Buffer + APP_Rx_ptr_in) = *Buf++;
         APP_Rx_ptr_in++;
     }
     #else
     uint32_t i = 0;
     if (linecoding.datatype == 7)
-    {                                
+    {
         for (i = 0; i < Len; i++)
         {
 //			do
@@ -262,7 +263,7 @@
             if(APP_Gdata_param.rx_structure.APP_Rx_ptr_in == CDC_APP_RX_DATA_SIZE)
             {
                 APP_Gdata_param.rx_structure.APP_Rx_ptr_in = 0;
-            }  
+            }
         }
     }
     else if (linecoding.datatype == 8)
@@ -290,7 +291,7 @@
             if(APP_Gdata_param.rx_structure.APP_Rx_ptr_in == CDC_APP_RX_DATA_SIZE)
             {
                 APP_Gdata_param.rx_structure.APP_Rx_ptr_in = 0;
-            }  
+            }
         }
     }
     #endif
@@ -299,7 +300,7 @@
 
 /**
   * @brief  Get_TxBuf_length
-  *         Get the length of the remaining data to be transmitted    
+  *         Get the length of the remaining data to be transmitted
   * @param  NONE
   * @retval Result receive data length
   */
@@ -316,7 +317,7 @@
 
 /**
   * @brief  Get_RxBuf_rsaddr
-  *         Get reading receive data starting position.    
+  *         Get reading receive data starting position.
   * @param  NONE
   * @retval Result received data is read starting position
   */
@@ -327,64 +328,74 @@
 
 /**
   * @brief  Get_RxData
-  *         Get receive data by byte     
+  *         Get receive data by byte
   * @param  NONE
-  * @retval Result receive data 
+  * @retval Result receive data
   */
-int32_t VCP_GetRxChar(void)
+extern uint8_t usbFlowCtrl;
+uint8_t VCP_GetRxChar(void)
 {
-    /* 没有接收到新数据 */
-	int ret = -1;
-    if (!APP_Gdata_param.tx_structure.Tx_counter)
-    {
-        return -1;
-    }else{ 
-      //  NVIC_DisableIRQ(USB_IRQn);
-        if (APP_Gdata_param.tx_structure.APP_Tx_ptr_out >= CDC_APP_TX_DATA_SIZE)
-        {
-          APP_Gdata_param.tx_structure.APP_Tx_ptr_out = 0;
-        }
-        APP_Gdata_param.tx_structure.Tx_counter--;
-		ret = (APP_Gdata_param.tx_structure.APP_Tx_Buffer[APP_Gdata_param.tx_structure.APP_Tx_ptr_out++]);
-   //     NVIC_EnableIRQ(USB_IRQn);
-  // 	MyPrintf("ret =%x\n",ret);
-        return ret;
-    }
+	uint8_t ret;
+  ret = (APP_Gdata_param.tx_structure.APP_Tx_Buffer[APP_Gdata_param.tx_structure.APP_Tx_ptr_out++]);
+	if (APP_Gdata_param.tx_structure.APP_Tx_ptr_out >= CDC_APP_TX_DATA_SIZE)
+  {
+     APP_Gdata_param.tx_structure.APP_Tx_ptr_out = 0;
+  }
+	#ifdef USB_FLOWCTRL
+	if((VCP_GetRxBuflen()+CDC_DATA_OUT_PACKET_SIZE)<CDC_APP_TX_DATA_SIZE)
+	{
+		if(usbFlowCtrl==1)
+		{
+			//MyPrintf("\r\n\r\n usbFlowCtrl=0\r\n\r\n");
+			usbFlowCtrl=0;
+			NVIC_EnableIRQ(USB_IRQn);
+		}
+	}
+	#endif
+	return ret;
 }
 
 /**
   * @brief  Get_RxBuf_length
-  *         Get receive data length     
+  *         Get receive data length
   * @param  NONE
   * @retval Result receive data length
   */
 uint32_t VCP_GetRxBuflen(void)
 {
-    return (APP_Gdata_param.tx_structure.Tx_counter);
+	uint32_t inPtr=APP_Gdata_param.tx_structure.APP_Tx_ptr_in;
+    if(inPtr>=APP_Gdata_param.tx_structure.APP_Tx_ptr_out)
+		{
+			return (inPtr-APP_Gdata_param.tx_structure.APP_Tx_ptr_out);
+		}
+		else
+		{
+			return (CDC_APP_TX_DATA_SIZE-(APP_Gdata_param.tx_structure.APP_Tx_ptr_out-inPtr));
+		}
 }
 
 /**
   * @brief  Get_RxBuf_rsaddr
-  *         Get reading receive data starting position.    
+  *         Get reading receive data starting position.
   * @param  NONE
   * @retval Result received data is read starting position
   */
 int8_t * VCP_GetRxBufrsaddr(void)
 {
-    return(&(APP_Gdata_param.tx_structure.APP_Tx_Buffer[APP_Gdata_param.tx_structure.APP_Tx_ptr_out]));
+    return (int8_t*)(&(APP_Gdata_param.tx_structure.APP_Tx_Buffer[APP_Gdata_param.tx_structure.APP_Tx_ptr_out]));
 }
 
 /**
   * @brief  VCP_DataRx
-  *         Data received over USB OUT endpoint are sent over CDC interface 
+  *         Data received over USB OUT endpoint are sent over CDC interface
   *         through this function.
-  *           
+  *
   *         @note
-  *         This function will block any OUT packet reception on USB endpoint 
+  *         This function will block any OUT packet reception on USB endpoint
   *         untill exiting this function. If you exit this function before transfer
-  *         is complete on CDC interface (ie. using DMA controller) it will result 
+  *         is complete on CDC interface (ie. using DMA controller) it will result
   *         in receiving more data while previous ones are still not sent.
-  *                 
+  *
   * @param  Buf: Buffer of data to be received
   * @param  Len: Number of data received (in bytes)
   * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
@@ -392,24 +403,28 @@
 static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
 {
     uint32_t i;
-    MyPrintf("vcp_len =%X\n\r",Len);
+    //MyPrintf("vcp_len =%X\n\r",Len);
     for (i = 0; i < Len; i++)
     {
-        APP_Gdata_param.tx_structure.APP_Tx_Buffer[APP_Gdata_param.tx_structure.APP_Tx_ptr_in] = *(Buf + i);
-		APP_Gdata_param.tx_structure.APP_Tx_ptr_in++;
-        APP_Gdata_param.tx_structure.Tx_counter++;
-		if (APP_Gdata_param.tx_structure.Tx_counter > CDC_APP_TX_DATA_SIZE)
-        {
-            APP_Gdata_param.tx_structure.Tx_counter = CDC_APP_TX_DATA_SIZE;
-			APP_Gdata_param.tx_structure.APP_Tx_ptr_out++;
-			APP_Gdata_param.tx_structure.APP_Tx_ptr_out %= CDC_APP_TX_DATA_SIZE;
-        }
-        
-        if (APP_Gdata_param.tx_structure.APP_Tx_ptr_in >= CDC_APP_TX_DATA_SIZE)
-        {
-            APP_Gdata_param.tx_structure.APP_Tx_ptr_in = 0;
-        }
-    } 
+        APP_Gdata_param.tx_structure.APP_Tx_Buffer[APP_Gdata_param.tx_structure.APP_Tx_ptr_in++] = Buf[i];
+				if(APP_Gdata_param.tx_structure.APP_Tx_ptr_in >= CDC_APP_TX_DATA_SIZE)
+				{
+						APP_Gdata_param.tx_structure.APP_Tx_ptr_in = 0;
+				}
+
+				APP_Gdata_param.tx_structure.Tx_counter++;
+    }
+		#ifdef USB_FLOWCTRL
+		if((VCP_GetRxBuflen()+CDC_DATA_OUT_PACKET_SIZE)>=CDC_APP_TX_DATA_SIZE)
+		{
+			if(usbFlowCtrl==0)
+			{
+				usbFlowCtrl=1;
+				NVIC_DisableIRQ(USB_IRQn);
+				//MyPrintf("\r\n\r\n usbFlowCtrl=1\r\n\r\n");
+			}
+		}
+		#endif
     return USBD_OK;
 }
 
@@ -425,11 +440,11 @@
 static uint16_t VCP_COMConfig(uint8_t Conf)
 {
 	/*
-    if (Conf == DEFAULT_CONFIG)  
+    if (Conf == DEFAULT_CONFIG)
     {
 //        /* EVAL_COM1 default configuration */
 //        /* EVAL_COM1 configured as follow:
-//        - BaudRate = 115200 baud  
+//        - BaudRate = 115200 baud
 //        - Word Length = 8 Bits
 //        - One Stop Bit
 //        - Parity Odd
@@ -494,11 +509,11 @@
 //          {
 //            USART_InitStructure.UART_WordLength = UART_WordLength_8b;
 //          }
-//          else 
+//          else
 //          {
 //    //        USART_InitStructure.UART_WordLength = UART_WordLength_9b;
 //          }
-//          
+//
 //          break;
 //        default :
 ////          VCP_COMConfig(DEFAULT_CONFIG);
@@ -514,7 +529,7 @@
 
 /**
   * @brief  EVAL_COM_IRQHandler
-  *         
+  *
   * @param  None.
   * @retval None.
   */
@@ -533,7 +548,7 @@
         case UART_IT_ID_RX_RECVD:
             #ifdef USER_SPECIFIED_DATA_SOURCE
             if (linecoding.datatype == 7)
-            {                                
+            {
                 ra_data_re = UART_ReceiveData(UART1) & 0x7F;
             }
             else if (linecoding.datatype == 8)
@@ -543,13 +558,13 @@
             VCP_DataTx (&ra_data_re, 1);
             #else
 //            UART_ITConfig(UART1, UART_IT_RX_RECVD, DISABLE);
-            
+
             ra_data_re = UART_ReceiveData(UART1);
             VCP_DataTx (&ra_data_re, 1);
-            
+
 //            UART_ITConfig(UART1, UART_IT_RX_RECVD, ENABLE);
             #endif
-        
+
             /* If overrun condition occurs, clear the ORE flag and recover communication */
 //            (void)UART_ReceiveData(UART1);
             break;
Index: scpu_usb_CDC_Device_Demo/usbd_desc.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usbd_desc.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usbd_desc.c	(working copy)
@@ -16,14 +16,14 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   ******************************************************************************
-  */ 
+  */
 
 /* Includes ------------------------------------------------------------------*/
 #include "usbd_core.h"
@@ -37,36 +37,36 @@
   */
 
 
-/** @defgroup USBD_DESC 
+/** @defgroup USBD_DESC
   * @brief USBD descriptors module
   * @{
-  */ 
+  */
 
 /** @defgroup USBD_DESC_Private_TypesDefinitions
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_DESC_Private_Defines
   * @{
-  */ 
-#define USBD_VID                        0x0103
+  */
+#define USBD_VID                        0x3151
 
-#define USBD_PID                        0x6061
+#define USBD_PID                        0x6002
 //#define USBD_VID                        0x0483
 
 //#define USBD_PID                        0x5740
 
 /** @defgroup USB_String_Descriptors
   * @{
-  */ 
+  */
 #define USBD_LANGID_STRING              0x409
-#define USBD_MANUFACTURER_STRING        "MEGAHUNT1901"
+#define USBD_MANUFACTURER_STRING        "YICHIP3121"
 
-#define USBD_PRODUCT_HS_STRING          "MEGAHUNT1901 Virtual ComPort in HS mode"
+#define USBD_PRODUCT_HS_STRING          "YICHIP3121 Virtual ComPort in HS mode"
 #define USBD_SERIALNUMBER_HS_STRING     "00000000050B"
 
 #define USBD_PRODUCT_FS_STRING          "YICHIP3121 Virtual ComPort in FS Mode"
@@ -79,36 +79,36 @@
 #define USBD_INTERFACE_FS_STRING        "VCP Interface"
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_DESC_Private_Macros
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_DESC_Private_Variables
   * @{
-  */ 
+  */
 
 USBD_DEVICE USR_desc =
 {
   USBD_USR_DeviceDescriptor,
-  USBD_USR_LangIDStrDescriptor, 
+  USBD_USR_LangIDStrDescriptor,
   USBD_USR_ManufacturerStrDescriptor,
   USBD_USR_ProductStrDescriptor,
   USBD_USR_SerialStrDescriptor,
   USBD_USR_ConfigStrDescriptor,
   USBD_USR_InterfaceStrDescriptor,
-  
+
 };
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 /* USB Standard Device Descriptor */
@@ -141,7 +141,7 @@
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 /* USB Standard Device Descriptor */
@@ -161,36 +161,36 @@
 
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-    #pragma data_alignment=4   
+    #pragma data_alignment=4
   #endif
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 /* USB Standard Device Descriptor */
 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
 {
-     USB_SIZ_STRING_LANGID,         
-     USB_DESC_TYPE_STRING,       
+     USB_SIZ_STRING_LANGID,
+     USB_DESC_TYPE_STRING,
      LOBYTE(USBD_LANGID_STRING),
-     HIBYTE(USBD_LANGID_STRING), 
+     HIBYTE(USBD_LANGID_STRING),
 };
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_DESC_Private_FunctionPrototypes
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USBD_DESC_Private_Functions
   * @{
-  */ 
+  */
 
 /**
-* @brief  USBD_USR_DeviceDescriptor 
+* @brief  USBD_USR_DeviceDescriptor
 *         return the device descriptor
 * @param  speed : current device speed
 * @param  length : pointer to data length variable
@@ -203,7 +203,7 @@
 }
 
 /**
-* @brief  USBD_USR_LangIDStrDescriptor 
+* @brief  USBD_USR_LangIDStrDescriptor
 *         return the LangID string descriptor
 * @param  speed : current device speed
 * @param  length : pointer to data length variable
@@ -211,13 +211,13 @@
 */
 uint8_t *  USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
 {
-  *length =  sizeof(USBD_LangIDDesc);  
+  *length =  sizeof(USBD_LangIDDesc);
   return USBD_LangIDDesc;
 }
 
 
 /**
-* @brief  USBD_USR_ProductStrDescriptor 
+* @brief  USBD_USR_ProductStrDescriptor
 *         return the product string descriptor
 * @param  speed : current device speed
 * @param  length : pointer to data length variable
@@ -225,21 +225,21 @@
 */
 uint8_t *  USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
 {
- 
-  
+
+
   if(speed == 0)
-  {   
+  {
 //    USBD_GetString (USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
   }
   else
   {
-    USBD_GetString (USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);    
+    USBD_GetString (USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
   }
   return USBD_StrDesc;
 }
 
 /**
-* @brief  USBD_USR_ManufacturerStrDescriptor 
+* @brief  USBD_USR_ManufacturerStrDescriptor
 *         return the manufacturer string descriptor
 * @param  speed : current device speed
 * @param  length : pointer to data length variable
@@ -252,7 +252,7 @@
 }
 
 /**
-* @brief  USBD_USR_SerialStrDescriptor 
+* @brief  USBD_USR_SerialStrDescriptor
 *         return the serial number string descriptor
 * @param  speed : current device speed
 * @param  length : pointer to data length variable
@@ -261,18 +261,18 @@
 uint8_t *  USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
 {
   if(speed  == USB_OTG_SPEED_HIGH)
-  {    
+  {
 //    USBD_GetString (USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length);
   }
   else
   {
-    USBD_GetString (USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);    
+    USBD_GetString (USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
   }
   return USBD_StrDesc;
 }
 
 /**
-* @brief  USBD_USR_ConfigStrDescriptor 
+* @brief  USBD_USR_ConfigStrDescriptor
 *         return the configuration string descriptor
 * @param  speed : current device speed
 * @param  length : pointer to data length variable
@@ -281,19 +281,19 @@
 uint8_t *  USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
 {
   if(speed  == USB_OTG_SPEED_HIGH)
-  {  
+  {
 //    USBD_GetString (USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
   }
   else
   {
-    USBD_GetString (USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); 
+    USBD_GetString (USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
   }
-  return USBD_StrDesc;  
+  return USBD_StrDesc;
 }
 
 
 /**
-* @brief  USBD_USR_InterfaceStrDescriptor 
+* @brief  USBD_USR_InterfaceStrDescriptor
 *         return the interface string descriptor
 * @param  speed : current device speed
 * @param  length : pointer to data length variable
@@ -309,22 +309,22 @@
   {
     USBD_GetString (USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
   }
-  return USBD_StrDesc;  
+  return USBD_StrDesc;
 }
 
 /**
   * @}
-  */ 
+  */
 
 
 /**
   * @}
-  */ 
+  */
 
 
 /**
   * @}
-  */ 
+  */
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 
Index: scpu_usb_CDC_Device_Demo/usbd_usr.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usbd_usr.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_CDC_Device_Demo/usbd_usr.c	(working copy)
@@ -8,55 +8,53 @@
   ******************************************************************************
   * @attention
   *
-  * 
+  *
   ******************************************************************************
-  */ 
+  */
 
 /* Includes ------------------------------------------------------------------*/
 #include "yc3121.h"
 #include "usbd_usr.h"
 #include "usbd_ioreq.h"
-#if !defined(USE_MHSCPU_EVAL) && !defined(USE_GOLDDRAGON_107)
 #include "yc3121.h"
-#endif
 #include "usb_conf.h"
 
 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
 * @{
 */
 
-/** @defgroup USBD_USR 
+/** @defgroup USBD_USR
 * @brief    This file includes the user application layer
 * @{
-*/ 
+*/
 
 /** @defgroup USBD_USR_Private_TypesDefinitions
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Defines
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Macros
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Variables
 * @{
-*/ 
+*/
 
 USBD_Usr_cb_TypeDef USRD_cb =
 {
@@ -65,11 +63,11 @@
   USBD_USR_DeviceConfigured,
   USBD_USR_DeviceSuspended,
   USBD_USR_DeviceResumed,
-  
+
   USBD_USR_DeviceConnected,
-  USBD_USR_DeviceDisconnected,  
-  
-  
+  USBD_USR_DeviceDisconnected,
+
+
 };
 
 
@@ -80,7 +78,7 @@
 
 /** @defgroup USBD_USR_Private_Constants
 * @{
-*/ 
+*/
 
 /**
 * @}
@@ -90,50 +88,44 @@
 
 /** @defgroup USBD_USR_Private_FunctionPrototypes
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Functions
 * @{
-*/ 
+*/
 
 #define USER_INFORMATION1      "[Key]:RemoteWakeup"
 #define USER_INFORMATION2      "[Joystick]:Mouse emulation"
 
 
 /**
-* @brief  USBD_USR_Init 
+* @brief  USBD_USR_Init
 *         Displays the message on LCD for host lib initialization
 * @param  None
 * @retval None
 */
 void USBD_USR_Init(void)
-{  
+{
 //  /* Initialize LEDs */
 //  STM_EVAL_LEDInit(LED1);
-//#ifndef USE_MHSCPU_EVAL
 //  STM_EVAL_LEDInit(LED2);
 //  STM_EVAL_LEDInit(LED3);
 //  STM_EVAL_LEDInit(LED4);
-//#endif  
-//  
+//
 //  /* Configure the IOE on which the JoyStick is connected */
-//#if defined(USE_MHSCPU_EVAL) || defined(USE_GOLDDRAGON_107)
-//	JoyStick_GPIO_Config();
-//#else
 //	IOE_Config();
-//#endif
-//  
-//  /* Setup SysTick Timer for 20 msec interrupts 
+//
+//  /* Setup SysTick Timer for 20 msec interrupts
 //  This interrupt is used to probe the joystick */
 //  if (SysTick_Config(SystemCoreClock / 48))
-//  { 
-//    /* Capture error */ 
+//  {
+//    /* Capture error */
 //    while (1);
-//  } 
+//  }
 //  /* Initialize the LCD */
 //#if defined (USE_STM322xG_EVAL)
 //  STM322xG_LCD_Init();
@@ -147,43 +139,72 @@
 
 //  LCD_LOG_Init();
 
-//#ifdef USE_USB_OTG_HS 
+//#ifdef USE_USB_OTG_HS
 //  LCD_LOG_SetHeader(" USB OTG HS HID Device");
 //#else
 //  LCD_LOG_SetHeader(" USB OTG FS HID Device");
 //#endif
-//  LCD_UsrLog("> USB device library started.\n"); 
-//  LCD_LOG_SetFooter ("     USB Device Library v1.1.0" ); 
-//  
+//  LCD_UsrLog("> USB device library started.\n");
+//  LCD_LOG_SetFooter ("     USB Device Library v1.1.0" );
+//
 //  /* Information panel */
 //  LCD_SetTextColor(Green);
 //  LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 42, USER_INFORMATION1);
 //  LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, USER_INFORMATION2);
 //  LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR);
-  
+
 }
 
 /**
-* @brief  USBD_USR_DeviceReset 
+* @brief  USBD_USR_DeviceReset
 *         Displays the message on LCD on device Reset Event
 * @param  speed : device speed
 * @retval None
 */
+extern USB_OTG_CORE_HANDLE  USB_OTG_dev;
+extern USBD_DEVICE USR_desc;
+extern USBD_Class_cb_TypeDef  USBD_CDC_cb;
 void USBD_USR_DeviceReset(uint8_t speed )
 {
 // switch (speed)
 // {
-//   case USB_OTG_SPEED_HIGH: 
+//   case USB_OTG_SPEED_HIGH:
 //     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [HS]" );
 //     break;
 
-//  case USB_OTG_SPEED_FULL: 
+//  case USB_OTG_SPEED_FULL:
 //     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [FS]" );
 //     break;
 // default:
 //     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [??]" );
-//     
+//
 // }
+
+    USB_OTG_dev.dev.zero_replay_flag =0;
+    memset((uint8_t*)&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
+    USB_OTG_dev.dev.device_status = USB_OTG_DEFAULT;
+
+    USBD_Init(&USB_OTG_dev,
+        #ifdef USE_USB_OTG_HS
+              USB_OTG_HS_CORE_ID,
+        #else
+              USB_OTG_FS_CORE_ID,
+        #endif
+              &USR_desc,
+              &USBD_CDC_cb,
+              &USRD_cb);
+
+        USB_OTG_WRITE_REG8(CORE_USB_CLEAR,0x40);
+        USB_OTG_WRITE_REG8(USB_SOFCNT,0);
+		USB_OTG_WRITE_REG8(USB_SOFCNTHI,0);
+
+        USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
+        USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
+        USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
+//        MyPrintf("usb reset\n");
 }
 
 
@@ -223,7 +244,7 @@
 }
 
 /**
-* @brief  USBD_USR_DeviceSuspended 
+* @brief  USBD_USR_DeviceSuspended
 *         Displays the message on LCD on device suspend Event
 * @param  None
 * @retval None
@@ -236,7 +257,7 @@
 
 
 /**
-* @brief  USBD_USR_DeviceResumed 
+* @brief  USBD_USR_DeviceResumed
 *         Displays the message on LCD on device resume Event
 * @param  None
 * @retval None
@@ -249,7 +270,7 @@
 
 /**
 * @}
-*/ 
+*/
 void my_delay_ms(int ms)
 {
 	int delay_num;
@@ -264,7 +285,7 @@
 }
 /**
 * @}
-*/ 
+*/
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 
Index: scpu_usb_ccid_Device_Demo/usb_main.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_ccid_Device_Demo/usb_main.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_ccid_Device_Demo/usb_main.c	(working copy)
@@ -9,9 +9,9 @@
   * @attention
   *
   ******************************************************************************
-  */ 
+  */
 
-/* Includes ------------------------------------------------------------------*/ 
+/* Includes ------------------------------------------------------------------*/
 
 
 #include "usbd_ccid_core.h"
@@ -27,33 +27,30 @@
 
 USB_OTG_CORE_HANDLE  USB_OTG_dev;
 
-void usb_init()
+void usb_reg_init()
 {
-					USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x00);
-					my_delay_ms(1);
-					USB_OTG_WRITE_REG8(CORE_USB_TRIG,0xc0); 
-					 USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x3c);
-					 USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
-					 USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
-					 USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
-					 USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
-					 USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
-					 USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
+    USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x00);
+    my_delay_ms(1);
+    USB_OTG_WRITE_REG8(CORE_USB_TRIG,0xc0);
+    USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x3c);
+    USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
+    USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
+    USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
 
 
 }
 
 void usb_main(void)
 {
-	volatile uint16_t temp1=0,temp2=0,cnt=0;
-	enable_clock(CLKCLS_BT);	
+	enable_clock(CLKCLS_BT);
 	BT_CLKPLL_EN = 0xff;
 	enable_clock(CLKCLS_USB);
-//	SYSCTRL_HCLK_CON &= (~(1 << 11));
 	SYSCTRL_HCLK_CON |= 1 << 11;
-	usb_init();
-	
-   enable_intr(INTR_USB); 
+	usb_reg_init();
+
    MyPrintf("YICHIP SCPU USB CCID Demo V1.0.\n");
    memset(&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
 
@@ -61,62 +58,29 @@
     #ifdef USE_USB_OTG_HS
           USB_OTG_HS_CORE_ID,
     #else
-          USB_OTG_FS_CORE_ID, 
+          USB_OTG_FS_CORE_ID,
     #endif
-          &USR_desc, 
-          &USBD_CCID_cb, 
+          &USR_desc,
+          &USBD_CCID_cb,
           &USRD_cb);
+    enable_intr(INTR_USB);
+
 
-      
       while (1)
  {
-				uint16_t temp1,temp2,cnt;
-				temp2 = temp1;
-				temp1 = USB_OTG_READ_REG8(USB_SOFCNT)|( USB_OTG_READ_REG8(USB_SOFCNTHI)<<8); 
-				if((temp2 == temp1) && (temp1 !=0))
-				{
-				  cnt++;
-				}
-				else 
-				{
-					cnt = 0;
-				}
-				
-				if(cnt >10000)
-				{
-					MyPrintf("reset ");
-					USB_OTG_dev.dev.zero_replay_flag =0;
-					memset(&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
-					USB_OTG_dev.dev.device_status = USB_OTG_DEFAULT;
-
-					USBD_Init(&USB_OTG_dev,
-    #ifdef USE_USB_OTG_HS
-          USB_OTG_HS_CORE_ID,
-    #else
-          USB_OTG_FS_CORE_ID, 
-    #endif
-          &USR_desc, 
-          &USBD_CCID_cb, 
-          &USRD_cb);
-					temp1=temp2=cnt=0;
-					USB_OTG_WRITE_REG8(CORE_USB_CLEAR,0x40);
-					USB_OTG_WRITE_REG8(USB_SOFCNT,0);
-					usb_init();
-				
-				}
         if (USB_OTG_dev.dev.device_status_new == USB_OTG_END)
         {
 //            MyPrintf("> Cmp USB_OTG_CONFIGURED.\n");
-            /* send CCID notification message on interrupt pipe */	
+            /* send CCID notification message on interrupt pipe */
 //					if(Getslotstatus_flag ==0)
 //					{
 //						my_delay_ms(5);
-//            
+//
 //					}
-					CCID_IntMessage(&USB_OTG_dev);  
+					CCID_IntMessage(&USB_OTG_dev);
         }
         resp_CCID_CMD(&USB_OTG_dev);
-  }  
+  }
 
 
 }
@@ -140,6 +104,6 @@
 
 
 
- 
+
 
 
Index: scpu_usb_ccid_Device_Demo/usbd_usr.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_ccid_Device_Demo/usbd_usr.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_ccid_Device_Demo/usbd_usr.c	(working copy)
@@ -8,9 +8,9 @@
   ******************************************************************************
   * @attention
   *
-  * 
+  *
   ******************************************************************************
-  */ 
+  */
 
 /* Includes ------------------------------------------------------------------*/
 #include "usbd_usr.h"
@@ -22,38 +22,38 @@
 * @{
 */
 
-/** @defgroup USBD_USR 
+/** @defgroup USBD_USR
 * @brief    This file includes the user application layer
 * @{
-*/ 
+*/
 
 /** @defgroup USBD_USR_Private_TypesDefinitions
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Defines
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Macros
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Variables
 * @{
-*/ 
+*/
 
 USBD_Usr_cb_TypeDef USRD_cb =
 {
@@ -62,11 +62,11 @@
   USBD_USR_DeviceConfigured,
   USBD_USR_DeviceSuspended,
   USBD_USR_DeviceResumed,
-  
+
   USBD_USR_DeviceConnected,
-  USBD_USR_DeviceDisconnected,  
-  
-  
+  USBD_USR_DeviceDisconnected,
+
+
 };
 
 
@@ -77,7 +77,7 @@
 
 /** @defgroup USBD_USR_Private_Constants
 * @{
-*/ 
+*/
 
 /**
 * @}
@@ -87,52 +87,81 @@
 
 /** @defgroup USBD_USR_Private_FunctionPrototypes
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Functions
 * @{
-*/ 
+*/
 
 #define USER_INFORMATION1      "[Key]:RemoteWakeup"
 #define USER_INFORMATION2      "[Joystick]:Mouse emulation"
 
 
 /**
-* @brief  USBD_USR_Init 
+* @brief  USBD_USR_Init
 *         Displays the message on LCD for host lib initialization
 * @param  None
 * @retval None
 */
 void USBD_USR_Init(void)
-{  
-  
+{
+
 }
 
 /**
-* @brief  USBD_USR_DeviceReset 
+* @brief  USBD_USR_DeviceReset
 *         Displays the message on LCD on device Reset Event
 * @param  speed : device speed
 * @retval None
 */
+extern USB_OTG_CORE_HANDLE  USB_OTG_dev;
+extern USBD_DEVICE USR_desc;
+extern USBD_Class_cb_TypeDef  USBD_CCID_cb;
 void USBD_USR_DeviceReset(uint8_t speed )
 {
 // switch (speed)
 // {
-//   case USB_OTG_SPEED_HIGH: 
+//   case USB_OTG_SPEED_HIGH:
 //     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [HS]" );
 //     break;
 
-//  case USB_OTG_SPEED_FULL: 
+//  case USB_OTG_SPEED_FULL:
 //     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [FS]" );
 //     break;
 // default:
 //     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [??]" );
-//     
+//
 // }
+
+    USB_OTG_dev.dev.zero_replay_flag =0;
+    memset((uint8_t*)&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
+    USB_OTG_dev.dev.device_status = USB_OTG_DEFAULT;
+
+    USBD_Init(&USB_OTG_dev,
+        #ifdef USE_USB_OTG_HS
+              USB_OTG_HS_CORE_ID,
+        #else
+              USB_OTG_FS_CORE_ID,
+        #endif
+              &USR_desc,
+              &USBD_CCID_cb,
+              &USRD_cb);
+
+        USB_OTG_WRITE_REG8(CORE_USB_CLEAR,0x40);
+        USB_OTG_WRITE_REG8(USB_SOFCNT,0);
+		USB_OTG_WRITE_REG8(USB_SOFCNTHI,0);
+
+        USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
+        USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
+        USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
+//        MyPrintf("usb reset\n");
 }
 
 
@@ -172,7 +201,7 @@
 }
 
 /**
-* @brief  USBD_USR_DeviceSuspended 
+* @brief  USBD_USR_DeviceSuspended
 *         Displays the message on LCD on device suspend Event
 * @param  None
 * @retval None
@@ -185,7 +214,7 @@
 
 
 /**
-* @brief  USBD_USR_DeviceResumed 
+* @brief  USBD_USR_DeviceResumed
 *         Displays the message on LCD on device resume Event
 * @param  None
 * @retval None
@@ -213,11 +242,11 @@
 
 /**
 * @}
-*/ 
+*/
 
 /**
 * @}
-*/ 
+*/
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 
Index: scpu_usb_hid_Device_Demo/usb_conf.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_hid_Device_Demo/usb_conf.h	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_hid_Device_Demo/usb_conf.h	(working copy)
@@ -16,8 +16,8 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
@@ -30,23 +30,22 @@
 #define __USB_CONF__H__
 
 /* Includes ------------------------------------------------------------------*/
-#include "Yc3121.h" 
-//#include "mhscpu_eval.h" 
+#include "Yc3121.h"
 
 
 
 /** @addtogroup USB_OTG_DRIVER
   * @{
   */
-  
+
 /** @defgroup USB_CONF
   * @brief USB low level driver configuration file
   * @{
-  */ 
+  */
 
 /** @defgroup USB_CONF_Exported_Defines
   * @{
-  */ 
+  */
 
 /* USB Core and PHY interface configuration.
    Tip: To avoid modifying these defines each time you need to change the USB
@@ -55,30 +54,30 @@
    */
 /****************** USB OTG FS PHY CONFIGURATION *******************************
 *  The USB OTG FS Core supports one on-chip Full Speed PHY.
-*  
-*  The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor 
+*
+*  The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor
 *  when FS core is used.
 *******************************************************************************/
 #ifndef USE_USB_OTG_FS
  //#define USE_USB_OTG_FS
 #endif /* USE_USB_OTG_FS */
 
-#ifdef USE_USB_OTG_FS 
+#ifdef USE_USB_OTG_FS
  #define USB_OTG_FS_CORE
 #endif
 
 /****************** USB OTG HS PHY CONFIGURATION *******************************
 *  The USB OTG HS Core supports two PHY interfaces:
-*   (i)  An ULPI interface for the external High Speed PHY: the USB HS Core will 
+*   (i)  An ULPI interface for the external High Speed PHY: the USB HS Core will
 *        operate in High speed mode
 *   (ii) An on-chip Full Speed PHY: the USB HS Core will operate in Full speed mode
 *
 *  You can select the PHY to be used using one of these two defines:
-*   (i)  USE_ULPI_PHY: if the USB OTG HS Core is to be used in High speed mode 
+*   (i)  USE_ULPI_PHY: if the USB OTG HS Core is to be used in High speed mode
 *   (ii) USE_EMBEDDED_PHY: if the USB OTG HS Core is to be used in Full speed mode
 *
-*  Notes: 
-*   - The USE_ULPI_PHY symbol is defined in the project compiler preprocessor as 
+*  Notes:
+*   - The USE_ULPI_PHY symbol is defined in the project compiler preprocessor as
 *     default PHY when HS core is used.
 *   - On STM322xG-EVAL and STM324xG-EVAL boards, only configuration(i) is available.
 *     Configuration (ii) need a different hardware, for more details refer to your
@@ -96,46 +95,46 @@
  //#define USE_EMBEDDED_PHY
 #endif /* USE_EMBEDDED_PHY */
 
-#ifdef USE_USB_OTG_HS 
+#ifdef USE_USB_OTG_HS
  #define USB_OTG_HS_CORE
 #endif
 
 /*******************************************************************************
 *                      FIFO Size Configuration in Device mode
-*  
-*  (i) Receive data FIFO size = RAM for setup packets + 
+*
+*  (i) Receive data FIFO size = RAM for setup packets +
 *                   OUT endpoint control information +
 *                   data OUT packets + miscellaneous
 *      Space = ONE 32-bits words
 *     --> RAM for setup packets = 10 spaces
-*        (n is the nbr of CTRL EPs the device core supports) 
+*        (n is the nbr of CTRL EPs the device core supports)
 *     --> OUT EP CTRL info      = 1 space
-*        (one space for status information written to the FIFO along with each 
+*        (one space for status information written to the FIFO along with each
 *        received packet)
-*     --> data OUT packets      = (Largest Packet Size / 4) + 1 spaces 
+*     --> data OUT packets      = (Largest Packet Size / 4) + 1 spaces
 *        (MINIMUM to receive packets)
-*     --> OR data OUT packets  = at least 2*(Largest Packet Size / 4) + 1 spaces 
+*     --> OR data OUT packets  = at least 2*(Largest Packet Size / 4) + 1 spaces
 *        (if high-bandwidth EP is enabled or multiple isochronous EPs)
 *     --> miscellaneous = 1 space per OUT EP
-*        (one space for transfer complete status information also pushed to the 
+*        (one space for transfer complete status information also pushed to the
 *        FIFO with each endpoint's last packet)
 *
-*  (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for 
+*  (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
 *       that particular IN EP. More space allocated in the IN EP Tx FIFO results
 *       in a better performance on the USB and can hide latencies on the AHB.
 *
 *  (iii) TXn min size = 16 words. (n  : Transmit FIFO index)
-*   (iv) When a TxFIFO is not used, the Configuration should be as follows: 
+*   (iv) When a TxFIFO is not used, the Configuration should be as follows:
 *       case 1 :  n > m    and Txn is not used    (n,m  : Transmit FIFO indexes)
 *       --> Txm can use the space allocated for Txn.
 *       case2  :  n < m    and Txn is not used    (n,m  : Transmit FIFO indexes)
 *       --> Txn should be configured with the minimum space of 16 words
-*  (v) The FIFO is used optimally when used TxFIFOs are allocated in the top 
+*  (v) The FIFO is used optimally when used TxFIFOs are allocated in the top
 *       of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
 *   (vi) In HS case12 FIFO locations should be reserved for internal DMA registers
-*        so total FIFO size should be 1012 Only instead of 1024       
+*        so total FIFO size should be 1012 Only instead of 1024
 *******************************************************************************/
- 
+
 /****************** USB OTG HS CONFIGURATION **********************************/
 #ifdef USB_OTG_HS_CORE
  #define RX_FIFO_HS_SIZE                          512
@@ -151,10 +150,10 @@
  #ifdef USE_ULPI_PHY
   #define USB_OTG_ULPI_PHY_ENABLED
  #endif
- #ifdef USE_EMBEDDED_PHY 
+ #ifdef USE_EMBEDDED_PHY
    #define USB_OTG_EMBEDDED_PHY_ENABLED
  #endif
- #define USB_OTG_HS_INTERNAL_DMA_ENABLED 
+ #define USB_OTG_HS_INTERNAL_DMA_ENABLED
  #define USB_OTG_HS_DEDICATED_EP1_ENABLED
  #define USB_OTG_HS_LOW_PWR_MGMT_SUPPORT
 #endif
@@ -187,7 +186,7 @@
                                      ((size) == 64)  || \
                                      ((size) == 128) || \
                                      ((size) == 256) || \
-                                     ((size) == 512)) 
+                                     ((size) == 512))
 //#define USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
 // #define USB_OTG_FS_SOF_OUTPUT_ENABLED
 
@@ -209,24 +208,24 @@
 #define USB_OTG_DEV_DMA_EP_NUM              0x81
 /****************** C Compilers dependant keywords ****************************/
 /* In HS mode and when the DMA is used, all variables and data structures dealing
-   with the DMA during the transaction process should be 4-bytes aligned */    
+   with the DMA during the transaction process should be 4-bytes aligned */
 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
   #if defined   (__GNUC__)        /* GNU Compiler */
     #define __ALIGN_END    __attribute__ ((aligned (4)))
-    #define __ALIGN_BEGIN         
-  #else                           
+    #define __ALIGN_BEGIN
+  #else
     #define __ALIGN_END
     #if defined   (__CC_ARM)      /* ARM Compiler */
-      #define __ALIGN_BEGIN    __align(4)  
+      #define __ALIGN_BEGIN    __align(4)
     #elif defined (__ICCARM__)    /* IAR Compiler */
-      #define __ALIGN_BEGIN 
+      #define __ALIGN_BEGIN
     #elif defined  (__TASKING__)  /* TASKING Compiler */
-      #define __ALIGN_BEGIN    __align(4) 
-    #endif /* __CC_ARM */  
-  #endif /* __GNUC__ */ 
+      #define __ALIGN_BEGIN    __align(4)
+    #endif /* __CC_ARM */
+  #endif /* __GNUC__ */
 #else
   #define __ALIGN_BEGIN
-  #define __ALIGN_END   
+  #define __ALIGN_END
 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
 
 /* __packed keyword used to decrease the data type alignment to 1-byte */
@@ -234,7 +233,7 @@
   #define __packed    __packed
 #elif defined (__ICCARM__)     /* IAR Compiler */
   #define __packed    __packed
-#elif defined   ( __GNUC__ )   /* GNU Compiler */                        
+#elif defined   ( __GNUC__ )   /* GNU Compiler */
   #define __packed    __attribute__ ((__packed__))
 #elif defined   (__TASKING__)  /* TASKING Compiler */
   #define __packed    __unaligned
@@ -242,37 +241,37 @@
 
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USB_CONF_Exported_Types
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 /** @defgroup USB_CONF_Exported_Macros
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup USB_CONF_Exported_Variables
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 /** @defgroup USB_CONF_Exported_FunctionsPrototype
   * @{
-  */ 
+  */
 /**
   * @}
-  */ 
+  */
 
 
 #endif //__USB_CONF__H__
@@ -280,11 +279,11 @@
 
 /**
   * @}
-  */ 
+  */
 
 /**
   * @}
-  */ 
+  */
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 
Index: scpu_usb_hid_Device_Demo/usb_main.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_hid_Device_Demo/usb_main.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_hid_Device_Demo/usb_main.c	(working copy)
@@ -9,9 +9,9 @@
   * @attention
   *
   ******************************************************************************
-  */ 
+  */
 
-/* Includes ------------------------------------------------------------------*/ 
+/* Includes ------------------------------------------------------------------*/
 
 
 
@@ -27,22 +27,22 @@
 
 USB_OTG_CORE_HANDLE  USB_OTG_dev;
 
-void usb_init()
+void usb_reg_init()
 {
-					USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x00);
-		//			my_delay_ms(1);
-					USB_OTG_WRITE_REG8(CORE_USB_TRIG,0xc0); 
-					 USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x3c);
-					 USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
-					 USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
-					 USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
-					 USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
-					 #ifdef USB_HID_DEMO_TEST
-					  USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf2);
-					  #else
-					 USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
-					 #endif
-					 USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
+    USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x00);
+    my_delay_ms(1);
+    USB_OTG_WRITE_REG8(CORE_USB_TRIG,0xc0);
+    USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x3c);
+    USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
+    USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
+    USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
+    #ifdef USB_HID_DEMO_TEST
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf2);
+    #else
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
+    #endif
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
 
 
 }
@@ -51,62 +51,31 @@
 {
 	uint8_t ReceiveCode = 0x41;
 	int8_t x = 0, y = 0;
-    
-	enable_clock(CLKCLS_BT);	
+
+	enable_clock(CLKCLS_BT);
 	BT_CLKPLL_EN = 0xff;
 	enable_clock(CLKCLS_USB);
 	SYSCTRL_HCLK_CON |= 1 << 11;
-	usb_init();
-	
-       enable_intr(INTR_USB); 
-   memset(&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
+	usb_reg_init();
+
+  memset(&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
 
   USBD_Init(&USB_OTG_dev,
         #ifdef USE_USB_OTG_HS
               USB_OTG_HS_CORE_ID,
         #else
-              USB_OTG_FS_CORE_ID, 
+              USB_OTG_FS_CORE_ID,
         #endif
               &USR_desc,
-              &USBD_HID_cb, 
+              &USBD_HID_cb,
               &USRD_cb);
+	enable_intr(INTR_USB);
     MyPrintf("YICHIP SCPU HID Device Demo V1.0.\n");
 
-  #ifdef USB_HID_MS_DEMO      
+  #ifdef USB_HID_MS_DEMO
       while (1)
  {
- 		    #ifndef POWER_FROM_USB
-				uint16_t temp1,temp2,cnt;
-				temp2 = temp1;
-				temp1 = USB_OTG_READ_REG8(USB_SOFCNT)|( USB_OTG_READ_REG8(USB_SOFCNTHI)<<8); 
-				if((temp2 == temp1) && (temp1 !=0))
-				    cnt++;
-				else 
-					cnt = 0;
-				
-				if(cnt ==10000)
-				{
-					MyPrintf("reset ");
-					USB_OTG_dev.dev.zero_replay_flag =0;
-					memset(&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
-					USB_OTG_dev.dev.device_status = USB_OTG_DEFAULT;
-
-                              	 USBD_Init(&USB_OTG_dev,
-                                      #ifdef USE_USB_OTG_HS
-                                            USB_OTG_HS_CORE_ID,
-                                      #else
-                                            USB_OTG_FS_CORE_ID, 
-                                      #endif
-                                            &USR_desc,
-                                            &USBD_HID_cb, 
-                                            &USRD_cb);
-					temp1=temp2=cnt=0;
-					USB_OTG_WRITE_REG8(CORE_USB_CLEAR,0x40);
-					USB_OTG_WRITE_REG8(USB_SOFCNT,0);
-					usb_init();
-				
-				}
-		     #endif
+
 		#ifdef USB_HID_DEMO_TEST
 			   if (USB_OTG_dev.dev.device_status_new== USB_OTG_END)
 			   {
@@ -120,7 +89,7 @@
                                           	{
                               			ReceiveCode++;
                                           	}
-                                          
+
                               		switch (ReceiveCode)
                                           {
                                               case 0x41:                      /* 上 */
@@ -131,7 +100,7 @@
                                                               HID_IN_EP,
                                                               Buf,
                                                               4);
-                                                              
+
                                                   break;
                                               case 0x42:                      /* 下 */
                                                   y += 10;
@@ -165,7 +134,7 @@
                                           }
                              }
                 #endif
-  }  
+  }
 
 #endif
 }
@@ -190,6 +159,6 @@
 
 
 
- 
+
 
 
Index: scpu_usb_hid_Device_Demo/usbd_usr.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_hid_Device_Demo/usbd_usr.c	(revision 785)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_hid_Device_Demo/usbd_usr.c	(working copy)
@@ -8,55 +8,53 @@
   ******************************************************************************
   * @attention
   *
-  * 
+  *
   ******************************************************************************
-  */ 
+  */
 
 /* Includes ------------------------------------------------------------------*/
 #include "Yc3121.h"
 #include "usbd_usr.h"
 #include "usbd_ioreq.h"
-#if !defined(USE_MHSCPU_EVAL) && !defined(USE_GOLDDRAGON_107)
 #include "Yc3121.h"
-#endif
 #include "usb_conf.h"
 
 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
 * @{
 */
 
-/** @defgroup USBD_USR 
+/** @defgroup USBD_USR
 * @brief    This file includes the user application layer
 * @{
-*/ 
+*/
 
 /** @defgroup USBD_USR_Private_TypesDefinitions
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Defines
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Macros
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Variables
 * @{
-*/ 
+*/
 
 USBD_Usr_cb_TypeDef USRD_cb =
 {
@@ -65,11 +63,11 @@
   USBD_USR_DeviceConfigured,
   USBD_USR_DeviceSuspended,
   USBD_USR_DeviceResumed,
-  
+
   USBD_USR_DeviceConnected,
-  USBD_USR_DeviceDisconnected,  
-  
-  
+  USBD_USR_DeviceDisconnected,
+
+
 };
 
 
@@ -80,7 +78,7 @@
 
 /** @defgroup USBD_USR_Private_Constants
 * @{
-*/ 
+*/
 
 /**
 * @}
@@ -90,50 +88,44 @@
 
 /** @defgroup USBD_USR_Private_FunctionPrototypes
 * @{
-*/ 
+*/
 /**
 * @}
-*/ 
+*/
 
 
 /** @defgroup USBD_USR_Private_Functions
 * @{
-*/ 
+*/
 
 #define USER_INFORMATION1      "[Key]:RemoteWakeup"
 #define USER_INFORMATION2      "[Joystick]:Mouse emulation"
 
 
 /**
-* @brief  USBD_USR_Init 
+* @brief  USBD_USR_Init
 *         Displays the message on LCD for host lib initialization
 * @param  None
 * @retval None
 */
 void USBD_USR_Init(void)
-{  
+{
 //  /* Initialize LEDs */
 //  STM_EVAL_LEDInit(LED1);
-//#ifndef USE_MHSCPU_EVAL
 //  STM_EVAL_LEDInit(LED2);
 //  STM_EVAL_LEDInit(LED3);
 //  STM_EVAL_LEDInit(LED4);
-//#endif  
-//  
+//
 //  /* Configure the IOE on which the JoyStick is connected */
-//#if defined(USE_MHSCPU_EVAL) || defined(USE_GOLDDRAGON_107)
-//	JoyStick_GPIO_Config();
-//#else
 //	IOE_Config();
-//#endif
-//  
-//  /* Setup SysTick Timer for 20 msec interrupts 
+//
+//  /* Setup SysTick Timer for 20 msec interrupts
 //  This interrupt is used to probe the joystick */
 //  if (SysTick_Config(SystemCoreClock / 48))
-//  { 
-//    /* Capture error */ 
+//  {
+//    /* Capture error */
 //    while (1);
-//  } 
+//  }
 //  /* Initialize the LCD */
 //#if defined (USE_STM322xG_EVAL)
 //  STM322xG_LCD_Init();
@@ -147,43 +139,76 @@
 
 //  LCD_LOG_Init();
 
-//#ifdef USE_USB_OTG_HS 
+//#ifdef USE_USB_OTG_HS
 //  LCD_LOG_SetHeader(" USB OTG HS HID Device");
 //#else
 //  LCD_LOG_SetHeader(" USB OTG FS HID Device");
 //#endif
-//  LCD_UsrLog("> USB device library started.\n"); 
-//  LCD_LOG_SetFooter ("     USB Device Library v1.1.0" ); 
-//  
+//  LCD_UsrLog("> USB device library started.\n");
+//  LCD_LOG_SetFooter ("     USB Device Library v1.1.0" );
+//
 //  /* Information panel */
 //  LCD_SetTextColor(Green);
 //  LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 42, USER_INFORMATION1);
 //  LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, USER_INFORMATION2);
 //  LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR);
-  
+
 }
 
 /**
-* @brief  USBD_USR_DeviceReset 
+* @brief  USBD_USR_DeviceReset
 *         Displays the message on LCD on device Reset Event
 * @param  speed : device speed
 * @retval None
 */
+extern USB_OTG_CORE_HANDLE  USB_OTG_dev;
+extern USBD_DEVICE USR_desc;
+extern USBD_Class_cb_TypeDef  USBD_HID_cb;
 void USBD_USR_DeviceReset(uint8_t speed )
 {
 // switch (speed)
 // {
-//   case USB_OTG_SPEED_HIGH: 
+//   case USB_OTG_SPEED_HIGH:
 //     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [HS]" );
 //     break;
 
-//  case USB_OTG_SPEED_FULL: 
+//  case USB_OTG_SPEED_FULL:
 //     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [FS]" );
 //     break;
 // default:
 //     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [??]" );
-//     
+//
 // }
+
+    USB_OTG_dev.dev.zero_replay_flag =0;
+    memset((uint8_t*)&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
+    USB_OTG_dev.dev.device_status = USB_OTG_DEFAULT;
+
+    USBD_Init(&USB_OTG_dev,
+        #ifdef USE_USB_OTG_HS
+              USB_OTG_HS_CORE_ID,
+        #else
+              USB_OTG_FS_CORE_ID,
+        #endif
+              &USR_desc,
+              &USBD_HID_cb,
+              &USRD_cb);
+
+        USB_OTG_WRITE_REG8(CORE_USB_CLEAR,0x40);
+        USB_OTG_WRITE_REG8(USB_SOFCNT,0);
+		USB_OTG_WRITE_REG8(USB_SOFCNTHI,0);
+
+        USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
+        USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
+        USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
+        #ifdef USB_HID_DEMO_TEST
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf2);
+        #else
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
+        #endif
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
+//        MyPrintf("usb reset\n");
 }
 
 
@@ -223,7 +248,7 @@
 }
 
 /**
-* @brief  USBD_USR_DeviceSuspended 
+* @brief  USBD_USR_DeviceSuspended
 *         Displays the message on LCD on device suspend Event
 * @param  None
 * @retval None
@@ -236,7 +261,7 @@
 
 
 /**
-* @brief  USBD_USR_DeviceResumed 
+* @brief  USBD_USR_DeviceResumed
 *         Displays the message on LCD on device resume Event
 * @param  None
 * @retval None
@@ -249,11 +274,22 @@
 
 /**
 * @}
-*/ 
-
+*/
+void my_delay_ms(int ms)
+{
+	int delay_num;
+	while(ms-->0)
+	{
+		delay_num=(CPU_MHZ/1000)/8+400;
+		while(delay_num-->0)
+		{
+			__asm__("nop");
+		}
+	}
+}
 /**
 * @}
-*/ 
+*/
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 
Index: scpu_usb_printer_Device_Demo/usb_bsp.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usb_bsp.c	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usb_bsp.c	(working copy)
@@ -0,0 +1,563 @@
+/**
+  ******************************************************************************
+  * @file    usb_bsp.c
+  * @author  MCD Application Team
+  * @version V2.1.0
+  * @date    19-March-2012
+  * @brief   This file implements the board support package for the USB host library
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_bsp.h"
+#include "usb_conf.h"
+
+/** @addtogroup USBH_USER
+* @{
+*/
+
+/** @defgroup USB_BSP
+  * @brief This file is responsible to offer board support package
+  * @{
+  */
+
+/** @defgroup USB_BSP_Private_Defines
+  * @{
+  */
+//#define USE_ACCURATE_TIME
+#define TIM_MSEC_DELAY                     0x01
+#define TIM_USEC_DELAY                     0x02
+#define HOST_OVRCURR_PORT                  GPIOE
+#define HOST_OVRCURR_LINE                  GPIO_Pin_1
+#define HOST_OVRCURR_PORT_SOURCE           GPIO_PortSourceGPIOE
+#define HOST_OVRCURR_PIN_SOURCE            GPIO_PinSource1
+#define HOST_OVRCURR_PORT_RCC              RCC_APB2Periph_GPIOE
+#define HOST_OVRCURR_EXTI_LINE             EXTI_Line1
+#define HOST_OVRCURR_IRQn                  EXTI1_IRQn
+
+#ifdef USE_STM3210C_EVAL
+ #define HOST_POWERSW_PORT_RCC             RCC_APB2Periph_GPIOC
+ #define HOST_POWERSW_PORT                 GPIOC
+ #define HOST_POWERSW_VBUS                 GPIO_Pin_9
+#else
+ #ifdef USE_USB_OTG_FS
+  #define HOST_POWERSW_PORT_RCC            RCC_AHB1Periph_GPIOH
+  #define HOST_POWERSW_PORT                GPIOH
+  #define HOST_POWERSW_VBUS                GPIO_Pin_5
+ #endif
+#endif
+
+#define HOST_SOF_OUTPUT_RCC                RCC_APB2Periph_GPIOA
+#define HOST_SOF_PORT                      GPIOA
+#define HOST_SOF_SIGNAL                    GPIO_Pin_8
+
+/**
+  * @}
+  */
+
+
+/** @defgroup USB_BSP_Private_TypesDefinitions
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+
+/** @defgroup USB_BSP_Private_Macros
+  * @{
+  */
+/**
+  * @}
+  */
+
+/** @defgroup USBH_BSP_Private_Variables
+  * @{
+  */
+ErrorStatus HSEStartUpStatus;
+#ifdef USE_ACCURATE_TIME
+volatile uint32_t BSP_delay = 0;
+#endif
+/**
+  * @}
+  */
+
+/** @defgroup USBH_BSP_Private_FunctionPrototypes
+  * @{
+  */
+
+#ifdef USE_ACCURATE_TIME
+static void BSP_SetTime(uint8_t Unit);
+static void BSP_Delay(uint32_t nTime,uint8_t Unit);
+static void USB_OTG_BSP_TimeInit ( void );
+#endif
+/**
+  * @}
+  */
+
+/** @defgroup USB_BSP_Private_Functions
+  * @{
+  */
+
+/**
+  * @brief  USB_OTG_BSP_Init
+  *         Initilizes BSP configurations
+  * @param  None
+  * @retval None
+  */
+
+void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
+{
+
+//// EXTI_InitTypeDef EXTI_InitStructure;
+// #ifdef USE_STM3210C_EVAL
+
+//  RCC_OTGFSCLKConfig(RCC_OTGFSCLKSource_PLLVCO_Div3);
+//  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_OTG_FS, ENABLE) ;
+
+//#else // USE_STM322xG_EVAL
+//  GPIO_InitTypeDef GPIO_InitStructure;
+// #ifdef USE_USB_OTG_FS
+//
+//  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);
+//
+//  /* Configure SOF VBUS ID DM DP Pins */
+//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8  |
+//    GPIO_Pin_9  |
+//      GPIO_Pin_11 |
+//        GPIO_Pin_12;
+//
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+//  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+//  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
+//  GPIO_Init(GPIOA, &GPIO_InitStructure);
+//
+//  GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_OTG1_FS) ;
+//  GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_OTG1_FS) ;
+//  GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ;
+//  GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
+//
+//  /* this for ID line debug */
+//
+//
+//  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10;
+//  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+//  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+//  GPIO_Init(GPIOA, &GPIO_InitStructure);
+//  GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ;
+
+
+//  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
+//  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
+// #else // USE_USB_OTG_HS
+
+//  #ifdef USE_ULPI_PHY // ULPI
+//  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
+//                         RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOH |
+//                           RCC_AHB1Periph_GPIOI, ENABLE);
+//
+//
+//  GPIO_PinAFConfig(GPIOA,GPIO_PinSource3, GPIO_AF_OTG2_HS) ; // D0
+//  GPIO_PinAFConfig(GPIOA,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // CLK
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // D1
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource1, GPIO_AF_OTG2_HS) ; // D2
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // D7
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_OTG2_HS) ; // D3
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_OTG2_HS) ; // D4
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource12,GPIO_AF_OTG2_HS) ; // D5
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_OTG2_HS) ; // D6
+//  GPIO_PinAFConfig(GPIOH,GPIO_PinSource4, GPIO_AF_OTG2_HS) ; // NXT
+//  GPIO_PinAFConfig(GPIOI,GPIO_PinSource11,GPIO_AF_OTG2_HS) ; // DIR
+//  GPIO_PinAFConfig(GPIOC,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // STP
+//
+//  // CLK
+//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ;
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+//  GPIO_Init(GPIOA, &GPIO_InitStructure);
+//
+//  // D0
+//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3  ;
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+//  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+//  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
+//  GPIO_Init(GPIOA, &GPIO_InitStructure);
+//
+//
+//
+//  // D1 D2 D3 D4 D5 D6 D7
+//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1  |
+//    GPIO_Pin_5 | GPIO_Pin_10 |
+//      GPIO_Pin_11| GPIO_Pin_12 |
+//        GPIO_Pin_13 ;
+//
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+//  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+//  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
+//  GPIO_Init(GPIOB, &GPIO_InitStructure);
+//
+//
+//  // STP
+//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  ;
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+//  GPIO_Init(GPIOC, &GPIO_InitStructure);
+//
+//  //NXT
+//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+//  GPIO_Init(GPIOH, &GPIO_InitStructure);
+//
+//
+//  //DIR
+//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+//  GPIO_Init(GPIOI, &GPIO_InitStructure);
+//
+//
+//  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS |
+//                         RCC_AHB1Periph_OTG_HS_ULPI, ENABLE) ;
+//
+//  #else
+
+//  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);
+//
+//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12  |
+//    GPIO_Pin_13 |
+//      GPIO_Pin_14 |
+//        GPIO_Pin_15;
+//
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+//  GPIO_Init(GPIOB, &GPIO_InitStructure);
+//
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource12, GPIO_AF_OTG2_FS) ;
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_OTG2_FS) ;
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource14,GPIO_AF_OTG2_FS) ;
+//  GPIO_PinAFConfig(GPIOB,GPIO_PinSource15,GPIO_AF_OTG2_FS) ;
+//  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS, ENABLE) ;
+//  #endif
+// #endif //USB_OTG_HS
+//#endif //USE_STM322xG_EVAL
+
+//
+//  /* Configure pin for overcurrent detection */
+//  RCC_APB2PeriphClockCmd(HOST_OVRCURR_PORT_RCC, ENABLE);
+//
+//  /* Configure SOF Pin */
+//  GPIO_InitStructure.GPIO_Pin = HOST_OVRCURR_LINE;
+//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
+//  GPIO_Init(HOST_OVRCURR_PORT, &GPIO_InitStructure);
+//
+//  /* Connect Button EXTI Line to Button GPIO Pin */
+//  GPIO_EXTILineConfig(HOST_OVRCURR_PORT_SOURCE, HOST_OVRCURR_PIN_SOURCE);
+//
+//  /* Configure Button EXTI line */
+//  EXTI_InitStructure.EXTI_Line = HOST_OVRCURR_EXTI_LINE;
+//  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
+//  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
+//  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
+//  EXTI_Init(&EXTI_InitStructure);
+//   USB_OTG_BSP_TimeInit();
+}
+/**
+  * @brief  USB_OTG_BSP_EnableInterrupt
+  *         Configures USB Global interrupt
+  * @param  None
+  * @retval None
+  */
+void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
+{
+//  NVIC_InitTypeDef NVIC_InitStructure;
+//
+//  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
+//#ifdef USE_USB_OTG_HS
+//  NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn;
+//#else
+//  NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
+//#endif
+//  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
+//  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
+//  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+//  NVIC_Init(&NVIC_InitStructure);
+
+//
+//  /* Enable the Overcurrent Interrupt */
+//  NVIC_InitStructure.NVIC_IRQChannel = HOST_OVRCURR_IRQn;
+//  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
+//  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
+//  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+//
+//  NVIC_Init(&NVIC_InitStructure);
+}
+
+/**
+  * @brief  BSP_Drive_VBUS
+  *         Drives the Vbus signal through IO
+  * @param  state : VBUS states
+  * @retval None
+  */
+
+void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev, uint8_t state)
+{
+  /*
+  On-chip 5 V VBUS generation is not supported. For this reason, a charge pump
+  or, if 5 V are available on the application board, a basic power switch, must
+  be added externally to drive the 5 V VBUS line. The external charge pump can
+  be driven by any GPIO output. When the application decides to power on VBUS
+  using the chosen GPIO, it must also set the port power bit in the host port
+  control and status register (PPWR bit in OTG_FS_HPRT).
+
+  Bit 12 PPWR: Port power
+  The application uses this field to control power to this port, and the core
+  clears this bit on an overcurrent condition.
+  */
+//#ifndef USE_USB_OTG_HS
+//  if (0 == state)
+//  {
+//    /* DISABLE is needed on output of the Power Switch */
+//    GPIO_SetBits(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
+//  }
+//  else
+//  {
+//    /*ENABLE the Power Switch by driving the Enable LOW */
+//    GPIO_ResetBits(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
+//  }
+//#endif
+}
+
+/**
+  * @brief  USB_OTG_BSP_ConfigVBUS
+  *         Configures the IO for the Vbus and OverCurrent
+  * @param  None
+  * @retval None
+  */
+
+void  USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev)
+{
+#ifdef USE_USB_OTG_FS
+  GPIO_InitTypeDef GPIO_InitStructure;
+
+#ifdef USE_STM3210C_EVAL
+  RCC_APB2PeriphClockCmd(HOST_POWERSW_PORT_RCC, ENABLE);
+
+
+  /* Configure Power Switch Vbus Pin */
+  GPIO_InitStructure.GPIO_Pin = HOST_POWERSW_VBUS;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+  GPIO_Init(HOST_POWERSW_PORT, &GPIO_InitStructure);
+#else
+  #ifdef USE_USB_OTG_FS
+  RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOH , ENABLE);
+
+  GPIO_InitStructure.GPIO_Pin = HOST_POWERSW_VBUS;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
+  GPIO_Init(HOST_POWERSW_PORT,&GPIO_InitStructure);
+  #endif
+#endif
+
+  /* By Default, DISABLE is needed on output of the Power Switch */
+  GPIO_SetBits(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
+
+  USB_OTG_BSP_mDelay(200);   /* Delay is need for stabilising the Vbus Low
+  in Reset Condition, when Vbus=1 and Reset-button is pressed by user */
+#endif
+}
+
+/**
+  * @brief  USB_OTG_BSP_TimeInit
+  *         Initializes delay unit using Timer2
+  * @param  None
+  * @retval None
+  */
+static void USB_OTG_BSP_TimeInit ( void )
+{
+//#ifdef USE_ACCURATE_TIME
+//  NVIC_InitTypeDef NVIC_InitStructure;
+//
+//  /* Set the Vector Table base address at 0x08000000 */
+//  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00);
+//
+//  /* Configure the Priority Group to 2 bits */
+//  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
+//
+//  /* Enable the TIM2 gloabal Interrupt */
+//  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
+//  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
+//  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
+//  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+//
+//  NVIC_Init(&NVIC_InitStructure);
+//
+//  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
+//#endif
+}
+
+/**
+  * @brief  USB_OTG_BSP_uDelay
+  *         This function provides delay time in micro sec
+  * @param  usec : Value of delay required in micro sec
+  * @retval None
+  */
+void USB_OTG_BSP_uDelay (const uint32_t usec)
+{
+
+#ifdef USE_ACCURATE_TIME
+  BSP_Delay(usec,TIM_USEC_DELAY);
+#else
+  volatile uint32_t count = 0;
+  const uint32_t utime = (120 * usec / 7);
+  do
+  {
+    if ( ++count > utime )
+    {
+      return ;
+    }
+  }
+  while (1);
+#endif
+
+}
+
+
+/**
+  * @brief  USB_OTG_BSP_mDelay
+  *          This function provides delay time in milli sec
+  * @param  msec : Value of delay required in milli sec
+  * @retval None
+  */
+void USB_OTG_BSP_mDelay (const uint32_t msec)
+{
+#ifdef USE_ACCURATE_TIME
+    BSP_Delay(msec,TIM_MSEC_DELAY);
+#else
+    USB_OTG_BSP_uDelay(msec * 1000);
+#endif
+
+}
+
+
+/**
+  * @brief  USB_OTG_BSP_TimerIRQ
+  *         Time base IRQ
+  * @param  None
+  * @retval None
+  */
+
+void USB_OTG_BSP_TimerIRQ (void)
+{
+#ifdef USE_ACCURATE_TIME
+//  if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
+//  {
+//    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
+//    if (BSP_delay > 0x00)
+//    {
+//      BSP_delay--;
+//    }
+//    else
+//    {
+//      TIM_Cmd(TIM2,DISABLE);
+//    }
+//  }
+#endif
+}
+
+#ifdef USE_ACCURATE_TIME
+/**
+  * @brief  BSP_Delay
+  *         Delay routine based on TIM2
+  * @param  nTime : Delay Time
+  * @param  unit : Delay Time unit : mili sec / micro sec
+  * @retval None
+  */
+static void BSP_Delay(uint32_t nTime, uint8_t unit)
+{
+
+//  BSP_delay = nTime;
+//  BSP_SetTime(unit);
+//  while(BSP_delay != 0);
+//  TIM_Cmd(TIM2,DISABLE);
+}
+
+/**
+  * @brief  BSP_SetTime
+  *         Configures TIM2 for delay routine based on TIM2
+  * @param  unit : msec /usec
+  * @retval None
+  */
+static void BSP_SetTime(uint8_t unit)
+{
+//  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
+//
+//  TIM_Cmd(TIM2,DISABLE);
+//  TIM_ITConfig(TIM2, TIM_IT_Update, DISABLE);
+//
+//
+//  if(unit == TIM_USEC_DELAY)
+//  {
+//    TIM_TimeBaseStructure.TIM_Period = 11;
+//  }
+//  else if(unit == TIM_MSEC_DELAY)
+//  {
+//    TIM_TimeBaseStructure.TIM_Period = 11999;
+//  }
+//  TIM_TimeBaseStructure.TIM_Prescaler = 5;
+//  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
+//  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
+//
+//  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
+//  TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
+//
+//  TIM_ARRPreloadConfig(TIM2, ENABLE);
+//
+//  /* TIM IT enable */
+//  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
+//
+//  /* TIM2 enable counter */
+//  TIM_Cmd(TIM2, ENABLE);
+}
+
+#endif
+
+/**
+* @}
+*/
+
+/**
+* @}
+*/
+
+/**
+* @}
+*/
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Index: scpu_usb_printer_Device_Demo/usb_conf.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usb_conf.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usb_conf.h	(working copy)
@@ -0,0 +1,291 @@
+/**
+  ******************************************************************************
+  * @file    usb_conf.h
+  * @author  MCD Application Team
+  * @version V1.1.0
+  * @date    19-March-2012
+  * @brief   General low level driver configuration
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_CONF__H__
+#define __USB_CONF__H__
+
+/* Includes ------------------------------------------------------------------*/
+#include "yc3121.h"
+
+
+
+/** @addtogroup USB_OTG_DRIVER
+  * @{
+  */
+
+/** @defgroup USB_CONF
+  * @brief USB low level driver configuration file
+  * @{
+  */
+
+/** @defgroup USB_CONF_Exported_Defines
+  * @{
+  */
+
+/* USB Core and PHY interface configuration.
+   Tip: To avoid modifying these defines each time you need to change the USB
+        configuration, you can declare the needed define in your toolchain
+        compiler preprocessor.
+   */
+/****************** USB OTG FS PHY CONFIGURATION *******************************
+*  The USB OTG FS Core supports one on-chip Full Speed PHY.
+*
+*  The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor
+*  when FS core is used.
+*******************************************************************************/
+#ifndef USE_USB_OTG_FS
+ //#define USE_USB_OTG_FS
+#endif /* USE_USB_OTG_FS */
+
+#ifdef USE_USB_OTG_FS
+ #define USB_OTG_FS_CORE
+#endif
+
+/****************** USB OTG HS PHY CONFIGURATION *******************************
+*  The USB OTG HS Core supports two PHY interfaces:
+*   (i)  An ULPI interface for the external High Speed PHY: the USB HS Core will
+*        operate in High speed mode
+*   (ii) An on-chip Full Speed PHY: the USB HS Core will operate in Full speed mode
+*
+*  You can select the PHY to be used using one of these two defines:
+*   (i)  USE_ULPI_PHY: if the USB OTG HS Core is to be used in High speed mode
+*   (ii) USE_EMBEDDED_PHY: if the USB OTG HS Core is to be used in Full speed mode
+*
+*  Notes:
+*   - The USE_ULPI_PHY symbol is defined in the project compiler preprocessor as
+*     default PHY when HS core is used.
+*   - On STM322xG-EVAL and STM324xG-EVAL boards, only configuration(i) is available.
+*     Configuration (ii) need a different hardware, for more details refer to your
+*     STM32 device datasheet.
+*******************************************************************************/
+#ifndef USE_USB_OTG_HS
+ //#define USE_USB_OTG_HS
+#endif /* USE_USB_OTG_HS */
+
+#ifndef USE_ULPI_PHY
+ //#define USE_ULPI_PHY
+#endif /* USE_ULPI_PHY */
+
+#ifndef USE_EMBEDDED_PHY
+ //#define USE_EMBEDDED_PHY
+#endif /* USE_EMBEDDED_PHY */
+
+#ifdef USE_USB_OTG_HS
+ #define USB_OTG_HS_CORE
+#endif
+
+/*******************************************************************************
+*                      FIFO Size Configuration in Device mode
+*
+*  (i) Receive data FIFO size = RAM for setup packets +
+*                   OUT endpoint control information +
+*                   data OUT packets + miscellaneous
+*      Space = ONE 32-bits words
+*     --> RAM for setup packets = 10 spaces
+*        (n is the nbr of CTRL EPs the device core supports)
+*     --> OUT EP CTRL info      = 1 space
+*        (one space for status information written to the FIFO along with each
+*        received packet)
+*     --> data OUT packets      = (Largest Packet Size / 4) + 1 spaces
+*        (MINIMUM to receive packets)
+*     --> OR data OUT packets  = at least 2*(Largest Packet Size / 4) + 1 spaces
+*        (if high-bandwidth EP is enabled or multiple isochronous EPs)
+*     --> miscellaneous = 1 space per OUT EP
+*        (one space for transfer complete status information also pushed to the
+*        FIFO with each endpoint's last packet)
+*
+*  (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
+*       that particular IN EP. More space allocated in the IN EP Tx FIFO results
+*       in a better performance on the USB and can hide latencies on the AHB.
+*
+*  (iii) TXn min size = 16 words. (n  : Transmit FIFO index)
+*   (iv) When a TxFIFO is not used, the Configuration should be as follows:
+*       case 1 :  n > m    and Txn is not used    (n,m  : Transmit FIFO indexes)
+*       --> Txm can use the space allocated for Txn.
+*       case2  :  n < m    and Txn is not used    (n,m  : Transmit FIFO indexes)
+*       --> Txn should be configured with the minimum space of 16 words
+*  (v) The FIFO is used optimally when used TxFIFOs are allocated in the top
+*       of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
+*   (vi) In HS case12 FIFO locations should be reserved for internal DMA registers
+*        so total FIFO size should be 1012 Only instead of 1024
+*******************************************************************************/
+
+/****************** USB OTG HS CONFIGURATION **********************************/
+#ifdef USB_OTG_HS_CORE
+ #define RX_FIFO_HS_SIZE                          512
+ #define TX0_FIFO_HS_SIZE                         128
+ #define TX1_FIFO_HS_SIZE                         372
+ #define TX2_FIFO_HS_SIZE                          0
+ #define TX3_FIFO_HS_SIZE                          0
+ #define TX4_FIFO_HS_SIZE                          0
+ #define TX5_FIFO_HS_SIZE                          0
+
+// #define USB_OTG_HS_SOF_OUTPUT_ENABLED
+
+ #ifdef USE_ULPI_PHY
+  #define USB_OTG_ULPI_PHY_ENABLED
+ #endif
+ #ifdef USE_EMBEDDED_PHY
+   #define USB_OTG_EMBEDDED_PHY_ENABLED
+ #endif
+ #define USB_OTG_HS_INTERNAL_DMA_ENABLED
+ #define USB_OTG_HS_DEDICATED_EP1_ENABLED
+ #define USB_OTG_HS_LOW_PWR_MGMT_SUPPORT
+#endif
+
+/****************** USB OTG FS CONFIGURATION **********************************/
+// total fifo size <= 448 (512 - 64)
+#define RX1_FIFO_FS_SIZE                         	64
+#define RX2_FIFO_FS_SIZE                          	64
+#define RX3_FIFO_FS_SIZE                          	64
+#define RX4_FIFO_FS_SIZE                          	0
+#define RX5_FIFO_FS_SIZE                          	0
+#define RX6_FIFO_FS_SIZE                          	0
+#define RX7_FIFO_FS_SIZE                          	0
+
+#define TX1_FIFO_FS_SIZE                         	64
+#define TX2_FIFO_FS_SIZE                          	64
+#define TX3_FIFO_FS_SIZE                          	64
+#define TX4_FIFO_FS_SIZE                          	0
+#define TX5_FIFO_FS_SIZE                          	0
+#define TX6_FIFO_FS_SIZE                          	0
+#define TX7_FIFO_FS_SIZE                          	0
+
+/* EP0 IN/OUT share the same section FIFO*/
+#define TX0_FIFO_FS_SIZE                            64
+#define RX0_FIFO_FS_SIZE                            64
+
+#define IS_FIFO_SIZE(size)          (((size) == 0)   || \
+                                     ((size) == 8)   || \
+                                     ((size) == 16)  || \
+                                     ((size) == 32)  || \
+                                     ((size) == 64)  || \
+                                     ((size) == 128) || \
+                                     ((size) == 256) || \
+                                     ((size) == 512))
+//#define USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
+// #define USB_OTG_FS_SOF_OUTPUT_ENABLED
+
+/****************** USB OTG MISC CONFIGURATION ********************************/
+#define VBUS_SENSING_ENABLED
+
+/****************** USB OTG MODE CONFIGURATION ********************************/
+//#define USE_HOST_MODE
+#define USE_DEVICE_MODE
+//#define USE_OTG_MODE
+/****************** USB OTG DMA MODE CONFIGURATION ***************************/
+//#define USB_OTG_DMA_ENABLE              /* Enable DMA mode */
+
+/* BULK Transfer */
+//#define USE_USB_DMA_MODE1
+
+/* Only one endpoind can be enable */
+#define USB_OTG_DEV_DMA_EP_NUM              0x81
+
+/****************** C Compilers dependant keywords ****************************/
+/* In HS mode and when the DMA is used, all variables and data structures dealing
+   with the DMA during the transaction process should be 4-bytes aligned */
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined   (__GNUC__)        /* GNU Compiler */
+    #define __ALIGN_END    __attribute__ ((aligned (4)))
+    #define __ALIGN_BEGIN
+  #else
+    #define __ALIGN_END
+    #if defined   (__CC_ARM)      /* ARM Compiler */
+      #define __ALIGN_BEGIN    __align(4)
+    #elif defined (__ICCARM__)    /* IAR Compiler */
+      #define __ALIGN_BEGIN
+    #elif defined  (__TASKING__)  /* TASKING Compiler */
+      #define __ALIGN_BEGIN    __align(4)
+    #endif /* __CC_ARM */
+  #endif /* __GNUC__ */
+#else
+  //#define __ALIGN_BEGIN         __align(4)
+  #define __ALIGN_END    __attribute__ ((aligned (4)))
+  #define __ALIGN_BEGIN
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+
+/* __packed keyword used to decrease the data type alignment to 1-byte */
+#if defined (__CC_ARM)         /* ARM Compiler */
+  #define __packed    __packed
+#elif defined (__ICCARM__)     /* IAR Compiler */
+  #define __packed    __packed
+#elif defined   ( __GNUC__ )   /* GNU Compiler */
+//  #define __packed    __attribute__ ((__packed__))
+#elif defined   (__TASKING__)  /* TASKING Compiler */
+  #define __packed    __unaligned
+#endif /* __CC_ARM */
+
+/**
+  * @}
+  */
+
+
+/** @defgroup USB_CONF_Exported_Types
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+/** @defgroup USB_CONF_Exported_Macros
+  * @{
+  */
+/**
+  * @}
+  */
+
+/** @defgroup USB_CONF_Exported_Variables
+  * @{
+  */
+/**
+  * @}
+  */
+
+/** @defgroup USB_CONF_Exported_FunctionsPrototype
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+#endif //__USB_CONF__H__
+
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
Index: scpu_usb_printer_Device_Demo/usb_main.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usb_main.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usb_main.h	(working copy)
@@ -0,0 +1,18 @@
+#include "usbd_printer_core.h"
+#include "usbd_usr.h"
+#include "usbd_desc.h"
+#include <string.h>
+#include <stdio.h>
+#include "usb_dcd_int.h"
+
+
+
+
+
+
+
+
+void usb_main(void);
+
+
+
Index: scpu_usb_printer_Device_Demo/usb_main.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usb_main.c	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usb_main.c	(working copy)
@@ -0,0 +1,115 @@
+/**
+  ******************************************************************************
+  * @file    main.c
+  * @author  yichip
+  * @version V1.0.0
+  * @date    7-9-2018
+  * @brief   This file provides all the Application firmware functions.
+  ******************************************************************************
+  * @attention
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+
+
+
+
+#include <string.h>
+#include <stdio.h>
+#include "usb_dcd_int.h"
+#include "usbd_printer_core.h"
+#include "usbd_usr.h"
+#include "usbd_desc.h"
+#include "misc.h"
+#include "usbd_printer_vcp.h"
+
+
+USB_OTG_CORE_HANDLE  USB_OTG_dev;
+extern PRINTER_IF_Prop_TypeDef  APP_FOPS;
+
+
+void usb_reg_init()
+{
+    USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x00);
+    my_delay_ms(1);
+    USB_OTG_WRITE_REG8(CORE_USB_TRIG,0xc0);
+    USB_OTG_WRITE_REG8(CORE_USB_CONFIG,0x3c);
+    USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
+    USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
+    USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
+    USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
+
+
+}
+
+uint8_t Rxbuf[1024*2] = {0};
+int totalReceiveLen=0;
+void usb_main(void)
+{
+  int rxlen = 0;
+	enable_clock(CLKCLS_BT);
+	BT_CLKPLL_EN = 0xff;
+	enable_clock(CLKCLS_USB);
+	SYSCTRL_HCLK_CON |= 1 << 11;
+	usb_reg_init();
+
+  memset(&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
+
+  USBD_Init(&USB_OTG_dev,
+        #ifdef USE_USB_OTG_HS
+              USB_OTG_HS_CORE_ID,
+        #else
+              USB_OTG_FS_CORE_ID,
+        #endif
+              &USR_desc,
+              &USBD_PRINTER_cb,
+              &USRD_cb);
+	enable_intr(INTR_USB);
+	while(1)
+	{
+        rxlen = VCP_GetRxBuflen();
+        if(rxlen>0)
+        {
+            totalReceiveLen+=rxlen;
+            MyPrintf("totalReceiveLen=%d rxlen =%d\n\r",totalReceiveLen,rxlen);
+            for(int i=0; i<rxlen; i++)
+            {
+                Rxbuf[i] = VCP_GetRxChar();
+                MyPrintf("%02x ",Rxbuf[i]);
+            }
+            MyPrintf("\n");
+            #ifndef USB_FLOWCTRL
+            DCD_EP_Tx(&USB_OTG_dev,PRINTER_IN_EP,(uint8_t*)Rxbuf,rxlen);
+            #endif
+        }
+	}
+}
+
+
+
+
+
+
+
+void USB_IRQHandler(void)
+{
+	 USBD_OTG_ISR_Handler (&USB_OTG_dev);
+ //   NVIC_ClearPendingIRQ(USB_IRQn);
+ //   MyPrintf("YICHIP SCPU USB CCID handler startV1.0.\n");
+}
+
+
+
+
+
+
+
+
+
+
+
+
Index: scpu_usb_printer_Device_Demo/usbd_conf.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_conf.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_conf.h	(working copy)
@@ -0,0 +1,108 @@
+/**
+  ******************************************************************************
+  * @file    usbd_conf.h
+  * @author  MCD Application Team
+  * @version V1.1.0
+  * @date    19-March-2012
+  * @brief   USB Device configuration file
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USBD_CONF__H__
+#define __USBD_CONF__H__
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_conf.h"
+
+/** @defgroup USB_CONF_Exported_Defines
+  * @{
+  */
+#define USBD_CFG_MAX_NUM                1
+#define USBD_ITF_MAX_NUM                1
+
+#define USBD_SELF_POWERED
+
+#define USB_MAX_STR_DESC_SIZ            255
+
+/** @defgroup USB_VCP_Class_Layer_Parameter
+  * @{
+  */
+#define PRINTER_IN_EP                       0x81  /* EP1 for data IN */
+#define PRINTER_OUT_EP                      0x01  /* EP1 for data OUT */
+#define PRINTER_CMD_EP                      0x82  /* EP2 for PRINTER commands */
+
+/* PRINTER Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
+#ifdef USE_USB_OTG_HS
+ #define PRINTER_DATA_MAX_PACKET_SIZE       512  /* Endpoint IN & OUT Packet size */
+ #define PRINTER_CMD_PACKET_SZE             8    /* Control Endpoint Packet size */
+
+ #define PRINTER_IN_FRAME_INTERVAL          40   /* Number of micro-frames between IN transfers */
+ #define APP_RX_DATA_SIZE               2048 /* Total size of IN buffer:
+                                                APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > PRINTER_IN_FRAME_INTERVAL*8 */
+#else
+ #define PRINTER_DATA_MAX_PACKET_SIZE       64   /* Endpoint IN & OUT Packet size */
+ #define PRINTER_CMD_PACKET_SZE             8    /* Control Endpoint Packet size */
+
+ #define PRINTER_IN_FRAME_INTERVAL          5    /* Number of frames between IN transfers */
+ #define APP_TX_DATA_SIZE              (2048)
+ #define APP_RX_DATA_SIZE               2048 /* Total size of IN buffer:
+                                                APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > PRINTER_IN_FRAME_INTERVAL */
+#endif /* USE_USB_OTG_HS */
+
+#define APP_FOPS                        VCP_fops
+/**
+  * @}
+  */
+
+/** @defgroup USB_CONF_Exported_Types
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+/** @defgroup USB_CONF_Exported_Macros
+  * @{
+  */
+/**
+  * @}
+  */
+
+/** @defgroup USB_CONF_Exported_Variables
+  * @{
+  */
+/**
+  * @}
+  */
+
+/** @defgroup USB_CONF_Exported_FunctionsPrototype
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+#endif //__USBD_CONF__H__
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
Index: scpu_usb_printer_Device_Demo/usbd_desc.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_desc.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_desc.h	(working copy)
@@ -0,0 +1,120 @@
+/**
+  ******************************************************************************
+  * @file    usbd_desc.h
+  * @author  MCD Application Team
+  * @version V1.1.0
+  * @date    19-March-2012
+  * @brief   header file for the usbd_desc.c file
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+
+#ifndef __USB_DESC_H
+#define __USB_DESC_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbd_def.h"
+
+/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
+  * @{
+  */
+
+/** @defgroup USB_DESC
+  * @brief general defines for the usb device library file
+  * @{
+  */
+
+/** @defgroup USB_DESC_Exported_Defines
+  * @{
+  */
+#define USB_DEVICE_DESCRIPTOR_TYPE              0x01
+#define USB_CONFIGURATION_DESCRIPTOR_TYPE       0x02
+#define USB_STRING_DESCRIPTOR_TYPE              0x03
+#define USB_INTERFACE_DESCRIPTOR_TYPE           0x04
+#define USB_ENDPOINT_DESCRIPTOR_TYPE            0x05
+#define USB_SIZ_DEVICE_DESC                     18
+#define USB_SIZ_STRING_LANGID                   4
+
+/**
+  * @}
+  */
+
+
+/** @defgroup USBD_DESC_Exported_TypesDefinitions
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+
+/** @defgroup USBD_DESC_Exported_Macros
+  * @{
+  */
+/**
+  * @}
+  */
+
+/** @defgroup USBD_DESC_Exported_Variables
+  * @{
+  */
+extern  uint8_t USBD_DeviceDesc  [USB_SIZ_DEVICE_DESC];
+extern  uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ];
+extern  uint8_t USBD_OtherSpeedCfgDesc[USB_LEN_CFG_DESC];
+extern  uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC];
+extern  uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID];
+extern  USBD_DEVICE USR_desc;
+/**
+  * @}
+  */
+
+/** @defgroup USBD_DESC_Exported_FunctionsPrototype
+  * @{
+  */
+
+
+uint8_t *     USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length);
+uint8_t *     USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length);
+uint8_t *     USBD_USR_ManufacturerStrDescriptor ( uint8_t speed , uint16_t *length);
+uint8_t *     USBD_USR_ProductStrDescriptor ( uint8_t speed , uint16_t *length);
+uint8_t *     USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length);
+uint8_t *     USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length);
+uint8_t *     USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length);
+
+#ifdef USB_SUPPORT_USER_STRING_DESC
+uint8_t *     USBD_USR_USRStringDesc (uint8_t speed, uint8_t idx , uint16_t *length);
+#endif /* USB_SUPPORT_USER_STRING_DESC */
+
+/**
+  * @}
+  */
+
+#endif /* __USBD_DESC_H */
+
+/**
+  * @}
+  */
+
+/**
+* @}
+*/
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Index: scpu_usb_printer_Device_Demo/usbd_desc.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_desc.c	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_desc.c	(working copy)
@@ -0,0 +1,330 @@
+/**
+  ******************************************************************************
+  * @file    usbd_desc.c
+  * @author  MCD Application Team
+  * @version V1.1.0
+  * @date    19-March-2012
+  * @brief   This file provides the USBD descriptors and string formating method.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbd_core.h"
+#include "usbd_desc.h"
+#include "usbd_req.h"
+#include "usbd_conf.h"
+#include "usb_regs.h"
+#include "usbd_printer_core.h"
+/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
+  * @{
+  */
+
+
+/** @defgroup USBD_DESC
+  * @brief USBD descriptors module
+  * @{
+  */
+
+/** @defgroup USBD_DESC_Private_TypesDefinitions
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+/** @defgroup USBD_DESC_Private_Defines
+  * @{
+  */
+#define USBD_VID                        0x3151
+
+#define USBD_PID                        0x6003
+//#define USBD_VID                        0x0483
+
+//#define USBD_PID                        0x5740
+
+/** @defgroup USB_String_Descriptors
+  * @{
+  */
+#define USBD_LANGID_STRING              0x409
+#define USBD_MANUFACTURER_STRING        "YICHIP"
+
+#define USBD_PRODUCT_HS_STRING          "YC3121 Printer demo in HS mode"
+#define USBD_SERIALNUMBER_HS_STRING     "100000000004"
+
+#define USBD_PRODUCT_FS_STRING          "YC3121 Printer demo"
+#define USBD_SERIALNUMBER_FS_STRING     "000000000004"
+
+#define USBD_CONFIGURATION_HS_STRING    "Printer Config"
+#define USBD_INTERFACE_HS_STRING        "Printer Interface"
+
+#define USBD_CONFIGURATION_FS_STRING    "Printer Config"
+#define USBD_INTERFACE_FS_STRING        "Printer Interface"
+/**
+  * @}
+  */
+
+
+/** @defgroup USBD_DESC_Private_Macros
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+/** @defgroup USBD_DESC_Private_Variables
+  * @{
+  */
+
+USBD_DEVICE USR_desc =
+{
+  USBD_USR_DeviceDescriptor,
+  USBD_USR_LangIDStrDescriptor,
+  USBD_USR_ManufacturerStrDescriptor,
+  USBD_USR_ProductStrDescriptor,
+  USBD_USR_SerialStrDescriptor,
+  USBD_USR_ConfigStrDescriptor,
+  USBD_USR_InterfaceStrDescriptor,
+
+};
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+/* USB Standard Device Descriptor */
+__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
+  {
+    0x12,                       /*bLength */
+    USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
+//    0x00,                       /*bcdUSB */
+//    0x02,
+    0x10,                       /*bcdUSB */
+    0x01,
+//    0x00,                     /*bDeviceClass*/
+    0x00,                       /*bDeviceClass*/
+    0x00,                       /*bDeviceSubClass*/
+    0x00,                       /*bDeviceProtocol*/
+    USB_OTG_MAX_EP0_SIZE,       /*bMaxPacketSize*/
+    LOBYTE(USBD_VID),           /*idVendor*/
+    HIBYTE(USBD_VID),           /*idVendor*/
+    LOBYTE(USBD_PID),           /*idVendor*/
+    HIBYTE(USBD_PID),           /*idVendor*/
+//    0x00,                       /*bcdDevice rel. 2.00*/
+//    0x02,
+    0x00,                       /*bcdDevice rel. 1.00*/
+    0x02,
+    USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/
+    USBD_IDX_PRODUCT_STR,       /*Index of product string*/
+    USBD_IDX_SERIAL_STR,        /*Index of serial number string*/
+    USBD_CFG_MAX_NUM            /*bNumConfigurations*/
+  } ; /* USB_DeviceDescriptor */
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+/* USB Standard Device Descriptor */
+__ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
+{
+  USB_LEN_DEV_QUALIFIER_DESC,
+  USB_DESC_TYPE_DEVICE_QUALIFIER,
+  0x00,
+  0x02,
+  0x00,
+  0x00,
+  0x00,
+  0x40,
+  0x01,
+  0x00,
+};
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+  #if defined ( __ICCARM__ ) /*!< IAR Compiler */
+    #pragma data_alignment=4
+  #endif
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+/* USB Standard Device Descriptor */
+__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
+{
+     USB_SIZ_STRING_LANGID,
+     USB_DESC_TYPE_STRING,
+     LOBYTE(USBD_LANGID_STRING),
+     HIBYTE(USBD_LANGID_STRING),
+};
+/**
+  * @}
+  */
+
+
+/** @defgroup USBD_DESC_Private_FunctionPrototypes
+  * @{
+  */
+/**
+  * @}
+  */
+
+
+/** @defgroup USBD_DESC_Private_Functions
+  * @{
+  */
+
+/**
+* @brief  USBD_USR_DeviceDescriptor
+*         return the device descriptor
+* @param  speed : current device speed
+* @param  length : pointer to data length variable
+* @retval pointer to descriptor buffer
+*/
+uint8_t *  USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
+{
+  *length = sizeof(USBD_DeviceDesc);
+  return USBD_DeviceDesc;
+}
+
+/**
+* @brief  USBD_USR_LangIDStrDescriptor
+*         return the LangID string descriptor
+* @param  speed : current device speed
+* @param  length : pointer to data length variable
+* @retval pointer to descriptor buffer
+*/
+uint8_t *  USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
+{
+  *length =  sizeof(USBD_LangIDDesc);
+  return USBD_LangIDDesc;
+}
+
+
+/**
+* @brief  USBD_USR_ProductStrDescriptor
+*         return the product string descriptor
+* @param  speed : current device speed
+* @param  length : pointer to data length variable
+* @retval pointer to descriptor buffer
+*/
+uint8_t *  USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
+{
+
+
+  if(speed == 0)
+  {
+//    USBD_GetString (USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
+  }
+  else
+  {
+    USBD_GetString (USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
+  }
+  return USBD_StrDesc;
+}
+
+/**
+* @brief  USBD_USR_ManufacturerStrDescriptor
+*         return the manufacturer string descriptor
+* @param  speed : current device speed
+* @param  length : pointer to data length variable
+* @retval pointer to descriptor buffer
+*/
+uint8_t *  USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
+{
+  USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
+  return USBD_StrDesc;
+}
+
+/**
+* @brief  USBD_USR_SerialStrDescriptor
+*         return the serial number string descriptor
+* @param  speed : current device speed
+* @param  length : pointer to data length variable
+* @retval pointer to descriptor buffer
+*/
+uint8_t *  USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
+{
+  if(speed  == USB_OTG_SPEED_HIGH)
+  {
+//    USBD_GetString (USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length);
+  }
+  else
+  {
+    USBD_GetString (USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
+  }
+  return USBD_StrDesc;
+}
+
+/**
+* @brief  USBD_USR_ConfigStrDescriptor
+*         return the configuration string descriptor
+* @param  speed : current device speed
+* @param  length : pointer to data length variable
+* @retval pointer to descriptor buffer
+*/
+uint8_t *  USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
+{
+  if(speed  == USB_OTG_SPEED_HIGH)
+  {
+//    USBD_GetString (USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
+  }
+  else
+  {
+    USBD_GetString (USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
+  }
+  return USBD_StrDesc;
+}
+
+
+/**
+* @brief  USBD_USR_InterfaceStrDescriptor
+*         return the interface string descriptor
+* @param  speed : current device speed
+* @param  length : pointer to data length variable
+* @retval pointer to descriptor buffer
+*/
+uint8_t *  USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
+{
+  if(speed == 0)
+  {
+//    USBD_GetString (USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
+  }
+  else
+  {
+    USBD_GetString (USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
+  }
+  return USBD_StrDesc;
+}
+
+/**
+  * @}
+  */
+
+
+/**
+  * @}
+  */
+
+
+/**
+  * @}
+  */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
Index: scpu_usb_printer_Device_Demo/usbd_printer_vcp.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_printer_vcp.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_printer_vcp.h	(working copy)
@@ -0,0 +1,77 @@
+/**
+  ******************************************************************************
+  * @file    usbd_printer_vcp.h
+  * @author  MCD Application Team
+  * @version V1.1.0
+  * @date    19-March-2012
+  * @brief   Header for usbd_printer_vcp.c file.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USBD_PRINTER_VCP_H
+#define __USBD_PRINTER_VCP_H
+
+/* Includes ------------------------------------------------------------------*/
+#ifdef STM32F2XX
+ #include "stm32f2xx.h"
+#elif defined(STM32F10X_CL)
+ #include "stm32f10x.h"
+#endif /* STM32F2XX */
+
+#include "usbd_printer_core.h"
+#include "usbd_conf.h"
+
+
+
+/* Exported typef ------------------------------------------------------------*/
+/* The following structures groups all needed parameters to be configured for the
+   ComPort. These parameters can modified on the fly by the host through PRINTER class
+   command class requests. */
+typedef struct
+{
+  uint32_t bitrate;
+  uint8_t  format;
+  uint8_t  paritytype;
+  uint8_t  datatype;
+}LINE_CODING;
+
+
+
+/* Exported constants --------------------------------------------------------*/
+/* The following define is used to route the USART IRQ handler to be used.
+   The IRQ handler function is implemented in the usbd_printer_vcp.c file. */
+
+//#define EVAL_COM_IRQHandler            UART1_IRQHandler
+
+#define DEFAULT_CONFIG                  0
+#define OTHER_CONFIG                    1
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len);
+uint32_t VCP_GetTxBuflen(void);
+uint32_t VCP_GetTxBufrsaddr(void);
+uint8_t  VCP_GetRxChar(void);
+uint32_t VCP_GetRxBuflen(void);
+int8_t * VCP_GetRxBufrsaddr(void);
+#endif /* __USBD_PRINTER_VCP_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Index: scpu_usb_printer_Device_Demo/usbd_printer_vcp.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_printer_vcp.c	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_printer_vcp.c	(working copy)
@@ -0,0 +1,576 @@
+/**
+  ******************************************************************************
+  * @file    usbd_printer_vcp.c
+  * @author  MCD Application Team
+  * @version V1.1.0
+  * @date    19-March-2012
+  * @brief   Generic media access Layer.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+  *
+  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+  * You may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at:
+  *
+  *        http://www.st.com/software_license_agreement_liberty_v2
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  *
+  ******************************************************************************
+  */
+
+#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
+#pragma     data_alignment = 4
+#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
+
+/* Includes ------------------------------------------------------------------*/
+#include "usbd_printer_vcp.h"
+#include "usb_conf.h"
+#include "usbd_printer_core.h"
+#include "Misc.h"
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+LINE_CODING linecoding =
+  {
+    115200, /* baud rate*/
+    0x00,   /* stop bits-1*/
+    0x00,   /* parity - none*/
+    0x08    /* nb. of bits 8*/
+  };
+
+
+UART_InitTypeDef USART_InitStructure;
+
+/* These are external variables imported from PRINTER core to be used for IN
+   transfer management. */
+
+#ifdef USER_SPECIFIED_DATA_SOURCE
+extern uint8_t  *APP_Rx_Buffer;
+uint8_t COM_Rx_data_buf[2048];
+#else
+//extern uint8_t  APP_Rx_Buffer [];
+extern struct APP_DATA_STRUCT_DEF APP_Gdata_param;
+#endif                            /* Write PRINTER received data in this buffer.
+                                     These data will be sent over USB IN endpoint
+                                     in the PRINTER core functions. */
+//extern volatile uint32_t APP_Rx_ptr_in;
+                                  /* Increment this pointer or roll it back to
+                                     start address when writing received data
+                                     in the buffer APP_Rx_Buffer. */
+
+/* Private function prototypes -----------------------------------------------*/
+static uint16_t VCP_Init     (void);
+static uint16_t VCP_DeInit   (void);
+static uint16_t VCP_Ctrl     (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
+//static uint16_t VCP_DataTx   (uint8_t* Buf, uint32_t Len);
+static uint16_t VCP_DataRx   (uint8_t* Buf, uint32_t Len);
+
+static uint16_t VCP_COMConfig(uint8_t Conf);
+
+PRINTER_IF_Prop_TypeDef VCP_fops =
+{
+  VCP_Init,
+  VCP_DeInit,
+  VCP_Ctrl,
+  VCP_DataTx,
+  VCP_DataRx
+};
+
+/* Private functions ---------------------------------------------------------*/
+/**
+  * @brief  VCP_Init
+  *         Initializes the Media on the STM32
+  * @param  None
+  * @retval Result of the opeartion (USBD_OK in all cases)
+  */
+static uint16_t VCP_Init(void)
+{
+//    NVIC_InitTypeDef NVIC_InitStructure;
+
+    /**/
+    #ifdef USER_SPECIFIED_DATA_SOURCE
+    APP_Rx_Buffer = COM_Rx_data_buf;
+    #else
+    APP_Gdata_param.COM_config_cmp = 0;
+    #endif
+	memset(&APP_Gdata_param, 0, sizeof(APP_Gdata_param));
+    /* EVAL_COM1 default configuration */
+    /* EVAL_COM1 configured as follow:
+        - BaudRate = 115200 baud
+        - Word Length = 8 Bits
+        - One Stop Bit
+        - Parity Odd
+        - Hardware flow control disabled
+        - Receive and transmit enabled
+    */
+//    USART_InitStructure.UART_BaudRate = 115200;
+//    USART_InitStructure.UART_WordLength = UART_WordLength_8b;
+//    USART_InitStructure.UART_StopBits = UART_StopBits_1;
+//    USART_InitStructure.UART_Parity = UART_Parity_Odd;
+//    UART_Init(UART1, &USART_InitStructure);
+
+//    /* Enable the USART Receive interrupt */
+//    UART_ITConfig(UART1, UART_IT_RX_RECVD, ENABLE);
+
+//    /* Enable USART Interrupt */
+//    NVIC_InitStructure.NVIC_IRQChannel = UART1_IRQn;
+//    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+//    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+//    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+//    NVIC_Init(&NVIC_InitStructure);
+
+    return USBD_OK;
+}
+
+/**
+  * @brief  VCP_DeInit
+  *         DeInitializes the Media on the STM32
+  * @param  None
+  * @retval Result of the opeartion (USBD_OK in all cases)
+  */
+static uint16_t VCP_DeInit(void)
+{
+
+  return USBD_OK;
+}
+
+
+/**
+  * @brief  VCP_Ctrl
+  *         Manage the PRINTER class requests
+  * @param  Cmd: Command code
+  * @param  Buf: Buffer containing command data (request parameters)
+  * @param  Len: Number of data to be sent (in bytes)
+  * @retval Result USBD_Status
+  */
+static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
+{
+  switch (Cmd)
+  {
+  case SEND_ENCAPSULATED_COMMAND:
+    /*get PRINTER class GET DEVICE ID */
+
+    break;
+
+  case GET_ENCAPSULATED_RESPONSE:
+    /* Not  needed for this driver */
+    break;
+
+  case SET_COMM_FEATURE:
+    /* Not  needed for this driver */
+    break;
+
+  case GET_COMM_FEATURE:
+    /* Not  needed for this driver */
+    break;
+
+  case CLEAR_COMM_FEATURE:
+    /* Not  needed for this driver */
+    break;
+
+  case SET_LINE_CODING:
+    linecoding.bitrate = (uint32_t)(Buf[0] | (Buf[1] << 8) | (Buf[2] << 16) | (Buf[3] << 24));
+    linecoding.format = Buf[4];
+    linecoding.paritytype = Buf[5];
+    linecoding.datatype = Buf[6];
+    APP_Gdata_param.COM_config_cmp = 1;
+    MyPrintf("cmp=%X\n",APP_Gdata_param.COM_config_cmp);
+     MyPrintf("SET_LINE_CODING \n\r");
+    /* Set the new configuration */
+    VCP_COMConfig(OTHER_CONFIG);
+    break;
+
+  case GET_LINE_CODING:
+    Buf[0] = (uint8_t)(linecoding.bitrate);
+    Buf[1] = (uint8_t)(linecoding.bitrate >> 8);
+    Buf[2] = (uint8_t)(linecoding.bitrate >> 16);
+    Buf[3] = (uint8_t)(linecoding.bitrate >> 24);
+    Buf[4] = linecoding.format;
+    Buf[5] = linecoding.paritytype;
+    Buf[6] = linecoding.datatype;
+    break;
+
+  case SET_CONTROL_LINE_STATE:
+    /* Not  needed for this driver */
+    break;
+
+  case SEND_BREAK:
+    /* Not  needed for this driver */
+    break;
+
+  default:
+    break;
+  }
+
+  return USBD_OK;
+}
+
+int isUsbBufFull()
+{
+	int ret = 0;
+//	NVIC_DisableIRQ(USB_IRQn);
+	ret = APP_Gdata_param.rx_structure.Rx_counter >= PRINTER_APP_RX_DATA_SIZE;
+//	NVIC_EnableIRQ(USB_IRQn);
+	return ret;
+}
+/**
+  * @brief  VCP_DataTx
+  *         PRINTER received data to be send over USB IN endpoint are managed in
+  *         this function.
+  * @param  Buf: Buffer of data to be sent
+  * @param  Len: Number of data to be sent (in bytes)
+  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
+  */
+uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len)
+{
+    #ifdef USER_SPECIFIED_DATA_SOURCE
+    uint32_t i = 0;
+    for (i = 0; i < Len; i++)
+    {
+        *(APP_Rx_Buffer + APP_Rx_ptr_in) = *Buf++;
+        APP_Rx_ptr_in++;
+    }
+    #else
+    uint32_t i = 0;
+    if (linecoding.datatype == 7)
+    {
+        for (i = 0; i < Len; i++)
+        {
+//			do
+//			{
+//				if (isUsbBufFull())
+//				{
+//					int i;
+//					for (i = 0; i < 1000; i++);
+//				}else
+//				{
+//					break;
+//				}
+//			} while (1);
+            APP_Gdata_param.rx_structure.APP_Rx_Buffer[APP_Gdata_param.rx_structure.APP_Rx_ptr_in++] = (*Buf++) & 0x7F;
+  //          NVIC_DisableIRQ(USB_IRQn);
+            APP_Gdata_param.rx_structure.Rx_counter++;
+   //         NVIC_EnableIRQ(USB_IRQn);
+            /* To avoid buffer overflow */
+            if(APP_Gdata_param.rx_structure.APP_Rx_ptr_in == PRINTER_APP_RX_DATA_SIZE)
+            {
+                APP_Gdata_param.rx_structure.APP_Rx_ptr_in = 0;
+            }
+        }
+    }
+    else if (linecoding.datatype == 8)
+    {
+        for (i = 0; i < Len; i++)
+        {
+			/* Detect whether the buffer overflow */
+//            do
+//			{
+//				if (isUsbBufFull())
+//				{
+//					int i;
+//					/* Wait Buf Idle */
+//					for (i = 0; i < 1000; i++);
+//				}else
+//				{
+//					break;
+//				}
+//			} while (1);
+			APP_Gdata_param.rx_structure.APP_Rx_Buffer[APP_Gdata_param.rx_structure.APP_Rx_ptr_in++] = *Buf++;
+		//	NVIC_DisableIRQ(USB_IRQn);
+            APP_Gdata_param.rx_structure.Rx_counter++;
+      //      NVIC_EnableIRQ(USB_IRQn);
+            /* To avoid buffer overflow */
+            if(APP_Gdata_param.rx_structure.APP_Rx_ptr_in == PRINTER_APP_RX_DATA_SIZE)
+            {
+                APP_Gdata_param.rx_structure.APP_Rx_ptr_in = 0;
+            }
+        }
+    }
+    #endif
+    return USBD_OK;
+}
+
+/**
+  * @brief  Get_TxBuf_length
+  *         Get the length of the remaining data to be transmitted
+  * @param  NONE
+  * @retval Result receive data length
+  */
+uint32_t VCP_GetTxBuflen(void)
+{
+	uint32_t ret = 0x00;
+	if (APP_Gdata_param.rx_structure.APP_Rx_ptr_out < APP_Gdata_param.rx_structure.APP_Rx_ptr_in)
+		ret = APP_Gdata_param.rx_structure.APP_Rx_ptr_in - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+	else
+		ret = PRINTER_APP_RX_DATA_SIZE + APP_Gdata_param.rx_structure.APP_Rx_ptr_in \
+	          - APP_Gdata_param.rx_structure.APP_Rx_ptr_out;
+    return ret;
+}
+
+/**
+  * @brief  Get_RxBuf_rsaddr
+  *         Get reading receive data starting position.
+  * @param  NONE
+  * @retval Result received data is read starting position
+  */
+uint32_t VCP_GetTxBufrsaddr(void)
+{
+    return(APP_Gdata_param.rx_structure.APP_Rx_ptr_out);
+}
+
+/**
+  * @brief  Get_RxData
+  *         Get receive data by byte
+  * @param  NONE
+  * @retval Result receive data
+  */
+extern uint8_t usbFlowCtrl;
+uint8_t VCP_GetRxChar(void)
+{
+	uint8_t ret;
+  ret = (APP_Gdata_param.tx_structure.APP_Tx_Buffer[APP_Gdata_param.tx_structure.APP_Tx_ptr_out++]);
+	if (APP_Gdata_param.tx_structure.APP_Tx_ptr_out >= PRINTER_APP_TX_DATA_SIZE)
+  {
+     APP_Gdata_param.tx_structure.APP_Tx_ptr_out = 0;
+  }
+	#ifdef USB_FLOWCTRL
+	if((VCP_GetRxBuflen()+PRINTER_DATA_OUT_PACKET_SIZE)<PRINTER_APP_TX_DATA_SIZE)
+	{
+		if(usbFlowCtrl==1)
+		{
+			//MyPrintf("\r\n\r\n usbFlowCtrl=0\r\n\r\n");
+			usbFlowCtrl=0;
+			NVIC_EnableIRQ(USB_IRQn);
+		}
+	}
+	#endif
+	return ret;
+}
+
+/**
+  * @brief  Get_RxBuf_length
+  *         Get receive data length
+  * @param  NONE
+  * @retval Result receive data length
+  */
+uint32_t VCP_GetRxBuflen(void)
+{
+    uint32_t inPtr=APP_Gdata_param.tx_structure.APP_Tx_ptr_in;
+    if(inPtr>=APP_Gdata_param.tx_structure.APP_Tx_ptr_out)
+		{
+			return (inPtr-APP_Gdata_param.tx_structure.APP_Tx_ptr_out);
+		}
+		else
+		{
+			return (PRINTER_APP_TX_DATA_SIZE-(APP_Gdata_param.tx_structure.APP_Tx_ptr_out-inPtr));
+		}
+}
+
+/**
+  * @brief  Get_RxBuf_rsaddr
+  *         Get reading receive data starting position.
+  * @param  NONE
+  * @retval Result received data is read starting position
+  */
+int8_t * VCP_GetRxBufrsaddr(void)
+{
+    return (int8_t*)(&(APP_Gdata_param.tx_structure.APP_Tx_Buffer[APP_Gdata_param.tx_structure.APP_Tx_ptr_out]));
+}
+
+/**
+  * @brief  VCP_DataRx
+  *         Data received over USB OUT endpoint are sent over PRINTER interface
+  *         through this function.
+  *
+  *         @note
+  *         This function will block any OUT packet reception on USB endpoint
+  *         untill exiting this function. If you exit this function before transfer
+  *         is complete on PRINTER interface (ie. using DMA controller) it will result
+  *         in receiving more data while previous ones are still not sent.
+  *
+  * @param  Buf: Buffer of data to be received
+  * @param  Len: Number of data received (in bytes)
+  * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
+  */
+static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
+{
+    uint32_t i;
+    //MyPrintf("vcp_len =%X\n\r",Len);
+    for (i = 0; i < Len; i++)
+    {
+        APP_Gdata_param.tx_structure.APP_Tx_Buffer[APP_Gdata_param.tx_structure.APP_Tx_ptr_in++] = Buf[i];
+				if(APP_Gdata_param.tx_structure.APP_Tx_ptr_in >= PRINTER_APP_TX_DATA_SIZE)
+				{
+						APP_Gdata_param.tx_structure.APP_Tx_ptr_in = 0;
+				}
+
+				APP_Gdata_param.tx_structure.Tx_counter++;
+    }
+		#ifdef USB_FLOWCTRL
+		if((VCP_GetRxBuflen()+PRINTER_DATA_OUT_PACKET_SIZE)>=PRINTER_APP_TX_DATA_SIZE)
+		{
+			if(usbFlowCtrl==0)
+			{
+				usbFlowCtrl=1;
+				NVIC_DisableIRQ(USB_IRQn);
+				//MyPrintf("\r\n\r\n usbFlowCtrl=1\r\n\r\n");
+			}
+		}
+		#endif
+    return USBD_OK;
+}
+
+
+
+/**
+  * @brief  VCP_COMConfig
+  *         Configure the COM Port with default values or values received from host.
+  * @param  Conf: can be DEFAULT_CONFIG to set the default configuration or OTHER_CONFIG
+  *         to set a configuration received from the host.
+  * @retval None.
+  */
+static uint16_t VCP_COMConfig(uint8_t Conf)
+{
+	/*
+    if (Conf == DEFAULT_CONFIG)
+    {
+//        /* EVAL_COM1 default configuration */
+//        /* EVAL_COM1 configured as follow:
+//        - BaudRate = 115200 baud
+//        - Word Length = 8 Bits
+//        - One Stop Bit
+//        - Parity Odd
+//        - Hardware flow control disabled
+//        - Receive and transmit enabled
+//        */
+//        USART_InitStructure.UART_BaudRate = 115200;
+//        USART_InitStructure.UART_WordLength = UART_WordLength_8b;
+//        USART_InitStructure.UART_StopBits = UART_StopBits_1;
+//        USART_InitStructure.UART_Parity = UART_Parity_No;
+
+//        UART_Init(UART1, &USART_InitStructure);
+//        /* Enable the USART Receive interrupt */
+//        UART_ITConfig(UART1, UART_IT_RX_RECVD, ENABLE);
+//    }
+
+//    else
+//    {
+//        /* set the Stop bit*/
+//        switch (linecoding.format)
+//        {
+//        case 0:
+//          USART_InitStructure.UART_StopBits = UART_StopBits_1;
+//          break;
+//        case 1:
+//          USART_InitStructure.UART_StopBits = UART_StopBits_1_5;
+//          break;
+//        case 2:
+//          USART_InitStructure.UART_StopBits = UART_StopBits_2;
+//          break;
+//        default :
+//          VCP_COMConfig(DEFAULT_CONFIG);
+//          return (USBD_FAIL);
+//        }
+
+//        /* set the parity bit*/
+//        switch (linecoding.paritytype)
+//        {
+//        case 0:
+//          USART_InitStructure.UART_Parity = UART_Parity_No;
+//          break;
+//        case 1:
+//          USART_InitStructure.UART_Parity = UART_Parity_Even;
+//          break;
+//        case 2:
+//          USART_InitStructure.UART_Parity = UART_Parity_Odd;
+//          break;
+//        default :
+//          VCP_COMConfig(DEFAULT_CONFIG);
+//          return (USBD_FAIL);
+//        }
+
+//        /*set the data type : only 8bits and 9bits is supported */
+//        switch (linecoding.datatype)
+//        {
+//        case 0x07:
+//          /* With this configuration a parity (Even or Odd) should be set */
+//          USART_InitStructure.UART_WordLength = UART_WordLength_8b;
+//          break;
+//        case 0x08:
+//          if (USART_InitStructure.UART_Parity == UART_Parity_No)
+//          {
+//            USART_InitStructure.UART_WordLength = UART_WordLength_8b;
+//          }
+//          else
+//          {
+//    //        USART_InitStructure.UART_WordLength = UART_WordLength_9b;
+//          }
+//
+//          break;
+//        default :
+////          VCP_COMConfig(DEFAULT_CONFIG);
+//          return (USBD_FAIL);
+//        }
+
+//        USART_InitStructure.UART_BaudRate = linecoding.bitrate;
+
+////        UART_Init(UART1, &USART_InitStructure);
+//    }
+  return USBD_OK;
+}
+
+/**
+  * @brief  EVAL_COM_IRQHandler
+  *
+  * @param  None.
+  * @retval None.
+  */
+#if 0
+void EVAL_COM_IRQHandler(void)
+{
+    UART_TypeDef * UARTx = UART1;
+    uint8_t ra_data_re = 0x00;
+	switch(UARTx->OFFSET_8.IIR & 0x0f)
+	{
+        case UART_IT_ID_TX_EMPTY:
+//            /* Send the received data to the PC Host*/
+//            VCP_DataTx (0,0);
+
+            break;
+        case UART_IT_ID_RX_RECVD:
+            #ifdef USER_SPECIFIED_DATA_SOURCE
+            if (linecoding.datatype == 7)
+            {
+                ra_data_re = UART_ReceiveData(UART1) & 0x7F;
+            }
+            else if (linecoding.datatype == 8)
+            {
+                ra_data_re = UART_ReceiveData(UART1);
+            }
+            VCP_DataTx (&ra_data_re, 1);
+            #else
+//            UART_ITConfig(UART1, UART_IT_RX_RECVD, DISABLE);
+
+            ra_data_re = UART_ReceiveData(UART1);
+            VCP_DataTx (&ra_data_re, 1);
+
+//            UART_ITConfig(UART1, UART_IT_RX_RECVD, ENABLE);
+            #endif
+
+            /* If overrun condition occurs, clear the ORE flag and recover communication */
+//            (void)UART_ReceiveData(UART1);
+            break;
+        default :
+            break;
+    }
+}
+#endif
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Index: scpu_usb_printer_Device_Demo/usbd_usr.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_usr.c	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_usb/scpu_usb_printer_Device_Demo/usbd_usr.c	(working copy)
@@ -0,0 +1,320 @@
+/**
+  ******************************************************************************
+  * @file    usbd_usr.c
+  * @author  Megahuntmicro
+  * @version V1.0.0
+  * @date    21-October-2014
+  * @brief   This file includes the user application layer
+  ******************************************************************************
+  * @attention
+  *
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "yc3121.h"
+#include "usbd_usr.h"
+#include "usbd_ioreq.h"
+#include "yc3121.h"
+#include "usb_conf.h"
+
+/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
+* @{
+*/
+
+/** @defgroup USBD_USR
+* @brief    This file includes the user application layer
+* @{
+*/
+
+/** @defgroup USBD_USR_Private_TypesDefinitions
+* @{
+*/
+/**
+* @}
+*/
+
+
+/** @defgroup USBD_USR_Private_Defines
+* @{
+*/
+/**
+* @}
+*/
+
+
+/** @defgroup USBD_USR_Private_Macros
+* @{
+*/
+/**
+* @}
+*/
+
+
+/** @defgroup USBD_USR_Private_Variables
+* @{
+*/
+
+USBD_Usr_cb_TypeDef USRD_cb =
+{
+  USBD_USR_Init,
+  USBD_USR_DeviceReset,
+  USBD_USR_DeviceConfigured,
+  USBD_USR_DeviceSuspended,
+  USBD_USR_DeviceResumed,
+
+  USBD_USR_DeviceConnected,
+  USBD_USR_DeviceDisconnected,
+
+
+};
+
+
+
+/**
+* @}
+*/
+
+/** @defgroup USBD_USR_Private_Constants
+* @{
+*/
+
+/**
+* @}
+*/
+
+
+
+/** @defgroup USBD_USR_Private_FunctionPrototypes
+* @{
+*/
+/**
+* @}
+*/
+
+
+/** @defgroup USBD_USR_Private_Functions
+* @{
+*/
+
+#define USER_INFORMATION1      "[Key]:RemoteWakeup"
+#define USER_INFORMATION2      "[Joystick]:Mouse emulation"
+
+
+/**
+* @brief  USBD_USR_Init
+*         Displays the message on LCD for host lib initialization
+* @param  None
+* @retval None
+*/
+void USBD_USR_Init(void)
+{
+//  /* Initialize LEDs */
+//  STM_EVAL_LEDInit(LED1);
+//  STM_EVAL_LEDInit(LED2);
+//  STM_EVAL_LEDInit(LED3);
+//  STM_EVAL_LEDInit(LED4);
+//
+//  /* Configure the IOE on which the JoyStick is connected */
+//	IOE_Config();
+//
+//  /* Setup SysTick Timer for 20 msec interrupts
+//  This interrupt is used to probe the joystick */
+//  if (SysTick_Config(SystemCoreClock / 48))
+//  {
+//    /* Capture error */
+//    while (1);
+//  }
+//  /* Initialize the LCD */
+//#if defined (USE_STM322xG_EVAL)
+//  STM322xG_LCD_Init();
+//#elif defined(USE_STM324xG_EVAL)
+//  STM324xG_LCD_Init();
+//#elif defined (USE_STM3210C_EVAL)
+//  STM3210C_LCD_Init();
+//#else
+// #error "Missing define: Evaluation board (ie. USE_STM322xG_EVAL)"
+//#endif
+
+//  LCD_LOG_Init();
+
+//#ifdef USE_USB_OTG_HS
+//  LCD_LOG_SetHeader(" USB OTG HS HID Device");
+//#else
+//  LCD_LOG_SetHeader(" USB OTG FS HID Device");
+//#endif
+//  LCD_UsrLog("> USB device library started.\n");
+//  LCD_LOG_SetFooter ("     USB Device Library v1.1.0" );
+//
+//  /* Information panel */
+//  LCD_SetTextColor(Green);
+//  LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 42, USER_INFORMATION1);
+//  LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, USER_INFORMATION2);
+//  LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR);
+
+}
+
+/**
+* @brief  USBD_USR_DeviceReset
+*         Displays the message on LCD on device Reset Event
+* @param  speed : device speed
+* @retval None
+*/
+extern USB_OTG_CORE_HANDLE  USB_OTG_dev;
+extern USBD_DEVICE USR_desc;
+extern USBD_Class_cb_TypeDef  USBD_PRINTER_cb;
+void USBD_USR_DeviceReset(uint8_t speed )
+{
+// switch (speed)
+// {
+//   case USB_OTG_SPEED_HIGH:
+//     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [HS]" );
+//     break;
+
+//  case USB_OTG_SPEED_FULL:
+//     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [FS]" );
+//     break;
+// default:
+//     LCD_LOG_SetFooter ("     USB Device Library v1.1.0 [??]" );
+//
+// }
+
+    USB_OTG_dev.dev.zero_replay_flag =0;
+    memset((uint8_t*)&USB_OTG_dev, 0, sizeof(USB_OTG_dev));
+    USB_OTG_dev.dev.device_status = USB_OTG_DEFAULT;
+
+    USBD_Init(&USB_OTG_dev,
+        #ifdef USE_USB_OTG_HS
+              USB_OTG_HS_CORE_ID,
+        #else
+              USB_OTG_FS_CORE_ID,
+        #endif
+              &USR_desc,
+              &USBD_PRINTER_cb,
+              &USRD_cb);
+
+        USB_OTG_WRITE_REG8(CORE_USB_CLEAR,0x40);
+        USB_OTG_WRITE_REG8(USB_SOFCNT,0);
+		USB_OTG_WRITE_REG8(USB_SOFCNTHI,0);
+
+        USB_OTG_WRITE_REG8(CORE_USB_STATUS,0xFF);
+        USB_OTG_WRITE_REG8(CORE_USB_FIFO_EMPTY,0xFF);
+        USB_OTG_WRITE_REG8(CORE_USB_ADDR,0x00);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(0),0x70);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(1),0xf0);
+        USB_OTG_WRITE_REG8(CORE_USB_INT_MASK(2),0xff);
+//        MyPrintf("usb reset\n");
+}
+
+
+/**
+* @brief  USBD_USR_DeviceConfigured
+*         Displays the message on LCD on device configuration Event
+* @param  None
+* @retval Staus
+*/
+void USBD_USR_DeviceConfigured (void)
+{
+//    printf("> HID Interface started.\n");
+}
+
+
+/**
+* @brief  USBD_USR_DeviceConnected
+*         Displays the message on LCD on device connection Event
+* @param  None
+* @retval Staus
+*/
+void USBD_USR_DeviceConnected (void)
+{
+    MyPrintf("> USB Device Connected.\n");
+}
+
+
+/**
+* @brief  USBD_USR_DeviceDisonnected
+*         Displays the message on LCD on device disconnection Event
+* @param  None
+* @retval Staus
+*/
+void USBD_USR_DeviceDisconnected (void)
+{
+    MyPrintf("> USB Device Disconnected.\n");
+}
+
+/**
+* @brief  USBD_USR_DeviceSuspended
+*         Displays the message on LCD on device suspend Event
+* @param  None
+* @retval None
+*/
+void USBD_USR_DeviceSuspended(void)
+{
+    MyPrintf("\n> USB Device in Suspend Mode.\n");
+    /* Users can do their application actions here for the USB-Reset */
+}
+
+
+/**
+* @brief  USBD_USR_DeviceResumed
+*         Displays the message on LCD on device resume Event
+* @param  None
+* @retval None
+*/
+void USBD_USR_DeviceResumed(void)
+{
+    MyPrintf("\n> USB Device in Idle Mode.\n");
+    /* Users can do their application actions here for the USB-Reset */
+}
+
+/**
+* @}
+*/
+void my_delay_ms(int ms)
+{
+	int delay_num;
+	while(ms-->0)
+	{
+		delay_num=(CPU_MHZ/1000)/8+400;
+		while(delay_num-->0)
+		{
+			__asm__("nop");
+		}
+	}
+}
+/**
+* @}
+*/
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
