cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC state detection

developer2
Senior
Posted on October 04, 2013 at 17:53

Hi All,

i'm using STM32F407 in USB CDC mode,

i'm having issue when i'm sending bytes from STM to PC,

client application on PC is minicom,

issue is when i close minicom and STM runs into ''frozen'' state until i open minicom again, and after opening minicom everything continues in normal running state,

is there a way how to detect that client application is closed ? so i will stop sending bytes to PC,

i found that STM got Ctrl call with Cmd 0x22 when i close minicom and same code 0x22 when i open minicom :(

Thanks for all replies,

Kind regards,

4 REPLIES 4
jaimadafaca
Associate II
Posted on February 09, 2015 at 13:28

Hi all,

I have the same question. I'm interested to detect ''connection'' and ''unconection'' from virtual COM from Hyperterminal o similar...

If anyone could help us.... I'd be pleased.

Thank you in advance,

Best regards.

Jai.

jaimadafaca
Associate II
Posted on February 23, 2015 at 10:39

anyone could give me a hand about this issue?

I need to detect when host PC open and close an hyperterminal (o similar) the virtual COM.

Thanks in advance!

Best regards.

jmorris
Associate II
Posted on February 26, 2015 at 10:20

There is probably a better way by hacking the lower layers, but I was able to do this using a simple state machine in theTEMPLATE_Control callback in usbd_cdc_if_template.c file...

Set host_connected_cnt to 0 in theTEMPLATE_INIT() function then...

case
CDC_SET_CONTROL_LINE_STATE:
// get this on connect and disconnect no way to distinguish
// also get it on intial setup and cable connect disconnect
host_connected_cnt++;
host_connected= (host_connected_cnt&1) == 0;
if
(host_connected) dispatch(
''\030connected''
, 10);
break
;

This seems to work even when you connect/disconnect the cable then connect the terminal to the CDC.
jeantil88
Associate II
Posted on March 13, 2015 at 14:30

Hello,

could you please explain what exactly do the function
dispatch(
''\030connected''
, 10);
I have the problem when I close the COM port from PC app. The app return exception: device is in invalid state. Afterward the USB device has to be restarted in order to be able to communicate. Can anyone please help me with this issue? Thanks in advance. Tony