Skip to main content
Digimorf
Associate III
September 3, 2020
Question

Is it possible to use USB HID keyboard and mouse at the same time on a STM32F469?

  • September 3, 2020
  • 14 replies
  • 8874 views

Hello, I need to understand if it's possible to use both USB HID keyboard and mouse in a project powered by a STM32F469. I have thought about plug a mini HUB and connect both keyboard and mouse. Is there something I can start from? I have searched a lot but I can't find find something similar. Thanks

This topic has been closed for replies.

14 replies

Digimorf
DigimorfAuthor
Associate III
September 5, 2020

Thanks for the information, actually I just found this project on Github

STM32F4HUB

https://github.com/mori-br/STM32F4HUB

that seems to be really promising. I have tried it, and it finds correctly a hub. But it seems to have problems when reading devices plugged in. Sometimes it works but with one device only. The author says that this driver works with FS devices because of some problems of the USB.

I will try to port it to the stm32f469 ​and the latest HAL version.

But if someone has any ideas...

Pavel A.
September 5, 2020

Please note that this project is not finished and abandoned by the author.

The reason why it works only with FS devices is errata or the USB controller of STM32F4.

I haven't worked on the 'F4 USB recently and forgot details, please google or ask ST support.

Segger supports hubs in their USB host library and they say that newer STM32 F7, H7 do not suffer from that errata.

-- pa

Digimorf
DigimorfAuthor
Associate III
September 6, 2020

@Pavel A.​ 

Thank you for your answer, unfortunately, I can't change MCU at this stage of the project. For the release version I only support the use of the keyboard, but I was digging into the matter and check if there is the possibility to use a mouse also:

www.arcadeit.net

I will try to contact the support to know if in the 469 has the same issue, or if it has been solved in newer units.

I will go on doing research on this, but thanks.

Pavel A.
September 6, 2020

> I was digging into the matter and check if there is the possibility to use a mouse also:

Of course, mice work in general. But what surprised me that mice that can be found 'in wild' are much more diverse than keyboards.

Only few models support the basic 'boot' protocol featured in the ST example.

For most mice you'll need to parse HID descriptors and deal with complex report formats. Some of them have multiple HID collections and some even are composite (not clear why)

-- pa

Digimorf
DigimorfAuthor
Associate III
September 6, 2020

"For most mice you'll need to parse HID descriptors and deal with complex report formats. Some of them have multiple HID collections and some even are composite (not clear why)"... Oh, good :grinning_face_with_sweat: Once USB meant Universal Serial Bus... :rolling_on_the_floor_laughing:

Anyway, I have tested the STM32HUB project on a Discovery board with all keyboards (5) and mice (6) that I have. No one uses FS! All LS except for a wireless mouse by HP, and a combo Keyboard + Smart card reader that are FS. This concerns me a bit.

Digimorf
DigimorfAuthor
Associate III
September 17, 2020

I had an interesting test with STM32F4HUB code on the Discovery F4. Since all keyboard and mice that I have didn't work together through a HUB, I tried to understand if combo devices could work better, and I got an interesting surprise: do you remember those old adapters USB to PS/2 for using PS/2 Keyboard and mouse on one USB port? Good, that worked!

Not only with PS2 devices but also with USB kyb&mouse through a PS2 to USB single adapter on each end.

So I was able to use the USB keyboard and mouse through those adapters , see attachment. There are still some weird behaviors when resetting and starting the Discovery, but when the firmware doesn't "freeze" it works perfectly :)

0693W000003RwNOQA0.jpgWhat do you think?

This is the log text of the STM32F4HUB terminal:

