本帖最后由 jyl518-283289 于 2018-7-26 09:29 编辑 初学USB,请大家支持下! 采用STM32Cube生成STM32F103VBT6的MDK程序, 使用如下库函数 USBD_HID_SendReport(&hUsbDeviceFS,sendbuffer,20); 发送20个字节的数据,在USB抓到的数据可以看到,分成5次发送了??? 难道不能一次发送完成 吗?? 888 看红色部分即可 按键盘“a”键的数据明显是一次发送8个字节 代码如下: /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f1xx_hal.h" #include "cmsis_os.h" #include "usb_device.h" osThreadId defaultTaskHandle; osThreadId RS485_1Handle; uint8_t uart1_rx_buf[20]; uint8_t uart1_rx_len = 20; uint8_t uart1_rx_flag = 0; uint8_t sendbuffer[20]={0x02,0x30,0x31,0x01,0x00,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x93,0x03}; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); void StartDefaultTask(void const * argument); void RS485_1Task(void const * argument); int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128); defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); osThreadDef(RS485_1, RS485_1Task, osPriorityNormal, 0, 128); RS485_1Handle = osThreadCreate(osThread(RS485_1), NULL); osKernelStart(); while (1) { } } void RS485_1Task(void const * argument) { for(;;) { if(uart1_rx_flag) { HAL_GPIO_WritePin(DR1_GPIO_Port,DR1_Pin, GPIO_PIN_SET); //使能485_1发送 osDelay(100); HAL_UART_Transmit_IT(&huart1, uart1_rx_buf, uart1_rx_len); osDelay(100); HAL_GPIO_WritePin(DR1_GPIO_Port,DR1_Pin, GPIO_PIN_RESET); //使能485_1接收 uart1_rx_flag = 0; osDelay(100); USBD_HID_SendReport(&hUsbDeviceFS,sendbuffer,20); //此处发送20字节数据到PC机 osDelay(100); } } } |
Your UAT Feedback is needed within today.
STM32_USB_Device_Library
用STM32F4 Cube MX生成的USB Device C代码的BUG
STM32F446 USB和串口1 冲突
STM32f407ZG使用STM32CubeMX创建USB应用失败
请教stm32F105 USB开发资料去哪里下载
STM32F103VE-USB-VCOM发不出数据
STM32cubemx 配置出的 USB HID 电脑无法识别
[STM32L496] 求助USBCDC通信,PC端总是需要插拔USB线问题
STM32F USB DFU下载无法识别USB设备
HID_EPIN_SIZE 改了没有?不然描述符里虽然说 wMaxPacketSize 是0x8, 但是你的设备因为USB 驱动配置原因自己发不出去 0x8个字节
另外,我说的HID REPORT SIZE 不是 HID_MOUSE_REPORT_DESC_SIZE, 这个可能给你搞糊涂了。HID_MOUSE_REPORT_DESC_SIZE 是 USB HID 描述符本身的大小 (见HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE])。 在这个 USB HID 描述符里面会告诉操作系统这个设备的HID REPORT是多少字节,如何去处理,等等细节。你学习下USB HID规范就了解了。HID_MOUSE_ReportDesc这个array里面奥妙很多的。
具体请看 http://notes.iopush.net/stm32-custom-usb-hid-step-by-step-2/ 和 http://damogranlabs.com/2016/03/ ... -device-yes-please/
评分
查看全部评分
评分
查看全部评分
找了半天,没找到配置描述符,和报告描述符的位置,能否明示下!!
评分
查看全部评分
漂亮
试着改了几处,还是没成功。
将配置描述符USB_HID_CONFIG_DESC_SIZ 改为0x08 仍不行
另外报告描述符是改下面这里的数据吗?
同时,要让操作系统能够理解你的这个20字节Report,HID Report Descriptor里面的HID REPORT SIZE也需要改成20字节。
评分
查看全部评分
1、USBD_HID_ConfigDesc 里面End point的 wMaxPacketSize 值已由0x04改为0x08
2、HID Report Descriptor里面的HID REPORT SIZE也需要改成20字节。这个更改无从下手,试改几处都不行,如将HID_MOUSE_REPORT_DESC_SIZE值由74改为78
3、我把usbd_hid.c的文件内容全部贴在下面,请知道改么改个留个言。谢谢!谢谢!
2、Report,HID Report Descriptor里面的HID REPORT SIZE也需要改成20字节。
这条不知怎么下手,试改了几处仍不行,如改过HID_MOUSE_REPORT_DESC_SIZE,值由74改为78,但仍不行