Getting started with AVR-USB

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers

Getting started with AVR-USB

Post by Samh » Tue Feb 06, 2007 3:42 pm


I am currently doing a project where I need to send and receive information from a computer to a microcontroller.

I have read through examples and read the corresponding information. I am however getting unstuck when it comes to the computer side. I understand I need the libusb, but do I need to install this onto the computer that will use the program I write or do I just need these files when compiling my code?

I am using windows xp and am real trouble getting started testing some of the example projects. I am trying to use Visual studio c++, as this is the environment I am most comfortable with and am also using avr studio 4, using a c project.

Can some one please help me out and tell me eactly what files I need where when it comes to comiling my code into exe/hex


Rank 4
Rank 4
Posts: 167
Joined: Sat Dec 16, 2006 9:53 pm
Location: Oregon, USA

Post by Grendel » Wed Feb 07, 2007 12:41 am

To compile AVR firmware you'll also need WinAVR. As for how to use libusb, check out the AVRUSBBoot project.

Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Fri Feb 09, 2007 7:52 pm

You need libusb only if you create a custom class device. If you rely on libusb, you need the runtime library on every machine where the device is connected. And it must be properly installed. You need to read through the docs of libusb to manage all this.

If you base your design on a HID class device, you can get away without libusb. However, if you use VC, you need Microsoft's DDK. If you use minGW (which is free), the DDK is included. See the Automator project to see an example.


Compiling the Automator

Post by Rich » Fri Feb 09, 2007 8:27 pm


I am a member of the project group working with Sam. I have managed to compile the firmware, however the i cannot get the Automator to compile. The steps i've taken are as follows:

-Installed: WinAVR, MinGW, MSYS (in that order)

-Built the fltk library's (configure, make and make install in MSYS)

-Downloaded the libusb win32 device bin and copied the files into the MinGW include and lib directories (usb.h and libusb.a) as described in the avrusbboot project readme

The instructions for the automator suggest that the next step should be as simple as running the make file in the application directory, after commenting out the 3 lines and un-commenting the windows lines. However this does not work for me, i'm getting endless errors in the MSYS windows the current is:

usbcalls.o(.text+0x50):usbcalls.c: undefined reference to HidD_GetHidGuid@4'

plus a few more lines all relating to the HidD_.......... from the Hidsdi.h file
from playing around a bit ive got the impression that solving this problem will just reveal more.

Can anyone point out any problems with what i've done thus far? im using windows XP and have uninstalled Visual studios

Im just trying to get the automator to compile so i can then make the mods required for our project to the code. As i have aquired the gui.h and gui.c files from the fluid part of the make file would it be a better idea to try and compile it with visual studios? what DDK files would i need to achieve this?

Many Thanks


Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Fri Feb 09, 2007 9:45 pm

You don't need libusb for this project, but it should not harm either.

The undefined symbol means that you are not linking one of the required libraries or that the libraries are not in the appropriate order. In my version of MinGW, HidD_GetHidGuid is contained in libhid.a. This file is at mingw/i386-mingw32msvc/lib on my computer.

There are only a few HID calls, so I expect no more problems once you have this part settled.


Post by Rich » Fri Feb 09, 2007 10:21 pm

i dont have that file path under my MinGW installation directory. Although I do have the libhid.a file. is it possible that i have been using the wrong version of MinGW. I would expect the Application makefile to work without requiring any modifications?

Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Fri Feb 09, 2007 10:31 pm

"mingw" is the directory where minGW is installed on my machine.

I'm afraid you can't expect ANY makefile to work "out of the box" these days because software versions change so fast and nobody has the time to test with all versions currently in use.

Can you please post (or mail me, throug the support form) the following information:
- the Makefile you use
- the exact output of "make" after a "make clean"

Maybe the real cause is somewhere else.

make file

Post by make file » Fri Feb 09, 2007 10:37 pm

# Name: Makefile
# Project: Automator
# Author: Christian Starkjohann
# Creation Date: 2006-02-01
# Tabsize: 4
# Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH
# License: Proprietary, free under certain conditions. See Documentation.
# This Revision: $Id: Makefile 126 2006-02-12 14:45:15Z cs $

# Please read the definitions below and edit them as appropriate for your
# system:

