Question
USB OTG FS, DEVICE MODE AS A VCP. Receive data Issue.
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