cancel
Showing results for 
Search instead for 
Did you mean: 

How to know when VCP is connected to a program on a PC.

Stephen28
Associate III

I have been researching for the past 2 days and still have not found a solution. Here is the problem:

I have a custom self powered STM32F7 board that should stream data over the VCP when a terminal program is connected. I generated the HAL code using STM32CubeMX for CDC communication, and I am using TeraTerm on a PC. I start the STM32 program with TeraTerm off and USB unplugged. If USB_Transmit_HS is not commented out, the program crashes when I plug in the USB, otherwise the USB enumerates and shows up as a COM port that TeraTerm can open. Typing characters into TeraTerm generates USB events on the STM32 program, so we know the PC has made the connection.

So, with USB_Transmit_HS commented out, when I plug in the USB I see calls to CDC_Init_HS, CDC_GET_LINE_CODING, CDC_SET_CONTROL_LINE_STATE, and another to CDC_GET_LINE_CODING. When I turn on TeraTerm and open the COM port, I see 3 calls to CDC_GET_LINE_CODING. When I close TeraTerm, I get two calls to CDC_SET_CONTROL_LINE_STATE, and when I unplug the USB I get a call to CDC_DeInit_HS.

All of the CDC_GET_LINE_CODING are requesting 7 bytes of data, which decode to 115200,8,N,1. All of the CDC_SET_CONTROL_LINE_STATE have 0 bytes of data. When we look at Jan Axelson's book "USB Complete" we find the statement "In the SET_CONTROL_LINE_STATE request (22h), the host tells the device how to set the RS-232 control signals RTS and DTR. The host sends the control-line states in the third byte of the Setup transaction. Bit 0 is the state of DTR, and bit 1 is the state of RTS. Device firmware detects the request, accepts the data, and implements any changes to the bits." But there are no bytes transferred into the driver to test for DTR or RTS. I have followed the data chain down into the ISR.

I have found other references in the forum and others on ways to fix this, and none of those have worked for me.

How can I know that it is safe to start streaming data out the CDC when the COM port has finally been opened?

1 REPLY 1
T J
Lead

I am only new to using USB :(

but it worked almost immediately for me...

           CDCReturn = CDC_Transmit_FS(&Buf, length);

I thought that the return value gives you the transfer successful status.