AnsweredAssumed Answered

usb host

Question asked by mazarei.mohammad on Feb 26, 2017
Latest reply on Jun 21, 2018 by pokorny.igor.001

Hi Everyone,
I'm trying to read from the USB keyboard with  a custom board STM32F205RCT6 MCU.

I am using USB FS host (host only) with HAL library.but  it just works with some keyboards!

Other keyboards are detected by host but can not read data.
Can any one help me?

My Code:

int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */

  HAL_Init();
 
  /* Configure the system clock to 120 MHz */
  SystemClock_Config();

/* Init Host Library */
  USBH_Init(&hUSBHost, USBH_UserProcess, 0);
 
  /* Add Supported Class */
  USBH_RegisterClass(&hUSBHost, USBH_HID_CLASS);
 
  /* Start Host Process */
  USBH_Start(&hUSBHost);
 
  /* Run Application (Blocking mode) */
  while (1)
  {
    /* USB Host Background task */
    USBH_Process(&hUSBHost);
   
      if(USBH_HID_GetDeviceType(&hUSBHost) == HID_KEYBOARD)
      {

        hid_demo.keyboard_state = HID_KEYBOARD_IDLE;
        hid_demo.state = HID_DEMO_KEYBOARD;
                    //HID_KeyboardMenuProcess();
                    
                    HID_KEYBD_Info_TypeDef *k_pinfo;
                    char c;
                    k_pinfo = USBH_HID_GetKeybdInfo(&hUSBHost);
                    
                    if(k_pinfo != NULL)
                    {
                         
                         c = USBH_HID_GetASCIICode(k_pinfo);
                         
                         char str[5];
                         sprintf(str,"%c",c);
                         HAL_UART_Transmit(&huart2,k_pinfo->keys,6,10000);
                         
                    }
                    
               }
     }

 

Result (only detected Not read data)

USB Device Attached
PID: 1h
VID: 258ah
Address (#1) assigned.
Manufacturer : SINO WEALTH
Product : USB KEYBOARD
Serial Number : N/A
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Switching to Interface (#0)
Class    : 3h
SubClass : 1h
Protocol : 1h
KeyBoard device found!
HID class started.

Outcomes