Linux tip: How to reset device connected to USB port


Sometimes devices connected to USB ports need to be re-set. It’s not unusual GSM modems and WiFi dongles to freeze and the only way to bring them back to life is to remove and re-attach.

OLinuXino USB ports has power switches and current limiters which can be controller by Linux drivers.

After some experimenting we found that it’s not so easy actually to do it with the standard file system and shell.

A friend suggested to try this code. It worked very well, so here is how to use it. First you need to download and compile it, then to make it executable:

$ mkdir usbreset
$ cd usbreset
$ wget $ https://raw.githubusercontent.com/jkulesza/usbreset/master/usbreset.c
$ cc usbreset.c -o usbreset
$ chmod +x usbreset

Then you need to see where your USB device is. In our case I connected MOD-WIFI-R5370 WiFi USB dongle:

$ lsusb

you will see something like:

Bus 002 Device 039: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter

to reset this device use the command:

./usbreset /dev/bus/usb/002/039

The device USB port will be power off for a second then power on again.

All above is tested and work with official Olimex Linux images from images.olimex.com, but should work on other Linux distributions too.

7 Comments (+add yours?)

  1. andrea
    Jul 20, 2020 @ 10:22:05

    interesting tool. tried it..

    just a comment to say there’s a small typo in your usage example!

    you should just type as parameter, the bus/num of the target device, in the example above:

    $ ./usbreset 002/039

    i’ve got it as i run the utility without param and it told me so!

    bests

    PS it worked too, on my Debian buster running on laptop x86-64

    Reply

  2. frant0ny
    Jul 26, 2020 @ 21:19:45

    The uhubctl utility can be used for resetting USB devices connected to smart USB hub port by turning port power off and on. Please see https://github.com/mvp/uhubctl for details.

    Reply

  3. Trackback: ● NEWS ● #olimex #OpenHardware ☞ #Linux tip: How to reset device co… | Dr. Roy Schestowitz (罗伊)
  4. MIKE STAN
    Sep 02, 2020 @ 08:27:19

    The uhubctl utility can be used for resetting USB devices connected to smart USB hub port by turning port power off and on.

    Reply

  5. PvdB
    Jun 06, 2021 @ 12:44:17

    Very nice, easy way to solve my problem with hanging RFXcom interface.

    Reply

  6. Trackback: 用命令行远程重置USB设备 – My life's Work

Leave a comment