CPU是STM32F207VC,软件使用rt-thread,但是USB部分,还是按照裸奔的方法来移植USB代码,专门建一个任务来处理USB;
以下是我做了一下修改:
在 USBH_Status USBH_MSC_Handle(USB_OTG_CORE_HANDLE *pdev ,void *phost),修改
switch(USBH_MSC_BOTXferParam.MSCState)
{
case USBH_MSC_BOT_INIT_STATE:
USBH_MSC_Init(pdev);
//USBH_MSC_BOTXferParam.MSCState = USBH_MSC_BOT_RESET;
USBH_MSC_BOTXferParam.MSCState = USBH_MSC_GET_MAX_LUN;
break;
让它跳过USBH_MSC_BOTReset();
在int USBH_USR_MSC_Application(void)中,进行u盘的挂载;
现在枚举都没有问题,而且也能到达U盘的读操作:下面的读操作的代码:
static rt_size_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
{
BYTE status = USBH_MSC_OK;
if (RT_NULL == dev || !size) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
if(HCD_IsDeviceConnected(&USB_OTG_Core))
{
do
{
status = USBH_MSC_Read10(&USB_OTG_Core, buffer,pos,512 * size);
USBH_MSC_HandleBOTXfer(&USB_OTG_Core ,&USB_Host);
if(!HCD_IsDeviceConnected(&USB_OTG_Core))
{
return RES_ERROR;
}
}
while(status == USBH_MSC_BUSY );
}
if(status == USBH_MSC_OK)
return RES_OK;
return RES_ERROR;
}
单步进void USBH_MSC_HandleBOTXfer (USB_OTG_CORE_HANDLE *pdev ,USBH_HOST *phost),发现红色的代码段返回值不正常;URB_Status 会出现URB_ERROR;而且后面也没有对URB_ERROR进行处理,导致一直在这里死循环;
case USBH_MSC_BOT_DATAIN_STATE:
URB_Status = HCD_GetURB_State(pdev , MSC_Machine.hc_num_in);
/* BOT DATA IN stage */
if((URB_Status == URB_DONE) ||(USBH_MSC_BOTXferParam.BOTStateBkp != USBH_MSC_BOT_DATAIN_STATE))
{
BOTStallErrorCount = 0;
USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_BOT_DATAIN_STATE;
if(remainingDataLength > MSC_Machine.MSBulkInEpSize)
{
USBH_BulkReceiveData (pdev,
datapointer,
MSC_Machine.MSBulkInEpSize ,
MSC_Machine.hc_num_in);
remainingDataLength -= MSC_Machine.MSBulkInEpSize;
datapointer = datapointer + MSC_Machine.MSBulkInEpSize;
}
else if ( remainingDataLength == 0)
{
/* If value was 0, and successful transfer, then change the state */
USBH_MSC_BOTXferParam.BOTState = USBH_MSC_RECEIVE_CSW_STATE;
}
else
{
USBH_BulkReceiveData (pdev,
datapointer,
remainingDataLength ,
MSC_Machine.hc_num_in);
remainingDataLength = 0; /* Reset this value and keep in same state */
}
}
else if(URB_Status == URB_STALL)
{
/* This is Data Stage STALL Condition */
error_direction = USBH_MSC_DIR_IN;
USBH_MSC_BOTXferParam.BOTState = USBH_MSC_BOT_ERROR_IN;
/* Refer to USB Mass-Storage Class : BOT (www.usb.org)
6.7.2 Host expects to receive data from the device
3. On a STALL condition receiving data, then:
The host shall accept the data received.
The host shall clear the Bulk-In pipe.
4. The host shall attempt to receive a CSW.
USBH_MSC_BOTXferParam.BOTStateBkp is used to switch to the Original
state after the ClearFeature Command is issued.
*/
USBH_MSC_BOTXferParam.BOTStateBkp = USBH_MSC_RECEIVE_CSW_STATE;
}
break;
什么原因导致URB_Status 会出现URB_ERROR,出现URB_ERROR应该怎么处理?
|