AVR MKII pitfalls

Since I did not find a good summary I just wanted to share my experience connecting an AVR MKII to the arduino (using Ubuntu Linux). Maybe it is helpful for others.

Here comes the list of issues:

  1. I did not know that the MKII does not provide power to the board (should have read the manual...). Unless both LEDs are green the target has no power.

  2. Since I always used the booloader in usermode I did not figure immediately that I need to root in order to connect to the Arduino with Avrdude

  3. There may be more than one avrdude.conf file. In my setup there is one in /etc/ and one in /home/udo/Desktop/electronics/arduino-0016/hardware/tools. The first one was newer but did not contain the m328p entries. The second one is older but does contain them. So I copied the file included with arduino and overwote the file in /etc/. Could have been done differently for sure, but who cares.

  4. The first successful commandline setup was then:
    sudo avrdude -t -p m328p -P usb -c avrispmkII

Finally success :slight_smile:

Is there any means to achieve the same without executing avrdude as root?

Hi Udo,

  1. Since I always used the booloader in usermode I did not figure immediately that I need to root in order to connect to the Arduino with Avrdude

Is there any means to achieve the same without executing avrdude as root?

Yes, there is. The problem is that most USB- devices managed by Linux are initially setup to allow read and write operation only for root. But this can be changed by suppling a special file to the udev-daemon that changes the permissions for specific devices.

