23

I want to program a microcontroller (AVR) to control some leds through USB. It's just out of interest in how to build and program USB devices. There are some AVR microcontrollers that support the USB protocol or I could implement the USB protocol in an another microcontroller myself, but I wonder what to use to write your own drivers on the computer.

My level in system programming: total noob (hence the question)

So what is the literature you people would advice to get good knowledge of the USB technology and how to write your own drivers and beyond?

P.S.: I know:

  • C (probably will need it here)

  • Java (probably won't need it here)

  • Python (hope can use it here)

  • assembler (hopefully won't need it here XD).

  • ...

P.P.S: driver development differs for different OS's. I use Linux and Windows, so any material related to one or both of these systems is welcome.

EDWH
  • 493
  • 2
  • 5
  • 11

10 Answers10

10

Well, although you can develop and write your own USB driver, the beauty of USB is that you don't need to write your own driver. the USB Implementers Forum has defined class specifications for all the standard device classes. If you can make your device fit into a standard device class the driver has already been written for you!

If you truly want to become familiar with USB development, you should start by reviewing the USB approved class specification documents.

Benubird
  • 15,843
  • 24
  • 83
  • 128
J Edward Ellis
  • 1,318
  • 1
  • 11
  • 20
5

If you are into framework for AVR microcontrollers with hardware USB then take a look into LUFA, and if you are into AVRs with software USB then look into V-USB. They have both implemented many USB classes so you don't have to do it on your own - just use them.

avra
  • 3,671
  • 16
  • 19
3

That sounds like a great project! I'd suggest starting off with something a little simpler since you're - as you say - a "total n00b". I'm not sure what hardware you currently have (or have in mind) but what I would suggest for the total beginner is the STK500. It's a development board that's very well supported in both Linux and Windows and will give you the most flexibility. It comes with LEDs and switches built in for your projects, but you will need to get a microcontroller. And for that I recommend the ATMega32, a great multi-purpose IC that's also well supported and has lots of documentation on the web.

Once you get those I suggest you do your development on Linux using avr-gcc (make sure to also install avr-libc). If you're using Ubuntu it's easy to get all the packages you need:

% sudo apt-get install gcc-avr avr-libc avrdude

Those should get you up and running. I'd suggest Googling around for help writing your first programs but another good resource is the online materials for this class at Cornell.

That's enough to get your feet wet with AVR microcontrollers and the development tools. The sky is the limit at that point but since you said you want to get into USB I'd suggest using the excellent V-USB framework to have your ATMega32 act as a USB device. After that, as they say, the steps to flipping LEDs are a piece of cake :).

Devrin
  • 1,030
  • 1
  • 10
  • 11
3

I wonder what to use to write your own drivers on the computer

  1. libusb (here, here and here)
  2. wdk
  3. WinDriver

For libusb variants info read this

Community
  • 1
  • 1
avra
  • 3,671
  • 16
  • 19
1

You could us libusb. It's powerful and cross-platform.

But what you're trying to do is a rather simple control interface. You can sidestep most of the complexity by using HIDAPI, I think.

http://www.signal11.us/oss/hidapi/

HID devices often use generic drivers that come packaged into the OS. That way you don't actually have to write any drivers ever, you just make your device compliant with the generic driver and tailor the client software to it.

I think this is what's usually done in the hobbyist electronics field, which is what you're interested in here.

HIDAPI is even recommended for simple communications with HID devices in the libusb FAQ since its a bit more complicated to do it across platforms using libusb.

CptAJ
  • 1,127
  • 1
  • 13
  • 20
0

I had built my own test bed based on the ARDUINO UNO and i was using the ionlabs programmer of type usbasp and it worked perfectly fine but it did not allow to convert the TTL back to Rs-232 and hence i couldn't use the features such as serial.print() and i had to install the ftdi cable which allowed me to do this. The drivers were the libusb 1.xx working just fine.

If you want to program the AVR you can use the ARDUINO software bundle or the stino to upload the programs. You need to know c(only basics).

lakshya_arora
  • 761
  • 5
  • 18
0

I created a USB-keyboard adapter last year for my capstone. I did not do the host programming but used existing code that you can find on the web.But I did program the device side and for that I got a lot of help from this website Teensy Look into their "Code Library" which has code for Keyboard, Mouse and others. Also, the USB protocol handbook will always be useful and you should always consult it when you are doing stuff with USB.

KuroNeko
  • 199
  • 2
  • 7
  • 17
0

The Microsoft documentation area of the WDK (Windows Development Kit) is recently available on MSDN. There is a section on USB, though you would be best to read the earlier sections first, in particular the "Getting Started" areas. They assume you'll be using C as the programming language for driver development.

For Linux, the Linux USB website should be able to point you in the right direction. In particular you'll want the Programming Guide for Linux USB Device Drivers.

Arvanitis Christos
  • 259
  • 1
  • 2
  • 15
Orbling
  • 19,537
  • 3
  • 48
  • 64
0

One good way to go is just to develop a HID device, since the driver is built in to most higher level OSes and pretty flexible for simple IO like you are talking about. Another good option is just using a USB RS232 device or software. I use PICs which have a number of nice devices with USB onboard.

kenny
  • 18,952
  • 7
  • 47
  • 82
0

I wonder whether your AVB acts as a host or device. I guess your board is a usb device and you need to light the leds on your board. So, it may be a good way to initialize your board as a HID device. To achieve this goal, you need a HID gadget software stack running on your board. References as follows:

  1. gadget framework in uboot
  2. HID specefication usb org
  3. debug tools such as USB Protocol Analyzer
  4. libusb running on Host PC to send packets
Kai Qiu
  • 1
  • 1