2014-09-24 11:45 PM
Hello!
I'm using the USB CDC class implementation provided by STM32CubeMX 4.3.0 (firmware library v1.3.0). Is it possible to check on the microcontroller if the virtual COM port has been opened? I want to transmit a version string via USB, but this would only be reasonable if the port is opened, otherwise the user will not receive the information. Regards, Thomas #stm32 #cdc #usb #vcp2014-09-25 07:56 AM
Hi
I am not familiar with the Cube implementation, I am still using the old USB OTG driver. I think they are similar (identical all bar naming of variables and functions) Some where in the guts of the driver, it knows if the USB is connected because it goes through a USB connected IRQ. I am affraid you will have to dig around the code to find it.2014-09-26 12:36 AM
If you want to know if the device is configured:
if (pdev->dev_state == USBD_STATE_CONFIGURED) ... If you want to know if you have a CDC device and it is connected, use a global variable inside the HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) procedure. If USBD_LL_DevConnected status is USBD_OK you should change the value of the global variable to 1 (or whatever you prefer). You should write the code to update this global variable into every related procedure (HAL_PCD_DisconnectCallback , HAL_PCD_SuspendCallback, HAL_PCD_ResumeCallback).2014-09-26 01:55 AM
Here is the solution that I tested and it is working fine:
2014-09-26 03:46 AM
Hi Thomas,
When you open the COM port, you get a call to ComPort_Config(). You can use it to get notification for opening COM port.I've tested it with Hercule on Windows7 and it may depend on OS (but it was called twice !).Regards,Heisenberg.2018-05-23 01:11 AM
Sorry for posting to old thread, but for others searching for a solution, this is what I did:
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
{... case CDC_SET_CONTROL_LINE_STATE: { USBD_SetupReqTypedef * req = (USBD_SetupReqTypedef *)pbuf; if(req->wValue &0x0001 != 0) { // DTR is set... } }break;
...}2018-09-26 08:39 PM
That's solve my problem, thanks.