23 #define TIMEOUT_1SEC 1000
24 #define TIMEOUT_2SEC 2000
25 #define DEFAULT_TIMEOUT TIMEOUT_2SEC
28 static USBH_Ep_TypeDef *epOut = NULL;
29 static USBH_Ep_TypeDef *epIn = NULL;
32 static int timeoutFactor;
35 STATIC_UBUF(csw, CSW_LEN);
41 static void ResetRecovery(
void);
65 DEBUG_USB_API_PUTS(
"\nMSDBOT_Init(), typedef size error");
75 if (epIn->parentDevice->speed == PORT_FULL_SPEED)
101 int timeout, result, direction, retVal;
105 result = USBH_WriteB(epOut, cbw, CBW_LEN, DEFAULT_TIMEOUT);
107 if (result != CBW_LEN)
120 timeout = DEFAULT_TIMEOUT + (len / timeoutFactor);
123 result = USBH_ReadB(epIn, data, len, timeout);
125 result = USBH_WriteB(epOut, data, len, timeout);
129 if (result == USB_STATUS_EP_STALLED)
132 USBH_UnStallEpB(epIn);
134 USBH_UnStallEpB(epOut);
137 else if (result <= 0)
145 result = USBH_ReadB(epIn, csw, CSW_LEN, DEFAULT_TIMEOUT);
147 if (result != CSW_LEN)
149 if (result == USB_STATUS_EP_STALLED)
152 USBH_UnStallEpB(epIn);
154 USBH_UnStallEpB(epOut);
156 result = USBH_ReadB(epIn, csw, CSW_LEN, DEFAULT_TIMEOUT);
158 if (result != CSW_LEN)
171 if (CswValid(pCbw) && CswMeaningful(pCbw))
173 if (pCsw->
bCSWStatus == USB_CLASS_MSD_CSW_CMDPASSED)
199 if (((pCsw->
bCSWStatus == USB_CLASS_MSD_CSW_CMDPASSED) ||
200 (pCsw->
bCSWStatus == USB_CLASS_MSD_CSW_CMDFAILED)) &&
231 static void ResetRecovery(
void)
233 USBH_ControlMsgB(&epIn->parentDevice->ep0,
234 USB_SETUP_DIR_H2D | USB_SETUP_RECIPIENT_INTERFACE |
235 USB_SETUP_TYPE_CLASS_MASK,
243 USBH_UnStallEpB(epIn);
244 USBH_UnStallEpB(epOut);
uint32_t dCBWDataTransferLength
int MSDBOT_Xfer(void *cbw, void *data)
Perform an MSD Bulk Only Transfer (BOT).
int MSDBOT_Init(USBH_Ep_TypeDef *out, USBH_Ep_TypeDef *in)
MSDBOT module initialization.
Definitions for the Bulk Only Transport protocol of USB Mass Storage devices.
Bulk Only Transport (BOT) Command Block Wrapper (CBW) typedef.
Bulk Only Transport (BOT) Command Status Wrapper (CSW) typedef.