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.

3 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: