USB

RTT 2.0.1 USB存储设备问题,枚举到USBREQ_GET_MAX_LUN后复位

发布于 2015-10-12 16:50:11
RTT 2.0.1 USB存储设备问题,枚举到USBREQ_GET_MAX_LUN后复位
不能获取CBW包,

是不是底层哪还没写好,组件用的都是2.0.1带的

弄了很久一直还是这样,在获取完USBREQ_GET_MAX_LUN后复位然后一直_get_device_descriptor又复位再设置USB_ConfigEP



Bus Hound 6.01 capture on Windows Vista (x64). Complements of www.perisoft.net

Device - Device ID (followed by the endpoint for USB devices)
(15) USB Input Device
(23) Unknown USB Device (Device Descriptor Request Failed)
(27) Unknown USB Device (Invalid Device Descriptor)
(30) USB Mass Storage Device
(31) USB Mass Storage Device
(32) STM SD Flash Disk [ROM=1.0 ]
Length - Total transfer length
Phase - Phase Type
CTL USB control transfer
IN Data in transfer
RESET bus reset
USTS USB status
ok command complete
Data - Hex dump of the data transferred
Descr - Description of the phase
Cmd... - Position in the captured data


Device Length Phase Data Description Cmd.Phase.Ofs(rep)
------ -------- ----- ------------------------ ---------------- ------------------
30.0 CTL 80 06 00 01 00 00 12 00 GET DESCRIPTOR 1.1.0
30.0 18 IN 12 01 00 02 08 00 00 40 .......@ 1.2.0
ff 0e 01 00 00 02 01 02 ........ 1.2.8
03 01 .. 1.2.16
30.0 CTL 80 06 00 02 00 00 09 00 GET DESCRIPTOR 2.1.0
30.0 9 IN 09 02 20 00 01 01 00 c0 .. ..... 2.2.0
32 2 2.2.8
30.0 CTL 80 06 00 02 00 00 20 00 GET DESCRIPTOR 3.1.0
30.0 32 IN 09 02 20 00 01 01 00 c0 .. ..... 3.2.0
32 09 04 00 00 02 08 06 2....... 3.2.8
50 00 07 05 02 02 40 00 P.....@. 3.2.16
00 07 05 82 02 40 00 00 .....@.. 3.2.24
30.0 CTL 80 06 00 03 00 00 02 00 GET DESCRIPTOR 4.1.0
30.0 2 IN 04 03 .. 4.2.0
30.0 CTL 80 06 00 03 00 00 04 00 GET DESCRIPTOR 5.1.0
30.0 4 IN 04 03 09 04 .... 5.2.0
30.0 CTL 80 06 03 03 09 04 02 00 GET DESCRIPTOR 6.1.0
30.0 2 IN 1a 03 .. 6.2.0
30.0 CTL 80 06 03 03 09 04 1a 00 GET DESCRIPTOR 7.1.0
30.0 26 IN 1a 03 33 00 32 00 30 00 ..3.2.0. 7.2.0
32 00 31 00 39 00 31 00 2.1.9.1. 7.2.8
39 00 38 00 33 00 30 00 9.8.3.0. 7.2.16
31 00 1. 7.2.24
30.0 CTL 00 09 01 00 00 00 00 00 SET CONFIG 8.1.0
30.0 CTL 01 0b 00 00 00 00 00 00 SET INTERFACE 9.1.0
30.0 CTL a1 fe 00 00 00 00 01 00 GET MAX LUN 10.1.0
30.0 1 IN 00 . 10.2.0
30.2 USTS c0000004 stall pid 11.1.0(6)
30 RESET 12.1.0(6)
30 ok 12.2.0



nitialize rti_start:0 done

| /
- RT - Thread Operating System
/ | 2.0.1 build Oct 12 2015
2006 - 2015 Copyright by rt-thread team
do components intialization.
initialize rti_board_end:0 done
initialize st7735_init:0 done
initialize rt_spi_init:0 done
initialize key_io_init:0 done
initialize finsh_system_init:0 done
initialize dfs_init:0 done
initialize elm_init:0 done
W25Q16BV or W25Q16CL or W25Q16CV detection

