Send data through USB as a virtual COM

Showing results for 
Search instead for 
Did you mean: 

Send data through USB as a virtual COM

Contributor I

Hi all!

I am trying to include a virtual COM through an USB in KEIL uVision5 with the API and functions that KEIL provides. 

I have been improving my code, and now I am at the point to be able to receive characters from the host (PC). My problem now is that I don't understand how the function "USBD_CDCn_ACM_SendData" works.

My purpose is to include the function "USBD_CDC_ACM_WriteData" inside "SendData" function. I know that WriteData is an asynchronous function, but it never interrupts the program.

My code is:

// Called when when all data was sent.
void USBD_CDC0_ACM_SendData (int32_t len) {
  // Add code for handling new data send
	int32_t cnt;
	cnt = USBD_CDC_ACM_WriteData(0, mantTxBuf, len);
	if(cnt<0) {}

 where "mantTxBuf" is my pointer to the transmitter buffer. I am sharing the same buffer with UART and USB, because my intention is that when I use the USB, the UART will be disable and viceversa. I am secure that there are data ready to be sent on my buffer, but this function never interrupts.

I have tried to implement the "WriteData" function inside the function "USBD_CDC0_ACM_DataSent" ( but it neither interrupts.

I have the following questions about it:

   1. How "USBD_CDCn_ACM_SendData" works?

   2. Should I implement the asynchronous function to send data ("USBD_CDC_ACM_WriteData") as a independent function?

   3. Is there another strategy to send data when I have characters in my Tx buff ("mantTxBuff")??


Thank you very much!


0 Kudos
0 Replies