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

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Alloc
Rank 1
Rank 1
Posts: 20
Joined: Tue Feb 19, 2008 10:52 pm
Location: Germany (Hessen)
Contact:

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

Post by Alloc » Sat Nov 15, 2008 4:18 am

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.

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

Post by christian » Wed Nov 19, 2008 10:07 pm

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.

Alloc
Rank 1
Rank 1
Posts: 20
Joined: Tue Feb 19, 2008 10:52 pm
Location: Germany (Hessen)
Contact:

Post by Alloc » Wed Nov 19, 2008 10:15 pm

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

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

Post by christian » Wed Nov 19, 2008 10:29 pm

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.

Alloc
Rank 1
Rank 1
Posts: 20
Joined: Tue Feb 19, 2008 10:52 pm
Location: Germany (Hessen)
Contact:

Post by Alloc » Thu Nov 20, 2008 1:44 am

Okay, thanks =)

Post Reply