rt_usbd_device_new
rt_usbd_config_new
rt_usbd_function_new
rt_usbd_interface_new
rt_usbd_altsetting_new
rt_usbd_endpoint_new
rt_usbd_endpoint_new
rt_usbd_altsetting_add_endpoint
rt_usbd_altsetting_add_endpoint
rt_usbd_interface_add_altsetting
rt_usbd_set_altsetting
rt_usbd_find_altsetting
rt_usbd_function_add_interface
rt_usbd_config_add_function
rt_usbd_device_add_config
assigned 2
assigned 2
rt_usbd_set_config
rt_usbd_find_config
message type 5
reset 0
finsh>>message type 5
reset 0
message type 0
_get_device_descriptor
message type 5
reset 0
message type 0
_set_address 3
message type 0
_get_device_descriptor
message type 0
_get_config_descriptor
message type 0
_get_string_descriptor
message type 0
_get_string_descriptor
message type 0
_get_string_descriptor
message type 0
_get_device_descriptor
message type 0
_get_config_descriptor
message type 0
_get_config_descriptor
message type 0
_get_string_descriptor
message type 0
_get_string_descriptor
message type 0
_get_string_descriptor
message type 0
_get_string_descriptor
message type 0
_set_config
rt_usbd_set_config
rt_usbd_find_config
USB_Configure: 1
USB_DisableEP: 0x02
USB_ConfigEP: 0x02 64
USB_EnableEP: 0x02
USB_ResetEP: 0x02
USB_DisableEP: 0x82
USB_ConfigEP: 0x82 64
USB_EnableEP: 0x82
USB_ResetEP: 0x82
Mass storage function enabled
message type 0
rt_usbd_find_interface
mstorage_interface_handler
USBREQ_GET_MAX_LUN
message type 5
reset 7
message type 0
_get_device_descriptor
message type 5
reset 7
message type 0
_set_address 4
message type 0
_get_device_descriptor
message type 0
_set_config
rt_usbd_set_config
rt_usbd_find_config
USB_Configure: 1
USB_DisableEP: 0x02
USB_ConfigEP: 0x02 64
USB_EnableEP: 0x02
USB_ResetEP: 0x02
USB_DisableEP: 0x82
USB_ConfigEP: 0x82 64
USB_EnableEP: 0x82
USB_ResetEP: 0x82
message type 5
reset 7
message type 0
_get_device_descriptor
message type 5
reset 7
message type 0
_set_address 3
message type 0
_get_device_descriptor
message type 0
_set_config
rt_usbd_set_config
rt_usbd_find_config
USB_Configure: 1
USB_DisableEP: 0x02
USB_ConfigEP: 0x02 64
USB_EnableEP: 0x02
USB_ResetEP: 0x02
USB_DisableEP: 0x82
USB_ConfigEP: 0x82 64
USB_EnableEP: 0x82
USB_ResetEP: 0x82
message type 5
reset 7
message type 0
_get_device_descriptor
message type 5
reset 7
message type 0
_set_address 4
message type 0
_get_device_descriptor
message type 0
_set_config
rt_usbd_set_config
rt_usbd_find_config
USB_Configure: 1
USB_DisableEP: 0x02
USB_ConfigEP: 0x02 64
USB_EnableEP: 0x02
USB_ResetEP: 0x02
USB_DisableEP: 0x82
USB_ConfigEP: 0x82 64
USB_EnableEP: 0x82
USB_ResetEP: 0x82
message type 5
reset 7
message type 0
_get_device_descriptor
message type 5
reset 7
message type 0
_set_address 3
message type 0
_get_device_descriptor
message type 0
_set_config
rt_usbd_set_config
rt_usbd_find_config
USB_Configure: 1
USB_DisableEP: 0x02
USB_ConfigEP: 0x02 64
USB_EnableEP: 0x02
USB_ResetEP: 0x02
USB_DisableEP: 0x82
USB_ConfigEP: 0x82 64
USB_EnableEP: 0x82
USB_ResetEP: 0x82
message type 5
reset 7
message type 0
_get_device_descriptor
message type 5
reset 7
message type 0
_set_address 4
message type 0
_get_device_descriptor
message type 0
_set_config
rt_usbd_set_config
rt_usbd_find_config
USB_Configure: 1
USB_DisableEP: 0x02
USB_ConfigEP: 0x02 64
USB_EnableEP: 0x02
USB_ResetEP: 0x02
USB_DisableEP: 0x82
USB_ConfigEP: 0x82 64
USB_EnableEP: 0x82
USB_ResetEP: 0x82
message type 5
reset 7
message type 0
_get_device_descriptor
message type 5
reset 7
message type 0
_set_address 3
message type 0
_get_device_descriptor
message type 0
_set_config
rt_usbd_set_config
rt_usbd_find_config
USB_Configure: 1
USB_DisableEP: 0x02
USB_ConfigEP: 0x02 64
USB_EnableEP: 0x02
USB_ResetEP: 0x02
USB_DisableEP: 0x82
USB_ConfigEP: 0x82 64
USB_EnableEP: 0x82
USB_ResetEP: 0x82




