Page 1 of 3

USB Host, what solution?

Posted: Sun Apr 18, 2021 3:08 pm
by BennehBoy
I'd like to build a small adapter using an STM32 (although I'm open to suggestions) which will translate HID mouse signals to legacy 5 volt 16 bit computers.

As an example, to use USB mice on legacy Amiga/or Atari computers.

There are adapters based on PIC's that will do this for a _very_ specific subset of Microsoft PS2 compatible USB mice, but I'd like to be able to use _any_ HID mouse. https://github.com/EmberHeavyIndustries/HID2AMI I also don't really need the game controller support.

I know there's a product out there based on an STM32f103 that does this, but it is closed source and a bit expensive.

So, what are the options, ideally I'd like to be able to use a ready made framework with the host stack implemented - ie have to do as little integration/rebaking as possible. So I think that presently this rules our the STM core. I think it also rules out rogers core - unless someone knows better (I thought perhaps USB Composite might cater for this but it doesn't).

It doesn't look like mbed fares any better either.

So, is my only option to go bare metal and use Cube?

Re: USB Host, what solution?

Posted: Mon Apr 19, 2021 9:09 am
by stevestrong
I would use a F4x1 pill and some apps already available on the net, like this:
https://damogranlabs.com/2018/02/stm32- ... -keyboard/
g**gle is your friend 8-)

Re: USB Host, what solution?

Posted: Mon Apr 19, 2021 9:30 am
by fpiSTM
Currently no USB host is supported by the core. A PR introduced this for Mass storage but always a WIP and doesn't not covered HID but a least USB host library is now accessible.
https://github.com/stm32duino/Arduino_C ... /pull/1088

Re: USB Host, what solution?

Posted: Mon Apr 19, 2021 9:30 am
by BennehBoy
stevestrong wrote: Mon Apr 19, 2021 9:09 am I would use a F4x1 pill and some apps already available on the net, like this:
https://damogranlabs.com/2018/02/stm32- ... -keyboard/
g**gle is your friend 8-)
Google is my friend :D

You've linked a page that shows how to set up a USB client as a HIB mouse & keyboard.

I want to set up a USB host that can convert inbound HID mouse reports to GPIO signals, so the reverse scenario so to speak.

Anyhow FWIW, I've found some useful information on how to do part of this in CUBE IDE. Relevant links below:

https://www.instructables.com/Setting-U ... 32CubeIDE/
https://www.youtube.com/watch?v=Co4ChSgVSek
https://github.com/glitterkitty/Arduino ... ga-Adapter

What I was asking here, is whether there's a framework way to do this, ie arduino, mbed, etc.

Re: USB Host, what solution?

Posted: Mon Apr 19, 2021 9:31 am
by BennehBoy
fpiSTM wrote: Mon Apr 19, 2021 9:30 am Currently no USB host is supported by the core. A PR introduced this for Mass storage but always a WIP and doesn't not covered HID but a least USB host library is now accessible.
https://github.com/stm32duino/Arduino_C ... /pull/1088
Yup I was aware of this and that it didn't cover what I wanted to do, thanks.

Re: USB Host, what solution?

Posted: Mon Apr 19, 2021 12:55 pm
by ag123
think cube ide has option to select the host otg driver. possibly 'more complicated' since it needs to poll and enumerate the devices.
i think there could be additional circuit requirements, e.g. that for usb host maybe the resistors should be pull down rather than pull up.
think the mass storage pr is possibly done by those doing the marlin 3d printer firmware. that pr would kind of make it possible to print from a usb flash drive. that is a big improvement.

Re: USB Host, what solution?

Posted: Mon Apr 19, 2021 1:44 pm
by stevestrong
According to this link you do it in CubeMX: https://controllerstech.com/stm32-usb-host-hid/

Re: USB Host, what solution?

Posted: Mon Apr 19, 2021 2:18 pm
by Bakisha
Hi, i successfully connected mouse and keyboard to my STM32F411CE WeAct board, using this guide:
https://www.youtube.com/watch?v=MlhUG4GsOT0
I didn't use any pins for VUSB sense, like shown in video, and i used uart1 (dongle on PA9/PA10) to send relative mouse movements (plus buttons).
I used female usb on protoboard, PA11 direct to D-, and PA12 to D+ (no cable connected to onboard USB-C, uploading with ST-LINK V2)

Tested mouse and keyboard, and it works, but on wireless mouse/keyboard dongle only keyboard works.

I tried to make it as a Arduino sketch, by coping all .h and .c files from Cube project, but no luck (always something not defined).

Re: USB Host, what solution?

Posted: Mon Apr 19, 2021 3:20 pm
by BennehBoy
Well I have a 401 pill set up and working as USB HOST in OTG mode and can decode and send the HID mouse reports to serial :D

Just have to integrate the amiga quadrature encoding and send that out to GPIO & some level shifters now :geek:

So ~ $6 and a little bit of learning.

The hardest part was getting the clock configuration correct.

Re: USB Host, what solution?

Posted: Mon Apr 19, 2021 9:00 pm
by BennehBoy
Well, I've got the code flushed out and it functions, BUT...

To get the quadrature signal output to emulate the amiga mouse requires a 150us duration for each pulse, I've tried to implement this with a timer (internal using a prescaler matching the clock, so for the 401 with 84mz clock, I'm using 84-1 to get 1mhz, or 1us per count). This causes the MC to lock hard. :cry:

I assume this may be the USB event handler interrupt getting stomped on.

Does anyone have any tips? The documentation seems a bit opaque to me at the moment.

Happy to just do some ridiculous loop and avoid a timer altogether if need be. Not very elegant, but will work.