AnsweredAssumed Answered

USB OTG FS, DEVICE MODE AS A VCP. Receive data Issue.

Question asked by bompart.romy on Feb 23, 2014
Latest reply on Oct 19, 2015 by ragazzi.valerio
Hi Guys, 

      I would like understand the procedure that the USB CDC does when it is going to receive data over the USB interface ( If you can explain me, would be great).  

       I could see that VCP_DataTx sends data through an Array called APP_Rx_Buffer. This function also has a "pointer" called APP_Rx_ptr_in which is used to avoid buffer overflow. But at the end, I quite don't understand. How Does the USB CDC works to send and receive data?

       Therefore,  How can I receive data over the USB interface using the VCP_DataRx function?, I don't wanna use usart interfaces. 

       This is the function that sends data over the usb. Works Fine.
uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len)
{
    uint32_t tx_counter = 0;
     
    while(tx_counter < Len){
        APP_Rx_Buffer[APP_Rx_ptr_in] = *(Buf+tx_counter);
         
        APP_Rx_ptr_in++;
         
        /* To avoid buffer overflow */
        if(APP_Rx_ptr_in == APP_RX_DATA_SIZE)
        {
            APP_Rx_ptr_in = 0;
        }
         
        tx_counter++;
    }
  return USBD_OK;
}

This is the function that Receive, but uses the Usart. I would like to receive over the USB as well.
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
{
  uint32_t i;
   
  for (i = 0; i < Len; i++)
  {
    USART_SendData(EVAL_COM1, *(Buf + i) );
    while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TXE) == RESET);
  }
  
  return USBD_OK;
}


I was wondering, Does the Buff argument in VCP_DataRx is filled out by the CDC core library?, If this is true. I just have to detect when USB receives something using an interruption. Am I correct? 

Outcomes