stm32f4 discovery开发板usb全速修改测试

来源:互联网 发布:身份证号码找人软件 编辑:程序博客网 时间:2024/05/17 17:42
===============================   博客点滴积累,部分话语和知识点来源于网络,感谢网络资源的提供者======

时间有点长了,根据映像写的,哎,以后做记录要及时呀!!!

1 开发环境 

软件环境: keil4.70, stm32f4cubef4 版本1.3,  HIDDemo_V1.0.2_Setup
 硬件环境:stm32f4 stm32f4discovery    STM32F407VGT6,晶振8MHZ ARM 32-bit Cortex-M4 core,最高运行频率为168MHz  内部集成1 MB Flash memory,192+4 KB SRAM
2 以下以STM324xG_EVAL板为基础修改hid通信测试
路径为:stm32cubef4\STM32Cube_FW_F4_V1.5.0\Projects\STM324xG_EVAL\Applications\USB_Device\CustomHID_Standalone\MDK-ARM
修改有:
1)修改MCU型号和晶振频率(STM32F407VGT6,晶振8MHZ  搜索所有的HSE_VALUE = 8000000 
2)修改系统分频,晶振变了,分频要修改(HSE Frequency(Hz)  = 8000000 PLL_M  = 8 PLL_N = 336
     PLL_P = 2 PLL_Q = 7)

3)选择STM324xG-EVAL_USBD-FS ,修改LED对应的引脚,hid通信测试应该就没有问题

如果想HID双向数据通信可以参考这篇文章:http://www.embed-net.com/forum.php?mod=viewthread&tid=5#lastpost

3 修改实现自定义设备(思路完全来自参考文章http://www.embed-net.com/thread-18-1-1.html)

1)PC基于libusb的实现完全来自参考文章

2)usb设备端修改有:

a 配置描述符 一个输出端点中断模式8字节,一个输入端点批量模式40字节

* USB CUSTOM_HID device Configuration Descriptor */
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
{
  0x09, /* bLength: Configuration Descriptor size */
  USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration 2*/
  USB_CUSTOM_HID_CONFIG_DESC_SIZ,
  /* wTotalLength: Bytes returned 32*/
  0x00,
  0x01,         /*bNumInterfaces: 1 interface*/
  0x01,         /*bConfigurationValue: Configuration value*/
  0x00,         /*iConfiguration: Index of string descriptor describing
  the configuration*/
  0xC0,         /*bmAttributes: bus powered */
  0x32,         /*MaxPower 100 mA: this current is used for detecting Vbus*/
  
  /************** Descriptor of CUSTOM HID interface ****************/
  /* 09 */
  0x09,         /*bLength: Interface Descriptor size*/
  USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type 4*/
  0x00,         /*bInterfaceNumber: Number of Interface*/
  0x00,         /*bAlternateSetting: Alternate setting*/
  0x02,         /*bNumEndpoints*/
  0x00,         /*bInterfaceClass: CUSTOM_HID*/
  0x00,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
  0x00,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
  0,            /*iInterface: Index of string descriptor*/
  /******************** Descriptor of Custom HID endpoints ********************/
  /* 18 */
  0x07,          /*bLength: Endpoint Descriptor size*/
  USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/
  
  CUSTOM_HID_EPIN_ADDR,     /*bEndpointAddress: Endpoint Address (IN) 0x81*/
  0x02,          /*bmAttributes: bulk endpoint*/
  CUSTOM_HID_EPIN_SIZE, /*wMaxPacketSize:  0x28*/
  0x00,
  0x00,          /*bInterval: Polling Interval (20 ms)*/
  /* 25 */
  
  0x07,         /* bLength: Endpoint Descriptor size */
  USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: 5 */
  CUSTOM_HID_EPOUT_ADDR,  /*bEndpointAddress: Endpoint Address (OUT)0x01*/
  0x03, /* bmAttributes: Interrupt endpoint */
  CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 0x08 */
  0x00,
  0x14, /* bInterval: Polling Interval (20 ms) */
  /* 32 */
} ;

b   USBD_CUSTOM_HID_Init()函数打开端点类型修改
static uint8_t  USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev, 
                               uint8_t cfgidx)
{
  uint8_t ret = 0;
  USBD_CUSTOM_HID_HandleTypeDef     *hhid;
  /* Open EP IN */
  USBD_LL_OpenEP(pdev,
                 CUSTOM_HID_EPIN_ADDR,
                 USBD_EP_TYPE_BULK,
                 CUSTOM_HID_EPIN_SIZE);  
  
  /* Open EP OUT */
  USBD_LL_OpenEP(pdev,
                 CUSTOM_HID_EPOUT_ADDR,
                 USBD_EP_TYPE_INTR,
                 CUSTOM_HID_EPOUT_SIZE);

………………

c CustomHID_ReportDesc 报告描述符等等删除,修改CustomHID_OutEvent 将buf数据缓存,此数据端点输出数据

static int8_t CustomHID_OutEvent(uint8_t *buf)

uint8_t i;
uint8_t tmp = 0;
for(i = 0; i < 8; i++)
{
ReviBuffer[i] = buf[i];
tmp = tmp ^ ReviBuffer[i];
}
  }

主要修改就这么多,usb上传数据USBD_CUSTOM_HID_SendReport()函数,接收使用的是CustomHID_OutEvent()函数。

所有思路来自参考文章,非常感谢……

0 0