2014-02-23 08:22 AM
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 #solved2014-02-26 06:24 AM
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()2014-03-05 05:51 AM
Hi Sung.Chen_Chung,
Thank you very much. I did it. Have a good one.2014-05-29 02:30 PM
where is the function USBDataTx()?
i search the entire workspace it is not there2014-05-29 03:58 PM
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.
2015-10-19 03:32 AM
Hi romy, i have the
same problem
, i want tosend and receive data
only
via USB
.Could you
give me
some help?
would you share theusbd_cdc_interface.c
file
?
I would like to
study it.
Thank you very much for helping
.