# Use the following 3 lines on Unix and Mac OS X:
#USBFLAGS= `libusb-config --cflags`
#USBLIBS= `libusb-config --libs`

# Use the following 3 lines on Windows and comment out the 3 above:
USBLIBS= -lhid -lusb -lsetupapi

CC= gcc
CXX= g++
CXXFLAGS= -O2 -Wall `fltk-config --cxxflags`
LIBS= `fltk-config --ldstaticflags` $(USBLIBS)

OBJ= automator.o gui.o parser.o usbcalls.o

all: $(PROGRAM)

fltk-config --post $(PROGRAM)

automator.o: automator.cpp gui.h

gui.cpp gui.h: gui.fl
fluid -c gui.fl

strip: $(PROGRAM)
strip $(PROGRAM)

rm -f gui.cpp gui.h $(OBJ) $(PROGRAM)

$(CC) $(ARCH_COMPILE) $(CFLAGS) -c $*.c -o $*.o

$(CXX) $(ARCH_COMPILE) $(CXXFLAGS) -c $*.cpp -o $*.o


Post by Rich » Fri Feb 09, 2007 10:39 pm

automator.exe is the output as far as im aware. if you could come up with a list of the files i require in specific locations i could check them off?


Post by Rich » Fri Feb 09, 2007 10:42 pm

earlier you said that libusb is not required for this project, however i was getting problems with the makefile line

USBLIBS= -lhid -lusb -lsetupapi

on the "-lusb", once i moved the files across as described in my first post this error stopped occuring an i ended up where i am now.

Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Fri Feb 09, 2007 10:44 pm

Yes, automator.exe is the output. I could probably come up with a list of files, but not with locations because these depend on various user choices.

Please also post the output of "make" after a "make clean". The exact error messages might give me a hint.


Post by Rich » Sat Feb 10, 2007 12:01 am

$ make clean
rm -f gui.cpp gui.h automator.o gui.o parser.o usbcalls.o Automator.exe

Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Sat Feb 10, 2007 12:08 am

That must have been a misunderstanding. I meant that you should do a "make clean" and then type "make" in the command line. The interesting part is the output of this second command, the "make" without parameters. This is where the errors are printed, after all. I only asked for the "make clean" to be sure that all modules are built and thus all warnings printed.


Post by Rich » Sat Feb 10, 2007 12:20 am

$ make clean


$ make
g++ -O2 -Wall `fltk-config --cxxflags` -c automator.cpp -o automator.o
automator.cpp: In function `void mainSaveToFile()':
automator.cpp:150: warning: `fl_ask' is deprecated (declared at
g++ -O2 -Wall `fltk-config --cxxflags` -c gui.cpp -o gui.o
gcc -O2 -Wall -c parser.c -o parser.o
gcc -O2 -Wall -c usbcalls.c -o usbcalls.o
g++ -O2 -Wall `fltk-config --cxxflags` -o Automator.exe automator.o gui.o parse r.o usbcalls.o `fltk-config --ldstaticflags` -lhid -lusb -lsetupapi
usbcalls.o(.text+0x50):usbcalls.c: undefined reference to `HidD_GetHidGuid@4'
usbcalls.o(.text+0x149):usbcalls.c: undefined reference to `HidD_GetAttributes@8 '
usbcalls.o(.text+0x1ad):usbcalls.c: undefined reference to `HidD_GetManufacturer String@12'
usbcalls.o(.text+0x1fd):usbcalls.c: undefined reference to `HidD_GetProductStrin g@12'
usbcalls.o(.text+0x2de):usbcalls.c: undefined reference to `HidD_SetFeature@12'
usbcalls.o(.text+0x36e):usbcalls.c: undefined reference to `HidD_GetFeature@12'
make: *** [Automator.exe] Error 1

Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Sun Feb 11, 2007 1:12 pm

OK. This may be a mismatch in the declaration of the HID functions.

We have a bit of a hack with these declarations since a header file was missing with my version of MinGW. Your MinGW may have this header and you should use it if it's there.

The header file is "hidsdi.h". Simply rename the file in the project to "hidsdi.h.disabled" and try to build (make clean; make). The library may require the right version of this header file.

Post Reply