How to tell if a terminal program is listening to a CDC device?
I am using STM32Cube_FW_F7_V1.15.0 with a STM32F723IET6 implementing the internal HS USB as device. I have implemented the CDC VCP device. I plug the USB cable into a host computer, running either Windows or linux. If I am running a terminal program on the host computer, I am able to send characters to the host. If I am not running any receiver on the host (but still plugged in), if I try to send characters to the host, CDC_Transmit_HS() returns USBD_BUSY. Since I need to check for this case when the connection is up and I am sending characters normally, my program hangs on this condition if there is no listener running on the host.
What I really need is to detect the condition of whether the host has opened the device, so I can buffer my data until the device is opened on the host. In testing with a Windows 10 host, I found that hUsbDeviceHS.dev_state == USBD_STATE_CONFIGURED is true after the device is configured, whether or not the connection is there. I also found that hUsbDeviceHS.ep0_state == USBD_EP0_IDLE on startup even if the connection is not there, and it does not change if the connection is established, but if the connection is then stopped, ep0_state changes to USBD_EP0_STATUS_IN. It goes back to USBD_EP0_IDLE when a new connection is opened. So after the first connection, I can use ep0_state to test if the connection is opened. This is nearly what I want, but the behavior is different when the host is linux. In that case, I cannot use ep0_state to determine if the connection is open.
I also looked at hUsbDeviceHS.dev_connection_status, but this is always 0. There doesn't seem to be any code to set it to another value. It would be great if I can add a bit of code to make this report the connection status.
I need a reliable way to determine this condition. I could not find any documentation indicating how to do this. Any help would be greatly appreciated!
