• AVR Freaks

Problem with clearing stall on bulk pipes on PIC32 / USB library 2.8

Author
nwright98
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2011/05/16 07:01:16
  • Location: 0
  • Status: offline
2011/05/16 07:09:21 (permalink)
0

Problem with clearing stall on bulk pipes on PIC32 / USB library 2.8

Hello,

I was having a problem with a generic bulk device on the PIC32.  The device stalls the bulk in pipe on an error, and after I issue a ClearFeature(HALT) on the bus the stall would still be present on subsequent in transfers.  I loaded example MSD firmware for the PIC32 starter kit and observed that the stalls clear correctly using that firmware (based on 2.6.)

The difference between the two versions of the library is that 2.8 doesn't clear the STALL bit in the UEP register.  I copied that code over from 2.6 and the firmware now works correctly.  Was this intentionally removed from 2.8?  If so, is there some other mechanism that should be clearing the stall?

Thanks,
Nick
#1

4 Replies Related Threads

    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:Problem with clearing stall on bulk pipes on PIC32 / USB library 2.8 2011/05/16 14:43:29 (permalink)
    0

    I tested "USB Device - Mass Storage - Internal Flash" example of v2.8 (v2010-10-19) stack on USB20CV (compliance test by USB.org, r1.4.4.1), using Explorer16 + PIC32MX795F512L PIM.

    The MSC example passes all Ch9 tests successfully, including Halt Endpoint test. But it fails most of MSC tests (passed just seven tests out of 23)

    Halt Endpoint test flips endpoint HALT status using Set_/Clear_Feature( ENDPOINT_HALT ) requests. And it checks HALT status using Get_Status request. This test doesn't put any bulk/interrupt transfer to the target endpoint.

    The MSC example fails the MSC tests which examine device response for error and its recovery. These tests involves STALL response of bulk IN/OUT EPs and Clear_Feature( ENDPOINT_HALT ). I don't yet examine the cause of fails, if it lies in MSC process, or in support routines in usb_device.c. But I remember, these errors have survived since old stack versions.

    The device stalls the bulk in pipe on an error, and after I issue a ClearFeature(HALT) on the bus the stall would still be present on subsequent in transfers.

    I'll test it by writing simpler code than MSC. 

    The difference between the two versions of the library is that 2.8 doesn't clear the STALL bit in the UEP register.

    U1EPx.EPSTALL bit has no problem, if it would be left set. This bit indicates history of STALL response.

    Tsuneo
    #2
    nwright98
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2011/05/16 07:01:16
    • Location: 0
    • Status: offline
    Re:Problem with clearing stall on bulk pipes on PIC32 / USB library 2.8 2011/05/17 06:00:17 (permalink)
    0
    chinzei
    I tested "USB Device - Mass Storage - Internal Flash" example of v2.8 (v2010-10-19) stack on USB20CV (compliance test by USB.org, r1.4.4.1), using Explorer16 + PIC32MX795F512L PIM.

    The MSC example passes all Ch9 tests successfully, including Halt Endpoint test. But it fails most of MSC tests (passed just seven tests out of 23)

    Halt Endpoint test flips endpoint HALT status using Set_/Clear_Feature( ENDPOINT_HALT ) requests. And it checks HALT status using Get_Status request. This test doesn't put any bulk/interrupt transfer to the target endpoint.


    I tested my code with USBCV as well and got the same results (prior to the fix).  The problem doesn't seem to appear until data has been sent through the bulk pipe.  The same code works fine on a PIC18F66J50 on another product.

    chinzei
    U1EPx.EPSTALL bit has no problem, if it would be left set. This bit indicates history of STALL response.


    That was my understanding as well, but the only change I made to the code was to clear the EPSTALL bit in USBStdFeatureReqHandler() as follows:

    added the following at the top of the function:


        #if defined(__C32__)
            DWORD* pUEP;
        #else
            unsigned int* pUEP;            
        #endif


    and this at the beginning of the code that clears the stall:


                //If it was not a SET_FEATURE
                //point to the appropriate UEP register
                #if defined(__C32__)
                    pUEP = (DWORD*)(&U1EP0);
                    pUEP += (SetupPkt.EPNum*4);
                #else
                    pUEP = (unsigned int*)(&U1EP0+SetupPkt.EPNum);
                #endif

                //Clear the STALL bit in the UEP register
                *pUEP &= ~UEP_STALL;


    Perhaps there is some difference in the PIC32 hardware for the function of the UEP EPSTALL bit.
    #3
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:Problem with clearing stall on bulk pipes on PIC32 / USB library 2.8 2011/05/17 06:26:22 (permalink)
    0
    OK, the bug was reproduced on my side, too.

    Test code
    I picked up "USB Device - WinUSB - Generic Driver Demo" example for the base code.
    The modification for this test is simple.

    On the firmware, one extra command (0x82) is added, which calls USBStallEndpoint() for the bulk IN EP.
    This firmware was loaded to Explorer16 + PIC32MX795F512L PIM
      
    C:\Microchip Solutions v2010-10-19\USB Device - WinUSB - Generic Driver Demo\
    WinUSB Simple Demo - Firmware\main.c

    void ProcessIO(void)
    {  
            ...

            switch(OUTPacket[0])                    //Data arrived, check what kind of command might be in the packet of data.
            {
                case 0x80:  //Toggle LED(s) command from PC application.
                    ...
                    break;
                case 0x81:  //Get push button state command from PC application.
                    ...
                    break;

                case 0x82:  // HALT bulk IN EP                     // <-------
                    USBStallEndpoint(USBGEN_EP_NUM, IN_TO_HOST);   // <-------
                    break;                                         // <-------
            }


    On the PC app, two buttons are added to the form, and button click routines are written, as follows.
    The first button send STALL command (0x82) to the device over bulk OUT endpoint.
    The second button calls WinUsb_ResetPipe() for the bulk IN pipe, which sends Clear_Feature( ENDPOINT_HALT ).
    It was better to add Timeout policy...
      
    C:\Microchip Solutions v2010-10-19\USB Device - WinUSB - Generic Driver Demo\
    WinUSB Simple Demo - PC Application - MS VC++ 2005 Express\Form1.h

        [DllImport("winusb.dll" , CharSet = CharSet::Seeifdef, EntryPoint="WinUsb_ResetPipe", CallingConvention=CallingConvention::Winapi)]
        extern "C" BOOL WinUsb_ResetPipe(
            WINUSB_INTERFACE_HANDLE InterfaceHandle,
            UCHAR PipeID);

        public ref class Form1 : public System::Windows::Forms::Form
        {
                ...
                ...
    private: System::Void Stall_btn_Click(System::Object^  sender, System::EventArgs^  e) {    // STALL button
             ULONG BytesWritten = 0;
             unsigned char OutputPacketBuffer[64];
             OutputPacketBuffer[0] = 0x82;                                              // send 0x82
             WinUsb_WritePipe(MyWinUSBInterfaceHandle, 0x01, &OutputPacketBuffer[0], 64, &BytesWritten, NULL); 
             }

    private: System::Void Recover_btn_Click(System::Object^  sender, System::EventArgs^  e) {   // Recover button
                 WinUsb_ResetPipe( MyWinUSBInterfaceHandle, 0x81);                  // call reset pipe
             }


    Result
    Two problems were found.
    1) After bulk IN EP returns STALL, bulk OUT EP also causes STALL (screen_shot: left)
    2) Clear_Feature( ENDPOINT_HALT ) doesn't clear HALT condition on bulk IN EP. Bulk IN EP keeps STALL (screen_shot: right)

    I didn't yet try your fix.
    I'll report it afterward.

    Tsuneo
    post edited by chinzei - 2011/05/17 07:05:26

    Attached Image(s)

    #4
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:Problem with clearing stall on bulk pipes on PIC32 / USB library 2.8 2011/05/18 06:22:21 (permalink)
    0
    Using above test code, I checked this problem on other PIC MCUs.
    As this result shows, STALL problems seem to be common on PIC32MX and PIC24F.
    Smells like silicon bug, though no description about this trouble is found on errata.

    PIC32MX
    Explorer16 + PIC32MX795F512L PIM  -- STALL problems occur
    Explorer16 + PIC32MX460F512L PIM  -- STALL problems occur

    PIC24F
    Explorer16 + PIC24FJ64GB004  PIM  -- STALL problems occur
    Explorer16 + PIC24FJ256GB110 PIM  -- STALL problems occur
    Explorer16 + PIC24FJ256GB210 PIM  -- STALL problems occur

    PIC18F
    PIC18F46J50 PIM           -- No problem
    PIC18F47J53 PIM           -- No problem
    PIC18F87J50 PIM           -- No problem
    PICDEM FSUSB (PIC18F4550) -- No problem

    Under testing
    PIC24FJ256DA210 Dev Board
    Low Pin Count USB Dev Kit


    PIC18F MCUs are free from this problem.
    Here is a trace on PICDEM FSUSB. It works as expected.

    Tsuneo
    post edited by chinzei - 2011/05/18 06:31:45

    Attached Image(s)

    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5