CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

USB CDC it's being detached and reattached itself.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

USB CDC it's being detached and reattached itself.
PostPosted: Fri Jun 16, 2017 12:52 pm     Reply with quote

If the Main program, outside of any interrupt, have a huge delay, like 2 seconds, the USB CDC will be detached and reattached itself, without actually being unplugged?

I'm using USB CDC library on a PIC18f67J50 and initializing USB calling usb_init_cs(); from the Main and have a connection sense pin defined.

Also I periodically call usb_task(); except when a routine that turn on a special device; at that moment I can hear a sound in the PC that indicates that an USB device was unplugged.
Two seconds later the PC play another sound indicating that an USB device was plugged.

I thought that the routine usb_task(); only check the connection sense pin to attach and detach the device properly.

Can be this delay the problem or I should check something more?
_________________
Electric Blue
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jun 16, 2017 1:12 pm     Reply with quote

It 'could' be the PC depending on what OS, what version of OS and which USB drivers you're using..... not to mention what other programs(aps) are active or dormant on the PC.... even an unwanted 'update' in the background can change 'things'...sigh
Unlike the good old days of REAL RS-232... USB can be a bloody nightmare to debug.
I got rid of 99.9944% of them problems by cutting PC code in Delphi.
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Fri Jun 16, 2017 1:27 pm     Reply with quote

Is your USB interrupt driven?.
Is this interrupt enabled?.

If the USB interrupt is being handled, then 'yes' in normal use after enumeration, usb_task only needs to be called to handle a few bits of housekeeping. First the multiple enumeration that can occur particularly on USB3 systems during boot. Then handling overflows in the usb buffers. Then handling the power management events. One thing that can make this last occur, is 'selective suspend'. This might be causing your problem. You need to get to the power management settings and disable this. Otherwise if your code is not directly talking to the usb device, Windows can decide to set it to idle. The recovery from this is handled by usb_task if it happens.

<https://www.tenforums.com/tutorials/73187-turn-off-usb-selective-suspend-windows-10-a.html>

How quickly this triggers depends on the machine and drivers, but can be only a few mSec on current versions of Windows. Basically as soon as the port is deemed 'idle'.
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Fri Jun 16, 2017 1:58 pm     Reply with quote

Yes, the USB interrupt driven, that's why I'm amazed about the fact that the PC is detaching my device.
The USB interrupt is being activated not by my code but by USB CDC library.

I'm using Windows 7 x64 and the other PC's mostly are Windows 7 x32.

I tried disabling selective suspend but nothing seems to change in the behavior, anyway, thanks for the tip.
_________________
Electric Blue
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jun 16, 2017 3:46 pm     Reply with quote

There was a similar 'thread' some months ago and it appears there are 4 or 5 (maybe more...) programs that have some control over USB in a PC. EACh and every one has to be looked at and properly configured AND somehow 'locked' to NOT be altered by anyone or any program from then on. PITA programming at it's finest...

Maybe search the forum ? (USB shutting down or similar keywords...)

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group