USB Components: pic_usb does not implement req_Set_Interface

Forum for problems or queries regarding the Flowcode application and compiler usage.

Moderators: Benj, Mods

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

USB Components: pic_usb does not implement req_Set_Interface

Postby kersing » Mon Apr 13, 2009 9:34 pm

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
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
Benj
Matrix Staff
Posts: 14151
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4079 times
Contact:

Re: USB Components: pic_usb does not implement req_Set_Interface

Postby Benj » Mon Apr 13, 2009 10:11 pm

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.