/*----------------------------------------------------------------------------
* U S B - K e r n e l
*----------------------------------------------------------------------------
* Name: usbhw.c
* Purpose: USB Hardware Layer Module for NXP's LPC17xx MCU
* Version: V1.20
*----------------------------------------------------------------------------
* This software is supplied "AS IS" without any warranties, express,
* implied or statutory, including but not limited to the implied
* warranties of fitness for purpose, satisfactory quality and
* noninfringement. Keil extends you a royalty-free right to reproduce
* and distribute executable files created using this software for use
* on NXP Semiconductors LPC family microcontroller devices only. Nothing
* else gives you the right to use this software.
*
* Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
*----------------------------------------------------------------------------
* History:
* V1.20 Added USB_ClearEPBuf
* V1.00 Initial Version
*----------------------------------------------------------------------------*/
#include
#include

#include "stm32f10x.h"

#include "usb.h"
#include "usb_cfg.h"
#include "usb_regs.h"
#include "usb_hw.h"
#include "usb_user.h"

#define RT_DEBUG_USB_HW (0)

#define EP_Mask(ep) (uint8_t)(ep&0x7f)
#define vSetEPRxStatus(st) (SaveRxStatus = st)
#define vSetEPTxStatus(st) (SaveTxStatus = st)

static uint16_t SaveRxStatus;
static uint16_t SaveTxStatus;

/*
* USB Initialize Function
* Called by the User to initialize USB
* Return Value: None
*/
void USB_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn; //USB低优先级中断请求
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级 1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级为 0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

_SetISTR(0);
_SetCNTR(IMR_MSK);
}

/*
* USB Connect Function
* Called by the User to Connect/Disconnect USB
* Parameters: con: Connect/Disconnect
* Return Value: None
*/

void USB_Connect(uint32_t con)
{

}

/*
* USB Reset Function
* Called automatically on USB Reset
* Return Value: None
*/
void USB_Reset(void)
{
_SetBTABLE(BTABLE_ADDRESS);

/* Initialize Endpoint 0 */
_SetEPType(ENDP0, EP_CONTROL);
_SetEPRxAddr(ENDP0, ENDP0_RXADDR);
_SetEPTxAddr(ENDP0, ENDP0_TXADDR);
_SetEPRxCount(ENDP0, USB_MAX_PACKET0);
_SetEPTxCount(ENDP0, USB_MAX_PACKET0);
_SetEPRxStatus(ENDP0, EP_RX_VALID);
_SetEPTxStatus(ENDP0, EP_TX_NAK);
_Clear_Status_Out(ENDP0);

/* Initialize Endpoint 1 */
_SetEPType(ENDP1, EP_INTERRUPT);
_SetEPRxAddr(ENDP1, ENDP1_RXADDR);
_SetEPTxAddr(ENDP1, ENDP1_TXADDR);
_SetEPRxCount(ENDP1, USB_MAX_PACKET0);
_SetEPTxCount(ENDP1, USB_MAX_PACKET0);
_SetEPRxStatus(ENDP1, EP_RX_VALID);
_SetEPTxStatus(ENDP1, EP_TX_NAK);

/* Initialize Endpoint 2 */
_SetEPType(ENDP2, EP_BULK);
_SetEPRxAddr(ENDP2, ENDP2_RXADDR);
_SetEPTxAddr(ENDP2, ENDP2_TXADDR);
_SetEPRxCount(ENDP2, USB_MAX_PACKET0);
_SetEPTxCount(ENDP2, USB_MAX_PACKET0);
_SetEPRxStatus(ENDP2, EP_RX_VALID);
_SetEPTxStatus(ENDP2, EP_TX_NAK);

USB_SetAddress(0);
}

/*
* USB Suspend Function
* Called automatically on USB Suspend
* Return Value: None
*/
void USB_Suspend(void)
{
/* Performed by Hardware */
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_Suspend
"));
}

/*
* USB Resume Function
* Called automatically on USB Resume
* Return Value: None
*/
void USB_Resume(void)
{
/* Performed by Hardware */
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_Resume
"));
}

