How to reset USB port on Jetson

From RidgeRun Developer Wiki

Introduction

There are some situations where the USB port is needed to be reseted. For example, a situation where a program uses a USB camera, exits, and then the video devices at /dev/video# vanishes. By simply unplug and replug the camera can solve the situation, however this is not always posible nor practical, because maybe camera must be always connected or is inaccessible.

This short wiki will show steps for a software alternative to solve this situation.

Identifying the USB device

1- Unplug the device and execute:

sudo dmesg -c

2- Plug the camera and execute:

dmesg

You will get an output similar to the following:

nvidia@nvidia-desktop:~$ dmesg
[25615.034704] tegra-xusb 3530000.xhci: exiting ELPG
[25615.039453] tegra-xusb 3530000.xhci: Firmware timestamp: 2019-07-08 19:32:42 UTC, Version: 55.15 release
[25615.040842] tegra-xusb 3530000.xhci: exiting ELPG done
[25615.265730] usb 1-2: new high-speed USB device number 54 using tegra-xusb
[25615.287292] usb 1-2: New USB device found, idVendor=8086, idProduct=0ad6
[25615.287318] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[25615.287334] usb 1-2: Product: Intel(R) RealSense(TM) Depth Camera 450 
[25615.287348] usb 1-2: Manufacturer: Intel(R) RealSense(TM) Depth Camera 450 
[25615.291047] uvcvideo: Unknown video format 00000050-0000-0010-8000-00aa00389b71
[25615.291089] uvcvideo: Unknown video format 00000032-0000-0010-8000-00aa00389b71
[25615.292074] uvcvideo: Found UVC 1.50 device Intel(R) RealSense(TM) Depth Camera 450  (8086:0ad6)

We have now identified that the camera uses the usb 1-2 device.

Enable bind/unbind options

We want to enable write options to the USB binding mechanism.

1- Run the following command to enable read/write options for the usb bind and unbind files

sudo chmod 666 /sys/bus/usb/drivers/usb/bind /sys/bus/usb/drivers/usb/unbind

2- Verify correct permissions are enabled by running the following command:

ls -lha /sys/bus/usb/drivers/usb/bind /sys/bus/usb/drivers/usb/unbind

You will get an output similar to the following:

nvidia@nvidia-desktop:~$ ls -lha /sys/bus/usb/drivers/usb/bind /sys/bus/usb/drivers/usb/unbind
-rw-rw-rw- 1 root root 4,0K mar 26 16:25 /sys/bus/usb/drivers/usb/bind
-rw-rw-rw- 1 root root 4,0K mar 26 16:25 /sys/bus/usb/drivers/usb/unbind

Reset the device

Once the device is in the condition where it needs to be reset, using the device ID we found on Identifying the USB device run the following commands:

echo "1-2" | sudo tee /sys/bus/usb/drivers/usb/unbind
echo "1-2" | sudo tee /sys/bus/usb/drivers/usb/bind

Device should now be fully operational.