OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 8759|回复: 5

usb hid STM32可以发出,就是收不到数据

[复制链接]

2

主题

15

帖子

0

精华

初级会员

Rank: 2

积分
71
金钱
71
注册时间
2015-3-18
在线时间
7 小时
发表于 2016-2-24 13:24:37 | 显示全部楼层 |阅读模式
5金钱
程序是原子例程的触控鼠标改的,就修改了下描述文件。把LCD显示去掉。
改完之后PC上位机可以收到下位机发出的数据,可是上位机不能发给你下位机
上位机软件上点发送,显示发出数据字节数为-1,这点很不解,什么意思呢。
球高手解答


const uint8_t Joystick_DeviceDescriptor[JOYSTICK_SIZ_DEVICE_DESC] =
  {
    0x12,                       /*bLength */
    USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType 描述符类型,设备描述符为0x01*/
    0x00,                       /*bcdUSB USB版本*/
    0x02,
    0x00,                       /*bDeviceClass*/
    0x00,                       /*bDeviceSubClass*/
    0x00,                       /*bDeviceProtocol*/
    0x40,                       /*bMaxPacketSize 64 端点0最大包长*/
    0x83,                       /*idVendor (0x0483)*/
    0x04,
    0x50,                       /*idProduct = 0x5710*/
    0x57,
    0x00,                       /*bcdDevice rel. 2.00*/
    0x02,
    1,                          /*Index of string descriptor describing
                                                  manufacturer */
    2,                          /*Index of string descriptor describing
                                                 product*/
    3,                          /*Index of string descriptor describing the
                                                 device serial number */
    0x01                        /*bNumConfigurations*/
  }
  ; /* Joystick_DeviceDescriptor */


/* USB Configuration Descriptor */
/*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
//配置描述符
const uint8_t Joystick_ConfigDescriptor[JOYSTICK_SIZ_CONFIG_DESC] =
  {
    0x09, /* bLength: Configuration Descriptor size */
    USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
    JOYSTICK_SIZ_CONFIG_DESC, 0x00,/* wTotalLength: Bytes returned */

    0x01,         /*bNumInterfaces: 1 interface*/
    0x01,         /*bConfigurationValue: Configuration value*/
    0x00,         /*iConfiguration: Index of string descriptor describing
                                     the configuration*/
    0x80,         /*bmAttributes: Self powered */
    0x32,         /*MaxPower 100 mA: this current is used for detecting Vbus*/

    /************** 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*/
    0x03,         /*bInterfaceClass: HID*/
    0x00,//0x01,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
    //0x02,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
    0x00,           //该接口不使用协议
    0,            /*iInterface: Index of string descriptor*/
    /******************** Descriptor of Joystick Mouse HID ********************///HID描述符
    /* 18 */
    0x09,         /*bLength: HID Descriptor size*/
    HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
    0x11,         /*bcdHID: HID Class Spec release number*/
    0x01,
    0x00,         /*bCountryCode: Hardware target country*/
    0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/
    0x22,         /*bDescriptorType*/
    JOYSTICK_SIZ_REPORT_DESC,/*wItemLength: Total length of Report descriptor*/
    0x00,
    /******************** Descriptor of Joystick Mouse endpoint ********************///端点描述符
    /* 27 */
    0x07,          /*bLength: Endpoint Descriptor size*/
    USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/

    0x81,          /*bEndpointAddress: Endpoint Address (IN)*/
    0x03,          /*bmAttributes: Interrupt endpoint*/
    0x40,          /*wMaxPacketSize: 64 Byte max */
    0x00,
    0x01,          /*bInterval: Polling Interval (32 ms)*/
    /* 34 */
    /******************** Descriptor of Joystick Mouse endpoint ********************///端点描述符
    0x07,          /*bLength: Endpoint Descriptor size*/
    USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/

    0x01,          /*bEndpointAddress: Endpoint Address (OUT)*/
    0x03,          /*bmAttributes: Interrupt endpoint*/
    0x40,          /*wMaxPacketSize: 64 Byte max */
    0x00,
    0x01,          /*bInterval: Polling Interval (32 ms)*/
    /* 34 */
  }
  ; /* MOUSE_ConfigDescriptor */
  //报告描述符
