Which microcontroller for USB HOST for HID devices? - Page 1
Forum section: electronics / general

author: nockieboy
author_rank: Super Contributor
timestamp: February 03, 2021, 04:58:14 pm
content: Hi everyone,I'm in the process of developing a GPU for my home-made 8-bit computerover here, using an FPGA. The current prototype has a PS/2 keyboard interface, which the FPGA reads and makes the converted ASCII keycodes available to the host computer.I'm upgrading the prototype to a more powerful FPGA and would like to drop the PS/2 interface and use a USB port instead, so I can use the far more current (and cheaper) USB keyboards that are available instead of the dwindling pool of PS/2 keyboards that are getting harder to find.I've tried connecting the FPGA to the USB port via a MAX3421E, but testing and development of the FPGA interface for that is going much slower than expected. So I got to wondering if it wouldn't be easier to just use a microcontroller with USB HOST support to handle the USB keyboard (and mouse, possibly), and just translate the inbound keycodes/data from the USB port to an interface to the FPGA?TL;DR:What would be the best microcontroller for the above application? Here's my wishlist:* USB HOST support (so I can just plug in a keyboard and start typing)* Must be SMALL, must be SMD - QFN and BGA packages are certainly options* Cheaper is better* A simple-as-possible development toolchain* Needing the least supporting components (some decoupling, I guess an external crystal as it's using USB)I suspect thenew RP2040 chipwould be perfect for me (overkill, perhaps) - I don't need a degree in engineering to understand the toolchain - but it's not available for purchase as individual chips yet, and may not be until summer or beyond. It'd be wasteful to de-chip the RPi Pico board, but I'm not against the idea. I have an awareness of the STM32-series of chips, but I've had difficulty in the past getting into their toolchain. A good enough reason now would make me spend more time learning the toolchain, but if there are alternatives that are easier, then that's a good result.Any suggestions welcome.

author: hexreader
author_rank: Frequent Contributor
timestamp: February 03, 2021, 05:07:36 pm
content: This gadget is easy to use...https://www.hobbytronics.co.uk/usb-host-keyboard?keyword=hostI do not know if it fits your requirement.I think it is even possible to download the firmware to your own (identical) PIC. Might be wrong...

author: nockieboy
author_rank: Super Contributor
timestamp: February 03, 2021, 05:39:30 pm
content: Quote from: hexreader on February 03, 2021, 05:07:36 pmAh yes, I've seen this before and discounted it as my GPU project is open source and I'd like to keep all the components of it that way. Plus, whilst it may slow things down and cause a lot of whining on my behalf, I like to learn how these things work and a black-box like the Hobbytronics product doesn't tick that box.It is, however, pretty much identical to what I want to do. I hadn't really thought about PIC chips as in my (very limited) experience with them, they've always been DIP, but maybe I shouldn't be so quick to discount them.Quote from: hexreader on February 03, 2021, 05:07:36 pmHmm.. I'm not so sure, having had a look - their chips seem to have a custom bootloader that is required to install the software to prevent pirating (their words, not mine).

author: ataradov
author_rank: Super Contributor
timestamp: February 03, 2021, 06:36:42 pm
content: Consider SAMD21. The smallest package is QFN32. From the external components you will need a crystal and a couple capacitors.SAMD21 is used in Arduino Zero, so there are a ton of example code out there.

author: langwadt
author_rank: Super Contributor
timestamp: February 03, 2021, 06:45:38 pm
content: USB host implemented in the FPGA?

author: ataradov
author_rank: Super Contributor
timestamp: February 03, 2021, 06:49:18 pm
content: It is a lot more work that it needs to be. You will still need USB PHY, which will take 12 pins and USB host controller would require quite a bit of effort to implement.Way easier to put the micro, which will take the same space on the board, and will just work.

author: langwadt
author_rank: Super Contributor
timestamp: February 03, 2021, 07:21:30 pm
content: Quote from: ataradov on February 03, 2021, 06:49:18 pmsure the a micro is less work, butyou can do low/full speed USB without a phy, if you don't have to strictly follow the spec you don't even need a transceiverso two pins is all that is needed, just like V-USB does USB in software on an AVRand since keyboards are afaik low speed USB what clock speed that is available isn't that critical as long as you can hit 1.5MBit

author: up8051
author_rank: Frequent Contributor
timestamp: February 03, 2021, 07:50:42 pm
content: CH554

author: ataradov
author_rank: Super Contributor
timestamp: February 03, 2021, 08:10:37 pm
content: In that case CH9350 is a ready USB HID host to UART converter.But it is not fun to deal with part with Chinese-only documentation.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 03, 2021, 08:24:18 pm
content: Otherwise you have the FTDI FT260:https://ftdichip.com/products/ft260q/It just works, has normal support and documentation, and is cheap.

