Author Topic: Endpoint STALLed  (Read 12657 times)

Nik

  • Member
  • ***
  • Posts: 40
Endpoint STALLed
« on: February 09, 2014, 03:19:45 pm »
Hello,

I am trying to implement USB MSD Host using MAX3421.
My device gets enumerated properly.

But on sending a SCSI request(Test Unit Ready or Read capacity) , I get Endpoint STALL error.

Any pointers to get it working ?

Appreciate your time and help.



Regards,
Nik

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Endpoint STALLed
« Reply #1 on: February 09, 2014, 05:39:46 pm »
In the mass storage class, STALL can indicate many things including invalid received CBW, the device has less than or more than the requested amount of data to return, the device can't complete a command.

Compare what you're sending with a working host.

 

tsybezoff

  • Member
  • ***
  • Posts: 10
Re: Endpoint STALLed
« Reply #2 on: February 10, 2014, 06:50:26 am »
When my colleague used MAX USB Chips for host msd driver, he operated with data-toggle register . 'Cause in enumaration process standard usb max host driver has a data-toggle control, but all configuration process is absent at this driver. So, you should look at data-toggle control in enumaration process.

Nik

  • Member
  • ***
  • Posts: 40
Re: Endpoint STALLed
« Reply #3 on: February 10, 2014, 01:28:33 pm »
Thanks Jan, tsybezoff,

I did try something differently to see if my CBW was wrong. It worked for CBW but now I have issues in receiving CSW. Working on it.

Thanks again.

Regards,
Nik

Nik

  • Member
  • ***
  • Posts: 40
Re: Endpoint STALLed
« Reply #4 on: February 10, 2014, 02:01:07 pm »
Hi again,

I have  a very basic doubt.

Do I need to send anything (from Host to Device) to read the CSW (from Device to Host) ?


Regards,
Nik

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: Endpoint STALLed
« Reply #5 on: February 10, 2014, 03:34:05 pm »
Do I need to send anything (from Host to Device) to read the CSW (from Device to Host) ?
The CSW should be automatically available on the IN pipe when the command completes.

The host must send an IN of course. The driver doesn't have to send anything specific to get the CSW. It should be available after the data transfer (if any) is complete.

Nik

  • Member
  • ***
  • Posts: 40
Re: Endpoint STALLed
« Reply #6 on: February 10, 2014, 04:47:16 pm »
Thank Barry.

I implemented what you had mentioned.

There no error when I send the CBW and read the CSW. But the CSW data is not at all correct.


Regards,
Nik

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: Endpoint STALLed
« Reply #7 on: February 10, 2014, 08:11:37 pm »
What's wrong with the CSW data?

Nik

  • Member
  • ***
  • Posts: 40
Re: Endpoint STALLed
« Reply #8 on: February 11, 2014, 11:58:29 am »
I think my BULK-IN transfer is at fault.

Please have a look at the code below and let me know if something is missing :


UINT8_T  fnReadCapacity(void)
{

   UINT8_T au8BotCommand[31];
   UINT8_T au8CSWReceive[13];

    //CBW Signature in Little Endian
    au8BotCommand[3] =  0x55;
    au8BotCommand[2] =  0x53;
    au8BotCommand[1] =  0x42;
    au8BotCommand[0] =  0x43;

    //CBW Tag in Little Endian
    au8BotCommand[7] =  0x25;
    au8BotCommand[6] =  0x49;
    au8BotCommand[5] =  0x44;
    au8BotCommand[4] =  0x41;

    //Data Transfer Length in Little Endian
    au8BotCommand[11] = 0x08;
    au8BotCommand[10] = 0x00;
    au8BotCommand[9]  = 0x00;
    au8BotCommand[8]  = 0x00;


    //Data Transfer direction
    au8BotCommand[12] = 0x80;  //Device to host

    //LUN
    au8BotCommand[13] = 0x00;  //Zero

    //CBW Length
    au8BotCommand[14] = 0x0A;

    //Read Capacity command in Little Endian
    au8BotCommand[24] = 0x25;
    au8BotCommand[23] = 0x00;
    au8BotCommand[22] = 0x00;
    au8BotCommand[21] = 0x00;
    au8BotCommand[20] = 0x00;
    au8BotCommand[19] = 0x00;
    au8BotCommand[18] = 0x00;
    au8BotCommand[17] = 0x00;
    au8BotCommand[16] = 0x00;
    au8BotCommand[15] = 0x00;

     //Host Bulk Out (SCSI Read CBW)

     u8LocalReturn = fnUsbHostBulkOut(25, au8BotCommand);

   

    Bulk-Out is giving back success.
   //Bulk Out was successful
   if(SUCCESS == u8LocalReturn)
   {
     
     //Host Bulk In (EP and data length)
     u8LocalReturn = fnUsbHostBulkIn(READ_CAPACITY_DATA_LENGTH,
                                          au8ReadCapacityData);


    //Bulk In was successful
      if(SUCCESS == u8LocalReturn)
      {
        Bulk-In is failing. I am getting EP Stall error.
      }

  }




}



