Author Topic: Getting started with USB  (Read 6824 times)

0 Members and 1 Guest are viewing this topic.

Offline 97hilfelTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: it
Getting started with USB
« on: July 06, 2016, 09:41:37 pm »
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
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Getting started with USB
« Reply #1 on: July 06, 2016, 11:20:46 pm »
That really depends on what you want to do. There are plenty of development boards for microcontrollers with USB support.
Alex
 

Offline 97hilfelTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: it
Re: Getting started with USB
« Reply #2 on: July 07, 2016, 11:37:44 am »
I want to get started with driver development.
And currently I dont wanna worry about the MCU part
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: Getting started with USB
« Reply #3 on: July 07, 2016, 02:43:23 pm »
I want to get started with driver development.
And currently I dont wanna worry about the MCU part
Get 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.
 

Offline 97hilfelTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: it
Re: Getting started with USB
« Reply #4 on: July 07, 2016, 03:27:33 pm »
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.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Getting started with USB
« Reply #5 on: July 07, 2016, 04:14:55 pm »
I want to get started with driver development. And currently I dont wanna worry about the MCU part
I 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?
Alex
 

Offline 97hilfelTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: it
Re: Getting started with USB
« Reply #6 on: July 07, 2016, 04:20:50 pm »
I will post the link to a site later


Gesendet von iPhone mit Tapatalk
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5315
  • Country: gb
Re: Getting started with USB
« Reply #7 on: July 07, 2016, 04:30:59 pm »
I want to get started with driver development.
And currently I dont wanna worry about the MCU part

If 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?
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Getting started with USB
« Reply #8 on: July 07, 2016, 04:55:35 pm »
Here is a good book:
https://www.amazon.com/USB-Complete-Developers-Guide-Guides/dp/1931448280

The 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.
 

Offline Kilrah

  • Supporter
  • ****
  • Posts: 1852
  • Country: ch
Re: Getting started with USB
« Reply #9 on: July 07, 2016, 05:45:26 pm »
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...
 

Offline mtdoc

  • Super Contributor
  • ***
  • Posts: 3575
  • Country: us
Re: Getting started with USB
« Reply #10 on: July 07, 2016, 06:30:26 pm »
Maybe outdated, but this might be helpful.
 
The following users thanked this post: Kilrah

Offline 97hilfelTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: it
Re: Getting started with USB
« Reply #11 on: July 07, 2016, 07:55:36 pm »
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).aspx
Since 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?
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Getting started with USB
« Reply #12 on: July 07, 2016, 08:09:19 pm »
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.
 

Offline 97hilfelTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: it
Re: Getting started with USB
« Reply #13 on: July 07, 2016, 08:16:00 pm »
well I dont want to get started with the hardcore stuff, first off all I may want to create a custon HID
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Getting started with USB
« Reply #14 on: July 07, 2016, 08:20:25 pm »
Since I am a C# programmer I want to get startet to beginn with a C# based solution no fancy C++ or something else.
You 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.
« Last Edit: July 07, 2016, 08:22:24 pm by ataradov »
Alex
 

Offline 97hilfelTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: it
Re: Getting started with USB
« Reply #15 on: July 07, 2016, 08:54:35 pm »
Ok thanks will look trough it
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2522
  • Country: us
Re: Getting started with USB
« Reply #16 on: July 07, 2016, 09:51:43 pm »
Check out the DLP Design USB products.  Easy to learn but expensive.  The ones with MCU on them have the firmware source code available after you purchase the item.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3781
  • Country: de
Re: Getting started with USB
« Reply #17 on: July 07, 2016, 10:02:55 pm »
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).aspx
Since 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?

Well, 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 actually build your 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.
 

Offline 97hilfelTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: it
Re: Getting started with USB
« Reply #18 on: July 07, 2016, 11:04:39 pm »
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).aspx
Since 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?

Well, 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 actually build your 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.
I 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.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3781
  • Country: de
Re: Getting started with USB
« Reply #19 on: July 08, 2016, 07:26:33 pm »

I 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.

Well, you still didn't say what 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.

« Last Edit: July 08, 2016, 07:28:36 pm by janoc »
 
The following users thanked this post: Kilrah

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5315
  • Country: gb
Re: Getting started with USB
« Reply #20 on: July 08, 2016, 09:03:21 pm »

I 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.

Well, you still didn't say what 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.

^ 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.
 

Offline 97hilfelTopic starter

  • Regular Contributor
  • *
  • Posts: 66
  • Country: it
Re: Getting started with USB
« Reply #21 on: July 09, 2016, 11:56:17 am »
I try to get started with usb


Gesendet von iPhone mit Tapatalk
 

Offline Kilrah

  • Supporter
  • ****
  • Posts: 1852
  • Country: ch
Re: Getting started with USB
« Reply #22 on: July 09, 2016, 12:12:40 pm »
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.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2522
  • Country: us
Re: Getting started with USB
« Reply #23 on: July 09, 2016, 12:26:43 pm »
well I dont want to get started with the hardcore stuff, first off all I may want to create a custon HID

Might 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!)
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3781
  • Country: de
Re: Getting started with USB
« Reply #24 on: July 09, 2016, 11:17:30 pm »
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 like http://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?

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf