你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32 USB中断传输的问题,急!

[复制链接]
xchke 提问时间:2010-4-2 12:51 /
        大家好,最近用STM32英贝特开发板调试USB,例程JoyStickMouse用端点EP1来发送数据(EP1_IN),我想添加一个端点来接收数据,情况如下:
1) 添加EP_OUT端点,用bus hound调试,能正确进行读、写;
2) 添加EP2_OUT端点,则bus hound只能接收数据无法发数据;
3) 如果改为EP1_OUT、EP2_IN,则bus hound只能发数据无法接收数据。
似乎,在中断模式下,只能用EP1进行收发数据,请各位指教!
涉及的相关代码如下:

/**************************************************************
//描述符修改
**************************************************************/
/************** Descriptor of Joystick Mouse interface ****************/
    /* 09 */
    0x09,         /*bLength: Interface Descriptor size*/
    USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
    0x00,         /*bInterfaceNumber: Number of Interface*/
    0x00,         /*bAlternateSetting: Alternate setting*/
    0x02,         /*bNumEndpoints: Number of endpoints except EP0*/
    0x00,         /*bInterfaceClass: HID*/
    0x00,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
    0x00,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
    0,            /*iInterface: Index of string descriptor*/
    /******************** Descriptor of EP1_OUT ********************/
    /* 18 */
    0x07,          /*bLength: Endpoint Descriptor size*/
    USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/

    0x01,          /*bEndpointAddress: Endpoint Address (OUT)*/ 
                // bit 3...0 : the endpoint number
                // bit 6...4 : reserved
                // bit 7     : 0(OUT), 1(IN)
    0x03,          /*bmAttributes: Interrupt endpoint*/
     // bit 1...0 : Transfer type
                //                00(CONTROL), 01(ISOCHRONOUS), 10(BULK), 11(INTERRUPT)
                // bit 3...2 : Synchronization type
                //                00(No Synch), 01(Asynchronous), 10(Adaptive), 11(Synchronous)
                // bit 5...4 : Endpoint Usage type
                //                00(data), 01(Feedback), 10(Implicit feedback data endpoint), 11(Reserved)
                // bit 7...6 : Reserved, must be zero
    0x40,          /*wMaxPacketSize: 64 Byte max */
    0x00,
    0x0a,          /*bInterval: Polling Interval (10 ms)*/

     /* 25 */
 /******************** Descriptor of EP2_IN ********************/    
    0x07,          /*bLength: Endpoint Descriptor size*/
    USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/

    0x82,          /*bEndpointAddress: Endpoint Address (IN)*/
    0x03,          /*bmAttributes: Interrupt endpoint*/
    0x04,          /*wMaxPacketSize: 4 Byte max */
    0x00,
    0x0a,          /*bInterval: Polling Interval (10 ms)*/
/* 32 */

/**************************************************************
//复位函数
**************************************************************/
//*******************************************************
//  TODO: Add your code here!
//*******************************************************
  /* Initialize Endpoint 1 */
  // Set the endpoint type
  SetEPType(ENDP1, EP_INTERRUPT);
  // Set the endpoint data buffer address
  SetEPRxAddr(ENDP1, ENDP1_RXADDR);
  // Set the number of recevie data
  SetEPRxCount(ENDP1, ENDP1_PACKETSIZE);
  // Initialize the RX/TX status
  SetEPRxStatus(ENDP1, EP_RX_VALID);
  SetEPTxStatus(ENDP1, EP_TX_DIS);

  /* Initialize Endpoint 2 */
  // Set the endpoint type
  SetEPType(ENDP2, EP_INTERRUPT);
  // Set the endpoint data buffer address
  SetEPTxAddr(ENDP2, ENDP2_TXADDR);
  // Set the number of transmit data
  SetEPTxCount(ENDP2, 4);
  // Initialize the RX/TX status
  SetEPRxStatus(ENDP2, EP_RX_DIS);
  SetEPTxStatus(ENDP2, EP_TX_NAK);

/**************************************************************
//正确接收数据回调函数
**************************************************************/
void CTR_OUT1(void)
{
  unsigned char  pRev[64];
  unsigned short wCount;  
 
  wCount = GetEPRxCount(ENDP1);    //获取收到的长度
  PMAToUserBufferCopy(pRev, GetEPRxAddr(ENDP1), wCount);  //复制数据
  SetEPRxValid(ENDP1);   //设置端点有效,以接收下一次数据
}
/**************************************************************
//发送数据
**************************************************************/
/*copy mouse position info in ENDP1 Tx Packet Memory Area*/
  UserToPMABufferCopy(Mouse_Buffer, GetEPTxAddr(ENDP2), 4);
  /* Set the number of transmit data */
  SetEPTxCount(ENDP2, 4);
  /* enable endpoint for transmission */
  SetEPTxValid(ENDP2);

/**************************************************************
//正确发送数据回调函数
**************************************************************/
void CTR_IN2(void)
{
 SetEPRxStatus(ENDP2, EP_RX_DIS);
 SetEPTxStatus(ENDP2, EP_TX_NAK);
}
收藏 评论0 发布时间:2010-4-2 12:51

举报

0个回答
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版