Page 1 of 1
Problem with usb_control_msg
Posted: Tue Oct 20, 2009 12:18 am
by Jonatan
Hi
I'm trying to use V-Usb to control a display, among other things. To send text to the display I thought I would use control messages, using usbFunctionWrite() to get the string data.
I've got the communication up and running: there are valid calls to usbFunctionSetup(), but usbFunctionWrite() is never called. Thus I never get any data.
I've created a very basic program based on libusb running on Ubuntu. When I call usb_control_msg() to send the string data i get error -75 returned ("Value too large for defined data type"). I need some help to decode that!
My call to usb_control_msg() looks like this:
Code: Select all
char *buf = "Hello World";
usb_control_msg (handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, 123, 0, 0, buf, strlen (buf), 5000);
Re: Problem with usb_control_msg
Posted: Tue Oct 20, 2009 6:43 pm
by Saimon
You post:
"My call to usb_control_msg() looks like this:
Code: Select all
char *buf = "Hello World";
usb_control_msg (handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, 123, 0, 0, buf, strlen (buf), 5000);"
You try to send data to default endpoint 0, thus try to use "USB_ENDPOINT_IN" flag
Ma be i'm wrong? but try to use this:
"
char *buf = "Hello World";
usb_control_msg (handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 123, 0, 0, buf, strlen (buf), 5000);"
I hope it help to you!
Re: Problem with usb_control_msg
Posted: Thu Oct 22, 2009 10:25 am
by Guest
You were absolutely right! Using USB_ENDPOINT_IN I get no error message.
However, there is one more problem: usbFunctionWrite() is still never called.
I have USB_CFG_IMPLEMENT_FN_WRITE enabled in usbconfig.h
This is my usbFunctionSetup:
Code: Select all
static uint8_t usb_buffer [256];
static uint8_t usb_pos, usb_func, usb_remaining;
usbMsgLen_t usbFunctionSetup (uchar data[8])
{
usbRequest_t* rq = (void*) data;
usb_func = rq->bRequest;
switch (usb_func) {
case LUXREQ_DISPLAY_STRING:
usb_remaining = rq->wLength.word;
usb_pos = 0;
return USB_NO_MSG;
default:
return USB_NO_MSG;
}
}
I've used a display to make sure that the first switch-case (LUXREQ_DISPLAY_STRING) is reached, and rq->wLength holds the correct length (the length of data sent by usb_control_msg() from the PC).
Any ideas?
Re: Problem with usb_control_msg
Posted: Thu Oct 22, 2009 10:27 am
by ionte
The message above was sent by me. Forgot to login.
Re: Problem with usb_control_msg
Posted: Fri Oct 23, 2009 7:08 pm
by Saimon
If you need to call usbFunctionWrite? you must return 0xFF in usbFunctionSetup!
This is necessary for V-USB lib driver! my email:
lleeloo@mail.ruSorry for my English!
Re: Problem with usb_control_msg
Posted: Sat Oct 24, 2009 12:37 am
by ionte
Hi,
I do return USB_NO_MSG which is defined as 255 in usbdrv.h:
Code: Select all
#define USB_NO_MSG ((usbMsgLen_t)-1) /* constant meaning "no message" */
I tried with the value 255, to avoid the macro, but same result.
Any other ideas?
Re: Problem with usb_control_msg
Posted: Mon Oct 26, 2009 11:11 pm
by christian
And did you configure V-USB with USB_CFG_IMPLEMENT_FN_WRITE defined to 1 in usbconfig.h?
Re: Problem with usb_control_msg
Posted: Wed Nov 18, 2009 8:32 pm
by lll7
I've got the same problem usbFunctionWrite() is never called. I've made all those steps with configuring usbconfig.h also my program returns USB_NO_MSG in usbFunctionSetup(), i've check it by using blinking diode. In usbFunctionWrite() i just want to flash a diode but it dosen't work. Have anyone have some ideas, can it be becouse of the HID device type(Mouse) witch i'm using?
Re: Problem with usb_control_msg
Posted: Thu Nov 19, 2009 12:03 am
by Saimon
Hi! Try to write new clear project and call usbFunctionWrite. Make shure that cstack and heap are correct. And if you try to call usbFunctionWrite in HID example, i'm not shure that usbFunctionWrite is called by V-USB driver at all.
Re: Problem with usb_control_msg
Posted: Thu Nov 19, 2009 10:28 am
by lll7
Problem solved it was because of HID type of my device i've changed it and all works fine.
Re: Problem with usb_control_msg
Posted: Tue Dec 22, 2009 11:56 am
by tommyjunge
Hi,
Problem solved it was because of HID type of my device i've changed it and all works fine.
is it not possible to send usbFunctionWrite to an HID device?
Do I need to use LibUSB in this case or can I do the same thing with HID?
Thanks, Tom
Re: Problem with usb_control_msg
Posted: Tue Dec 22, 2009 5:19 pm
by christian
If you want to send arbitrary control messages, you need libusb. Otherwise you can only send those controls defined in the USB HID paper.
Re: Problem with usb_control_msg
Posted: Tue Dec 22, 2009 8:41 pm
by tommyjunge
Where can I find the HID USB paper?
Re: Problem with usb_control_msg
Posted: Tue Dec 22, 2009 9:02 pm
by christian