Question
stm32cube, usb host, hid mouse/keyboard
Posted on October 09, 2016 at 14:54
hello,
I've been trying to set up some basic usb comunication with a usb mouse using my stm32f4 discvery. there are no usb examples for my board so I went in to look at other boards. I generated a project with cube inlcuding USB_OTG_FS in host only mode and four IO pins for LED's. I had a look in the files and it seemed like reading mouse buttons would be fairly trivial, but I can't make it work. if I run [code]devtype = USBH_HID_GetDeviceType(&hUsbHostFS);[/code] it detects the device correctly. [code]USBH_HID_MouseInit(&hUsbHostFS)[/code] returns USBH_OK but no matter what I try [code]mouse=USBH_HID_GetMouseInfo(&hUsbHostFS);[/code] is always NULL ''USBH_HID_MouseInit'' is never mentioned in the documentation(DM00105256.pdf) also, only the RTOS examples use them. Reading the standalone example, it would seem that to comunicate with a mouse would be as simple as runing GetDeviceType, and GetMouseInfo, but I can't get it to work. this is all the code I added, it's executed in the main while [code] if(Appli_state == APPLICATION_READY){ switch(state) { case 0: devtype = USBH_HID_GetDeviceType(&hUsbHostFS); if(devtype == HID_MOUSE){ HAL_GPIO_WritePin(GPIOD,GPIO_PIN_14,1); HAL_GPIO_WritePin(GPIOD,GPIO_PIN_12,0); state=1; } else if(devtype == HID_KEYBOARD){ HAL_GPIO_WritePin(GPIOD,GPIO_PIN_14,0); HAL_GPIO_WritePin(GPIOD,GPIO_PIN_12,1); state=2; } else{ HAL_GPIO_WritePin(GPIOD,GPIO_PIN_14,0); HAL_GPIO_WritePin(GPIOD,GPIO_PIN_12,0); } break; case 1: if(USBH_HID_MouseInit(&hUsbHostFS)==0){ HAL_GPIO_WritePin(GPIOD,GPIO_PIN_15,1); state=3; } else { HAL_GPIO_WritePin(GPIOD,GPIO_PIN_15,0); state=0; } break; case 3: mouse=USBH_HID_GetMouseInfo(&hUsbHostFS); if(mouse != NULL)HAL_GPIO_WritePin(GPIOD,GPIO_PIN_13,1); else HAL_GPIO_WritePin(GPIOD,GPIO_PIN_13,0); break; default: break; } } if(Appli_state != APPLICATION_READY) state=0; [/code]