author: ataradov
author_rank: Super Contributor
timestamp: February 03, 2021, 08:25:28 pm
content: FT260 is a device-only. OP needs a host.

author: nockieboy
author_rank: Super Contributor
timestamp: February 03, 2021, 10:19:40 pm
content: Quote from: langwadt on February 03, 2021, 06:45:38 pmI'm currently developing a USB interface using a MAX3421E to interface with the FPGA. That's complicated enough (I've got as far as enumeration and progress has slowed dramatically) - the issue is that I'm no expert with FPGAs, so progress is really slow now. I wanted to speed it up, not slow it down even further. Besides, a USB host in the FPGA would take up a lot of valuable block RAM and probably also need an HDL CPU in there to manage the stack etc. That would be a big complication for me when there are simpler, external solutions.Quote from: ataradov on February 03, 2021, 08:10:37 pmMy Cantonese isn't very good, and as for my Mandarin, well... less said the better.The CH559 looked interesting, but again the documentation is all primarily in Chinese which is - as you rightly point out - no fun at all.Quote from: ataradov on February 03, 2021, 06:36:42 pmI'll go take a look in some more detail at this suggestion - sounds like it could be the sweet spot between capability, price and ease of development for me. Thanks.

author: JPortici
author_rank: Super Contributor
timestamp: February 04, 2021, 06:17:12 am
content: also, PIC24 and PIC32 MX/MM have USB variants that come with 28pin DIP/SSOP/QFN packages, the good old MLA has ready made examples for HID host keyboard and mouse. They require at least an external clock/crystal, but then i think you can bypass everything else (power switch and overurrent logic)

author: Berni
author_rank: Super Contributor
timestamp: February 04, 2021, 06:56:08 am
content: Ah nice to hear that 8bit GPU project is still going.I would definitely go for a separate MCU to handle this. Things like PIC24 or STM32 chips with USB Host ports would work well. You can get examples for running HID devices on both to get you up and running quickly. If you like you can even get the MCU to read USB thumb drives and expose its contents for easily getting data onto that 8bit computer. Can operate as a C64 style intelligent disk drive that handles the filesystem for you.Communicating with the MCU can be done over a SPI slave port. It uses fairly few pins, is pretty fast and requires very little logic in the FPGA.

author: nockieboy
author_rank: Super Contributor
timestamp: February 04, 2021, 07:51:44 am
content: Quote from: JPortici on February 04, 2021, 06:17:12 amI'll take a closer look at the PIC range - it's been a few years since I even dabbled with them - but I suspect I've found my solution in the SAMD21; the dev environment and existing software base I can make use of for examples and guides is pretty strong, although I know PIC will have a fair few examples too.Quote from: Berni on February 04, 2021, 06:56:08 amHi Berni!That's another reason I didn't go for the 'black box' suggestion earlier in the thread. With a SAMD/PIC managing the USB, it leaves a LOT of flexibility in terms of what I can attach and make use of. The possibilities of USB storage are certainly not lost on me and I'd love to move away from the CompactFlash card I'm currently using to something more modern.I'm using SPI to communicate with the MAX3421E on my test board currently, so will probably stick with that interface for the final SAMD/PIC solution.

author: Berni
author_rank: Super Contributor
timestamp: February 04, 2021, 08:29:39 am
content: Yeah i guessed you would want other things than keyboards, including things like mice or gamepads.One thing to watch out for is that the simple USB host examples might not support USB hubs. Since if you start using it for more than just a keyboard then you will likely want the ability to simultaneously plug in multiple things. Most MCUs only have a single USB Host port so this means using a hub to create more ports from it. Tho one way to sidestep that is to simply use multiple MCUs.

author: ataradov
author_rank: Super Contributor
timestamp: February 04, 2021, 08:31:34 am
content: Yes, D21 would have issues with hubs. And the easiest solution would be indeed to use multiple D21s.

author: Nominal Animal
author_rank: Super Contributor
timestamp: February 04, 2021, 01:42:15 pm
content: Quote from: nockieboy on February 04, 2021, 07:51:44 amAre you aware of theArduino USB Host Shield(GitHub) project using MAX3421E also? It's basically exactly that: a SPI interface to an USB Host port using MAX3421E.Software is licensed under GPL, and schematics under CC by-nc-sa 3.0.

author: voltsandjolts
author_rank: Unknown
timestamp: February 04, 2021, 01:49:26 pm
content: If your looking for a quick ready-to-go solution but closed source there is this:https://www.hobbytronics.co.uk/usb-hostI have no affiliation, just used their FTDI host in the past which worked fine.

author: nockieboy
author_rank: Super Contributor
timestamp: February 04, 2021, 01:53:35 pm
content: Quote from: Nominal Animal on February 04, 2021, 01:42:15 pmYes, aware of that project and similarities to my current test setup. The issue I'm having is translating the relatively high level code and libraries into Verilog. I'm no expert with either and it's proving to be an uphill struggle, hence this thread looking for something simpler (and, actually, cheaper than using the MAX3421E).Quote from: voltsandjolts on February 04, 2021, 01:49:26 pmYes, this was suggesting earlier up the thread - an interesting device, but as my project is open source this is of little use to me.

author: nockieboy
author_rank: Super Contributor
timestamp: February 04, 2021, 01:59:45 pm
content: Quote from: ataradov on February 03, 2021, 06:36:42 pmI'm looking at the Itsybitsy M0 Express (have ordered one for testing) and it appears it doesn't even need an external crystal?! That makes it even cheaper.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 04, 2021, 05:10:27 pm
content: Quote from: ataradov on February 03, 2021, 08:25:28 pmOops, missed that, sorry.Then good luck implementing robust USB host with HID support on a random MCU. It's a recipe for endless compatibility pain.FTDI has a whole USB host series:https://ftdichip.com/product-category/products/ic/not as cheap, certainly, but not overly pricey either.

author: ataradov
author_rank: Super Contributor
timestamp: February 04, 2021, 07:48:12 pm
content: Quote from: nockieboy on February 04, 2021, 01:59:45 pmThe crystal is not needed when operating as a device. As a device D21 supports clock recovery. It looks at the SOF markers and adjusts its clock so that SOF frames appear at 1 ms intervals.You will need a crystal for the host mode, since there is no internal clock source accurate enough for the USB operation.

author: nockieboy
author_rank: Super Contributor
timestamp: February 04, 2021, 08:49:51 pm
content: Quote from: ataradov on February 04, 2021, 07:48:12 pmOh that's annoying - it looks like the Itsybitsy M0 Express doesn't have an external crystal on it... so won't be much use for USB host testing...

author: ataradov
author_rank: Super Contributor
timestamp: February 04, 2021, 08:53:42 pm
content: You can supply external clock.But also, with the micro USB connector, you would need an adapter cable to connect external devices.

author: nockieboy
author_rank: Super Contributor
timestamp: February 04, 2021, 08:58:17 pm
content: Quote from: ataradov on February 04, 2021, 08:53:42 pmYeah, it's just an extra thing to sort out though - no real issue, just glad you mentioned it otherwise I might have missed that in the small print in the datasheet!I'm probably going to use a micro USB connector on the final board anyway if I'm going to use two - there isn't room for more than one full-size USB connector, so adapter cables will be necessary. (I ordered one with the Itsybitsy).

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 04, 2021, 09:56:36 pm
content: PIC24 (from memory 24FJ64GB002) can do USB host without a crystal. Available in 28 pin DIP,SO,SSOP and QFN

author: ataradov
author_rank: Super Contributor
timestamp: February 04, 2021, 10:22:21 pm
content: Quote from: mikeselectricstuff on February 04, 2021, 09:56:36 pmThis is questionable. The datasheet is vague, but I don't see how it is possible.It has "FRC Accuracy @ 8 MHz" typical +/-0.25 % (min -1.25%, max +1 %). So already strange. 8 MHz would have to be multiplied to 48 MHz to eventually get 12 MHz, so the final accuracy would be worse.But even if we assume +/-0.25%, it is still not enough to operate a compliant host. USB spec requires +/-0.05% accuracy for hosts.It would probably work in practice at room temperature, especially for HID devices. But will definitely violate the spec.

author: Berni
author_rank: Super Contributor
timestamp: February 05, 2021, 06:49:32 am
content: Even if it doesn't have a crystal you can probably bodge one on there.As for when it is integrated onto the real PCB you don't need a crystal if you already have a FPGA on there. Just make the FPGA output the correct clock frequency on a pin and wire that straight into the crystal input pin.

author: nockieboy
author_rank: Super Contributor
timestamp: February 09, 2021, 11:18:33 am
content: Okay, so it looks like I'm going with the SAMD21 MCU for this application. I'm testing with an Itsybitsy M0 Express currently, just waiting on a USB OTG adapter cable to test a keyboard, but I'm getting events from the USB port, so it's looking good so far.Thanks everyone.