cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 USB Host HID mouse

Fernando Cola
Associate II

Hi, I'm developing an application using a custom board based on STM32F429BI.

Here is my setup/configurations

- STM32 CubeMX 1.1.0 to generate code initialization.

- Using USB_HS port configure as HOST

- Using STM32 HID Host Driver

- Using FreeRTOS

- Using USB mouse device for testing

- Using as starting point a sample application from the USB Host Labs - HID Host Lab - https://www.st.com/content/st_com/en/support/learning/stm32-education/stm32-moocs/STM32-USB-training.html

I'm following the STM USB Hid Host tutorial on: https://www.youtube.com/watch?v=MlhUG4GsOT0&list=PLnMKNibPkDnFFRBVD206EfnnHhQZI4Hxa&index=23&t=0s

I'm enable to enumerate the USB device and everything seems fine. The picture bellow is my USB analyzer showing the communication between USB host and device.

0693W000000UYEHQA4.png

Everything seems fine, however I'm not getting any package on the Host side with mouse's X and Y position.

The following handler for USB packages is never called in the host side.

void USBH_HID_EventCallback(USBH_HandleTypeDef *phost) {
 
	HID_KEYBD_Info_TypeDef *keybd_info;
 
	uint8_t keycode;
 
	HID_HandleTypeDef *HID_Handle =
 
			(HID_HandleTypeDef *) phost->pActiveClass->pData;
 
	if (HID_Handle->Init == USBH_HID_KeybdInit) {
 
		keybd_info = USBH_HID_GetKeybdInfo(phost);
 
		keycode = USBH_HID_GetASCIICode(keybd_info);
 
		uart_length = sprintf(uart_tx_buffer, "Key pressed: 0x%x\n", keycode);
 
		HAL_UART_Transmit(&huart3, uart_tx_buffer, (uint16_t) uart_length,
 
				1000);
 
 
 
	} else if (HID_Handle->Init == USBH_HID_MouseInit) {
 
		USBH_HID_GetMouseInfo(phost);
 
		uart_length =
 
				sprintf(uart_tx_buffer,
 
						"Mouse action: x= 0x%x, y= 0x%x, button1 = 0x%x, button2 = 0x%x, button3 = 0x%x \n",
 
						mouse_info.x, mouse_info.y, mouse_info.buttons[0],
 
						mouse_info.buttons[1], mouse_info.buttons[2]);
 
		HAL_UART_Transmit(&huart3, uart_tx_buffer, (uint16_t) uart_length,
 
				1000);
 
	}
 
}
 

Also, I'm not getting any further packages on the USB analyzer.

Am I missing and initialization from the USB host to the device?

0 REPLIES 0