Skip to main content
Associate III
January 31, 2024
Solved

HID mouse doesn't move

  • January 31, 2024
  • 2 replies
  • 4461 views

We are trying to move the mouse cursor using HID.
However, the mouse cursor does not move even though it is USBD_OK in the USBD_HID_SendReport.
Why doesn't it work?


[IDE]STM32CubeIDE 1.14.0

Connectivity -> USB_OTG_FS -> [Mode]Device_Only

Middleware -> USB_DEVICE -> [Class For FS IP]HID

[board]​ NUCLEO-F446RE


[Our code]

typedef struct
{
 int8_t buttons;
 int8_t x;
 int8_t y;
 int8_t wheel;
} Mouse;
Mouse mouse_status = {0};

uint32_t before_time[sizeof(Mouse) / sizeof(int8_t)] = {0};
extern USBD_HandleTypeDef hUsbDeviceFS;

int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_USB_DEVICE_Init();
USBD_HID.Init(&hUsbDeviceFS,0);
/* Infinite loop */
while (1)
{
//送信
mouse_status.x = 1;
USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t *)&mouse_status, sizeof(Mouse));
HAL_Delay(1000);
}

(Edited to format the code)

Best answer by mƎALLEm

Referring to NUCLEO-F446RE UM there is no USB connector except ST-Link port.

SofLit_0-1706792649317.png

How did you connect the USB device to your PC?

If you intended to use STLINK as your USB Device interface it will not work as this connector is dedicated to STLINK/Virtual COM. So you need to use another board for example NUCLEO-F446ZE:

SofLit_0-1706801921020.png

 

 

2 replies

mƎALLEm
Technical Moderator
January 31, 2024

Hello,

 

uint8_t HID_Buffer[4];

HID_Buffer[0] = 0;
HID_Buffer[1] = x++;
HID_Buffer[2] = y++;
HID_Buffer[3] = 0;
USBD_HID_SendReport(&USBD_Device, HID_Buffer, 4);

 

Where x is the abscissa and y is the coordinate of the cursor. 

You need to change x and /or y to let the cursor move.

In your code x is constant and equal to 1.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
mƎALLEm
Technical Moderator
January 31, 2024

I can send you a project if you want that makes the cursor moves on your PC screen but done around an F7 device. But still the same implementation.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Andrew Neil
Super User
January 31, 2024

Use this button to properly post source code:

AndrewNeil_0-1706715219174.png

 

To get that extra row of icons, press this button:

AndrewNeil_1-1706715219177.png

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
mƎALLEm
Technical Moderator
January 31, 2024

Need to move this button to the list on the top. Since this one is hidden we always face the same issue on the community :)

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Andrew Neil
Super User
January 31, 2024

@mƎALLEm wrote:

Need to move this button to the list on the top. 


The change has, apparently, been requested: 

https://community.st.com/t5/feedback-forum/formatting-code-should-be-easier/m-p/633246/highlight/true#M955

Whether that will help people to use it remains to be seen ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.