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

Post Reply
kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

USB Components: pic_usb does not implement req_Set_Interface

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

― C.S. Lewis

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

Re: USB Components: pic_usb does not implement req_Set_Interface

Post 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.

Post Reply