APP RUNNING...
MCU-ID 10076413
HAL_HCD_MspInit
USB Device Attached
USBH_LL_GetSpeed 2 (LOW=2,FULL=1)
addrd: 0x00, pipe: 0
addrd: 0x80, pipe: 1
USBH_ParseDevDesc
12 01 01 01 00 00 00 08
Enum mps: 8, addr: 0
USBH_ParseDevDesc
12 01 01 01 00 00 00 08 B4 04 81 80 06 01 01 02 00 01
PID : 8081h
VID : 4b4h
Address (#5) assigned.
USBH_ParseCfgDesc, number of interfaces: 2
itfclass 0x03
USBH_ParseInterfaceDesc, itf 0, class 0x03, subclass: 0x01, proto: 0x01, numep 1
itfclass 0x03
USBH_ParseInterfaceDesc, itf 1, class 0x03, subclass: 0x01, proto: 0x02, numep 1
Manufacturer : Cypress
Product : PS/2 to USB Adapter
Serial Number : N/A
Enumeration done.
This device has only 1 configuration.
Default configuration set.
INTERFACES: 2
Switching to Interface (#0)
Class : 3h
SubClass : 1h
Protocol : 1h
HID LEN 65 - 0
KeyBoard found.
addrd: 0x81, pipe: 2
IN size=8, num 2, addr 0x81, pool 10, lowspeed? 1
Switching to Interface (#1)
Class : 3h
SubClass : 1h
Protocol : 2h
HID LEN 52 - 1
Mouse found.
addrd: 0x82, pipe: 3
IN size=4, num 3, addr 0x82, pool 10, lowspeed? 1
Switching to Interface (#0)
HID class started.
KEYB 10
KEYB 0
KEYB 17
KEYB 0
BUTTON 0
BUTTON 0
BUTTON 0
BUTTON 0

This could be an easy solution to use those old devices also :)

Pavel A.
September 17, 2020

Nice. Cypress is a good company, their stuff is reliable.

By the way, once we've made a STM32F4 based host for USB keyboard & mouse and PS/2 keyboard and mouse - all in one.

It was kind of a KVM switch. For the remote (device) end I wanted to use these PS/2 to USB adapters, because they are LS and very compatible with everything.

-- pa

waclawek.jan
Super User
September 17, 2020

Okay, but this is not a hub, but a 2-interface single HID device.

JW

Digimorf
DigimorfAuthor
Associate III
September 18, 2020

Yes, I know. The point is that I need to find a good way to use keyboard and mouse at the same time on a single USB port of the STM32F469. Maybe, since there are issues on handling multiple devices through a HUB (that mixes FS and LS), it could be a good idea to use a composite device. I was wondering if a wireless keyboard and mouse combo could be a good solution.

Digimorf
DigimorfAuthor
Associate III
September 27, 2020

From my last research I realized that the latest version of USB Host library by ST seems not supporting multiple interfaces. More precisely , considering the file "usbh_core.c", in the case "HOST_CHECK_CLASS:" of the function "USBH_Process", the only interface considered is the 0 indexed:

phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass

The code STM32F4HUB , instead checks more interfaces, in fact the interfaces is updated and then analyzed.

 phost->pActiveClass = NULL;
 uint8_t itf = phost->device.current_interface;
 
 for (idx = 0; idx < USBH_MAX_NUM_SUPPORTED_CLASS ; idx ++)
 {
 if(phost->pClass[idx] != NULL)
 {
 if((phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[itf].bInterfaceClass) ||
 (phost->pClass[idx]->ClassCode == 0x03 && phost->device.DevDesc.bDeviceClass == 0xFF) )
 {
 phost->pActiveClass = phost->pClass[idx];
 }
 }
 }

I have tried the STM32F4HUB library with a wireless keyboard and mouse composite and it reads both interfaces correctly

 
APP RUNNING...
MCU-ID 10076413
DeInitStateMachine
 
HAL_HCD_MspInit
USB Device Connected
USBH_LL_Connect Id 0
 
USBH_LL_GetSpeed 1 (LOW=2,FULL=1)
USBH_ParseDevDesc
12 01 10 01 00 00 00 08
Enum mps: 8, addr: 0
USBH_ParseDevDesc
12 01 10 01 00 00 00 08 DA 00 10 85 00 01 01 02 00 01
PID : 8510h
VID : dah
PROTO: 0h
CLASS: 0h
Address (#5) assigned.
USBH_ParseCfgDesc, number of interfaces: 2
itfclass 0x03
USBH_ParseInterfaceDesc, itf 0, class 0x03, subclass: 0x01, proto: 0x02, numep 1
itfclass 0x03
USBH_ParseInterfaceDesc, itf 1, class 0x03, subclass: 0x01, proto: 0x01, numep 1
Manufacturer : Telink
Product : Wireless Receiver
Serial Number : N/A
Enumeration done.
This device has only 1 configuration.
Default configuration set.
INTERFACES: 2
Switching to Interface (#0)
Class : 3h
SubClass : 1h
Protocol : 2h
HID LEN 142 - 0
Mouse found.
IN size=8, num 2, addr 0x82, pool 4, lowspeed? 0
Switching to Interface (#1)
Class : 3h
SubClass : 1h
Protocol : 1h
HID LEN 59 - 1
KeyBoard found.
IN size=8, num 3, addr 0x81, pool 10, lowspeed? 0
Switching to Interface (#0)
HID class started.
 

but this driver is not really stable because it reads keyboard keystrokes, but as soon as I move the mo use it seems to reset the host and then it hangs.

Switching to Interface (#0)
HID class started.
KEYB 10
KEYB 0
KEYB 7
KEYB 21
KEYB 21
KEYB 10
KEYB 0
KEYB 22
KEYB 0
KEYB 9
KEYB 0
KEYB 22
KEYB 0
KEYB 9
KEYB 9
KEYB 9
KEYB 0
KEYB 22
KEYB 0
KEYB 9
KEYB 0
USB Device Connected
USBH_LL_Connect Id 0
 
USBH_LL_GetSpeed 1 (LOW=2,FULL=1)

I am trying now to modify the ST driver to read multiple interface, but do you have an idea or suggestions ?

Digimorf
DigimorfAuthor
Associate III
October 2, 2020

The work is going further, now the interfaces of the wireless device are detected correctly. The driver still needs fixes because the data coming from the mouse seem to be misaligned. The keyboard is ok instead. When standalone keyboard or mouse are plugged in, everything is perfect. So still a bit of work is waiting for me, but I am getting there. :)

0693W000004IUqdQAG.jpg

KNiko.3
Visitor II
August 19, 2022

Hi all! Who can share this working example code?

I'm also trying to connect a wireless mouse and keyboard as a composite device.

October 2, 2020

It may be possible to use an external module,

(Arduino + MAX3421e)

https://github.com/felis/UHS30

(Arduino + CH559)

https://www.youtube.com/watch?v=Th88RiSmj2w

ST does not seem to want to help the user much to make software, perhaps because there are other alternatives, such as using another processor with an operating system, Linux, Android, such as Raspberri Pi.