Page 1 of 1

AVR-USB hangs when using usbSetInterrupt(0, 0)

Posted: Sat Nov 15, 2008 4:18 am
by Alloc
Hi,

I wrote a little fw which indicates whether the host should read data by setting it's interrupt1-in-flag. When I call the usbSetInterrupt-method by eg

Code: Select all

usbSetInterrupt(&LED_PORT, 1);
it works fine. If I (at the same codeline) call it by

Code: Select all

usbSetInterrupt(0, 0);
libUsb also returns from

Code: Select all

usb_interrupt_read(handle, USB.REQ_TYPE_DIR_DEVICE_TO_HOST | 1, buffer, buffer.length, 24*60*60*1000);
but the control transfer directly following it

Code: Select all

usb_control_msg(handle, USB.REQ_TYPE_DIR_DEVICE_TO_HOST |  USB.REQ_TYPE_TYPE_VENDOR | USB.REQ_TYPE_RECIP_DEVICE, 1, 0, 0, buffer, buffer.length, 5000);
does endlessly return

Code: Select all

error sending control message: Protocol error
and usb_interrupt_read doesn't block anymore.

AVR-source and accessing Java-source attached.

Regards,
Chris

/Edit:
To clarify two things ... When I use

Code: Select all

usbSetInterrupt(0, 0);
while the device isn't opened the function getString in Main.java fails to get the requested information of AVR-USB.
AVR-USB hanging does not mean that the whole uC hangs ... It's just AVR-USB not responding to requests.

Posted: Wed Nov 19, 2008 10:07 pm
by christian
usbSetInterrupt() requires a pointer as the first argument and a byte count (greater than zero!) as the second. Anything else may result in corruption of the internal data structures.

Posted: Wed Nov 19, 2008 10:15 pm
by Alloc
Hi christian,

thanks for the reply. Thought I could use it with zero bytes since it's used that way in the RemoteSensor example.
So is there any way to set the usb-interrupt without any data? Or do I have to use a dummy byte?

Regards,
Chris

Posted: Wed Nov 19, 2008 10:29 pm
by christian
OK, you're right. My comment about passing zero length messages is wrong, this is explicitly handled in the driver.

However, a zero sized message may not be handled correctly by the host. This is actually a bug in the RemoteSensor example. You should send at least one dummy byte.

Posted: Thu Nov 20, 2008 1:44 am
by Alloc
Okay, thanks =)