View topic - Usb device driver programming

Usb device driver programming

anything that doesn't fit to other groups.

Usb device driver programming

Postby wallace » Tue Dec 20, 2011 11:35 pm

Hello, i need a hand here with few questions.
I am writing device driver for the usb data aquisition device. When i plug the device in the 'usb -vvv' command returns three devices. USB hub, audio codec and FT232R. I know it should be visible as audio codec and serial port (ft232r) however, what for is the USB hub? That was first one.

The next thing, can you provide me any examples, or tutorials on usb programming in qnx? I`ve written simple program that should attach to found usb devices, however it returns "no such device" error code - so, no devices found. This is the error code when usbd_device_ident_t struct is filled with data specfific for pendrive i`ve plugged in. But when i filled that struct with data specefic for usb hub, the errror code was "device bussy"

The program lists usb controllers, but no reasonable number of devices currently connected is provided. It is 12 for every controller.

I`m attaching source code with its output and usb -vvv output

Thanks.
wallace
Active Member
 
Posts: 15
Joined: Tue Dec 20, 2011 11:11 pm

Re: Usb device driver programming

Postby maschoen » Wed Dec 21, 2011 10:49 am

wallace wrote:Hello, i need a hand here with few questions.
however, what for is the USB hub? That was first one.


USB hubs are not passive devices. They appear as devices on the bus just like other devices. Even if you are not using an external hub, most computers with USB connections have a hub intenally.


The next thing, can you provide me any examples, or tutorials on usb programming in qnx? I`ve written simple program that should attach to found usb devices, however it returns "no such device" error code - so, no devices found. This is the error code when usbd_device_ident_t struct is filled with data specfific for pendrive i`ve plugged in. But when i filled that struct with data specefic for usb hub, the errror code was "device bussy"


As a starter, you probably want to get ahold of a good generic boot on USB. There is a lot of terminology that goes along with USB that you have to understand.

Somewhere around there is an example of a USB driver, I think the parallel port driver.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Re: Usb device driver programming

Postby Tim » Wed Dec 21, 2011 5:28 pm

Wallace,

Is your device reporting as a HID device? Those are handled differently than non-HID devices.

There is a USB ddk available. I think it's on the QNX web site still (was last time I went there a year or so ago). It had non-HID USB examples for a mouse, keyboard and printer.

Tim
Tim
Senior Member
 
Posts: 1469
Joined: Wed Mar 10, 2004 12:28 am

Re: Usb device driver programming

Postby wallace » Wed Dec 21, 2011 5:50 pm

Generally the device is reported as 3 devices:
- usb hub
- audio codec, HID device
- usb serial uart ft232

Regarding the ddk usb. What is it EXACTLY? All the functions usbd_*() are present in my system, and I can use whenever I want. Why do I need the ddk usb?

Because usbd_attach() returns "resource bussy" for each device mentioned above I am confused what to do. Is there any method to obtain name or any id of driver that uses the device and slay it?

Tim could you pass me the examples, please? (errfet@gmail.com)
wallace
Active Member
 
Posts: 15
Joined: Tue Dec 20, 2011 11:11 pm

Re: Usb device driver programming

Postby maschoen » Wed Dec 21, 2011 7:37 pm

wallace wrote:Generally the device is reported as 3 devices:

Regarding the ddk usb. What is it EXACTLY? All the functions usbd_*() are present in my system, and I can use whenever I want. Why do I need the ddk usb?


With a USB driver, you are not interacting with hardware directly. The actual hardware in your system is a chip that is communicated with by inp() and outp() calls. You don't do this. Instead there is a USB driver called io-usb that does this. The usb_*() interface allows your driver to connect to io-usb and get access to the devices that are connected. The bus itself has limited bandwidth. You can request different types of bandwidth. For example you request a guaranteed delivery of data. The io-usb program is responsible for managing the bandwidth.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Re: Usb device driver programming

Postby wallace » Thu Dec 22, 2011 1:21 pm

Thank you, its much more clear now. Is it mandatory to use ddk to write drivers, or is there any other way (i`m asking cause i have qnx + momentics educational version and I dont have the code that is requierd to download ddk).
The question that remains is, what to do when usbd_attach() returns "resource bussy"?
wallace
Active Member
 
Posts: 15
Joined: Tue Dec 20, 2011 11:11 pm

Re: Usb device driver programming

Postby wallace » Sat Dec 24, 2011 11:22 pm

Is it possible to get access to the usb controller by pci_*() interface (pci -vv returns its vendor and product ID), and then using in()/out() functions perform IO operations with data that finally should be send to the connected device?
Last edited by wallace on Wed Jan 04, 2012 2:40 pm, edited 1 time in total.
wallace
Active Member
 
Posts: 15
Joined: Tue Dec 20, 2011 11:11 pm

Re: Usb device driver programming

Postby wallace » Sun Dec 25, 2011 6:18 pm

Could you please provide me a simple example how to use insertion and removal callbacks with usb devices? The documentation is too enigmatic about it. The other method (loop through all devices) doesn`t work for me, when I try to attach it returns that device is bussy.
wallace
Active Member
 
Posts: 15
Joined: Tue Dec 20, 2011 11:11 pm

Re: Usb device driver programming

Postby wallace » Sun Dec 25, 2011 10:30 pm

Ok, I decided to get accest to the device by accessing the io-usb by usbd_* interface. However the usbd_attach() function (as I`ve written above) returns EBUSSY. I`ve googled for it, and found post on foundry27: http://community.qnx.com/sf/discussion/ ... _pagenum=1

The general idea is to use io-hid with igndev option, this should cause that no driver uses it. I`ve added the proper line to main() function, it doesn`t work however.

I`m posting my code:

#define CODEC_VENDOR 0x08bb
#define CODEC_PRODUCT 0x29b2
#define CODEC_CLASS 0x01
#define CODEC_SUB_STREAMING 0x02
#define CODEC_SUB_CONTROL 0x01
#define CODEC_PROTO 0x00

int main(int argc, char *argv[]) {

system("io-hid -dusb igndev=0x08bb:0x29b2 &");

usbd_device_ident_t interest = {
CODEC_VENDOR,
CODEC_PRODUCT,
CODEC_CLASS,
CODEC_SUB_CONTROL,
CODEC_PROTO
};
usbd_funcs_t funcs = {
NULL,
NULL,
NULL,
NULL
};

usbd_connect_parm_t cparms = {
NULL,
USB_VERSION,
USBD_VERSION,
0,
NULL,
NULL,
0,
&interest,
&funcs,
USBD_CONNECT_WAIT
};
struct usbd_connection *connection;
int error;

error = usbd_connect(&cparms, &connection);
cout<<strerror(error)<<endl;

usbd_hcd_info_t info;

usbd_device_instance_t instance;
int busno, devno;
usbd_device * device;

for (busno = 0; busno < 5; ++busno){
for ( devno = 0; devno< 5; ++devno){
memset(&instance, 0, sizeof(usbd_device_instance_t));
instance.path = busno, instance.devno = devno;
error = usbd_attach(connection, & instance, 0, &device);
cout<<"bus: "<<busno<<", dev: "<<devno<<", "<<strerror(error)<<endl;
}

}

return EXIT_SUCCESS;
}
Could you give ma any clue please?
wallace
Active Member
 
Posts: 15
Joined: Tue Dec 20, 2011 11:11 pm


Return to General Programming

Who is online

Users browsing this forum: No registered users and 2 guests