INT8_T fnUsbHostBulkIn(UINT32_T u32Length, UINT8_T * ptu8DataBuffer)
{
  UINT16_T u16BytesRead;

  UINT16_T u16LMaxPacketSize = u16MaxPacketSize;

  UINT32_T u32TotalTransferred = ZERO;

  UINT16_T u16ResultCode;

  INT8_T s8LocalReturn;

  UINT8_T u8TransferStatus;

  UINT8_T u8NoOfBytesReceived;

  printf("USB Host Bulk In\n");



  // Set toggle value.
  fnWriteMax3421Reg(rHCTL, u8RecvToggle);

  u8TransferStatus = INCOMPLETE_TRANSFER;

  while ((u8TransferStatus == INCOMPLETE_TRANSFER))
  {

    // Start IN transfer
    u16ResultCode = fnUsbSendPktToDev(tokIN, u8InEpAddress);


    if (u16ResultCode)
    {
      s8LocalReturn = u16ResultCode;
      break;
    }



   else
   {

     // number of received bytes
     u8NoOfBytesReceived = fnReadMax3421Reg(rRCVBC);

      // Read the data from the FIFO.
     fnReadBytes(rRCVFIFO, u16BytesRead, ptu8DataBuffer);

     // Clear the IRQ & free the buffer
     fnWriteMax3421Reg(rHIRQ,bmRCVDAVIRQ);


     // add this packet's byte count to total transfer length
     u32TotalTransferred += u8NoOfBytesReceived;


     // Check for transfer complete
     if ((u8NoOfBytesReceived < u16LMaxPacketSize) || (u32TotalTransferred >= u32Length))
     {

       u8TransferStatus = COMPLETE_TRANSFER ;

       s8LocalReturn = u16ResultCode;

       //To make sure we break out of the while loop,
       //although TRANSFER_COMPLETE will break it
       break;
     }

     else
     {
       ;
     }

   }

return (u8LocalReturn);


}



Any help is greatly appreciated.


Regards,
Nik

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: Endpoint STALLed
« Reply #9 on: February 11, 2014, 01:29:14 pm »
You signature is backwards. The BOT spec says:

dCBWSignature:
Signature that helps identify this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW.

So 55 should be first. It looks like you wrote the word backwards, and then put the indexes in backwards. Personally, I have a function for writing words in USB order, so my code would say:

PutUSBWord32(&au8BotCommand[0], 0x43425355);

Then I don't confuse myself.
« Last Edit: February 11, 2014, 01:33:54 pm by Barry Twycross »

Nik

  • Member
  • ***
  • Posts: 40
Re: Endpoint STALLed
« Reply #10 on: February 11, 2014, 02:07:37 pm »
Thank Barry !

That was really stupid.

Having fixed the CBW signature, I am still having STALL issue.

The part
   // Start IN transfer
      u16ResultCode = fnUsbSendPktToDev(tokIN, u8InEpAddress);


is giving back STALL error. It is called  while doing Host Bulk In (CSW).


Regards,
Nik

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: Endpoint STALLed
« Reply #11 on: February 11, 2014, 03:48:58 pm »
It looks like you have the same issue with the transfer length.

Nik

  • Member
  • ***
  • Posts: 40
Re: Endpoint STALLed
« Reply #12 on: February 11, 2014, 03:58:05 pm »
Barry, I had fixed that when you pointed out the Signature issue.

Here is my new set of command data :

//CBW Signature in Little Endian
    au8BotCommand[0] =  0x55;
    au8BotCommand[1] =  0x53;
    au8BotCommand[2] =  0x42;
    au8BotCommand[3] =  0x43;



    //CBW Tag in Little Endian
    au8BotCommand[4] =  0x25;
    au8BotCommand[5] =  0x49;
    au8BotCommand[6] =  0x44;
    au8BotCommand[7] =  0x41;

    //Data Transfer Length in Little Endian
    au8BotCommand[8]   = 0x08;
    au8BotCommand[9]   = 0x00;
    au8BotCommand[10]  = 0x00;
    au8BotCommand[11]  = 0x00;


    //Data Transfer direction
    au8BotCommand[12] = 0x80;  //Device to host

    //LUN
    au8BotCommand[13] = 0x00;  //Zero

    //CBW Length
    au8BotCommand[14] = 0x0A;

    //Read Capacity command
    au8BotCommand[24] = 0x25;
    au8BotCommand[23] = 0x00;
    au8BotCommand[22] = 0x00;
    au8BotCommand[21] = 0x00;
    au8BotCommand[20] = 0x00;
    au8BotCommand[19] = 0x00;
    au8BotCommand[18] = 0x00;
    au8BotCommand[17] = 0x00;
    au8BotCommand[16] = 0x00;
    au8BotCommand[15] = 0x00;


Thank you again !

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: Endpoint STALLed
« Reply #13 on: February 11, 2014, 07:04:18 pm »
Next question would be what's the device? Is it a device which is expected to behave well, or something like a cheap memory stick which isn't.

You could try sending a request sense to see what the device is complaining about, if you can get request sense to work. If its a dubious device, you could try sending it a few inquiries and test unit readies first. I'm not sure a read capacity should work if the unit isn't ready, so a test unit ready is a good idea anyway.

tsybezoff

  • Member
  • ***
  • Posts: 10
Re: Endpoint STALLed
« Reply #14 on: February 12, 2014, 02:28:23 am »
//Read Capacity command
    au8BotCommand[24] = 0x25;
    au8BotCommand[23] = 0x00;
    au8BotCommand[22] = 0x00;
    au8BotCommand[21] = 0x00;
    au8BotCommand[20] = 0x00;
    au8BotCommand[19] = 0x00;
    au8BotCommand[18] = 0x00;
    au8BotCommand[17] = 0x00;
    au8BotCommand[16] = 0x00;
    au8BotCommand[15] = 0x00;

May be au8BotCommand[15] = 0x25;