Getting started with Xmega: programming software2010/05/25
(first edit of iPhone version)
Once you have the required programming hardware for your Xmega, you need to figure out how to actually use it to load your code. You can’t just shove it at the programmer and hope it does something intelligent (though that would be nice), you have to talk the particular language of each programmer. At least for the Atmel programmers there’s one main protocol (STK500[v2]), but there are so many variations even within that one protocol as to make anybody’s head spin. Luckily, that’s why people write programming tools: to hide the (sometimes unnecessary) complexity of the programming hardware.
Right off the bat, I’ll list the default AVRStudio as the most integrated solution. However, that’s about all I can tell you, since I only use it for reference and recovery when I run into problems or complications with my usual method. Hopefully somebody who already uses it or learns how can post further details, which I can fold into this tutorial if desired.
AVRDude is the other major piece of software, and the only one I use to actually load code. It’s an open-source tool capable of using any of several dozen types of programming hardware to flash most every AVR out there (and then some). It works best on Unix-style systems (Linux, Mac) but presumably runs just fine on Windows as well, as it’s packaged with the Win-AVR bundle.
When I put projects together, I typically start with a simple shell script that compiles, preps and downloads the firmware in one go. This is somewhat peculiar to my work patterns as I don’t use an IDE of any sort (not even emacs). Makefiles are the more common but also somewhat more involved method. Most projects I create that use more than one source file are implemented with Make, but more on that later.
The actual command to flash the chip is something along the lines of:
avrdude -pavrisp2 -Pusb -cx192a3 -U w:flash:myprog.srec
The -p argument sets the programming tool to be used, and -P tells avrdude which port to use. usb is the connection method for all of the currently available Xmega-compatible programmers, though my current project uses a bootloader that implements the avr910 protocol over a standard serial port, e.g. /dev/ttyUSB0. The chip being programmed is given by the -c, and -U specifies an upload operation, in this case writing to flash the contents of myprog.srec.