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