Problem with usb_control_msg

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Jonatan

Problem with usb_control_msg

Post by Jonatan » Tue Oct 20, 2009 12:18 am

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);

Saimon

Re: Problem with usb_control_msg

Post by Saimon » Tue Oct 20, 2009 6:43 pm

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!

Guest

Re: Problem with usb_control_msg

Post by Guest » Thu Oct 22, 2009 10:25 am

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?

ionte
Posts: 4
Joined: Tue Oct 20, 2009 12:08 am

Re: Problem with usb_control_msg

Post by ionte » Thu Oct 22, 2009 10:27 am

The message above was sent by me. Forgot to login.

Saimon

Re: Problem with usb_control_msg

Post by Saimon » Fri Oct 23, 2009 7:08 pm

If you need to call usbFunctionWrite? you must return 0xFF in usbFunctionSetup!
This is necessary for V-USB lib driver! my email: lleeloo@mail.ru
Sorry for my English!

ionte
Posts: 4
Joined: Tue Oct 20, 2009 12:08 am

Re: Problem with usb_control_msg

Post by ionte » Sat Oct 24, 2009 12:37 am

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?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Problem with usb_control_msg

Post by christian » Mon Oct 26, 2009 11:11 pm

And did you configure V-USB with USB_CFG_IMPLEMENT_FN_WRITE defined to 1 in usbconfig.h?

lll7

Re: Problem with usb_control_msg

Post by lll7 » Wed Nov 18, 2009 8:32 pm

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?

Saimon

Re: Problem with usb_control_msg

Post by Saimon » Thu Nov 19, 2009 12:03 am

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.

lll7
Posts: 1
Joined: Wed Nov 18, 2009 8:34 pm

Re: Problem with usb_control_msg

Post by lll7 » Thu Nov 19, 2009 10:28 am

Problem solved it was because of HID type of my device i've changed it and all works fine.

tommyjunge

Re: Problem with usb_control_msg

Post by tommyjunge » Tue Dec 22, 2009 11:56 am

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

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Problem with usb_control_msg

Post by christian » Tue Dec 22, 2009 5:19 pm

If you want to send arbitrary control messages, you need libusb. Otherwise you can only send those controls defined in the USB HID paper.

tommyjunge

Re: Problem with usb_control_msg

Post by tommyjunge » Tue Dec 22, 2009 8:41 pm

Where can I find the HID USB paper?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Problem with usb_control_msg

Post by christian » Tue Dec 22, 2009 9:02 pm


Post Reply