Franxois
Posts: 13
Joined: Fri Apr 27, 2012 9:33 am

Turn OFF and ON USB

Thu Feb 07, 2013 5:39 pm

I would like to reset the USB port, just like if we unplug and plug usb device but remotly

I find the command

Code: Select all

echo 1 > /sys/devices/platform/bcm2708_usb/bussuspend 
but it seems to turn off ethernet and USB. I lost the remote control and I'm forced to hard reboot the raspberry.

Code: Select all

echo 1 > /sys/devices/platform/bcm2708_usb/bussuspend ; echo 0 > /sys/devices/platform/bcm2708_usb/bussuspend
don't seem to bring it back.
Would you see something I could try ?

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Turn OFF and ON USB

Thu Feb 07, 2013 6:01 pm

LAN is connected via USB so resetting the USB port would effectively reset any connections associated with it.
As for no coming back up that's probably because losing your ssh session would mean the second command never gets executed.
If you need to reset the USB ports put the commands into a script file (chmod +x to make it executable) and then ./(script filename) to run.

Richard S.

User avatar
rew
Posts: 445
Joined: Fri Aug 26, 2011 3:25 pm

Re: Turn OFF and ON USB

Sun Feb 10, 2013 10:21 am

Richard, if you enter the two commands at once with the semicolon in between, your second command will be executed.

Unplugging the hardware when it is configured will not always be handled
very graceful. Plugging it back in immediately doesn't work too well either. I'd make a script:

Code: Select all

#!/bin/sh
ifdown eth0
sleep 0.1
echo 1 > ...suspend
sleep 1
echo 0 > ...suspend
sleep 2
ifup eth0
Note that I bring down/up the interface before and after. It's something I'd try if it didn't work at first. I'm not sure I spelled things correctly. Try it manually first. (will cost you a reboot once you find the correct ifdown command. :-) )

ssh sessions can stay alive for hours without a link inbetween. IIRC tcpip is required to send a keepalive every 3 hours or so. Many home-routers will drop a connection after something like 15 minutes. Many home-users will not complain about this, so those horrible un-compliant devices continue to be sold. That's why I've set my ssh daemon to send an ssh-keepalive every 5 minutes or so. This will keep my ssh sessions beyond the 15 minute timeout of the router, but it will also cause a tcp timeout and reset after 5 +a few minutes after the link drops.
Check out our raspberry pi addons: https://www.bitwizard.nl/shop/

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: Turn OFF and ON USB

Sun Feb 10, 2013 5:24 pm

What is the difference between a soft reboot and a hard reboot of the pi? this line of attack is of interest to me because my connection over usb to the pi gets dropped for less than a second and then I cannot reestablish the connection without going through lots of hoops including a reboot. generally CTL-ALT-DEL works even when system will not taking commands (have keyboard plugged in but no monitor). But once in a while, it takes a few reboots before things get working again.
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: Turn OFF and ON USB

Sun Feb 10, 2013 7:46 pm

Franxois wrote:

Code: Select all

echo 1 > /sys/devices/platform/bcm2708_usb/bussuspend 

Code: Select all

echo 1 > /sys/devices/platform/bcm2708_usb/bussuspend ; echo 0 > /sys/devices/platform/bcm2708_usb/bussuspend
There seem to be syntax or content errors in your echo commands, wiping out the normal contents of the bussuspend file.

Contents of my bussuspend file (on Arch, assume it is the same for both systems) is the following all on one line (when usb devices working), your echo command would wipe out everything and replace it with a single digit:

Code: Select all

cat /sys/devices/platform/bcm2708_usb/bussuspend
Bus Suspend =  0x1 
I see another file that may be related in problem solving, /sys/devices/platform/bcm2708_usb/busconnected, contents being (when usb device attached):

Code: Select all

Bus Connected = 0x1 
Your echo needs to include the whole line, if you want to change the setting in one of the above files, not just a single digit, enclosed in quotes, but I am clueless about what will actually achieve what you want. I believe the syntax for first echo command you suggested is probably:

Code: Select all

echo "Bus Suspend =  0x1"  > /sys/devices/platform/bcm2708_usb/bussuspend 
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: Turn OFF and ON USB

Sun Feb 10, 2013 10:59 pm

Whoops, I see I made a typo, copying the contents by hand of bussuspend. When USB is NOT in suspension, the line reads:

Bus Suspend = 0x0

