Skip to content

STM32(F4) USB HID support #4752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Gigahawk opened this issue May 12, 2021 · 6 comments · Fixed by #4754
Closed

STM32(F4) USB HID support #4752

Gigahawk opened this issue May 12, 2021 · 6 comments · Fixed by #4754
Labels
enhancement stm support issues that involve helping a user accomplish a task usb
Milestone

Comments

@Gigahawk
Copy link

I've bought a Feather STM32F405 Express and was expecting I could get it to act as a USB keyboard, but turns out USB_HID (and quite a lot of other features) aren't implemented for STM32 chips yet.

Is there any effort being made to implement USB_HID support?

@dhalbert
Copy link
Collaborator

dhalbert commented May 12, 2021

USB HID (and MIDI) are theoretically available, but they are not turned on. The problem is that the USB physical interface (PHY) that is connected to the USB connector only has 4 endpoint pairs. One pair is reserved for control purposes, one pair is used for mass storage (CIRCUITPY), and two pairs (well, 1.5), are used for the CDC serial (REPL connection). So that leaves none for anything else.

There is another USB PHY on the chip, a HS-capable one with more endpoints, but it is not connected to anything. It is not connected on the PyBoard either. I'm not sure why, but I think there was some reason.

With dynamic USB descriptors available in CircuitPython, it would be possible to disable the REPL and enable HID. It wouldn't be that pleasant a development experience. You might consider a different board with more endpoints, such as an RP2040, a SAMD, etc.

@Gigahawk
Copy link
Author

Is there documentation on how to disable the REPL?

Or better yet, route it to the serial port so I can just hook up a separate adapter to get to it.

@dhalbert
Copy link
Collaborator

This is all really, really new, and we're still getting the edges smoothed off, but we will think about enabling the possibility of HID while at the same time leaving it off at runtime by default on the STM32F4 boards. See the usb_hid and usb_cdc doc here: https://circuitpython.readthedocs.io/en/latest/shared-bindings/index.html.

@tannewt
Copy link
Member

tannewt commented May 13, 2021

There is another USB PHY on the chip, a HS-capable one with more endpoints, but it is not connected to anything. It is not connected on the PyBoard either. I'm not sure why, but I think there was some reason.

Most of the STM chips have HS peripherals but no HS PHY. They require a separate UTMI chip for the HS PHY. That's why they aren't used very often.

@tannewt tannewt added stm support issues that involve helping a user accomplish a task usb labels May 13, 2021
@tannewt tannewt added this to the Support milestone May 13, 2021
@Gigahawk
Copy link
Author

@dhalbert thanks, calling usb_cdc.disable() in boot.py makes usb_hid work.

The cherry on top would be access to the REPL via the dedicated serial pins, is there any way to do that?

@SuperThunder
Copy link

Although it doesn't solve the issue in CircuitPython, I think it's worth mentioning this Arduino library: https://www.onetransistor.eu/2020/03/usb-multimedia-keys-on-arduino-stm32.html

This library worked with my STM32F411 using the stm32duino core, which also appears to explicitly support the F405 Express you have @Gigahawk .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement stm support issues that involve helping a user accomplish a task usb
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants