USB programming

hi, I try to use a usb port under QNX 6.2. I have a pb with the function usbd_connect() (which is actually the first one I test). I copyed in a main programm what is written in the HELP:

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/usbdi.h>

int main()
{
_uint32 USB_VENDOR_ATMEL;
_uint32 USB_PRODUCT_ATMEL_43USB355;
int argc;
char **argv;
void (*insertion)(struct usbd_connection *, usbd_device_instance_t *instance);
void (*removal)(struct usbd_connection *, usbd_device_instance_t *instance);

usbd_device_ident_t interest = {
USB_VENDOR_ATMEL,
USB_PRODUCT_ATMEL_43USB355,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
};

usbd_funcs_t funcs = {
_USBDI_NFUNCS,
insertion,
removal,
NULL
};

usbd_connect_parm_t cparms = {
NULL,
USB_VERSION,
USBD_VERSION,
0,
argc,
argv,
0,
&interest,
&funcs
};

struct usbd_connection *connection;
int error;

error = usbd_connect(&cparms, &connection);

}

When I try to get the executable, it doesn’t recognize the function (“undefined reference usbd_connect”). So I guess I have to build the executable thanks to a library in which usbd_connect.o is referenced (qcc -o prog_static prog.o -Bstatic -L ./-l lib.a), or something like that ? If guess right, where is this library (and is it the same library for usbd_attach(), usbd_descriptor(), etc…) ? Or am I totally wrong and if so, could anyone explain me how to solve this pb?

Try linking against libusbdi.so.2 (-l usbdi). I only used the ddk myself for writing usb drivers.

Thx martin, I have been able to create the executable but when I try to run it, I get the following message:
/bin/sh: ./usb: Attempting to exec shared lib

I compiled the program by writing:
qcc -shared -o executable program.o -L ./-l libusbdi.so.2
I also tried:
qcc -shared -o executable program.o -L ./-l usbdi
qcc -shared -o executable program.o -L -lusbdi

I’m always able to compile but never to run it. What should I do?
thx

Try this:
qcc -o executable program.o -lusbdi

yeah thanks dude! It seems to work now :smiley:

Now I ghave a pb with the function usbd_alloc_urb. I declared

struct usbd_urb *urb, *link;

and then wrote:

urb = usbd_alloc_urb(link);

but when I try to run the executable, I get an error message saying “core dumped”.

Are urb and linked well declared? (I think yes but can be mistaken)
Should I set link a specific value, and if so what kind of value is it?

thx

You should be doing: usbd_alloc_urb(NULL).
Check the doc’s for this function and you will see that ‘link’ specifies multiple urb’s linked together. This isn’t implemented yet.

Martin.

I started to comunicate wiith the USB port via a microcontroller.
I wrote all the instructions that were given on the qnx web support.
Now I try to send data to the USB port.

donnee = (char*)calloc(1,sizeof(char));
donnee = “0”;
printf("%d",*donnee);

if ( usbd_io(urb,pipe_out,func,donnee,USBD_TIME_DEFAULT)== EOK)
{
printf(“donnee transmise \n”);
}

but then the main program which is in the microcontroller stops running (the DEL stop flickering).

So is there a function to use to make the program in the microcontroller running again? Or how can I debug this?

Thx
guillaume

I think that you should take a look at the usb ddk. There are examples in there how to send/receive data. Basically what you should do is first use one of the usbd_setup* functions to setup your urb and then use the usbd_io function to submit your urb to the USB stack.

Martin.

hi, I am now able to send data but I have a little problem to get it. When I try to get a number that I put manually in the microcontroller, most of the time, I obtain “0”. When I use a loop, I obtain several “0” and after a variable number on loops, I obtain the right number. Why does this happen? Is there a condition to stop the loop that means we get the right number? Thx,
guillaume

EDIT: here is the part of my code where there might be an error

//############## USBD_SET_INTERRUPT ENTREE #########

urb2 = usbd_alloc_urb(NULL);
taille_donnee_recue = sizeof(unsigned char);
adresse_donnee_recue = usbd_alloc(taille_donnee_recue);

if ( usbd_setup_interrupt(urb2,URB_DIR_IN,adresse_donnee_recue,taille_donnee_recue) == EOK)
{
printf(“setup interrupt d entree effectue \n”);
}

//################ USBD_IO ENTREE #####################.
donnee_recue = adresse_donnee_recue ;

for(i=1;i<=15;i++)
{
if(usbd_io(urb2,pipe_in,func2,donnee_recue,0)==EOK)
printf(“donnee recue: %d \n”,*donnee_recue);
}

Maybe because you specified a timeout of 0 (last parameter of usbd_io) and/or your urb status is busy?. You should really check the usb ddk!!!

it seems that my pb comes from the urb I/O is still active (usbd_urb_status
returns “EBUSY”). I checked the DDK but the only examples I have are related
to mouse and printer. It didn’t help me a lot in this case.In my code I use
the following functions in this order :
usbd_connect();
usbd_attach();
usbd_device_descriptor();
usbd_configuration_descriptor();
usbd_interface_descriptor();
usbd_parse_descriptors();
usbd_open_pipe();
usbd_setup_interrupt();
??usbd_urb_status();??
usbd_io(); #where there is a problem.

So maybe I forgot something. Should I use another function (but which one? I was not able to find it) to deactivate the urb I/O?
thx