2024-01-30 10:04 PM - last edited on 2024-01-31 07:46 AM by SofLit
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)
Solved! Go to Solution.
2024-02-01 05:04 AM - edited 2024-02-01 07:39 AM
Referring to NUCLEO-F446RE UM there is no USB connector except ST-Link port.
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:
2024-01-31 07:31 AM - edited 2024-01-31 07:42 AM
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.
2024-01-31 07:33 AM
Use this button to properly post source code:
To get that extra row of icons, press this button:
2024-01-31 07:35 AM
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.
2024-01-31 07:38 AM
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 :)
2024-01-31 07:44 AM
@SofLit wrote:Need to move this button to the list on the top.
The change has, apparently, been requested:
Whether that will help people to use it remains to be seen ...
2024-01-31 07:47 AM
Yes I'm already aware.
I edited the original post to format the code.
2024-02-01 02:10 AM
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.
2024-02-01 02:18 AM
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?
2024-02-01 05:04 AM - edited 2024-02-01 07:39 AM
Referring to NUCLEO-F446RE UM there is no USB connector except ST-Link port.
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: