How to develop a usb driver for arduino boards under ubuntu

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Experts,

Hi,

For a LUFA based USB project I would like to develop a driver under linux ubuntu 14.04 OS.

Now I am looking for a reputable and open source usb driver development package to start with.

 

I tested libusb but it does not detect my device insertion and removal.

 

Could you recommend any other libraries.

BR,

Mehrdad,

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What sort of device does it appear as? HID?
You can always modify the source of the many existing usb kernel drivers.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tested libusb but it does not detect my device insertion and removal.

Well at hte first level it's not libusb that does the detecting. More to the point what does (a) dmesg and (b) lsusb say when you insert the device? IF they show activity then the next thing to look at is udev rules. This will be notified about the VID/PID that has appeared and will map it to a relevant device driver. It will also police the access rights. Above that then your app code, linked with libusb may be able to "see" the device but only if it has the right to do so. So you may need to change the udev rules to make the device more openly available before libusb can access it from a user level app. It *might* help to run the app+libusb code under sudo if the issue here is rights.

 

But as I say start at the bottom and see whether dmesg shows any kind of enumeration activity and can llsusb "see" the device and is it enumerating with the correct VID and PID ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the answer

But some information about my project:

1. It is a Arduino Leonardo board having a ATMEGA32U4 micro controller unit.

2. I changed LUFA's AudioInput demo program and loaded it into my board.

3. when I type lsusb I get my device as following line in the list: (both VID and PID are valid.)

 

Bus 002 Device 002: ID 03eb:2047 Atmel Corp. LUFA Audio Input Demo Application

 

4. When I type dmesg I get following lines of information:

 

[  128.456166] usb 2-2: new full-speed USB device number 2 using uhci_hcd
[  128.647575] usb 2-2: New USB device found, idVendor=03eb, idProduct=2047
[  128.647594] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  128.647607] usb 2-2: Product: LUFA Audio In Demo
[  128.647619] usb 2-2: Manufacturer: Dean Camera
[  128.785202] usbcore: registered new interface driver snd-usb-audio
[  283.955055] perf samples too long (5005 > 5000), lowering kernel.perf_event_max_sample_rate to 25000

 

5. I do not know any thing about udev rules. could you please give me some hints in this regard. at least some document to begin.

 

Best Regards

Mehrdad,

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You cannot reuse a VID/PID pair for a different device.

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

5. I do not know any thing about udev rules. could you please give me some hints in this regard. at least some document to begin.

 

Did you ask wikipedia for udev?

 

http://doc.ubuntu-fr.org/udev (sorry, could not find the translation)

 

http://ubuntuforums.org/showthre... : it uses /var/log/messages (dmesg which was hinted "just" prints this file on the screen)

it links to tutorials

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How are you querying libsub to find the device?

 

avrdude is a good example of how to interact with libusb. See line 365 onwards in this:

 

http://svn.savannah.nongnu.org/v...

 

Are you doing something similar to find the VID/PID (3EB:2047)? Are you saying you just don't see these values when enumerating the USB devices available?

 

As I say do things change if you run your access code under sudo?

 

If so then it probably is the case that you need udev access. There's an article about udev rules here:

 

http://hackaday.com/2009/09/18/h...

 

(at the bottom of that it even explains how avrdude may be given 0660 access).

Last Edited: Tue. Feb 10, 2015 - 10:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the answer,

Now I am reading the documents that you provided to me.

It seems to make a usb device usable in user mode code, I am supposed to use udev rules.

I had some expriences with avrdude to make it active for my usbasp programmer.

Now let me read the documents and check to see if I cound make my device work.

 

Again thanks for your great hints.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Experts again

Happy to say I could finally get my USB device work.

I read all the documents and surfing the web for other documents about udev rules.

this link is quite comprehensive and useful for newbies like me :

http://www.weather-watch.com/smf/index.php?topic=39257.0

 

 

I write a simple udev rule and add it to /etc/udev/rules.d/directory and after restarting system my code runs perfect.

 

ACTION!="add|change", GOTO="avr_end"

ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2047", MODE="0666", GROUP="plugdev"

LABEL="avr_end"

Now I  run following simple demo program from libusb examples folder:

 

static int find_MY_device(void)
{
	devh = libusb_open_device_with_vid_pid(NULL,0x3eb,0x2047);
	return devh ? 0 : -EIO;
}

int main(int argc, char **argv)
{
	int r = 1;

	r = libusb_init(NULL);
	if (r < 0) 
	{
		  fprintf(stderr, "failed to initialise libusb\n");
		 exit(1);
	}
        r = find_MY_device();
	if (r < 0) 
	{
		fprintf(stderr, "Could not find/open device\n");
		goto out;
	}

	r = libusb_detach_kernel_driver(devh,0);
	if(r < 0) 
	{
		fprintf(stderr, "libusb_detach_kernel_driver error %d\n", r);
//		goto out;
	}

	r = libusb_claim_interface(devh, 0);
	if(r < 0) 
	{
		fprintf(stderr, "usb_claim_interface error %d\n", r);
		goto out;
	}
	printf("claimed interface\n");

 

Now , when I call find_MY_device it returns success.

And I also could claim interface.

Now it is time to read data from my isochrounous endpoint to see if it works.

 

Best thing that I could ask now is : "Could I find any libusb based source code example that works with isochrounous endpoints?"

Also I would like to use callback based functions to be called when my usb device is attached or detached.

If there is any link please let me know.

 

Best Regards

Mehrdad,

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess just a general google for libusb (not necessarily anything related to AVR) should turn up loads of articles and examples but I tend to keep coming back to the avrdude source simply because it's a known working example of interaction with libusb that just happens to be in an AVR context. However I guess nothing says it's the "right" way to do it. I notice it scans for devices then manually attempts to match VID and PID yet you seem to have found a much more elegant solution there with the libusb_open_device_with_vid_pid() system call. Perhaps that didn't exist when avrdude was first created. then again perhaps the avrdude maintainers know some deep reason why their approach is "better". The problem is you never really know with this kind of thing unless you can actually find some authority saying something like "of course you don't want to use libusb_open_device_with_vid_pid() because of ..." ;-)