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

> Can you explain better how you fixed the first bug?

As I explained in the post I linked to, according to the startup procedure after device attach in RM, if speed change is detected, after port reset OTG_HCFG.FSLSPCS has to be set accordingly and then another port reset has to be performed. But, IMO, it's enough to set OTG_HCFG.FSLSPCS to 0b10 before port reset regardless of the detected speed, the only effect being that in FS (and problably HS and/or FS-on-HS-PHY, I don't use HS) the first SOF will appear sooner than after 1ms, which IMO has no adverse consequences.

Also, in my implementation (as I don't use Cube and only tried it and reported findings here), setup packet retry helped even without fiddling with OTG_HCFG.FSLSPCS, as the two keypads which did not respond on the first setup did respond reliably on second, so they probably woke up just missed the first setup packet.. While this is not guaranteed to work as it's not a proper wakeup sequence, setup ought to be retried as per USB 2.0 anyway.

> To confirm that I noticied that in the USBH_HID_MouseInit function (in usbh_hid_mouse.c file) the code is correct.

Thanks.

It's maybe also worth noting that the function used by the demo to actually pick the received data, USBH_HID_GetASCIICode(), is written lazily and picks only the first of the keypress data. This in case of rollover causes not only potentially missing keypresses, but also false ones due to the fact that keyboards are free to reorder the codes within a report.

JW

PS. I downloaded CubeF4 v1.23 to compare with v1.21 I used for these experiments, and find out if there was any progress meantime. Beyond cosmetic changes (removed version in comments at beginning of files) I did not find any change, well, except missing projects for Atollic... now how does this match the fact that ST bought Atollic?

Luca Giuliodori
Associate III

> It's maybe also worth noting that the function used by the demo to actually pick the received data, USBH_HID_GetASCIICode(), is written lazily and picks only the first of the keypress data. This in case of rollover causes not only potentially missing keypresses, but also false ones due to the fact that keyboards are free to reorder the codes within a report.

I fully share your opinion.

> PS. I downloaded CubeF4 v1.23 to compare with v1.21 I used for these experiments, and find out if there was any progress meantime. Beyond cosmetic changes (removed version in comments at beginning of files) I did not find any change, well, except missing projects for Atollic... now how does this match the fact that ST bought Atollic?

Very interesting observation

I add another question: when will ST release a new version of USB Stack to fix all these bugs? It is a long time these bugs are known (@Amel NASRI​  followed my reports and cases).

AAgha
Associate II

Hi

I did all of above instructions but i cant get any information from keyboards!!!

AAgha
Associate II

I am using stm32f407 discovery board with microsoft curve keyboard 3000

board identify the keyboard but cant get any information

also im using the stm32cube_FW_F4_V1.24.0 Library

someone help me please!

Thanks

Open a new thread, referring to this one. This one is too long.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I agree, ST managers are hopeless, over a decade now of poor USB support, and they wonder why they're losing market share.