The location where the udev-rules files are expected is usually (Ubuntu/OpenSuse the others I'm not sure) at
/etc/udev/rules.d/

What you have to do is to create a new File with the content

#Set permissions for the AVRIspMKII programmer granting read- and write-access for every user
ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2104", MODE="0666"

and copy it as root (last time I swear) to
/etc/udev/rules.d/avrispmk2.rules

Next time you plug in you programmer you should be able to upload as any user.

If you need some background info on udev
http://www.reactivated.net/writing_udev_rules.html

here is another udev-teaser: this file on my system arduino.rules

 #Set permissions and a link for my arduino boards
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="10101010", SYMLINK+="arduino.LedControl"
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="12345678", SYMLINK+="arduino.BitLash"

creates a special link for my boards so I can talk to them using port
/dev/arduino.BitLash and /dev/arduino.LedControl

Eberhard

Great. This is really helpful advice. After figuring out that udevinfo should be called udevadm I even understand how to get hold of the attributes :slight_smile:

It gave me

  looking at parent device '/devices/pci0000:00/0000:00:1d.2/usb4/4-1':
    KERNELS=="4-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="a0"
    ATTRS{bMaxPower}==" 90mA"
    ATTRS{urbnum}=="26"
    ATTRS{idVendor}=="0403"
    ATTRS{idProduct}=="6001"
    ATTRS{bcdDevice}=="0600"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="8"
    ATTRS{speed}=="12"
    ATTRS{busnum}=="4"
    ATTRS{devnum}=="2"
    ATTRS{version}==" 2.00"
    ATTRS{maxchild}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="FTDI"
    ATTRS{product}=="FT232R USB UART"
    ATTRS{serial}=="A7004mNS"

Hence

ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A7004mNS", SYMLINK+="freeduino.1"

should give me a stable link to freeduino #1 right? That is you solved my issue how to enforce the proper order of the controllers.

Thank you very much!

ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A7004mNS", SYMLINK+="freeduino.1"

should give me a stable link to freeduino #1 right?

Yes should work. Stabel in the sense of: The link to this specific board is created when you plug the board in and deleted when you unplug it.
This is not diffrent from the standard device-files /dev/ttyUSB0 which are also created dynamically.

I only had a slight problem with on of my arduino boards, on which the serial number contained a char-value of '\0'. The rule didn't work then looks like it it was designed to work only with printable chars.

I had to change the serial-number of the board (or better the serial of the USB2Serial chip) with the MProg-tool which is now the FTProg-tool at
http://www.ftdichip.com/Resources/Utilities.htm#FT_Prog
Thats why my boards use such nice serials like "12345678" and "10101010"

Eberhard

Way cool. I have to try this immediately after my vacation :slight_smile:

Is there any means to achieve the same without executing avrdude as root?

I see that you got the help needed. Just thought I would tell you and other readers that I had the same problem, and wrote about how I solved it at http://jarduino.com/2009/06/avrisp-mkii-permission-problems-with-avrdude-and-ubuntu-9-04-amd64/ with an improved version at http://jarduino.com/2009/07/improved-udev-rules-for-mcu-programmers-and-usb-serial-adapters/

I had some trouble along the way, and made some mistakes, and want to share them so that others do not have to repeat my mistakes.

For any Atmel AVRISP MkII the following line should work (and make a symlink):

ATTR{idVendor}=="03eb", ATTR{idProduct}=="2104", MODE="0660", GROUP="plugdev", SYMLINK+="avrispmkII-%n"

For Atmel AVR Dragon and Microchip PICkit 2 the following lines should work:

ATTR{idVendor}=="03eb", ATTR{idProduct}=="2107", MODE="0660", GROUP="plugdev", SYMLINK+="avrdragon-%n"
ATTR{idVendor}=="04d8", ATTR{idProduct}=="0033", MODE="0660", GROUP="plugdev", SYMLINK+="pickit2-%n"

Make sure that you are a member of the plugdev group, though.

Edit: About avrdude control files: I created a .avrduderc file in my home directory, setting my default programmer and adding the 328p definition (from Arduino's avrdude file). First lines of this file:

#
# Johan Adler 090702
#
# Choose default programmer, add support for ATmega328p
#

default_programmer = "avrispmkII";


#------------------------------------------------------------
# ATmega328
#------------------------------------------------------------

part
    id              = "m328p";
    desc            = "ATMEGA328P";

By now I have somewhat mixed success and I am somewhat confused.

I have added two files:

udo@laptop:/etc/udev/rules.d$ cat 30-programmer.rules 

#Set permissions for the AVRIspMKII programmer granting read- and write-access for every user
ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2104", MODE="0666", SYMLINK+="avrispmkII-%n"

udo@laptop:/etc/udev/rules.d$ cat 38-usb-serial-adapters.rules
 
# add symlink for prolific serial adapters to show up with serial number
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="ttyUSB-$attr{serial}"

The usb serial adapters file works as expected:

udo@laptop:/dev$ ls -l ttyUSB*
crw-rw---- 1 root dialout 188, 0 2009-10-20 21:18 ttyUSB0
lrwxrwxrwx 1 root root         7 2009-10-20 21:18 ttyUSB-A7004mO1 -> ttyUSB0

So this works and I think I understand why.

But the other one does not at all work as expected:

udo@laptop:/dev$ ls -l avr* usbdev2.4*
lrwxrwxrwx 1 root root      14 2009-10-20 21:23 avrispmkII-00 -> usbdev2.4_ep00
lrwxrwxrwx 1 root root      14 2009-10-20 21:25 avrispmkII-02 -> usbdev2.4_ep02
lrwxrwxrwx 1 root root      15 2009-10-20 21:23 avrispmkII-2 -> bus/usb/002/004
lrwxrwxrwx 1 root root      14 2009-10-20 21:25 avrispmkII-82 -> usbdev2.4_ep82
crw-rw-rw- 1 root root 252, 14 2009-10-20 21:23 usbdev2.4_ep00
crw-rw-rw- 1 root root 252, 13 2009-10-20 21:25 usbdev2.4_ep02
crw-rw-rw- 1 root root 252, 12 2009-10-20 21:25 usbdev2.4_ep82

There are actually 2 issues here:

  1. It creates 4 symlinks for one programmer and I do not understand why
  2. I still need to run avrdude as root and I do not understand why. The error it gives is:
udo@laptop:/etc/udev/rules.d$  avrdude -t -p m328p -P usb -c avrispmkII
avrdude: usb_open(): cannot read serial number "error sending control message: Operation not permitted"
avrdude: usb_open(): cannot read product name "error sending control message: Operation not permitted"
avrdude: usbdev_open(): error setting configuration 1: could not set config 1: Operation not permitted
avrdude: usbdev_open(): did not find any USB device "usb"

Once I add sudo it immediately works. So the rule does not fix my initial problem. Do you have any hints why (1) and (2) happen and how to fix them?

Udo: About the permissions that you set in your 30-programmer.rules file, you are doing it quite right but you left out one thing. As you can see in the output of ls -l avr* usbdev2.4* the owner and group of your AVRisp MkII is still root. To solve this part of the problem just add GROUP="plugdev" to your rule, and make sure that you are a member of this group.

The reason that I did not get multiple symlinks might be that I have other commands in my rules file too, as you can see in my original description of my solution. The complete rules file I use is available here. It looks as if the omission of SUBSYSTEM=="usb" will give you one symlink for each USB endpoint.

If you are using one programmer and have no need for other rules in the same file I guess that both your problems can be solved by changing your rule to:

SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2104", MODE="0660", GROUP="plugdev", SYMLINK+="avrispmkII-%n"

Reducing my version to just the AVRisp MkII would give this file:

SUBSYSTEM!="usb", GOTO="mcu-prog_rules_end"
SYSFS{idVendor}=="03eb", SYSFS{idProduct}=="2104", MODE="0660", GROUP="plugdev", SYMLINK+="avrispmkII-%n"
LABEL="mcu-prog_rules_end"

As for your serial adapters rule, it looks great but the vendor and product ID that you use are for FTDI, not Prolific as your comment states.

Edit: If you wish, you could of course make the FTDI symlink more readable by changing the symlink to an actual name:

ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A7004mNS", SYMLINK+="ttyUSB-freeduino.1"

Hi,
the Symlinks issue
In old Unix tradition udev creates a file in the /dev directory for every USB-interface on a USB-device. The AVRIspMKII has 3 Interfaces, which produces 3 Links one for each interface.

Do you really need the Symlinks at all?
If youre happy with AVRDude you don't need to create any symbolic link to the device-files because it uses libusb to talk to the programmer.
If you want to write your own app for the programmer, you should also use libusb .

So if there is not some exotic reason for it you can remove the symbolic link section from the rule.

Still need to be root
This could be caused by a wrong advice on writing udev rules.
I had this problem when updating to Ubuntu 8.10 :
The README for udev says

Files should be named xx-descriptive-name.rules, the xx should be
chosen first according to the following sequence points:

< 60 most user rules; if you want to prevent an assignment being
overriden by default rules, use the := operator.

these cannot access persistent information such as that from
vol_id

< 70 rules that run helpers such as vol_id to populate the udev db

< 90 rules that run other programs (often using information in the
udev db)

=90 rules that should run last

but I had to learn the hard way that seems not to be true any more for more recent version of udev (and by that newer Linux-distributions in general).

There is a rule that resets the ownership for all usb-devices which is applied very late in the sequence (I think its it starts with 60-).
Since you rule is evaluated quite early (30-
) the MODE-arg is overwritten by the later rule.

The offical version from the udev-team is you should not use any rule-files with numbers any more.

When I complained that the README says the opposite the udev-people blamed the Ubuntu-Team for not updating the File, and the Ubuntu-Team blamed the udev-team fro not telling them about the new policiy >:(

Try to rename you rule "30-programmer.rules" to "programmer.rules" so it is applied later in the sequence. This worked for me.

If not, what flavor of Linux are you on?
Eberhard

wayoda: The symlink may be from my earlier post, I used it mainly for debugging, to make it easier to find the programmer and check permissions on it, but it does no harm so I have left it like that.

As I wrote this morning the modified version of my rule that Udo used causes udev to create one symlink for each USB endpoint in addition to one for the device. The rule (with symlink) that I use, on Ubuntu 9.04, will create one and only one symlink on my system, as far as I have seen.

In my post earlier today I also explained the problem Udo had with permissions, which is obvious from the ls-listing he was kind enough to include. My rules have numbers in the 30:s and I still get the permissions I intend, want and need. It works fine for me (still Ubuntu 9.04, though I might add that it is the 64 bit version).

What distro do you use? What rules are resetting your permissions? Is it anything that you have installed? As you may have read on my blog that I linked to earlier I had problems with Virtualbox claiming ownership of all USB devices, in a rulefile numbered 00, executed as the very first rule.

Udo: On a second look at your post I notice that your original generic ttyUSB0 belongs to the dialout group, that you are most likely a member of, but you do not set the group of your symlink, so I am not quite sure if it will be accessible for you. Is it?

Hi Johan ,
Your 30-programmer.rules file creates 4 symlinks on my KUbuntu 9.04 32-bit machine.
Also you it does not set the permissions right (I think they are reset in file "/lib/udev/rules.d/50-udev-default.rules" )
Running avrdude shows exactly the same error that Udo quoted.

Renaming the file from "30-programmer.rules" to "programmer.rules" resolved the issue. (No need to run avrdude with sudo)

My udev-version is 141.

Eberhard

wayoda: Interesting, I will have to check that when I get home. I know that my installation of Virtualbox has done things to the udev rules, but I am not aware of it actually changing any default rules.

The rules I suggested are straight from my box, where it works just as intended.

If you use unnumbered rules, how is the execution order determined?

Edit: Does you 50-default rules also reset the group membership, or could that be why my rules work for me? Maybe it is not the permissions per se, but the group, since I change it to a group that I am a member of?

The rules I suggested are straight from my box, where it works just as intended.
If you use unnumbered rules, how is the execution order determined?

Udev sorts the files in ascii-order by their names, so rules starting with any kind of digit are evaluated first. The it goes on by the lexical order of the files. So any rules not starting with a digit will be evaluated after all distribution-supplied rules.

Does you 50-default rules also reset the group membership, or could that be why my rules work for me? Maybe it is not the permissions per se, but the group, since I change it to a group that I am a member of?

Sounds reasonable. Since I'm the only user my machine I don't need an extra users-group for my USB-hardware.

Eberhard

Now I renamed my rules to not start with numbers --> without changing any rule content avrispmkii works as desired.

Then I removed the symlink part of the avrisp rule --> it does not show up anymore at all.

In addition I changed the comment as suggested to FTDI and added the missing prolific entry.

/etc/udev/rules.d# cat programmer.rules 

#Set permissions for the AVRIspMKII programmer granting read- and write-access for every user
ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2104", MODE="0666"


/etc/udev/rules.d# cat usb-serial-adapters.rules 
# add symlink for prolific serial adapters to show up with serial number
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="ttyUSB-$attr{serial}"

# add symlink for FTDI serial adapters to show up with serial number
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="ttyArduino-$attr{serial}"

/etc/udev/rules.d# ls -l /dev/ttyUSB* /dev/ttyArduino*
lrwxrwxrwx 1 root root         7 2009-10-21 17:20 /dev/ttyArduino-A7004mO1 -> ttyUSB0
lrwxrwxrwx 1 root root         7 2009-10-21 17:25 /dev/ttyUSB- -> ttyUSB1
crw-rw---- 1 root dialout 188, 0 2009-10-21 17:20 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1 2009-10-21 17:25 /dev/ttyUSB1

So now it works almost as desired: the mkii works for non root users, the arduino / freeduinos show up with serial numbers. The only thing that is still bugging me is why the ttyUSB shows an empty serial numbers. I will investigate this with udevadm and will report what I find out.

With regard to the question what I am using: I use Ubuntu 9.04.

Now I renamed my rules to not start with numbers --> without changing any rule content avrispmkii works as desired.

Then I removed the symlink part of the avrisp rule --> it does not show up anymore at all.

In addition I changed the comment as suggested to FTDI and added the missing prolific entry.

/etc/udev/rules.d# cat programmer.rules 

#Set permissions for the AVRIspMKII programmer granting read- and write-access for every user
ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2104", MODE="0666"


/etc/udev/rules.d# cat usb-serial-adapters.rules 
# add symlink for prolific serial adapters to show up with serial number
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="ttyUSB-$attr{serial}"

# add symlink for FTDI serial adapters to show up with serial number
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="ttyArduino-$attr{serial}"

/etc/udev/rules.d# ls -l /dev/ttyUSB* /dev/ttyArduino*
lrwxrwxrwx 1 root root         7 2009-10-21 17:20 /dev/ttyArduino-A7004mO1 -> ttyUSB0
lrwxrwxrwx 1 root root         7 2009-10-21 17:25 /dev/ttyUSB- -> ttyUSB1
crw-rw---- 1 root dialout 188, 0 2009-10-21 17:20 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1 2009-10-21 17:25 /dev/ttyUSB1

So now it works almost as desired: the mkii works for non root users, the arduino / freeduinos show up with serial numbers. The only thing that is still bugging me is why the ttyUSB shows an empty serial numbers. I will investigate this with udevadm and will report what I find out.

With regard to the question what I am using: I use Ubuntu 9.04.

Hi,

The only thing that is still bugging me is why the ttyUSB shows an empty serial numbers.

There is a good chance the serial number is not set for the prolific device.
The tool to use for these issues is "lsusb"

sudo lsusb -vvv -d 067b:2303

will list all USB-property settings for the prolific adapters. There should be an iSerial-entry but it should be empty, don't really know what it will look like then.

Compare to the listing for your FTDI-arduino

sudo lsusb -vvv -d 0403:6001

But since you are running Ubuntu 9.04 it is even easier: You also find your serial devices in /dev/serial/by-id

ls -all /dev/serial/by-id/
insgesamt 0
drwxr-xr-x 2 root root 80 2009-10-21 17:49 .
drwxr-xr-x 4 root root 80 2009-10-21 17:43 ..
lrwxrwxrwx 1 root root 13 2009-10-21 17:43 usb-FTDI_FT232R_USB_UART_12345678-if00-port0 -> ../../ttyUSB0
lrwxrwxrwx 1 root root 13 2009-10-21 17:49 usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_XMEGA-A1-USB-if00-port0 -> ../../ttyUSB1

This is the listing when I have an Arduino and an XMega board plugged in.
The naming scheme is : usb----

So this a pretty unique devicename you get for free (no custom udev-rule necessary). But beware this seems tpo be Ubuntu specific. Not availabale on OpenSuse for instance.

Eberhard

Ok, I got

/etc/udev/rules.d# lsusb -vvv -d 067b:2303

Bus 004 Device 009: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x067b Prolific Technology, Inc.
  idProduct          0x2303 PL2303 Serial Port
  bcdDevice            3.00
  iManufacturer           1 Prolific Technology Inc.
  iProduct                2 USB-Serial Controller
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           39
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x000a  1x 10 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0000
  (Bus Powered)



/etc/udev/rules.d# udevadm info --attribute-walk --name=/dev/ttyUSB1
 
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:1d.2/usb4/4-1/4-1:1.0/ttyUSB1/tty/ttyUSB1':
    KERNEL=="ttyUSB1"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:1d.2/usb4/4-1/4-1:1.0/ttyUSB1':
    KERNELS=="ttyUSB1"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="pl2303"
    ATTRS{port_number}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:1d.2/usb4/4-1/4-1:1.0':
    KERNELS=="4-1:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="pl2303"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bNumEndpoints}=="03"
    ATTRS{bInterfaceClass}=="ff"
    ATTRS{bInterfaceSubClass}=="00"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{modalias}=="usb:v067Bp2303d0300dc00dsc00dp00icFFisc00ip00"
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1d.2/usb4/4-1':
    KERNELS=="4-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="80"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{urbnum}=="20"
    ATTRS{idVendor}=="067b"
    ATTRS{idProduct}=="2303"
    ATTRS{bcdDevice}=="0300"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="12"
    ATTRS{busnum}=="4"
    ATTRS{devnum}=="9"
    ATTRS{version}==" 1.10"
    ATTRS{maxchild}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Prolific Technology Inc."
    ATTRS{product}=="USB-Serial Controller"

  looking at parent device '/devices/pci0000:00/0000:00:1d.2/usb4':
    KERNELS=="usb4"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bMaxPower}=="  0mA"
    ATTRS{urbnum}=="188"
    ATTRS{idVendor}=="1d6b"
    ATTRS{idProduct}=="0001"
    ATTRS{bcdDevice}=="0206"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="12"
    ATTRS{busnum}=="4"
    ATTRS{devnum}=="1"
    ATTRS{version}==" 1.10"
    ATTRS{maxchild}=="2"
    ATTRS{quirks}=="0x0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Linux 2.6.28-15-generic uhci_hcd"
    ATTRS{product}=="UHCI Host Controller"
    ATTRS{serial}=="0000:00:1d.2"
    ATTRS{authorized_default}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1d.2':
    KERNELS=="0000:00:1d.2"
    SUBSYSTEMS=="pci"
    DRIVERS=="uhci_hcd"
    ATTRS{vendor}=="0x8086"
    ATTRS{device}=="0x27ca"
    ATTRS{subsystem_vendor}=="0x17aa"
    ATTRS{subsystem_device}=="0x200a"
    ATTRS{class}=="0x0c0300"
    ATTRS{irq}=="18"
    ATTRS{local_cpus}=="ffffffff,ffffffff"
    ATTRS{local_cpulist}=="0-63"
    ATTRS{modalias}=="pci:v00008086d000027CAsv000017AAsd0000200Abc0Csc03i00"
    ATTRS{enable}=="1"
    ATTRS{broken_parity_status}=="0"
    ATTRS{msi_bus}==""

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

--> you are right. The serial is not set :frowning:

So I have to search a tool to set it. Maybe there is a similar tool for the prolifics as for the arduino's FTDI. Let's see.

With regard to the /dev/serial/by-id: this is cool, for the arduino this means that I would not have needed any rule. So maybe I will just drop it. But for the prolific this is not enough. Uniqueness is not what I need. What I need are persistent (in time) IDs. This is not guaranteed by this approach.

So I will keep searching. But at least my initial problem is solved. And some others are now solved as well. The prolific issue is only a minor nuisance. Somewhere at the end of my list.

Had I read about your Prolific trouble earlier I could have told you about the lack of serial number. Please let me know if you find a solution, I would find it useful too.

This is my current /etc/udev/rules.d/40-usb-serial-adapters.rules. At the end you can see my attempt at solving the Prolific problem, giving unique names to adapters but they are not persistent over time. I do not spend a lot of time or energy trying to solve this, it is no major problem for me.

(I made some changes in my usb-serial-adapters rules file, in order to get the symlinks to point to the ttyUSB* devices, and found that it needs a number of 40 or higher in order to work. I found the number using grep ttyUSB /lib/udev/rules.d/*, the first rule mentioning ttyUSB was numbered 40.)

# udevadm info --attribute-walk --path=/sys/bus/usb-serial/devices/ttyUSB0

KERNEL!="ttyUSB*", GOTO="local_usb__rules_end"
ATTRS{idVendor}=="0403", GOTO="local_usb__process_ftdi"
ATTRS{idVendor}=="067b", GOTO="local_usb__process_prolific"

LABEL="local_usb__process_ftdi"

# Modern Device BUB
ATTRS{serial}=="A6007NVf", SYMLINK+="ftdi-md-bub-1"
ATTRS{serial}=="A6007ntk", SYMLINK+="ftdi-md-bub-2"
ATTRS{serial}=="A6007NEG", SYMLINK+="ftdi-md-bub-3"

# SparkFun: 5V FTDI Basic/FT232R Breakout Board
ATTRS{serial}=="A6007Cp2", SYMLINK+="ftdi-sf-b5v-1"
ATTRS{serial}=="A6007CId", SYMLINK+="ftdi-sf-b5v-2"
ATTRS{serial}=="A6007DtI", SYMLINK+="ftdi-sf-bob-1"
ATTRS{serial}=="A6007Dtw", SYMLINK+="ftdi-sf-bob-2"

# FTDI cable (original from FTDI)
ATTRS{serial}=="FTE3HIKO", SYMLINK+="ftdi-cable"

# Arduino
ATTRS{serial}=="A7006QLL", SYMLINK+="ftdi-arduino-2k9"
ATTRS{serial}=="A6007AgC", SYMLINK+="ftdi-arduino-mega"
ATTRS{serial}=="A6009aKI", SYMLINK+="ftdi-emcs-mega-1"
ATTRS{serial}=="A6009aKL", SYMLINK+="ftdi-emcs-mega-2"
ATTRS{serial}=="A7004IkW", SYMLINK+="ftdi-seeed-mega-1"
ATTRS{serial}=="A7004I2Q", SYMLINK+="ftdi-seeed-mega-2"
ATTRS{serial}=="A7004HYi", SYMLINK+="ftdi-seeed-mega-3"

# Digi USB dev board
ATTRS{idProduct}=="ee18", ATTRS{product}=="MaxStream PKG-U", SYMLINK+="ftdi-digi-xbib"

GOTO="local_usb__rules_end"

LABEL="local_usb__process_prolific"

# GlobalSat (PS/2 adapter cable, USB GPS)
ATTRS{idProduct}=="2303", ATTRS{bcdDevice}=="0300", ATTRS{product}=="USB-Serial Controller", SYMLINK+="pl2303-globalsat-%M-%m-%n"

# Other Prolific adapters, all lacking serial number
ATTRS{idProduct}=="2303", ATTRS{bcdDevice}=="0202", SYMLINK+="pl2303-%M-%m-%n"

LABEL="local_usb__rules_end"

wayoda: Thanks for the information about ls /dev/serial/by-id

For the AVRisp MkII, I have experimented with simplifying the rules, and for me it still works. The file is still numbered 39, and on my system the permissions are the intended, and I can use the programmer without sudo. The full path and name in my case is /etc/udev/rules.d/39-mcu-programmers.rules

# udev rules file for some usb connected mcu programmers

# Atmel devices
#

ATTR{idVendor}=="03eb", ATTR{idProduct}=="2104", MODE="0660", GROUP="plugdev", SYMLINK+="avrispmkII"

#ATTR{idVendor}=="03eb", ATTR{idProduct}=="2103", MODE="0660", GROUP="plugdev", SYMLINK+="avrunknown-%n"
#ATTR{idVendor}=="03eb", ATTR{idProduct}=="2107", MODE="0660", GROUP="plugdev", SYMLINK+="avrdragon-%n"

# Microchip devices
#

ATTR{idVendor}=="04d8", ATTR{idProduct}=="0033", MODE="0660", GROUP="plugdev", SYMLINK+="pickit2"

After plugging it in:

jadler@server:~$ ls -l /dev/avrispmkII /dev/bus/usb/002/116
lrwxrwxrwx 1 root root          15 2009-10-24 16:36 /dev/avrispmkII -> bus/usb/002/116
crw-rw-r-- 1 root plugdev 189, 243 2009-10-24 16:36 /dev/bus/usb/002/116

wayoda:

Sounds reasonable. Since I'm the only user my machine I don't need an extra users-group for my USB-hardware.

No, you may not, but some devices will be assigned to the plugdev group, with root still being the owner. Since normal users are members of this group, a device/file owned by this group and having appropriate group permissions will be useable by normal users. I think that this is the proper way of solving this kind of problem with access permissions to this kind of hardware.

I just made another experiment, the relevant line in the rules file is now:

ATTR{idVendor}=="03eb", ATTR{idProduct}=="2104", GROUP="plugdev"

That is, no attempts at modifying permissions, only group membership. I have also disabled the Virtualbox rules that also modifies these devices (and any other USB devices) to make sure that nothing else affects the outcome. The results (for me):

jadler@server:~$ lsusb|grep Atmel
Bus 002 Device 117: ID 03eb:2104 Atmel Corp. AVR ISP mkII
jadler@server:~$ ls -l /dev/bus/usb/002/117
crw-rw-r-- 1 root plugdev 189, 244 2009-10-24 16:45 /dev/bus/usb/002/117
jadler@server:~$ avrdude -P usb -p atmega1280

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9703

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

If I disable the AVRisp rule, the result is:

jadler@server:~$ lsusb|grep Atmel
Bus 002 Device 120: ID 03eb:2104 Atmel Corp. AVR ISP mkII
jadler@server:~$ ls -l /dev/bus/usb/002/120
crw-rw-r-- 1 root root 189, 247 2009-10-24 16:57 /dev/bus/usb/002/120
jadler@server:~$ avrdude -P usb -p atmega1280
avrdude: usb_open(): cannot read serial number "error sending control message: Operation not permitted"
avrdude: usb_open(): cannot read product name "error sending control message: Operation not permitted"
avrdude: usbdev_open(): error setting configuration 1: could not set config 1: Operation not permitted
avrdude: usbdev_open(): did not find any USB device "usb"

My conclusion is that it is the group membership is the solution, not the permissions. (Thank you, both of you, for motivating me to find this out! Now my rules will be even better.) And on my system, this still works just fine with the rule numbered 39 as before, or even numbered 00.

The file /lib/udev/rules.d/60-persistent-serial.rules is the one that assigns the /dev/serial/* symlinks and it contains some nice examples of udev rules.

/lib/udev/rules.d/40-avarice.rules contains rules for AVR Dragon and JTAG ICE mkII and could probably be used as a template for handling other µC programmers/interfaces. On my system it is this simple:

SUBSYSTEM!="usb_device", ACTION!="add", GOTO="avarice_end"

# Atmel Corp. JTAG ICE mkII
SYSFS{idVendor}=="03eb", SYSFS{idProduct}=="2103", MODE="660", GROUP="dialout"

# Atmel Corp. AVR Dragon
SYSFS{idVendor}=="03eb", SYSFS{idProduct}=="2107", MODE="660", GROUP="dialout"

LABEL="avarice_end"

wayoda: The dialout group is another one of the groups used for giving different non-root users access to different kinds of hardware, as you probably know.

Udo: What happens if you rename your programmer.rules to 00-programmer.rules and change the contents to:

ATTR{idVendor}=="03eb", ATTR{idProduct}=="2104", GROUP="dialout"

My guess is that it will work just fine this way too.

If you wish you could use either

SUBSYSTEM=="usb_device", ACTION=="add|change", ATTR{idVendor}=="03eb", ATTR{idProduct}=="2104", GROUP="dialout"

or

SUBSYSTEM!="usb_device", ACTION!="add|change", GOTO="mcu-programmers-end"
ATTR{idVendor}=="03eb", ATTR{idProduct}=="2104", GROUP="dialout", SYMLINK+="avrispmkII"
LABEL="mcu-programmers-end"

which may make the udev rule evaluation a bit faster, though I doubt you would notice it.