/*
* USB Remote Wakeup Function
* Called automatically on USB Remote Wakeup
* Return Value: None
*/
void USB_WakeUp(void)
{
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_WakeUp
"));
}

/*
* USB Remote Wakeup Configuration Function
* Parameters: cfg: Enable/Disable
* Return Value: None
*/

void USB_WakeUpCfg(uint32_t cfg)
{
/* Not needed */
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_WakeUpCfg
"));
}

/*
* USB Set Address Function
* Parameters: adr: USB Address
* Return Value: None
*/
void USB_SetAddress(uint8_t adr)
{
adr = adr & DADDR_ADD;

_SetDADDR(adr | DADDR_EF); /* set device address and enable function */
}

/*
* USB Configure Function
* Parameters: cfg: Configure/Deconfigure
* Return Value: None
*/
void USB_Configure(uint32_t cfg)
{
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_Configure: %d
", cfg));
}

/*
* Configure USB Endpoint according to Descriptor
* Parameters: pEPD: Pointer to Endpoint Descriptor
* Return Value: None
*/
void USB_ConfigEP(uep_desc_t pEPD)
{
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_ConfigEP: 0x%02x %d
",
pEPD->bEndpointAddress,
pEPD->wMaxPacketSize));

if((pEPD->bEndpointAddress & 0x80) == 0)//OUT
{
_SetEPRxCount(EP_Mask(pEPD->bEndpointAddress), pEPD->wMaxPacketSize);
}
else //IN
{
_SetEPTxCount(EP_Mask(pEPD->bEndpointAddress), pEPD->wMaxPacketSize);
}
}

/*
* Set Direction for USB Control Endpoint
* Parameters: dir: Out (dir == 0), In (dir <> 0)
* Return Value: None
*/
void USB_DirCtrlEP(uint32_t dir)
{
/* Not needed */

RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_DirCtrlEP
"));
}

/*
* Enable USB Endpoint
* Parameters: EPNum: Endpoint Number
* EPNum.0..3: Address
* EPNum.7: Dir
* Return Value: None
*/
void USB_EnableEP(uint8_t EPNum)
{
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_EnableEP: 0x%02x
", EPNum));

if((EPNum & 0x80) == 0) //OUT
{
_SetEPRxStatus(EP_Mask(EPNum), EP_RX_VALID);
}
else //IN
{
_SetEPTxStatus(EP_Mask(EPNum), EP_TX_VALID);
}
}

/*
* Disable USB Endpoint
* Parameters: EPNum: Endpoint Number
* EPNum.0..3: Address
* EPNum.7: Dir
* Return Value: None
*/
void USB_DisableEP(uint8_t EPNum)
{
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_DisableEP: 0x%02x
", EPNum));

if((EPNum & 0x80) == 0) //OUT
{
_SetEPRxStatus(EP_Mask(EPNum), EP_RX_DIS);
}
else //IN
{
_SetEPTxStatus(EP_Mask(EPNum), EP_TX_DIS);
}
}

/*
* Reset USB Endpoint
* Parameters: EPNum: Endpoint Number
* EPNum.0..3: Address
* EPNum.7: Dir
* Return Value: None
*/
void USB_ResetEP(uint8_t EPNum)
{
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_ResetEP: 0x%02x
", EPNum));

if((EPNum & 0x80) == 0) //OUT
{
_SetEPRxStatus(EP_Mask(EPNum), EP_RX_VALID);
}
else //IN
{
_SetEPTxStatus(EP_Mask(EPNum), EP_TX_NAK);
}
}

/*
* Set Stall for USB Endpoint
* Parameters: EPNum: Endpoint Number
* EPNum.0..3: Address
* EPNum.7: Dir
* Return Value: None
*/
void USB_SetStallEP(uint8_t EPNum)
{
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_SetStallEP: 0x%02x
", EPNum));

if((EPNum & 0x80) == 0) //OUT
{
_SetEPRxStatus(EP_Mask(EPNum), EP_RX_STALL);
}
else //IN
{
_SetEPTxStatus(EP_Mask(EPNum), EP_TX_STALL);
}
}

/*
* Clear Stall for USB Endpoint
* Parameters: EPNum: Endpoint Number
* EPNum.0..3: Address
* EPNum.7: Dir
* Return Value: None
*/
void USB_ClrStallEP(uint8_t EPNum)
{
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_ClrStallEP: 0x%02x
", EPNum));

if((EPNum & 0x80) == 0) //OUT
{
_SetEPRxStatus(EP_Mask(EPNum), EP_RX_VALID);
}
else //IN
{
_SetEPTxStatus(EP_Mask(EPNum), EP_TX_NAK);
}
}