Sorry about that. :o(
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

cdaaawg
Posts: 4
Joined: Tue Jan 08, 2013 6:42 am

Re: Turn OFF and ON USB

Mon Feb 11, 2013 2:15 am

I have been experimenting with this technique to see if I can work around some problems I'm having with gphoto2 on alarmpi. I get Permission denied even if I prepend sudo to the echo command.

Code: Select all

sudo echo 1 > /sys/devices/platform/bcm2708_usb/bussuspend
Sudo works on other commands. Enlightenment would be appreciated.

Carl
Last edited by cdaaawg on Sat Mar 16, 2013 2:25 pm, edited 1 time in total.

Franxois
Posts: 13
Joined: Fri Apr 27, 2012 9:33 am

Re: Turn OFF and ON USB

Mon Feb 11, 2013 11:21 am

Hi,

I think I found something.

I think the "Bus suspend = 0x0" is some kind of wrapper which add some text when we try to access to some value.
I used the buspower file and it's seems to work with my issue.

I use the rew's idea and here is a code which reset my GPRS dongle

Code: Select all

#!/bin/sh
ifdown eth0
sleep 0.1

echo 0 > /sys/devices/platform/bcm2708_usb/buspower

sleep 1

echo 1 > /sys/devices/platform/bcm2708_usb/buspower

sleep 2
ifup eth0

cdaaawg
Posts: 4
Joined: Tue Jan 08, 2013 6:42 am

Re: Turn OFF and ON USB

Sat Mar 16, 2013 2:58 pm

cdaaawg wrote:I have been experimenting with this technique to see if I can work around some problems I'm having with gphoto2 on alarmpi. I get Permission denied even if I prepend sudo to the echo command.

Code: Select all

sudo echo 1 > /sys/devices/platform/bcm2708_usb/bussuspend
Sudo works on other commands. Enlightenment would be appreciated.

Carl
The problem with the command is that _sudo_ is only applied to the _echo_ part of the command and not the redirection part (>) which attempts to write to a root-owned file. To write to that file as a normal user:

Code: Select all

sudo sh -c "echo 1 > /sys/devices/platform/bcm2708_usb/bussuspend"

CDenhart
Posts: 3
Joined: Sat Apr 11, 2015 2:21 pm
Location: NRW, Germany

Re: Turn OFF and ON USB

Tue Jun 21, 2016 9:48 pm

The filename for controlling USB power seems to have changed over the years.
I use this sequence successfully:

Code: Select all

service networking stop
sleep 5
echo 0 > /sys/devices/platform/soc/20980000.usb/buspower
sleep 10
echo 1 > /sys/devices/platform/soc/20980000.usb/buspower
sleep 5
service networking start

georgestewart88
Posts: 83
Joined: Fri Apr 15, 2016 6:19 am

Re: Turn OFF and ON USB

Thu Jan 12, 2017 5:34 pm

Hi,

I am trying this on a Pi 3

cannot create /sys/devices/platform/soc/20980000.usb/buspower: Directory nonexistent
cannot create /sys/devices/platform/bcm2708_usb/bussuspend: Directory nonexistent

Has the location changed?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3695
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Turn OFF and ON USB

Thu Jan 12, 2017 5:38 pm

Code: Select all

pi@raspberrypi:~$ ls -d /sys/devices/platform/soc/*.usb
/sys/devices/platform/soc/3f980000.usb
On Pi2 and Pi3 there is more memory, so the I/O space is pushed up to 3fxxxxxx.

georgestewart88
Posts: 83
Joined: Fri Apr 15, 2016 6:19 am

Re: Turn OFF and ON USB

Thu Jan 12, 2017 6:33 pm

I got this to work, but my USB ports tend to get into a very weird state. I thought this would allow me to reset without rebooting. Any thoughts? [Note this command usually works before I get in the weird state]

pi@pigts:/var $ sudo /var/usbreset/hub-ctrl.c/./hub-ctrl -h 1 -P 4 -p 0 ; sleep 3; /var/usbreset/hub-ctrl.c/./hub-ctrl -h 1 -P 4 -p 1
failed to control.
: Connection timed out
failed to control.
: Operation not permitted

PI_newbee
Posts: 182
Joined: Mon Aug 26, 2013 7:41 pm

Re: Turn OFF and ON USB

Fri Feb 10, 2017 10:17 am

HI.
I need to do the same reset thing as the Franxois and PhilE have suggested ( one on RSP2 and pne on RSP3 ),
but i was wondering if there is possibility to reboot just one USB row ? . I know it's very long shot and maybe not possible beacause of the HW design, but...

In one USB row i have 2 web cams and in the other row ( in one port ) is the USB sound card. Web cams are streaming all the time and if something goes wrong, i could have issues. The sound card is making problems and it looks like there is no other way to solve this accept to power it down and up again.

PIN

Return to “Advanced users”