cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeF4 Applications: USB Host HID Device Issue

bazookafighter
Associate II
Posted on March 11, 2016 at 10:16

As a start, I am an owner of an STM32F469I-Discovery board. When I tried out the USB Host applications that came with STM32CubeF4, whether it was ''HID_RTOS'' or ''HID_Standalone'', I could not input a single thing with my USB wired keyboards even though they were all enumerated successfully and I tried 3 different keyboards.

On the other hand, the USB mouse I had with me worked as intended by the examples provided. While I will admit that all 3 of the keyboards I tried are not your typical brand stuff (e.g. Logitech, Microsoft etc.) but some generic Chinese devices, they all work perfectly fine on Windows/Linux machines which leads to me to believe that it is very likely a software problem. As a matter of fact, I tried the same examples from STM32CubeF4 v1.10.00 and v1.11.00 and they both produced the same results which is not surprising since they are no changes as far as I could tell.

However, I cannot fully dismiss that it is not a hardware problem either. Therefore I would like to request all STM32F4xx users who have had success with using a USB keyboard in the examples which were mentioned above to provide more details about the keyboard you used.

If it is indeed a software problem, then perhaps ST may want to have a look at it. If it helps at all, I am posting the PID and VID of the USB wired keyboards I had used for my testing below.

Keyboard No. 1 - PID: 260h | VID: 9dah

Keyboard No. 2 - PID: 1503h |VID: 1241h

Keyboard No. 3 - PID: b23h | VID: 1a2ch

#otg #host #host #host #keyboard #host #stm32f4 #usb #usb
13 REPLIES 13

This looks like it is still valid today,,, Doing this has put me one step closer to getting HID Host working on an F767ZI.

Edit: Yep. I can confirm the above. Stepping through the code I couldn't get past the initial states so the USB callback never happened. I now have a working Kensington usb2 keyboard working fine.

BTW the first problem I had getting this going was the VBUS enable. I ended up adding a line after initialisation to push PG6 HIGH, which according to the docs is inverted. I haven't got time to go back and check this out properly just now.

I also had to invert for a Nucleo 767 ... I did it by swapping GPIO_Pin_SET and RESET in the usbh_platform.c

I also created a timer just in case the get report is required, in usbh_hid.c

in Process:

    case HID_IDLE:
      status = USBH_HID_GetReport(phost, 0x01U, 0U, HID_Handle->pData, (uint8_t)HID_Handle->length);
      if (status == USBH_OK)
      {
        HID_Handle->state = HID_SYNC;
      }
      else if (status == USBH_BUSY)
      {
    	  if(bcnt++ > 127) {					//*****
    		  HID_Handle->state = HID_SYNC;		//*****
    		  bcnt = 0;							//*****
    	  }										//*****
    	  else {								//*****
    		  HID_Handle->state = HID_IDLE;
    	  }										//*****
        status = USBH_OK;
      }
      else if (status == USBH_NOT_SUPPORTED)
      {
        HID_Handle->state = HID_SYNC;
        status = USBH_OK;
      }
      else
      {
        HID_Handle->state = HID_ERROR;
        status = USBH_FAIL;
      }
 
#if (USBH_USE_OS == 1U)
      phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
      (void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
      (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL);
#endif
#endif
      break;

This means the RFID keyboard emulator also works.

bcnt is a static int.

billium

Nice. Thank you very much for sharing. I've put both of your changes in and tested it

with a wired and wireless keyboard, it looks like it is working great.

For anyone else looking here in future:

The schematic for the Z767 Nucleo (MB1137.pdf) correctly shows an STMPS2151STR VBUS control IC which has a positive enable signal.

If you're having VBUS problems it might be worth checking the schematic of your dev board.

Hello,

I also face the same issue of the USB keyboard not working using ST USB host HID class library on stm32f756zg mcu.

I have similarly tried the ST library on the STM32f429zi mcu and it is working on this mcu. It is weird that the library is working on one mcu and not on another.

I have applied the patch provided as a solution but it did not work for me.

Please suggest why is this happening that the usb keyboard is not detected on stm32f756zg mcu.