This document will be of use to anyone who cannot (or will not) use Atmel's excellent and free AVR Studio.
The instructions in this document explain how to combine code written for AVRs using WebbotLib with the compiled processor specific static library without using AVR Studio.
This document does not contain information on uploading compiled code to an AVR.
There are
a few ways of acheiving building code for AVRs but they all involve
manipulating the avr-gcc compiler and associated tools (an AVR specific
compiler based on Gnu Compiler Collection).
Also required are the AVR LibC C libraries.
1. Implement avr-gcc and associated tools from the command line.
2. Use a Makefile to automate the gcc build process.
3. Use Apache Ant to automate the gcc build process. (Not discussed in this doc. A document on Ant will follow. ***Insert Future Link Here***)
4. Run AVR Studio in Wine. (Not recommended for new users. See "Further reading" section at end.)
5. Configure an IDE other than AVR Studio. (See "Other methods of building your project" section at end.)
In this document we will discuss 1. and 2. from the list above.
Before you start make sure the following software tools are installed:
These tools are all available under some sort of Open Source license so are free to use.
4. WebbotLib (This is why we are here right?)
This page http://electrons.psychogenic.com/modules/arms/art/3/AVRGCCProgrammingGuide.php provides a more thorough description of these components.
Installing these components varies a little depending on your platform.
Depending on your distribution use your package manager to search for the 3 tools listed above.
For your first WebbotLib
program read WebbotLib-x-xx.pdf included in your WebbotLib package.
Read the stuff on AVR Studio as well so you get an idea of what we are
trying to achieve.
From here on i will presume you have the
sample Hello World program from WebbotLib-x-xx.pdf in a folder called
"~/Geek_projects/avr_projects/WebbotLib_test" and saved it with the
filename "main.c".
I will also presume you have installed WebbotLib in the directory /usr/lib/avr/lib/WebbotLib.
Edit these instructions to suit you install directories and filenames.
Implement avr-gcc and associated tools from the command line.
| # Name: Makefile # Created: 12/FEB/2010 to work with WebbotLib-1-15 # Last Updated: 12/FEB/2010 # PROJECT is the program file name used without the .c # Choose TARGET to match your MCU from this list: atmega8, atmega32, atmega168, atmega640, atmega329p, atmega2560, atmega2561 # Choose LIBRARY to match your MCU from this list: Webbot-ATMega8, Webbot-ATMega32, Webbot-ATMega168, Webbot-ATMega640, Webbot-ATMega328P,Webbot-ATMega2560, Webbot-ATMega2561 # CPU_SPEED is in Hz. 16MHz = 16000000. 8MHz = 8000000. 1MHz = 1000000 # WEBBOTLIB is where you unpacked WebbotLib. PROJECT = main TARGET = atmega2560 LIBRARY = Webbot-ATMega2560 CPU_SPEED = 16000000 WEBBOTLIB = /usr/lib/avr/lib/WebbotLib/ # If your system has problems finding avr-gcc, specify the full path here. GCC = avr-gcc LINKER = avr-objcopy COMPILE = -Wall -I"$(WEBBOTLIB)" -mmcu=$(TARGET) -Wall -gdwarf-2 -std=gnu99 -DF_CPU=$(CPU_SPEED)UL -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP LINK = -L"$(WEBBOTLIB)" -mmcu=$(TARGET) -Wl,-Map=WebbotTest.map -l$(LIBRARY) -lm -lc # symbolic targets: all: link compile: $(GCC) $(COMPILE) -c $(PROJECT).c -o $(PROJECT).o -MT $(PROJECT).o link: main.elf compile $(GCC) $(PROJECT).o $(LINK) -o $(PROJECT).elf copy: main.hex link $(LINKER) -O ihex $(PROJECT).elf $(PROJECT).hex clean: rm -f main.elf main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o main.s main.elf: rm -f main.elf main.hex: rm -f main.hex |
You will see avr-gcc commands like in Method 1. Hopefully no errors.
If you want to delete all the working files so you can build from scratch issue:
If you just want to compile the "main.o" file without linking it for whatever reason:
It
is beyond the scope of this document to go into detail on how to write
a Makefile but the one included here is enough to build simple projects
with WebbotLib.
Use Apache Ant to automate the gcc build process.
Ant
is used by Webbot to build the WebbotLib static libraries. As a tool it
is far better suited to building projects with multiple dependencies.
For more information about using Ant to build WebbotLib look here:
http://www.societyofrobots.com/member_tutorials/node/382
Run AVR Studio in Wine.
This is possible.
According to WineHQ.org if you get the right version of Wine and the right version of AVR studio it will run without problems.
http://appdb.winehq.org/objectManager.php?sClass=application&iId=402
My
experiment today for this article with Wine-1.1.38 and AVR Studio 4.18
was barely usable with particular issues using the mouse when selecting
files. (Things usually worked when i entered file paths and names by
the keyboard.)
So in summary, i advise against Wine unless you have exactly the versions of everything recommended by WineHQ.
Configure an IDE other than AVR Studio.
I have had good success with KontrollerLab on Linux. It integrates with most hardware programmers and has a serial console built in.
The down side of KontrollerLab is it is not possible to include external libaries (like WebbotLib) by default so you will be left hacking about with external Makefiles. It is posible to use external Makefiles from within KontrolerLab but it's a messy solution.
My current recomendation is Eclipse with the AVR plugin.
Eclipse runs on Windows, Mac, Linux, etc.
It is very very good once set up, integrates with Apache Ant, most hardware programmers and many other plug-ins.
The down side of Eclipse is that because it has an option for everything it takes a long time to set up.
At some point i intend to write a doc on how to set up Eclipse to work with WebbotLib but if anyone feels the need to do this first then please do.