/*
* Clear USB Endpoint Buffer
* Parameters: EPNum: Endpoint Number
* EPNum.0..3: Address
* EPNum.7: Dir
* Return Value: None
*/
void USB_ClearEPBuf(uint8_t EPNum)
{
RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_ClearEPBuf: 0x%02x
", EPNum));
}

/*
* Read USB Endpoint Data
* Parameters: EPNum: Endpoint Number
* EPNum.0..3: Address
* EPNum.7: Dir
* pData: Pointer to Data Buffer
* Return Value: Number of bytes read
*/
uint32_t USB_ReadEP(uint8_t EPNum, uint8_t *pData)
{
uint32_t wNBytes;
uint16_t wPMABufAddr = _GetEPRxAddr(EP_Mask(EPNum));

/* Get the number of received data on the selected Endpoint */
wNBytes = _GetEPRxCount(EP_Mask(EPNum));

/* Use the memory interface to read the selected Endpoint */
{
uint32_t n = (wNBytes + 1) >> 1;/* /2*/
uint32_t i;
uint32_t *pdwVal;
pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr);
for (i = n; i != 0; i--)
{
*(uint16_t*)pData++ = *pdwVal++;
pData++;
}
}

#if RT_DEBUG_USB_HW
{
int i = wNBytes;

RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("OUT %d :", EP_Mask(EPNum)));
pData -= i;
while(i--)
{
RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("0x%02x ", *pData++));
}
RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("
"));
}
#endif

//// if(EPNum == 0)
//// {
//// _SetEPRxStatus(ENDP0, SaveRState);
//// }
//
// _SetEPRxStatus(EP_Mask(EPNum), EP_RX_VALID);

return (wNBytes);
}

/*
* Write USB Endpoint Data
* Parameters: EPNum: Endpoint Number
* EPNum.0..3: Address
* EPNum.7: Dir
* pData: Pointer to Data Buffer
* cnt: Number of bytes to write
* Return Value: Number of bytes written
*/
uint32_t USB_WriteEP(uint8_t EPNum, uint8_t *pData, uint32_t cnt)
{
uint32_t wNBytes = cnt;
uint16_t wPMABufAddr = _GetEPTxAddr(EP_Mask(EPNum));

/* Use the memory interface to write the selected Endpoint */
if(wNBytes)
{
uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
uint32_t i, temp1, temp2;
uint32_t *pdwVal;
pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr);
for (i = n; i != 0; i--)
{
temp1 = *pData++;
temp2 = *pData++;
temp2 = temp1 + (temp2<<8);
*pdwVal++ = temp2;
}
}

/* Set the number of send data on the selected Endpoint */
_SetEPTxCount(EP_Mask(EPNum), wNBytes);

#if RT_DEBUG_USB_HW
{
int i = wNBytes;

RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("IN %d :", EP_Mask(EPNum)));
pData -= i;
while(i--)
{
RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("0x%02x ", *pData++));
}
RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("
"));
}
#endif

