2017-02-25 10:10 PM
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.
Solved! Go to Solution.
2018-01-18 01:03 AM
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.
2018-01-18 03:12 AM
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.
2018-01-18 03:56 AM
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
2018-01-18 04:17 AM
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% (
), I believe it needs some attention.2018-01-18 06:05 AM
Thanks! As soon as possible I'll try your patch and all other suggestions.
Regards
2018-01-18 06:41 AM
Hi,
See
https://deskthority.net/wiki/USB
for some additional information about USB keyboard operation and boot protocol.Regards,
Alex
2018-01-19 08:22 AM
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.
2018-01-26 07:30 AM
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
2018-02-07 08:45 PM
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 '
2018-02-08 07:22 AM
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.