WinAVR User Manual
WinAVR User Manual
=============================
Eric B. Weddington <arcanum@users.sf.net>
2.1 Manifest
~~~~~~~~~~~~
1. GNU Binutils 2.19
Binary utilities for AVR target (including assembler, linker, etc.).
2. GNU Compiler Collection (GCC) 4.3.2
C language and C++ language compiler for AVR target. There are
caveats for using the C++ compiler. See the installed avr-libc
User Manual in the <InstallDir>\doc directory.
3. avr-libc 1.6.6
C Standard Library for AVR.
4. AVRDUDE 5.6
avrdude is an open source programmer software that is user extensible.
5. GNU Debugger (GDB) / Insight 6.8
GDB is a command-line debugger. Insight is GDB with a GUI!
6. AVaRICE 2.9
avarice is a program for interfacing the Atmel JTAG ICE to GDB and users
can debug their AVR. Use it in conjunction with GDB.
7. SimulAVR 0.1.2.6
simulavr is used in conjunction with GDB to provide AVR simulation.
8. SRecord 1.38
SRecord is a collection of powerful tools for manipulating EPROM load files.
It reads and writes numerous EPROM file formats, and can perform many
different manipulations.
9. MFile
An automatic makefile generator for AVR GCC.
10. Programmers Notepad 2.0.8.718
Programming editor and IDE. This editor includes the Scintilla editor
component.
11. LibUSB 0.1.12.1 and device drivers
This is a USB library that is linked into AVRDUDE and AVaRICE to allow them
to connect to the Atmel JTAG ICE mkII and the Atmel AVRISP mkII. Drivers
for these devices are also included.
12. Cygwin DLLs
Certain DLLs from the Cygwin project are required for specific included
packages. See the Build Notes section for which packages require which DLL.
NOTE: Not all executables require these Cygwin DLLs.
13. Many native Win32 GNU programs and utilities including make and bash.
14. Tofrodos 1.6
A command-line text file line-ending convertor.
15. A Makefile Template for you to use in your projects.
16. Documentation for the various projects.
17. Source code patches used to build the various projects.
2.2 Layout
~~~~~~~~~~
Listed below are some directories you might want to know about.
`<install>` = The directory where you installed WinAVR.
*`<install>\bin`*::
The AVR software development programs. This directory should be in your
`PATH` environment variable. This includes:
- GNU Binutils
- GCC
- avrdude
- GNU Debugger (GDB)
- Insight
- AVaRICE
- SimulAVR
- SRecord
- Various required DLLs
*`<install>\utils\bin`*::
A collection of Unix programs built for the Windows
platform. The programs make and sh (bash) reside here. This directory
should be in your PATH environment variable.
*`<install>\avr\lib`*::
avr-libc libraries, startup files, linker scripts,
and stuff.
*`<install>\avr\include`*::
avr-libc header files. This is where, for
example, #include <string.h> comes from.
*`<install>\avr\include\avr`*::
avr-libc header files specific to the AVR
microprocessor. This is where, for example, #include <avr/io.h> comes
from.
*`<install>\lib`*::
GCC libraries, other libraries,headers and stuff.
*`<install>\libexec`*::
GCC program components
*`<install>\doc`*::
Various documentation. Before asking, RTFM! :-)
*`<install>\doc\avr-libc\examples`*::
Example projects with source code. Have fun!
*`<install>\sample`*::
Sample makefile (see below). Batch files to use in
compiling from AVR Studio 3.x (see below).
*`<install>\pn`*::
Programmers Notepad
*`<install>\mfile`*::
MFile
*`<install>\source`*::
Documentation on where to find the source code for the
various projects and source code patches that were used to build the tools.
*`<install>\utils\bin`*::
Utility programs, mainly from Unix-land that are used in building the
software, such as the shell (sh.exe), make.exe, and other programs called
from a Makefile.
*`<install>\utils\libusb\bin`*::
LibUSB programs and drivers.
2.5 LibUSB-Win32
~~~~~~~~~~~~~~~~
LibUSB-Win32 is a USB library that is linked into AVRDUDE and AVaRICE to allow
them to connect to the Atmel JTAG ICE mkII and the Atmel AVRISP mkII. Drivers
for these devices are also included. LibUSB is installed under:
`<install>\utils\libusb\bin`
The drivers for the JTAG ICE mkII and the AVRISP mkII are also located in the
above directory.
To install the LibUSB-Win32 drivers (when AVR Studio is not installed):
- Plug in your Atmel device (JTAG ICE mkII or AVRISP mkII).
- When Windows asks to locate drivers for this device, select "Install from
a list or specific location". Press Next.
- Uncheck the checkbox, "Search removable media".
- Check the checkbox "Include this location in the search" and select the
location of the drivers in the directory specified above. Press Next.
The driver will then be installed.
AVR Studio can install and use the USB drivers from Jungo (which is included as
part of the AVR Studio installation). However, the Jungo drivers and the
LibUSB-Win32 drivers are mutually exclusive; if one set is installed the other
set will not work.
You can uninstall the driver by plugging in the device (and making sure it is
powered on), use the Device Manager to find and select the device (under Jungo
or LibUSB-Win32, depending on which driver is installed), right click and select
"Uninstall". Then, install the other driver according to the correct procedures.
LibUSB also has a "filter" driver that is available, however, using this is
not recommended by the LibUSB author.
3.2 Compiler
~~~~~~~~~~~~
The compiler in WinAVR is the GNU Compiler Collection, or
http://gcc.gnu.org/[GCC]. This compiler is incredibly flexible and can be
hosted on many platforms, it can target many different different processors /
operating systems (back-ends), and can be configured for multiple different
languages (front-ends).
The GCC included in WinAVR is targeted for the AVR processor, is built to
execute on the Windows platform, and is configured to compile C, or C++.
CAUTION: There are caveats on using C++. See the avr-libc FAQ.
Because this GCC is targeted for the AVR, the main executable that is
created is prefixed with the target name: `avr-gcc.exe`. It is also referred to
as AVR GCC.
`avr-gcc` is just a "driver" program only. The compiler itself is called
`cc1.exe` for C, or `cc1plus.exe` for C++. Also, the preprocessor `cpp.exe`
will usually automatically be prepended with the target name: `avr-cpp.exe`.
The actual set of component programs called is usually derived from the suffix
of each source code file being processed.
GCC compiles a high-level computer language into assembly, and that is all. It
cannot work alone. GCC is coupled with another project, GNU Binutils, which
provides the assembler, linker, librarian and more. Since GCC is just a "driver"
program, it can automatically call the assembler and linker directly to build
the final program.
3.4 C Library
~~~~~~~~~~~~~
http://www.nongnu.org/avr-libc/[avr-libc] is the Standard C Library for
AVR GCC. It contains many of the standard C routines, and many non-standard
routines that are specific and useful for the AVR processor.
NOTE: The actual library is currently split into two main parts, libc.a and
libm.a, where the latter contains mathematical functions (everything mentioned
in <math.h>, and a bit more). Thus it is a good idea to always include the
`-lm` linker option. The WinAVR Makefile Template automatically includes the
`-lm` linker option. Also, there are additional libraries which allow a
customization of the printf and scanf function families.
avr-libc also contains the most documentation on how to use (and build) the
entire toolset, including code examples. The avr-libc user manual also
contains the FAQ on using the toolset.
3.6 Programming
~~~~~~~~~~~~~~~
After creating your software, you'll want to program your device. You can do
this by using the program `avrdude` which can interface with various hardware
devices to program your processor.
`avrdude` is a very flexible package. All the information about AVR processors
and various hardware programmers is stored in a text database. This database
can be modified by any user to add new hardware or to add an AVR processor
if it is not already listed.
3.7 Debugging
~~~~~~~~~~~~~
Debugging encompasses both simulation and emulation. Both are available in
WinAVR.
The GNU Debugger (`GDB`) is the main package that can be used for general
debugging. `GDB` is a command-line program only. `Insight` is GDB plus a GUI
written in Tcl/Tk. Both `GDB` and `Insight` are configured for the AVR and the
main executables are prefixed with the target name: `avr-gdb`, and
`avr-insight`. There is now also a "text mode" GUI for GDB: `avr-gdbtui`.
To do emulation with the JTAG ICE, GDB / Insight requires a "helper" program
called `avarice` which is also included.
To do simulation, GDB / Insight requires a different "helper" program called
`simulavr` which is also included.
There are also alternatives for simulation. Atmel offers a free package called
`AVR Studio` which can also do simulation. The latest version of `AVR Studio`
is 4.13. Note that `AVR Studio` is currently free to the public, but it is not
Open Source.
See the section, 5.0 Debugging, Simulating, and Emulating, for detailed
information on debugging.
////////////////////////////////////////////////////////////////////////////////
Building from AVR Studio 3.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is not currently recommended that you use AVR Studio 3.x as a build
environment. AVR Studio 3.x is no longer being developed by Atmel.
Programmers Notedpad is better for this. But if you want to, here's how
to do it.
Included in the <InstallDir>\sample directory are 2 batch files that
can be used to make your project from within the AVR Studio software
version 3.x from Atmel. These batch files are only needed if you have
Windows NT / 2000 / XP. For Windows 95 / 98 read on as well.
Currently there is only 3rd party compiler support with AVR Studio
version 3.x. There is NO 3rd party compiler support with AVR Studio
version 4.x at the time of this writing. AFAIK, you can have both versions
of AVR Studio side-by-side on your computer.
To make your project from AVR Studio version 3.x:
1. Copy gcc.bat and gcc2.bat from the <InstallDir>\sample directory to
your project directory.
2. In AVR Studio, set up a project with 2 targets: all, and clean. CAUTION!
When you create a target, in the Add New Target dialog, type in the name
of the target, and you MUST select an item from the "Copy Settings From"
drop-down list. If you do not select something from this list, AVR Studio
has been known to crash. Selecting the "Debug" item on this list is fine.
3. With the all target selected, go to menu Project > Settings. You should
get a dialog box titled Target Options.
4. The setting "Run 'compile' on each file in Source Files group" should
be unchecked.
5. The setting "Run linker/build stage tools" should be checked.
6. In the Run Stage Settings group, under the "If output contains the
following text:" heading, the edit box should have: "Errors: none".
7. Check the radiobutton "Don't run the code".
8. In the Command line box, write: gcc.bat all
9. Press OK.
10. Do the above for the clean target, except for number 7 in the Command
line box, write: gcc.bat clean
11. Save the project.
12. You can delete the targets debug and release.
In general, the batch files take care of calling the make program and
redirecting the output in a way that AVR Studio can handle. The one parameter
that the batch files accept is a target of your makefile that gets passed to
the make program.
For Windows 95 / 98, the batch files are unnecessary. AVR Studio can call the
Command line directly. To make your project, follow the directions outlined
above except for number 8 change it to:
8. In the Command line box, write: make all
Do the same thing for number 10 above. Instead of writing gcc.bat clean, write
make clean.
The make program executes according to your makefile. A makefile defines how
your project is built. For more information on the make program and writing
makefiles, see the Links below for GNU Manuals Online or in the
<InstallDir>\doc directory.
To have AVR Studio automatically load COFF files after build: select target,
Menu: Project > Settings, Target Options dialog, Extension of object file to
load, change obj to cof.
////////////////////////////////////////////////////////////////////////////////
6.2 Other
~~~~~~~~~~
Here are some links to free or open source components that may be useful.
http://www.sics.se/~adam/uip/[uIP - TCP/IP Stack for Embedded Microcontrollers]:
:
uIP is an implementation of the TCP/IP protocol stack intended for small
8-bit and 16-bit microcontrollers. It provides the necessary protocols for
Internet communication, with a very small code footprint and RAM
requirements - the uIP code size is on the order of a few kilobytes and RAM
usage is on the order of a few hundred bytes.
http://www.sics.se/~adam/pt/[Protothreads]::
Protothreads are extremely lightweight stackless threads designed for
severely memory constrained systems such as small embedded systems or
sensor network nodes. Protothreads provide linear code execution for
event-driven systems implemented in C. Protothreads can be used with or
without an underlying operating system.
7.1 Documentation
~~~~~~~~~~~~~~~~~
The first and best place to find help is in the documentation! WinAVR includes
the user manuals for many of the software tools that are shipped in the
package.
The documentation for any particular package may come in different formats
depending upon what is available from that package and available space
in the WinAVR installation. The different documentation formats that you'll
find in WinAVR are:
1. HTML - Hyper Text Markup Language. Requires a web browser to view.
2. PDF - Portable Document Format. Requires a PDF viewer such as Acrobat.
Additionally many user manuals can also be found online, especially packages
that are part of the GNU project. You can find links to many of these in the
Links section below.
For packages that have HTML, and PDF documentation, look in your
`<install>\doc` directory.
WinAVR installs on your desktop two shortcuts. One is to the HTML
documentation on avr-libc that is installed locally. The other shortcut is
to the GNU Manuals online (which requires Internet connection).
Help for other projects and tools included in WinAVR can usually be found at
the individual project's web page which usually includes links to their
mailing lists.
If you need help, do not contact the WinAVR developers personally! Use these
web sites and mailing lists first!
#1) 'When I run a program, why do I get the error "You have multiple copies of c
ygwin1.dll on your system."?'
Certain packages in WinAVR are built with Cygwin and are linked to their
emulation library: cygwin1.dll. If you also have Cygwin installed seperately,
these programs will find the cygwin1.dll that is shipped and included with
WinAVR, and will also find the cygwin1.dll in your Cygwin installation. If
these versions are different, you will get this error.
WinAVR must ship the cygwin1.dll file to support it's packages, as most people
do not have Cygwin installed on their system and it's not fair to ask people to
install such a huge package as a prerequisite.
Unfortunately, the http://cygwin.com/faq.html[Cygwin FAQ] says that the only
way around this is to remove other copies of cygwin1.dll. This would mean
either uninstalling Cygwin so the WinAVR programs work, or perhaps renaming
the cygwin1.dll found in the `<install>\bin` directory so the WinAVR programs
will use the cygwin1.dll that is in the Cygwin installation. However, if you do
the latter, note that the version of cygwin1.dll you have in your Cygwin
installation is probably different than the version of cygwin1.dll that was
used to build the WinAVR programs. In this case, use at your own risk.
#2) 'I have any of the following warnings when I create a COFF file, what should
I do?'
---------------------------------------------------------------------------
Warning: file {standard input} not found in symbol table, ignoring
Warning: ignoring function __vectors() outside any compilation unit
Warning: ignoring function __bad_interrupt() outside any compilation unit
Discarding local symbol outside any compilation unit: .__do_copy_data_start
Discarding local symbol outside any compilation unit: .__do_copy_data_loop
---------------------------------------------------------------------------
Nothing. These warnings can be ignored.
#3) 'I use WinAVR with AVR Studio. I get an error when avr-objcopy is creating t
he load file for the EEPROM. It says there are no sections to be copied.'
avr-objcopy is a part of GNU Binutils. In GNU Binutils 2.17 or later, the objcop
y
program was changed to return an error when there are no sections to be copied.
This is different than previous versions of the objcopy program. This is not
really an error, as it is ok if there are no sections to be copied.
The Makefile has to be aware of this new behaviour and to not accept this as
a real error. Use the WinAVR Makefile Template as the basis of your Makefile, or
use AVR Studio 4.13 (soon to be released, if not already) which has changed how
it generates its internal Makefile on GCC projects to correctly account for this
.
10.2 Credits
~~~~~~~~~~~~
Thank you to everyone who uses WinAVR!
- WinAVR software devleopment toolset distribution built by
Eric B. Weddington +
mailto:arcanum@users.sourceforge.net[email]
One person cannot do all of this alone. There are many, many people involved
in making this package what it is. I am deeply indebted to those people. Below
is an attempt at a list of credits. Any omissions are my fault and corrections
are solicited.
- Very Special Thanks to Joerg Wunsch for helping this project in
innummerable ways including writing the AVR COFF patch for binutils; patches
for GCC to help with debugging and binary constants; being the resident guru
on AVR Freaks; writing portions of this manual; reviewing all of my wacky
ideas; building SRecord; getting me in contact with the right people at the
right time ;-) ; spending the time to take me on a beautiful hike near his
home town; and for tolerating me over the years.
I don't know why he does it, but I am eternally grateful. :-)
- Very Special Thanks to major contributers to the AVR toolset: Denis Chertykov,
Marek Michalkiewicz, Theodore (Ted) A. Roth, Joerg Wunsch, Michael Stumpf,
Reiner Patommel, Brian S. Dean, Scott Finneran, David Gay, Jason Kyle,
Bjoern Haase, Anatoly Sokolov, Dmitry Xmelkov, Andy Hutchinson.
- Thanks to Brian Dessent and Dave Murphy (wintermute) for help in getting
the toolchain to work on Windows Vista. Thanks to Dave Murphy for the patch
for Insight.
- Very Special Thanks to Bjoern Haase for taking the time and effort to put
together the patches to add support for the ATmega256x devices and for the
last minute phone call with Joerg to resolve the last problem!
- Very Special Thanks to Colin O'Flynn for writing a tutorial on how to install
and configure WinAVR, writing a tutorial on how to use Insight, for testing
WinAVR, all around assistance, and helping on avrdude.
- Very Special Thanks to Torleif Sandnes for all his help in getting WinAVR
to work in AVR Studio in all its various ways.
- Thanks to SourceForge for hosting the WinAVR project.
- Very Special Thanks to Simon Steele for permission to include Programmers
Notepad in WinAVR. Programmer's Notepad is written and built by Simon Steele.
- Native Win32 Unix programs from:
* Karl M. Syring <http://www.weihenstephan.de/~syring/win32/UnxUtils.html>
* http://www.morpheus.demon.co.uk/ (bison and flex)
* http://www.mingw.org/[MinGW]
- Tofrodos 1.6 is written and built by Chistopher Heng
- Thanks to the following people for additional material for the
Makefile Template: Tim Henigan, Peter Fleury, Joerg Wunsch, Reiner Patommel,
Sander Pool, Frederik Rouleau, Markus Pfaff, and Carlos Lamas.
- Special Thanks to Markus Assfalg for all his input in doing AVR COFF
pre-alpha tests and to Svenn-Ivar Svendsen from Atmel Norway, who
willingly answered questions regarding Atmel's COFF specs.
- Very Special Thanks to Torleif Sandness of Atmel, the principal developer of
Atmel's ELF parser for AVR Studio, for really pioneering that area.
- Thanks to members of the AVR COFF Alpha Testing team, which include:
Wallace White, Markus Assfalg, Volkmar Dierkes, Marc Wetzel, Andrew Ghali,
Omer Sinan KAYA, Eric Weddington.
- Thanks to Atmel and to Advanced Micro Tools (AMTools), makers of
the VMLAB debugger tool, for assistance in the endeavour of writing
the AVR COFF patch.
- Special thanks to Nick Moore for designing the WinAVR logos!
- Special thanks to http://www.tulsawebdev.com[Brian Brill] for helping
to move around some large files for the first release; to Ted Roth
for hosting the first WinAVR release on the avr-libc web site.
- Very Special Thanks to *Ted Roth* and *Joerg Wunsch* for putting up with me
when I was starting out.
- And a Very Special Thank You to Atmel Corporation.
10.3 Future
~~~~~~~~~~~~
- AVR-Ada. We're still committed to adding the Ada compiler and AVR-Ada back in.
There are issues regarding build tools that have to be worked out, but progress
is happening.
- The next release of WinAVR will have a big new addition. Watch for it!
- The next release is planned for some time in May/June.
11.0 Links
----------
http://sourceforge.net/projects/winavr[WinAVR Project] +
http://winavr.sourceforge.net/[WinAVR Home Page]
http://sourceforge.net[SourceForge]
http://www.avrfreaks.net[AVR Freaks]
http://savannah.nongnu.org/mail/?group=avr[avr-gcc mailing list] +
http://savannah.nongnu.org/mail/?group=avr[avr-chat mailing list]
http://www.atmel.com[Atmel] +
http://www.atmel.com/products/avr/[Atmel AVR microcontrollers] +
http://www.atmel.com/dyn/products/tools.asp?family_id=607[Atmel's AVR Tools and
Software] +
http://www.atmel.no/beta_ware/[Atmel Norway's AVR Tools Beta Site]
http://www.gnu.org/[GNU Project]
http://www.gnu.org/manual/[GNU Manuals Online]
http://sources.redhat.com/binutils/[GNU Binutils]
http://www.gnu.org/software/gcc/[GNU Compiler Collection (GCC)]
http://www.gnu.org/software/gcc/onlinedocs/[GCC Manuals Online]
http://savannah.nongnu.org/projects/avr-libc/[avr-libc]
http://savannah.nongnu.org/projects/avrdude/[avrdude]
http://sourceforge.net/projects/avrdude-gui[avrdude-gui]
http://savannah.nongnu.org/projects/uisp/[uisp]
http://sources.redhat.com/gdb/[GNU Debugger (GDB)]
http://sources.redhat.com/insight/[Insight]
http://sourceforge.net/projects/avarice[avarice]
http://savannah.nongnu.org/projects/simulavr/[simulavr]
http://avr-ada.sourceforge.net/[AVR-Ada]
http://www.sax.de/~joerg/mfile/[MFile]
http://www.pnotepad.org/[Programmers Notepad] +
http://www.scintilla.org/[Scintilla]
http://srecord.sourceforge.net/[SRecord]
http://www.splint.org/[Splint]
http://libusb-win32.sourceforge.net/[LibUSB-Win32]
http://reality.sgiweb.org/davea/dwarf.html[dwarfdump]
http://www.cs.utah.edu/~regehr/stacktool/[stacktool]
http://www.barello.net/avrx/[AvrX]
http://www.ethernut.de/en/[EtherNut - Nut/OS]
http://www.freertos.org/[FreeRTOS]
http://webs.cs.berkeley.edu/tos/[TinyOS]
http://www.sics.se/~adam/contiki/[Contiki]
http://sourceforge.net/projects/xmk[XMK - eXtreme Minimal Kernel]
http://picoos.sourceforge.net/[Pico OS]
http://usmartx.sourceforge.net/[uSmartX]
http://libtom.org/?page=features&newsitems=5&whatfile=crypt[LibTomCrypt]
http://www.sics.se/~adam/uip/[uIP - TCP/IP Stack for Embedded Microcontrollers]
http://www.sics.se/~adam/pt/[Protothreads]
http://www.thefreecountry.com/[Tofrodos]
http://www.gnu.org/software/make/[GNU Make]
http://www.mingw.org/[MinGW]
http://www.cygwin.com/[Cygwin]
http://savannah.nongnu.org/projects/freeice[Free ICE]
http://pymite.python-hosting.com/[Pymite]
http://sourceforge.net/projects/nanovm[NanoVM]
http://www.catb.org/~esr/jargon/[Jargon]