AVR32 Development under (Debian/GNU) LinuxThis briefly describes how to set up a development environment for AVR32 microcontrollers under Debian GNU/Linux from a scratch installation to the execution of a simple hello-world program on the raw AVR32 (without any operating system). It's intended for experienced users. IntroductionAVR32 is a fairly new 32bit microcontroller core developed by Atmel. Design goals were high integration, low power consumption and a modern 32bit instruction set. Fortunately, Atmel decided to implement an AVR32 backend for the GCC compiler collection and to base the AVR32Studio IDE on Eclipse, so that high-quality development software is for free for Linux. Whether you would like to use a fancy IDE like Eclipse or prefer to work with Makefiles and an editor, the AVR32 GNU utils are your friends. Setting up AVR32Studio and the GNU UtilsGenerally speaking it works out in the way described by Atmel. Here are the basic steps for reference (for Debian/unstable, other versions or distributions will work similarly): Note: You do not have to install Eclipse and AVR32Studio if you prefer to use a terminal, a text editor and Makefiles. Simply skip all Eclipse/AVR32Studio steps below.
Setting up the JTAG Adapter: AVR JTAGICE MKiiI'm using the (much too expensive) AVR JTAGICE MKii as JTAG adapter (bought for 207 EUR) which is connected to the computer via USB. It runs fine when connected directly to an USB port on the motherboard but I had some trouble when inserting an USB-2.0 hub in between. When connecting the JTAG adapter, by default only root has access to it. Since no way I'm going to run AVR32Stdio as root, here is what gives all users in the group devel access to it: Add a file z70_jtagice.rules to /etc/udev/rules.d with the following content: # AVR JTAGICEmkII / USB. SUBSYSTEM=="usb", ATTR{idVendor}=="03eb", ATTR{idProduct}=="2103", MODE="660", GROUP="devel" Don't forget to put yourself into the group devel... Writing a Hello World Program (without AVR32Studio/Eclipse)This is how to do it without AVR32Studio/Eclipse and shows that is being done. Note that it is a good idea to launch AVR32Studio once before because it will automatically update the firmware of your JTAGICE MKii if needed! This is my private hello-world C code for an AT32UC3A1128 (with integrated flash). Basically, all it does is toggle the state of a pin which could be connected to a LED. Without the delay function and running from the internal RC oscillator the toggling will be in the kHz range and must be detected with an oscilloscope. #include <avr32/io.h> #define LED_MASK (1U<<19) int main() { AVR32_GPIO.port[1].gper = LED_MASK; // general purpose IO enable register AVR32_GPIO.port[1].oder = LED_MASK; // output drive enable register for(;;) { AVR32_GPIO.port[1].ovrs = LED_MASK; // output value register set //Delay(); AVR32_GPIO.port[1].ovrc = LED_MASK; // output value register clear //Delay(); } return(0); } In order to compile and link this program, you will use avr32-gcc: avr32-gcc -c -g -O2 -Wall -ffunction-sections -mpart=uc3a1128 -o hello_world.o hello_world.c avr32-gcc -g -Wl,--gc-sections -mpart=uc3a1128 -o hello_world.elf hello_world.o This creates a binary called hello_world.elf which can be programmed onto the AVR32 microcontroller using avr32program and the Atmel JTAGICE MKii (connected via USB): avr32program -c USB -pjtagicemkii program -finternal@0x80000000 -e -v -R --run -cint hello_world.elf Explaining the options in detail: program (without a dash at the beginning) is a command and the following options refer this command:
That's all. And it's easily combined into a Makefile. Note: You can optionally specify the option --part to avr32program which will verify that the correct microcontroller is attached prior to programming. For example, --part uc3a1128 would check for the AT32UC3A1128 used in this example. However, there is currently a bug somewhere in the code or in my microcontroller's ID registers because although it reads "32UC3A1128" on the 100pin TQFP case, avr32program detects it as "32UC3A0128" and consequently refuses to download flash content as long as the "wrong" --part option is present. For reference, this is a pretty universal Makefile which can do some more things: # Universal AVR32 Makefile for firmware without operating system. # Wolfgang Wieser 07/2008. PART = uc3a1128 CFLAGS = -g -O2 -Wall -ffunction-sections LDFLAGS = -g -Wl,--gc-sections HEADERS = prototypes.h SOURCES = hello_world.c delay.c exitmagic.c OBJECTS = $(SOURCES:.c=.o) .PHONY: all run clean program reset cont erase all: firmware.elf run: firmware.elf program clean: rm -f $(OBJECTS) firmware.elf: $(OBJECTS) avr32-gcc $(LDFLAGS) -mpart=$(PART) -o firmware.elf $(OBJECTS) program: firmware.elf avr32program -c USB -pjtagicemkii program -finternal@0x80000000 -v -e --run -R -cint firmware.elf reset: avr32program -c USB -pjtagicemkii reset -r cont: avr32program -c USB -pjtagicemkii run erase: avr32program -c USB -pjtagicemkii erase -finternal@0x80000000 chiperase: avr32program -c USB -pjtagicemkii chiperase .c.o: avr32-gcc -c $(CFLAGS) -mpart=$(PART) -o $*.o $< $(OBJECTS): $(HEADERS) The firmware is called firmware.bin and a simple make will compile it. Use make run to compile, download onto the MCU flash and start running. Note: If you program an UC3 core for the first time, you will get the following error: Erasing page failed Programming of at least one locked lock region has happend since the last read of FSR. The reason is that there is a factory-made protected USB bootloader in the flash. To get rid of the bootloader and use all the flash yourself (as needed for the example here), perform a chiperase with avr32program. You can do this with the above Makefile using make chiperase. Hello-World Development with AVR32Studio/EclipseIt's assumed that you are familiar with Eclipse. If not, check out the AVR32 Studio getting started guide available at Atmel.com! Launch AVR32Studio and scan for adapters. You should see the JTAGICE MKii when connected and udev set the access rights correctly. During the first start, AVR32Studio performed a firmware update for my JTAG adapter which went without problems. (During the upgrade the JTAGICE will re-connect to the USB.) Create a project and a new source file called hello_world.c as found in the previous chapter. Set the JTAG adapter properties (right click on the adapter) and the project properties (project menu) correctly. Except for hardware details (like the precise microcontroller and type of board connected) the defaults should work well. As board, I'm using a self-designed one and selected any board. Open the run dialog (run menu) and create a new run config (hello_world_runcfg) as "AVR32 application" (not "AVR32 Linux application" as we're running directly on the MCU without an operating system). It is important to select unlock and erase flash before programming, reset MCU after programming and start execution after programming. That's all, executing a project build followed by a run should do the trick.Ah, the part number bug described at the end of the previous chapter hit me harder with AVR32Studio. I had to change the complete project (including the compiler settings) to the (wrong) 32UC3A0128 - otherwise the studio refused to flash the MCU.
|