cancel
Showing results for 
Search instead for 
Did you mean: 

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

Digimorf
Associate III

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

20 REPLIES 20

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
Associate III

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
Associate III

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

Not applicable

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.

Digimorf
Associate III

This is true but I can't use external modules.

I have worked all day on this "difference" in parsing data and I have discovered that the composite device has the mouse interface that sends data in a different way than a normal single interface mouse. So I had to dig deeper and it seems to me that this driver from STMicroelectronics doesn't parse the HID report descriptor given by the device, but assumes it to be a standard (I mean single interface) mouse. Things now are getting harder, of course. If I am not wrong, and any help is appreciated, If I want this driver to be able to parse data correctly I need to implement a more advanced parser, so that it can collect data correctly from the device.

Not applicable

Hi,

Mouse is a device, keyboard is another device. To use more than one device on the same USB port, it is necessary to use a HUB. And the STM32CubeIDE library cannot even work with a keyboard with built-in touchpad, so imagine working with HUB.

Maybe you can use ChibiOS: USB Host stack and driver for STM32

"- HUB driver, tightly integrated with the high level driver, to connect multiple devices to the USB port." 

ChibiOS has its own IDE which is also based on Eclipse, and maybe it can be adapted on STM32CubeIDE, as it is also based on Eclipse.

ChibiOS Homepage

"ChibiOS is a complete development environment for embedded applications including RTOS, an HAL, peripheral drivers, support files and tools. ChibiOS also integrates external Open Source components in order to offer a complete solution for embedded devices." 

If you are lucky with this and are able to use HUB I would like to suggest that a Video be made on YouTube explaining step by step how to do it, I would be very grateful, especially if you can use RTOS. But if you can only use USB Host with RTOS and can make a video explaining how to do it, I would also be very grateful.

I tried to use ChibiOS, but I think I'm already too advanced in my project to start over from the beginning, I use a keyboard on one port and a USB stick on another. But I would like to use the keyboard with the built-in touchpad.

I commented a little on this in these posts:

https://community.st.com/s/question/0D50X0000Bviwg0/usb-host-hid-is-there-any-sample-code-for-reading-data-from-two-interfaces-of-the-same-device

https://community.st.com/s/question/0D50X0000BowGBSSQ2/stm32cubeide-usb-host-fs-15mbits-hid-mini-keyboard-touchpad-wireless-is-stopping-responding-when-it-enters-standby-or-touchpad-mode

Good luck!

Pavel A.
Evangelist III

@rtek1000​ Composite device is not same as hub so the hub driver won't help the OP with a composite device.

Though hub support is good to have.

The ST "mouse driver" is just a basic example, it works only with limited number of mice.

Of course with enough time one can research, bring in some HID parser and develop support for composite devices based on the ST code. But some of us don't have this luxury and are limited by time.

-- pa

Digimorf
Associate III

Thank you for your suggestion, actually in the beginning I thought about using an HUB to support both keyboard and mouse, but since I am going to release a Kit, www.acadeit.net that has a particular look, I don't like really the idea of having many cables around. In any case a wireless composite Keyboard Mouse is a good solution, even esthetically. Currently I got it working perfectly, so as soon as possible I will share the driver.

That is true but the USB port in the ArcadeIT would be used mainly for the keyboard and eventually a mouse. There is the support of a SD card upto 32GB, so no need of a pendrive. A parallel 6 buttons gamepad is provided, so the HUB is not really needed as long as a composite Keyboard Mouse device is working. For the mouse protocol, for now I did a trick, but when I will have time I will try to upgrade the parser.

Hi all! Who can share this working example code?

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