const uint8_t Joystick_ReportDescriptor[JOYSTICK_SIZ_REPORT_DESC] =
{
    0x05, 0x01,     /* USAGE_PAGE (Generic Desktop) */
    0x09, 0x00,     /* USAGE (Custom Device)        */
    0xa1, 0x01,     /* COLLECTION (Application)     */
       
        // NEW Start//////////////////////////////////////////////////
       
        /* The Input Report */
        //0x85, 0x01,                /* REPORT_ID (0x01)                                */
        0x09, 0x01,                /* USAGE (0x01)                                        */
        0x15, 0x00,                /* LOGICAL_MINIMUM (0)                         */
        0x26, 0x00, 0xFF,        /* LOGICAL_MAXIMUM (255)         */
        0x75, 0x08,         // REPORT_SIZE (8)
        0x95, 0x40,        //40,         // REPORT_COUNT (64)
        0x81, 0x02,         // INPUT (Data,Var,Abs)

        /* The Output Report */
        //0x85, 0x02,                /* REPORT_ID (0x02)                                */
        0x09, 0x02,                /* USAGE (0x02)                                        */
        0x15, 0x00,                /* LOGICAL_MINIMUM (0)                         */
        0x26, 0x00, 0xFF,        /* LOGICAL_MAXIMUM (255)         */
        0x75, 0x08,         // REPORT_SIZE (8)
        0x95, 0x40,        //40,         // REPORT_COUNT (64)
        0x91, 0x02,                // OUTPUT (Data,Var,Abs)

    0xc0            /* END_COLLECTION            */

}

QQ图片20160224132133.jpg

最佳答案

查看完整内容[请看2#楼]

找到原因了·········· void Joystick_Reset(void) { /* Set Joystick_DEVICE as not configured */ pInformation->Current_Configuration = 0; pInformation->Current_Interface = 0;/*the default Interface*/ /* Current Feature initialization */ pInformation->Current_Feature = Joystick_ConfigDescriptor[7]; SetBTABLE(BTABLE_ADDRESS); /* Initialize Endpoint 0 */ SetEPType(EN ...
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

2

主题

15

帖子

0

精华

初级会员

Rank: 2

积分
71
金钱
71
注册时间
2015-3-18
在线时间
7 小时
 楼主| 发表于 2016-2-24 13:24:38 | 显示全部楼层
找到原因了··········
void Joystick_Reset(void)
{
  /* Set Joystick_DEVICE as not configured */
  pInformation->Current_Configuration = 0;
  pInformation->Current_Interface = 0;/*the default Interface*/

  /* Current Feature initialization */
  pInformation->Current_Feature = Joystick_ConfigDescriptor[7];
  SetBTABLE(BTABLE_ADDRESS);
  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_INTERRUPT);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPRxAddr(ENDP1, ENDP1_RXADDR);
  SetEPTxCount(ENDP1, 64);
  SetEPRxCount(ENDP1, 64);
  SetEPRxStatus(ENDP1, EP_RX_VALID);
  SetEPTxStatus(ENDP1, EP_TX_NAK);
  

  /* Set this device to response on default address */
  SetDeviceAddress(0);
  bDeviceState = ATTACHED;
}

原本这个函数里面未使能接收···········。
回复

使用道具 举报

2

主题

15

帖子

0

精华

初级会员

Rank: 2

积分
71
金钱
71
注册时间
2015-3-18
在线时间
7 小时
 楼主| 发表于 2016-2-24 15:03:24 | 显示全部楼层
最后分享一下源码···
USB HID 描述符才是主要的·················

STM32 USB HID.rar

419.39 KB, 下载次数: 723

回复

使用道具 举报

3

主题

26

帖子

0

精华

初级会员

Rank: 2

积分
65
金钱
65
注册时间
2019-8-3
在线时间
18 小时
发表于 2020-12-14 18:07:40 | 显示全部楼层
我下载了,我的是问题是USB无不认识,怎么回事啊?
回复

使用道具 举报

7

主题

98

帖子

0

精华

高级会员

Rank: 4

积分
839
金钱
839
注册时间
2020-11-13
在线时间
135 小时
发表于 2021-1-14 16:23:04 | 显示全部楼层
philing 发表于 2020-12-14 18:07
我下载了,我的是问题是USB无不认识,怎么回事啊?

老哥解决了吗?我的显示是设备描述符请求失败,不知道啥原因。希望可以交流一下
回复

使用道具 举报

3

主题

26

帖子

0

精华

初级会员

Rank: 2

积分
65
金钱
65
注册时间
2019-8-3
在线时间
18 小时
发表于 2021-1-25 17:17:10 | 显示全部楼层
你的描述有问题
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-9 20:49

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表