Least painful way to add USB Host and Device - Page 1
Forum section: electronics / general

author: rheb1026
author_rank: Regular Contributor
timestamp: August 02, 2017, 07:25:59 pm
content: I'm working on a project with an STM32F4 as the processor and one of the specifications is to add USB connectivity. I'd like to add one host port so we can update firmware via a USB flash drive and read in data from a bar code scanner and I'd like to add one device/peripheral USB port so we can communicate with a PC at a later point.As it currently stands I've looked at the built in ST USB library, and I'm quite overwhelmed by it to say the least... Not to mention I don't want to use their HAL. I don't really know much about USB other than the most basic things and have no real desire to become an expert either. I'm wondering if someone can recommend a single chip solution to adding two USB ports?So far I've seen the FTDI VNC1L and the Cypress EZ-OTG. Does anyone have experience with either of these (good or bad)? Cost is not really a factor, within reason, and I would prefer to use UART/USART or SPI to communicate with the chip. Preference would go to a manufacturer that provides sample code. Forgot to add that data rate is not an issue either - even low speed would be okay in this applicationAre there any other options that I'm missing?

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: August 02, 2017, 08:03:47 pm
content: There are a few solutions which are basically preprogrammed MCUs, aimed primarily at storage - you'd need to look carefully at support for things like barcode readershttp://www.hobbytronics.co.uk/usb-host-flash-drivehttp://www.sunrom.com/p/serial-uart-to-usb-pen-driveI've seen at least one other.However to support other devices you probably have to dive into the manufacturer's library.If you don't want to integrate a big heap of library code into your application, an option would be to offload it to a second MCU, running just the USB stuff. This MCU could be chosen based on which manufacturer has the nicest/ most suitable/most understandable library.I've used the Microchip library in the past, just taking their example application and stripping out stuff I didn't need, but that was for a single device type.This will run on the 24F and 32MX parts, both available in 28 pin packages.Combining types will probably mean you will at the very least need to learn about how USB works to know how to use/adapt library code.

author: nctnico
author_rank: Super Contributor
timestamp: August 02, 2017, 08:11:34 pm
content: Check if LUFA is ported to the microcontroller. I have made a few projects using LUFA and it works OK but count on spending at least two weeks going through the code and examples.

author: rheb1026
author_rank: Regular Contributor
timestamp: August 03, 2017, 03:28:11 pm
content: Thank you both for the replies, I'll definitely look into those. Do you have any recommendations for reference material/books/tutorials for someone new to USB?

author: rstofer
author_rank: Super Contributor
timestamp: August 03, 2017, 05:22:05 pm
content: https://www.amazon.com/USB-Complete-Developers-Guide-Guides/dp/1931448280/ref=sr_1_1Scroll down and look at "Frequently Bought Together"

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: August 03, 2017, 06:20:01 pm
content: This one in particular :https://www.amazon.com/dp/1931448248/ref=rdr_ext_tmb

author: martinayotte
author_rank: Regular Contributor
timestamp: August 03, 2017, 07:49:38 pm
content: You can look at this forum too :http://stm32duino.com

author: rheb1026
author_rank: Regular Contributor
timestamp: August 04, 2017, 10:10:25 pm
content: Thanks, I'll see about getting those books. I found an older copy of the "USB Complete" by Jan Axelson online, which should keep me busy for a little while learning about the basics.I'll be sure to check out that site as well.I think in the end I may just go with ST's USB Library. I found an older standard peripheral version of it, so I can avoid the HAL mess. I spent the last hour or two just trying to get the OTG low level drivers to compile without errors... so not off to a great start