cancel
Showing results for 
Search instead for 
Did you mean: 

HID mouse doesn't move

pass3master
Associate III

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)

1 ACCEPTED SOLUTION

Accepted Solutions

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

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

9 REPLIES 9
SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.
Andrew Neil
Evangelist III

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

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

@SofLit 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 ...

Yes I'm already aware.

I edited the original post to format the code.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Thank you for answering.
We made the changes as per your advice, but the mouse remained stuck.
Are there any other issues?

In the first place, it is recognized as a virtual COM port in Device Manager.
We are using NUCLEO-F446RE.

Hello,

It could be related to the STLink since you have connected the board to power it up.

Could you please share your project so I could look at it deeply?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

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

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.