【问题标题】:Why does my usb HID output rubbish? STM32Cube为什么我的 USB HID 输出垃圾? STM32立方体
【发布时间】:2021-04-04 15:25:33
【问题描述】:

我正在尝试制作一个力反馈轮,但我不喜欢软件。 这应该切换按钮 0,但它没有。

typedef struct{
    uint8_t buttons;
    int8_t relativeMvt;
}steer_t;
steer_t steer = {0, 0};

while (1)
{
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);

    if(steer.buttons) steer.buttons = 0b00000000;
    else steer.buttons = 0b00000001;

    USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, steer, sizeof(steer));
    HAL_Delay(500);
}

我的报告描述符(这是我第一次使用):

运行该代码,按钮是静态的“ON”,如下所示:

只有当“relativeMvt”变量改变时,它们才会(随机)改变,非常奇怪。

我尝试过的:

  • 在 typeDef 中交换 relativeMvt 和按钮

  • 检查报告描述符大小等

  • #define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 2

    #define USBD_CUSTOM_HID_REPORT_DESC_SIZE 45

    #define CUSTOM_HID_EPIN_SIZE 2

我必须进行哪些更改才能使其正常工作?谢谢!

【问题讨论】:

  • 查看本教程eleccelerator.com/tutorial-about-usb-hid-report-descriptors。看起来您的 USAGE_MINIMUM 定义是错误的。您必须将其设置为 Button 1。
  • @veeman 这确实是一个很好的教程,我用它来制作它,但我还没有完全理解它。从那以后我就解决了

标签: usb stm32 hid stm32cubemx cubemx


【解决方案1】:

我已经解决了。我失踪了:

#include "usbd_customhid.h"

我在传递变量时忘记了“&”:

 USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, &steer, sizeof(steer));

【讨论】:

  • 您应该启用所有警告。一个好的编译器会捕捉到这种故障并警告你。
猜你喜欢
  • 2015-08-28
  • 2021-11-02
  • 2021-02-20
  • 2022-01-23
  • 2021-12-04
  • 1970-01-01
  • 2018-02-18
  • 2020-12-17
  • 1970-01-01
相关资源
最近更新 更多