Page 1 of 1

USB Components: pic_usb does not implement req_Set_Interface

Posted: Mon Apr 13, 2009 9:34 pm
by kersing
Hi,

pic_usb.h defines req_Set_Interface. However in pic_usb.c it is not used as it should be in usb_handle_standard_request. As a result the (Linux at least) USB stack waits a couple of seconds when trying to close a USB connection as it does not receive a reply to the request and has to wait for a timeout to occur.

According to the USB 2.0 specification a correct way to handle this request if only one interface is being used would be to stall endpoint0. A more generic approach to possible not implemented standard requests would be to stall endpoint0 in the default clause of the usb_handle_standard_request function.

The correct solution is:

Code: Select all

void usb_handle_standard_request(setup_data_packet sdp)
{
        switch (sdp.bRequest)
        {
                case req_Get_Descriptor:
... cut some lines...
                case req_Get_Status:
                                #ifdef USB_SELF_POWERED
                                        usb_send_one_byte(1);
                                #else
                                        usb_send_one_byte(0);   // bus powered
                                #endif
                                break;  
// add the lines below
                case req_Set_Interface:
                        usb_stall_ep0();
                        break;
 
The more generic solution:

Code: Select all

void usb_handle_standard_request(setup_data_packet sdp)
{
        switch (sdp.bRequest)
        {
                case req_Get_Descriptor:
... cut some lines...
                default:
// add the line below
                        usb_stall_ep0();
Best regards,

Jac

Re: USB Components: pic_usb does not implement req_Set_Interface

Posted: Mon Apr 13, 2009 10:11 pm
by Benj
Hi Jac

Many thanks for the bug spot and also the fix :P very much appreciated.

I will have a quick play just to make sure the fix you suggested doesn't cause any problems with any of the Microsoft source code we provide and post back my results.