5

I am using a USB 3G stick on a RPI B+ (3.18.7+) to ftp measurements from a sensor platform. To limit RF interference, and save power, I am turning it on and off a lot (which on the B+ is now possible, using the "hub-ctrl" command.

The problem is that, after switching it on and off for some tens of cycles, the device is no longer detected properly when switched on. (for full detail see http://www.raspberrypi.org/forums/viewtopic.php?f=28&t=101005)

Does anybody know if there is some sort or "restart" or "reset" that I can do to get usb to re-initialise and re-enumerate everything on the bus? (usb is not a kernel module on the pi, so loading and unloading is not possible)

Or is there maybe another way to do this switching, not using hub-ctrl (I suspect it is not de-registering the stick before it cuts the power or something)

1

As posted above an OS restart is your best choice for remotely or automatically doing this with no hardware changes; Does a 30 seconds window of downtime cause an issue for your application?

Another possibility would be adding a relay to a USB port and toggling it's +5v with GPIO pins, but that definitely adds complexity and would depend on how comfortable you are with both the programming and the hardware aspects. Also be careful in your selection of a relay or it will consume a substantial amount of power when enabled - there are more possible issues but most of those can be solved by including a small capacitor on the load side of the relay.

I'm sure you can find a pre-made add-on board for the Pi that would let you power-control a USB port (not on the Pi itself), or possibly even one that would provide your 3g functionality with the ability to toggle power built-in.

And I guess a final alternative would be diving deep in the code, patching the Linux kernel, and solving the problem for everyone... I don't suggest this one since I don't even have a clue where to start.

1

I haven't found what causes the USB bus to hang after power cycling it a number of times, but I found a way to reset the situation without having to reboot:

Using the usb_reset command that you can find in /usr/include/usb.h:

int usb_reset(usb_dev_handle *dev);

I reset the entire internal USB hub when the problem occurs. The easiest way is to put this command in the hub-ctrl.c file and recompile it to a different executable (that I called USBreset).

One complication is that, on a raspberry Pi, this will also reset your ethernet connection (tied to the internal USB hub). If you want to keep the link, you should run the command from a script that was started using something like nohup <skript> & (so it doesn't get killed when the tty link fails) and run /etc/init.d/networking restart after resetting the internal USB hub.

0

No, there is no proper way to restart the USB bus. The only way is to unplug it and plug it back in. This is hardware / low level driver issue.

I had similar problems on a normal Ubuntu desktop with other stuff. Sometimes a full system restart was required.

You could try a restart if the USB fails and try again on start. Not ideal, but automated.

  • Plugging and unplugging doesn't help (I think to the bus, it is exactly the same as turning power on and off anyway). What do you mean with 'try a restart'? Try the same USB command again, or restart the USB bus? – bart Feb 23 '15 at 7:30
  • Restart the OS. You cant restart the USB bus, unless you unload the USB driver.. but that doesn't even guarantee that. – Piotr Kula Feb 23 '15 at 11:34
0

Using gpio to toggle the power lines on the USB device seems to be the best solution. Here is what I found on the subject: https://electronics.stackexchange.com/questions/104564/how-to-create-usb-toggle-switch-controled-by-gpio

0

It might be possible if you restart udev, or forcing it to trigger.

Restart / Re-Load Rules

  1. Debian
    • service udev restart
  2. ArchLinux/RHEL
    • udevadm control --reload-rules

Re-Scan / Trigger

  • udevadm trigger

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.