cancel
Showing results for 
Search instead for 
Did you mean: 

usb host

1Ashena M
Associate
Posted on February 26, 2017 at 07:10

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.�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

#usb-host #usb-hid #usb-stm32f205

Note: this post was migrated and contained many threaded conversations, some content may be missing.
45 REPLIES 45
Posted on January 18, 2018 at 09:03

Thank you for your patch and suggestions. In my case I have problem also with keyboards and the my real problem, it's that stack doesn't work with my custom device; in this case the problem is the same (or is similar) to that of the mice or keyboards.

Can you send me the entire file 'usbh_hid.c'? The changes are not so clear in the attached file.

Posted on January 18, 2018 at 11:12

Hi Luca,

Below is link to the whole file.  There are other changes not related directly to the issue, though.

http://pavel_a.fastmail.fm/tmp/usbh_hid.c

Regards

Pavel A.

Posted on January 18, 2018 at 11:56

Thanks

st.mcu

,

through

https://community.st.com/0D50X00009XkeVgSAJ

I get it to work just fine.

The keyboards I've used are:

'Microsoft wired keyboard 600' that worked,

'Standart Leadership keyboard Cód.: 8496 USB' that worked after changes.

Thanks

pavel_a

,

you patch goes direct to the point, is just avoid HID_IDLE.

case HID_INIT:

HID_Handle->Init(phost);

HID_Handle->state = HID_SYNC; // skip HID_IDLE state

break;

Best Regards

William

Posted on January 18, 2018 at 12:17

I see your point, its not possible to attend to every specific non standart device. But when in 6 devices it has achieved the nominal functionality goals in just 33% (

https://community.st.com/0D50X00009XkeVgSAJ

https://community.st.com/0D50X00009XkX0ASAV

), I believe it needs some attention.

Posted on January 18, 2018 at 14:05

Thanks! As soon as possible I'll try your patch and all other suggestions.

Regards

Alex R
Senior
Posted on January 18, 2018 at 15:41

Hi,

See

https://deskthority.net/wiki/USB

for some additional information about USB keyboard operation and boot protocol.

Regards,

Alex

Posted on January 19, 2018 at 16:22

Thanks

pavel_a

‌ for the patch you provided besides to analysis you made.

The main update isaligned with

Chinzei.Tsuneo

‌'s proposal.

I will share this with our development team to apply the required fix in coming versions.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on January 26, 2018 at 15:30

Good news! I have applied the

pavel_a

patch and seems the USB stack works fine!

Thank you very much to all and I hope, as soon as possible, ST release the USB stack with these fixs.

Regards

Mr OK
Associate
Posted on February 08, 2018 at 05:45

Hi all, 

i have a same problem with USB Host HID, my project generated form CubeMX, 

when i debug  then case 'HOST_CLASS_REQUEST',  case 'ENUM_GET_SERIALNUM_STRING_DESC'

case 'CMD_WAIT' and GetDeviceType = 'HID_UNKNOWN' not '

Posted on February 08, 2018 at 15:22

Then did you applied the suggested fix? Does it work for you?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.