if(EP_Mask(EPNum) == 0)
{
if(_GetEPTxCount(EP_Mask(EPNum)))
{
SaveTxStatus = EP_RX_VALID;
SaveTxStatus = EP_TX_VALID;
RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("EP_RX_VALID EP_TX_VALID
"));
}
else
{
SaveTxStatus = EP_TX_VALID;

RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("EP_TX_VALID
"));
}

_SetEPRxTxStatus(ENDP0, SaveRxStatus, SaveTxStatus);
}

return (wNBytes);
}

/*
* Get USB Last Frame Number
* Parameters: None
* Return Value: Frame Number
*/
uint32_t USB_GetFrame(void)
{
uint32_t val;

RT_DEBUG_LOG(RT_DEBUG_USB | RT_DEBUG_USB_HW, ("USB_GetFrame
"));

return (val);
}

/*
* USB Interrupt Service Routine
*/
void USB_LP_CAN1_RX0_IRQHandler(void)
{
uint32_t wIstr;
uint32_t wCntr;

/* enter interrupt */
rt_interrupt_enter();

wIstr = _GetISTR(); /* Device Interrupt Status */
wCntr = _GetCNTR();

if(wIstr & wCntr & ISTR_CTR)
{
_SetISTR((uint16_t)CLR_CTR);

//while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
{
uint8_t EPnum = (uint8_t)(wIstr & ISTR_EP_ID);
uint8_t EPdir = (uint8_t)(wIstr & ISTR_DIR);
uint32_t EPval;

if(EPnum == 0)//端点0
{
SaveRxStatus = _GetEPRxStatus(ENDP0);
SaveTxStatus = _GetEPTxStatus(ENDP0);

_SetEPRxTxStatus(ENDP0, EP_RX_NAK, EP_TX_NAK);

if(EPdir)//传输方向OUT
{
EPval = _GetENDPOINT(ENDP0);

if(EPval & EP_SETUP)//Setup包
{
RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("USB_EP_SETUP
"));

_ClearEP_CTR_RX(ENDP0);

USB_P_EP[ENDP0](USB_EVT_SETUP);/* Setup Packet */
}
else if(EPval & EP_CTR_RX)
{
RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("USB_EP_OUT
"));

_ClearEP_CTR_RX(ENDP0);

//USB_P_EP[ENDP0](USB_EVT_OUT);/* OUT Endpoint */

if(_GetEPRxCount(ENDP0) == 0)
{
SaveRxStatus = EP_RX_STALL;
SaveTxStatus = EP_TX_STALL;

RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("EP_RX_STALL EP_TX_STALL
"));
}
else
{
SaveRxStatus = EP_RX_STALL;
SaveTxStatus = EP_TX_VALID;

RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("EP_RX_STALL EP_TX_VALID
"));
}
_SetEPRxTxStatus(ENDP0, SaveRxStatus, SaveTxStatus);
}
}
else//传输方向IN
{
RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("USB_EP_IN
"));

_ClearEP_CTR_TX(ENDP0);

//USB_P_EP[ENDP0](USB_EVT_IN);/* IN Endpoint */

if(_GetEPTxCount(ENDP0) == 0)
{
SaveRxStatus = EP_RX_STALL;
SaveTxStatus = EP_TX_STALL;

RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("EP_RX_STALL EP_TX_STALL
"));
}
else
{
SaveRxStatus = EP_RX_VALID;
SaveTxStatus = EP_TX_STALL;

RT_DEBUG_LOG(RT_DEBUG_USB_HW, ("EP_RX_VALID EP_TX_STALL
"));
}
_SetEPRxTxStatus(ENDP0, SaveRxStatus, SaveTxStatus);
}
}
else//端点1 2...
{
EPval = _GetENDPOINT(EPnum);

if(EPval & EP_CTR_RX)
{
_ClearEP_CTR_RX(EPnum);

USB_P_EP[EPnum](USB_EVT_OUT);/* OUT Endpoint */
}

if(EPval & EP_CTR_TX)
{
_ClearEP_CTR_TX(EPnum);

USB_P_EP[EPnum](USB_EVT_IN);/* IN Endpoint */
}
}
}
}

if(wIstr & wCntr & ISTR_RESET)
{
_SetISTR((uint16_t)CLR_RESET);
USB_Reset();

#if USB_RESET_EVENT
USB_Reset_Event();
#endif
}

if(wIstr & wCntr & ISTR_DOVR)
{
_SetISTR((uint16_t)CLR_DOVR);
}

if(wIstr & wCntr & ISTR_ERR)/* Error Interrupt */
{
_SetISTR((uint16_t)CLR_ERR);
}

if(wIstr & wCntr & ISTR_WKUP)
{
_SetISTR((uint16_t)CLR_WKUP);
}

if(wIstr & wCntr & ISTR_SUSP)
{
_SetISTR((uint16_t)CLR_SUSP);
}

if(wIstr & wCntr & ISTR_SOF)/* Start of Frame Interrupt */
{
_SetISTR((uint16_t)CLR_SOF);

#if USB_SOF_EVENT
USB_SOF_Event();
#endif
}

if(wIstr & wCntr & ISTR_ESOF)
{
_SetISTR((uint16_t)CLR_ESOF);
}

rt_interrupt_leave();

return;
}

/**
* @}
*/

查看更多

关注者
0
被浏览
3.1k
4 个回答
hoverxx
hoverxx 2015-10-12
LPC17xx的硬件?

STM32F103VET6
hoverxx
hoverxx 2015-10-16
一直没解决,砍掉所有USB相关组件,用RADIO的USB MSC了

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友