Page 1 of 1

USB power cycling problem

Posted: Fri Feb 20, 2015 8:56 am
by vthielen
I am having a problem with cycling USB bus power on the RPI B+ (3.18.7+).
I also posted this problem here (http://www.raspberrypi.org/forums/viewt ... 4&t=100562) before I knew exactly what it was, but below is what it comes down to:

Each time I power the USB bus off and on, a device plugged into it gets a higher Device number, and eventually the bus crashes (does not enumerate new devices any more)

As a demonstration, I wrote the python script at the bottom, which just turns the bus on and off and runs lsusb in an infinite loop.
I had trouble with a USB GSM modem, but even when I plug a simple TI launchpad (MSP430 experimenter board) in the bus, it will disappear after some cycles.

I have the impression that the USB controller or software thinks there are 82 devices on the bus, which is probably why it crashes.
Is there a way to completely reset the USB bus software/hardware so it will start counting from zero again?
Another solution would be a command that removes the device from the bus before I turn it off, so it would probably get the same Device number when it is switched on again.
I have tried without success:
- Increasing the sleep times in the script
- Running "/etc/init.d/udev restart"
- turning the entire hub off and on with "hub-ctrl -h 0 -p 0/1"
- “echo '1-1' | tee /sys/bus/usb/drivers/usb/unbind” (and re-bind afterwards)


The output of the python script when it starts to fail (after about 80 cycles) is:

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 081: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 082: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


the script itself is:

#!/usr/bin/python
from subprocess import call
import time

while True:
call(["hub-ctrl", "-h", "0", "-P", "2", "-p", "0"]) # turn off the USB modem
time.sleep(1)
call(["hub-ctrl", "-h", "0", "-P", "2", "-p", "1"]) # turn off the USB modem
time.sleep(2)
call(["lsusb"]) # print


When it (the modem) fails, I get the 4 lines below in the /var/log/messages file after unplugging and re plugging the device ONCE:
Feb 19 15:32:43 aardbei kernel: [ 8195.531922] usb 1-1.5: new full-speed USB device number 82 using dwc_otg
Feb 19 15:32:43 aardbei kernel: [ 8195.991933] usb 1-1.5: new full-speed USB device number 83 using dwc_otg
Feb 19 15:32:43 aardbei kernel: [ 8196.451884] usb 1-1.5: new full-speed USB device number 84 using dwc_otg
Feb 19 15:32:44 aardbei kernel: [ 8196.951966] usb 1-1.5: new full-speed USB device number 85 using dwc_otg

Re: USB power cycling problem

Posted: Sat Oct 10, 2015 11:11 am
by David Hedditch
I have a similar(ish) problem with my USB modem in my B+. I am running Raspbian and trying to power off the USB port.
I tried using this (https://github.com/codazoda/hub-ctrl.c), but it is written for Ubuntu. I tried it anyway and it just crashes whatever i've got plugged into the usb ports.

I have 2 questions:
1. If I do a "sudo reboot", will that power cycle my USB modem?
2. Is there a way to power cycle my modem when i'm running Raspbian?