Search code examples
usbstm32hidstm32cubemxcubemx

Why does my usb HID output rubbish? STM32Cube


I'm trying to make a force feedback wheel, but software isn't my cup of tea. This is supposed to toggle button 0 and it doesn't.

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);
}

My Report descriptor (this is the first time I'm using one):

enter image description here

Running that code, the buttons are static "ON" like so:

enter image description here

They DO change (randomly) only when the "relativeMvt" variable is changed, very weird.

What I've tried:

  • Swap relativeMvt and buttons in the typeDef

  • Check the report descriptor size etc

  • Cry

    #define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 2

    #define USBD_CUSTOM_HID_REPORT_DESC_SIZE 45

    #define CUSTOM_HID_EPIN_SIZE 2

What do I have to change to make it work? Thanks!


Solution

  • I've solved it. I was missing:

    #include "usbd_customhid.h"
    

    and I forgot the "&" when passing my variables:

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