Getting started with USB - Page 1
Forum section: electronics / beginners

author: 97hilfel
author_rank: Regular Contributor
timestamp: July 06, 2016, 09:41:37 pm
content: Hello everyone,I was thinking about getting started with USB.Is there a good guide/book I can use? And is there a good devboard?Felix

author: ataradov
author_rank: Super Contributor
timestamp: July 06, 2016, 11:20:46 pm
content: That really depends on what you want to do. There are plenty of development boards for microcontrollers with USB support.

author: 97hilfel
author_rank: Regular Contributor
timestamp: July 07, 2016, 11:37:44 am
content: I want to get started with driver development.And currently I dont wanna worry about the MCU part

author: Brutte
author_rank: Frequent Contributor
timestamp: July 07, 2016, 02:43:23 pm
content: Quote from: 97hilfel on July 07, 2016, 11:37:44 amGet FTDI chip/board/module.Like FT232B or FT232R (Full Speed). If you want something faster then FT232H (Hi-Speed).The company provides free libraries for every possible OS variant and you can find many examples of how to use that. The chip itself can be configured but not programmed, as the uC. So it is easy to start with. They provide a free tool (Mprog?) that does the configuration if you do not like the default settings.

author: 97hilfel
author_rank: Regular Contributor
timestamp: July 07, 2016, 03:27:33 pm
content: I will give it a look, I saw the osr usb fx2 (https://store.osr.com/product/osr-usb-fx2-learning-kit-v2/) but its a bit expensive for a small mcu, a seven segment display and a led bar.

author: ataradov
author_rank: Super Contributor
timestamp: July 07, 2016, 04:14:55 pm
content: Quote from: 97hilfel on July 07, 2016, 11:37:44 amI don't understand. Typically you develop a driver for specific tasks and most of the tasks are already covered by the OS drivers. How you can develop a driver for unknown hardware?

author: 97hilfel
author_rank: Regular Contributor
timestamp: July 07, 2016, 04:20:50 pm
content: I will post the link to a site laterGesendet von iPhone mit Tapatalk

author: Howardlong
author_rank: Super Contributor
timestamp: July 07, 2016, 04:30:59 pm
content: Quote from: 97hilfel on July 07, 2016, 11:37:44 amIf you can avoid that, I would do so. Writing core USB drivers for specific hardware is time consuming and demanding, more so if you are to support cross platform and cross architecture compatibility.I strongly recommend either using a class driver commonly already built into the OS, such as HID, mass storage device or Audio 1.0, or leverage WinUSB and/or LibUSB.How are you going to test anything without a target device?

author: rstofer
author_rank: Super Contributor
timestamp: July 07, 2016, 04:55:35 pm
content: Here is a good book:https://www.amazon.com/USB-Complete-Developers-Guide-Guides/dp/1931448280The Cypress FX2 series chips seem fairly popular but almost every ARM uC has a USB peripheral and can do host, client or OTG.I didn't find an inexpensive FX2 board, the Cypress development kit is over $400.I find it odd that Cypress bases their FX2 device on the 8051. Still, there are C compilers (and Pascal, for that matter) available.

author: Kilrah
author_rank: Unknown
timestamp: July 07, 2016, 05:45:26 pm
content: Do you want to write drivers that run on a microcontroller / embedded system, or on a PC? If the latter what OS? For what kind of device on the other end?Too little info and very different fields...

author: mtdoc
author_rank: Super Contributor
timestamp: July 07, 2016, 06:30:26 pm
content: Maybe outdated, butthis might be helpful.

author: 97hilfel
author_rank: Regular Contributor
timestamp: July 07, 2016, 07:55:36 pm
content: Ok here I am back,I found a few days ago this link:https://msdn.microsoft.com/en-us/library/windows/hardware/hh706183(v=vs.85).aspxSince I am a C# programmer I want to get startet to beginn with a C# based solution no fancy C++ or something else.Currently I am just interrested in getting a few basics and a general understanding of the Bus and then later on I want to get into some highspeed stuff and the costum classes stuff.May the teensy 3.2 a good startingpoint?

author: rstofer
author_rank: Super Contributor
timestamp: July 07, 2016, 08:09:19 pm
content: I used an earlier version of the Teensy as a HID device to link physical knobs, dials and switches to Microsoft Flight Simulator - it worked well.The thing is, I think you are looking at the wrong end! The Teensy will be a device, probably a HID device, and the PC HID USB driver is written by Microsoft. It works for all compliant HID devices. Same with the CDC and Mass Storage drivers - these are written by Microsoft (or the Linux wizards).If I recall correctly, I used Microsoft Visual Studio with an external toolchain to write the code for the Teensy. This was nice because the interface code for the Flight Simulator was written using the same Visual Studio.

author: 97hilfel
author_rank: Regular Contributor
timestamp: July 07, 2016, 08:16:00 pm
content: well I dont want to get started with the hardcore stuff, first off all I may want to create a custon HID

author: ataradov
author_rank: Super Contributor
timestamp: July 07, 2016, 08:20:25 pm
content: Quote from: 97hilfel on July 07, 2016, 07:55:36 pmYou can't write actual drivers in C#. But you can probably write application code if you use some standard protocol.Here is sample code (in plain C) that talks to USB HID device -https://github.com/ataradov/edbg/blob/master/dbg_win.c. No external drivers required, just the ones supplied with the OS. I'm pretty sure you can translate windows API function calls to C# 1:1.Edit: And here is example of USB HID to I2C-master gateway for Atmel SAM D21 -https://github.com/ataradov/dgw/tree/master/embedded. It works on SAM D21 Xplained Pro board. But those boards can be quite expensive.

author: 97hilfel
author_rank: Regular Contributor
timestamp: July 07, 2016, 08:54:35 pm
content: Ok thanks will look trough it

author: MarkF
author_rank: Super Contributor
timestamp: July 07, 2016, 09:51:43 pm
content: Check out theDLP Design USBproducts. Easy to learn but expensive. The ones with MCU on them have the firmware source code available after you purchase the item.

author: janoc
author_rank: Super Contributor
timestamp: July 07, 2016, 10:02:55 pm
content: Quote from: 97hilfel on July 07, 2016, 07:55:36 pmWell, if you are C# programmer, then I would start with learning C first. C# has no really good way to interface with hardware, so you will have to use external libraries written in C/C++ anyway. Talking to hardware also requires using bitwise operations and various bit twiddling tricks - easy to do in C/C++ but enormous pain and unreadable mess thanks to the idiotic C# type casting requirements.That MSDN link shows how to write Windows drivers - in C/C++. You can't do it in C#, sorry.However, if you are only starting, I would strongly recommend that you actually get your feet wet with libusb or HIDAPI libraries first. It is orders of magnitude simpler than poking around the poorly documented Windows internals. And you don't have to bother with signing the drivers or crashing your PC should you make a silly mistake.If you buy a Teensy (or whatever else) you will also program it in C/C++ (masochists use assembler), because it doesn't magically do anything by itself. C# is almost completely useless for embedded work.However, if your goal is only to learn to talk to hardware and not to actuallybuildyour own USB hardware, you don't need to buy anything - you can always use a USB keyboard, mouse or something similar for testing. There are plenty of USB devices around.

author: 97hilfel
author_rank: Regular Contributor
timestamp: July 07, 2016, 11:04:39 pm
content: Quote from: janoc on July 07, 2016, 10:02:55 pmI know most of the facts but I pretty much dont know where to get started. I learned how to code in assembler, sometimes stuff can be simpler and faster but as soon as you inplement a serial interface you are screwed up.

author: janoc
author_rank: Super Contributor
timestamp: July 08, 2016, 07:26:33 pm
content: Quote from: 97hilfel on July 07, 2016, 11:04:39 pmWell, you still didn't saywhat you actually want to do. Do you want to learn to build USB devices? Then the Teensy could be a good choice, along with some book on the USB protocol and the USB specs.You don't care about the hw, but you want to write drivers for some OS? (btw, why if you aren't manufacturing anything?) Then you should study the API of your OS of choice and the USB specs again.In both cases you will need C, though, so learning it to a good level would be a start. If you aren't comfortable with working with pointers, addresses, individual bits, bitwise operations, etc., you will have very hard time attempting to even understand how to write a driver. However, if you have hard time dealing with a serial interface, whether in assembler or another language, then I don't see how you can handle USB - it is a protocol several orders of magnitude more complex.

author: Howardlong
author_rank: Super Contributor
timestamp: July 08, 2016, 09:03:21 pm
content: Quote from: janoc on July 08, 2016, 07:26:33 pm^ This. If you tell us what you are specifically trying to achieve, we can give you some pointers. Right now all you've said is "I want something to eat", but we don't know if it's pizza, burger, fish'n'chips, noodles, etc: all of those you can either make yourself with some effort or, save some of that effort, and have some or all of it ready made for you. Without a reasonable starting point of reference you're likely to go hungry.

author: 97hilfel
author_rank: Regular Contributor
timestamp: July 09, 2016, 11:56:17 am
content: I try to get started with usbGesendet von iPhone mit Tapatalk

author: Kilrah
author_rank: Unknown
timestamp: July 09, 2016, 12:12:40 pm
content: But that doesn't mean anything.There are many subjects around USB, only once you pick one and decide of a particular thing you want to attempt around it will you be able to get advice.

author: MarkF
author_rank: Super Contributor
timestamp: July 09, 2016, 12:26:43 pm
content: Quote from: 97hilfel on July 07, 2016, 08:16:00 pmMight I suggest getting a joystick and writing a program to read all the inputs. It starts to get interesting when the basic sample programs don't support all the buttons and you have to add them. (Speaking from experience!)

author: janoc
author_rank: Super Contributor
timestamp: July 09, 2016, 11:17:30 pm
content: Well ... If you only want to talk to the device using a library like HIDAPI, then HID is OK and relatively easy protocol to handle from the host/application side.HOWEVER- if you mean you want to build a custom HID device (custom game controller, keyboard, etc.), then you are in a world of pain. HID builds on top of the basic USB, so you must first understand that -> USB specs and several sites likehttp://www.usbmadesimple.co.uk/are your friends.HID itself is a very complicated mess on top of this, especially building of the various descriptors if you want them to work over multiple OS-es (Windows can be super picky/noncompliant!).Of course, all of the above assumes that you know how to use the USB stack on your chosen microcontroller (Teensy, etc.).Again, if you want help, you need to be more precise - saying "I want to do something with USB" is meaningless, because there are so many things that could be done. You can also take an USB cable, plug it in and be done with it ... Satisfies "doing something with USB". See the problem with your communication?