My Notebook

How to fix device permissions for the USBasp programmer

Author
Date
Category
Electronics
USBasp

If you try to use the popular, open-hardware ISP programmer USBasp in Linux as a regular non-privileged user, you get an error message like this:

avrdude: Warning: cannot open USB device: Permission denied
avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor='www.fischl.de' product='USBasp'

Quick and Dirty Fix

The problem is that the device permissions by default only allow root to write to the device. By using the command lsusb you can find out the bus and device id of your USBasp device:

$ lsusb
...
Bus 003 Device 018: ID 16c0:05dc Van Ooijen Technische Informatica shared ID for use with libusb
...
$ ls -al /dev/bus/usb/003/018
crw-rw-r-- 1 root root 189, 273 23. Aug 11:23 /dev/bus/usb/003/018

The quick and dirty solution is to simply change the device permissions by hand. The downside of this is that you have to repeat this procedure every time you reconnect the device.

$ sudo chmod 666 /dev/bus/usb/003/018

Permanent Solution

The more sensible solution is to add a udev rule for the device. A udev rule simply matches certain properties of a device after it is connected and performs certain actions on it, like changing the file permissions.

The firmware package already contains a template for a udev rule in the directory bin/linux-nonroot/99-USBasp.rules and a small script to install it. The installation is trivial, because you just have to copy the 99-USBasp.rules file to /etc/udev/rules.d/.

$ sudo cp 99-USBasp.rules /etc/udev/rules.d/

Customizing the udev rule

The rule from the firmware package just sets the file permissions to 666, which is a bit crude. I wrote my own version of it for Arch Linux. In Arch Linux the group uucp is used for "Serial and USB devices such as modems, handhelds, RS-232/serial ports", so it makes sense to use it for the USBasp device.

# Set Group for USBasp
SUBSYSTEM=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", GROUP="uucp"

You also have to add your user to that group. For this to take effect you have to log out and then log in again.

gpasswd -a youruser uucp

Please note that the group is called uucp only in Arch Linux. Other distributions use a different group for the same thing. Ubuntu for example uses the group dialout.

References