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.
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on January 17, 2018 at 19:21

I'm seeing a similar issue with USB mice and STM32F446 and found kind of a workaround.

Attachedis part of my patchfor usbh_hid.c

The crucial point is tomove from state HID_INIT directly to state HID_SYNC, not to HID_IDLE.

Note: I don't understand why this works for me. As the OP said, he is not specialist in USB and expected the library to Just Work. So did I...

Regards,

Pavel

________________

Attachments :

pach_usbh_hid_002.txt.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy8B&d=%2Fa%2F0X0000000b4D%2FjH_j5xv3K1bU7H_4bTVEQeNqBQKujwCbPIybWCJzmKo&asPdf=false

View solution in original post

45 REPLIES 45
Artem Ugrimov
Associate
Posted on May 15, 2017 at 22:12

Hello Friend!

You solved this problem?

I also do not work usb host hid keyboard...

If you solve the problem, give the code.

yanming2013 mo
Associate II
Posted on May 26, 2017 at 12:33

Hi, I have the same problem!

Some keyboard are OK, but some keyboard can be detected but can't get the data.

I use STM32L496-NUCLEO board with STM32CUBEMX USB HID project.

Someone help me!

this GASIA keyboard can't read data:

0690X00000603qxQAA.jpg

----------------------------------------------------------------------------------

this SIGMACHIP keyboard can read data:

0690X00000603r7QAA.jpg
wwmentz
Associate II
Posted on November 09, 2017 at 20:09

Hi everyone,

I've got the same problem, in my custom PCB (stm32f401) an microsoft keyboard worked as expected, but an leadership keyboard didn't.

So, I've tryed an STM32F746G-DISCO, I run 4 examples:

STM32Cube_FW_F7_V1.4.0\Projects\STM32746G-Discovery\Applications\USB_Host\HID_RTOS\SW4STM32\STM32746G-DISCOVERY_USBH-FS

STM32Cube_FW_F7_V1.4.0\Projects\STM32746G-Discovery\Applications\USB_Host\HID_RTOS\SW4STM32\STM32746G-DISCOVERY_USBH-HS

\STM32Cube_FW_F7_V1.4.0\Projects\STM32746G-Discovery\Applications\USB_Host\HID_Standalone\SW4STM32\STM32746G-DISCOVERY_USBH-FS

\STM32Cube_FW_F7_V1.4.0\Projects\STM32746G-Discovery\Applications\USB_Host\HID_Standalone\SW4STM32\STM32746G-DISCOVERY_USBH-HS

and same result.

For me, it seems like a problem with USB HOST routines.

Someone already did it work?

I'm compiling with SW4STM32

Posted on January 17, 2018 at 17:05

>>For me, it seems like a problem with USB HOST routines.

Or a lack of understanding of how random keyboard behave. One would need to go beyond the 'doesn't work' level of understanding and look at the signalling and protocol and its behaviour with respect to the class and Microsoft's implementation of the class on a PC

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 17, 2018 at 17:20

You are right, I don't understand how protocol works. But from starting point, I tried the examples above, without any modifications in de code. Hardware is a STM32F746G-DISCO. Shouldnt this be able to comunicate?

Posted on January 17, 2018 at 17:52

>> Shouldn't this be able to communicate?

Correct, but ST's implementation of examples demonstrates how a nominal keyboard can be hosted, not all kinds of outliers, and things with more complicated behaviour and descriptors. That Microsoft's keyboard works suggests it has achieved the nominal functionality goals, that Brand X does not, means it is doing something outside the normal rather than ST's code being wrong. In the development of these devices in a commercial context, where you try hundreds of different brand keyboard, you're going to find some that behave differently, and you'll have to add code to address quirky cases or give your customers a list of working/tested keyboards that are supported by your product.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 17, 2018 at 17:53

Hi

Mentz.William

‌,

Similar issue is reported in

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

. It is being investigated deeply by our USB experts.

Waiting for analysis results, I suggest you apply the possible workaround provided by

Chinzei.Tsuneo

‌ in

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

(update of

USBH_HID_Process inSTM32CubeF4\Middlewares\ST\STM32_USB_Host_Library\Class\HID\Src\usbh_hid.c).

Please let us know in both cases: either it works or not?

Then, could you please let us know the exact keyboard(s) you used?

-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 17, 2018 at 19:21

I'm seeing a similar issue with USB mice and STM32F446 and found kind of a workaround.

Attachedis part of my patchfor usbh_hid.c

The crucial point is tomove from state HID_INIT directly to state HID_SYNC, not to HID_IDLE.

Note: I don't understand why this works for me. As the OP said, he is not specialist in USB and expected the library to Just Work. So did I...

Regards,

Pavel

________________

Attachments :

pach_usbh_hid_002.txt.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy8B&d=%2Fa%2F0X0000000b4D%2FjH_j5xv3K1bU7H_4bTVEQeNqBQKujwCbPIybWCJzmKo&asPdf=false
Posted on January 17, 2018 at 19:34

For

luca.giuliodori

‌ and other people having problems with mice: it appears that some mice pretend to support so called 'boot protocol' - this is required and checked by the ST 'HID class' module,

usbh_hid.c

. But these miceeither lie and do not behave per the boot protocol, or ignore the set mode request from usbh_hid.c (or there's some other bug thatfoilsthe set mode request). As result, these not compatible mice have report size != 4. The ST library code ignores this condition rather than indicate failure properly.

Find another mouse that really complies to the 'boot protocol' - orspend few thousand euros for a decent USB library that can parse HID reports (as Windows and Ubuntu do) and do not rely on the 'boot' protocol.

-- pa