cancel
Showing results for 
Search instead for 
Did you mean: 

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

romybompart
Associate II
Posted on February 23, 2014 at 17:22

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 thatVCP_DataTxsends data through an Array calledAPP_Rx_Buffer. This function also has a ''pointer'' calledAPP_Rx_ptr_in which is used to avoidbuffer 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 inVCP_DataRx is filled out by the CDC corelibrary?, If this is true. I just have to detect when USB receives something using an interruption. Am I correct?

#device #usb #cdc #vcp #fs #solved
5 REPLIES 5
chen
Associate II
Posted on February 26, 2014 at 15:24

Hi

''How Does the USB CDC works to send and receive data?''

The USB CDC example is quite mixed up. It uses the same buffer for receiving and sending. That is because the example simply forwards the data to the USART

To send data - just call USBDataTx()

To recieve data - VCP_DataRx() must be implemented. It must take the data from the input parameters and do some with it.

''How can I receive data over the USB interface using the VCP_DataRx function?''

This function will automatically be called when data comes in. It simply need to do something with it.

Read the documentation for the USB OTG about the different layers of the driver to understand how it all works.

It is all to do with the function pointer tables at each layer.

''

Does the Buff argument in VCP_DataRx is filled out by the CDC core library?

''

Yes.

''

If this is true. I just have to detect when USB receives something using an interruption. Am I correct?

''

No. The interrupt is handled by the USB OTG driver and will automatically call VCP_DataRx()

romybompart
Associate II
Posted on March 05, 2014 at 14:51

Hi Sung.Chen_Chung, 

   Thank you very much. I did it. 

Have a good one. 

epataky
Associate II
Posted on May 29, 2014 at 23:30

where is the function USBDataTx()?

 i search the entire workspace it is not there
Posted on May 30, 2014 at 00:58

STM32_USB-Host-Device_Lib_V2.1.0\Project\USB_Device_Examples\VCP\src\usbd_cdc_vcp.c

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);

There's like only 9 files in VCP source directory, and all the salient code is abstracted in the one ***_***_ vcp.c file. USBDataTx() is likely a typo, but given all the other context, and naming used by the OP it's unfortunate you focused so narrowly on it.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vlr
Associate II
Posted on October 19, 2015 at 12:32

Hi romy, i have the

same problem

, i want to

send and receive data

only

via USB

.

Could you

give me

some help?

would you share the

usbd_cdc_interface.c

file

?

I would like to

study it.

Thank you very much for helping

.