Nav:  [home][elec][pdev][avr32] > [avr32]
 

AVR32 Development under (Debian/GNU) Linux

This 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.

Introduction

AVR32 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 Utils

Generally 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.

  1. The AVR32Studio is based on Eclipse and will run on 32bit and 64bit operating systems (on 64bit if the standard set of 32bit shared libraries is installed). However the GNU utils for download on the Atmel page are 32bit only and unfortunately depend on some non-standard shared libs. This made me decide to install the whole AVR32 development system in a 32bit chroot. How to do this is beyond the scope of this document (I'm using schroot).
  2. Install the GNU untils. For Debian/unstable simply take the latest Ubuntu zip-file from Atmel (Click on "Tools and Software"), unpack it and install the contained .deb packages and with dpkg -i. You may have to install some required shared libraries before; dpkg will tell you that.
  3. Install Eclipse; you need it for AVR32Studio. You do not have to do a full-featured install; I only installed the debian packages eclipse-cdt, eclipse-platform, eclipse-rcp and all dependencies but without all the recommended additional packages. (Skip this and the next two steps if you do not want to use AVR32Studio/Eclipse.)
  4. Install AVR32Studio from Atmel (see link above; you need to fill in a registration form at Atmel.com but do not need an atmel-account with a password). I simply unpacked the zip-File in /opt/AVR32/ so that the studio is in /opt/AVR32/avr32studio/.
  5. When using a chroot, set up the call shell script in the 64bit system to launch AVR32Studio. I'm using (/usr/local/bin/avr32studio):
    #!/bin/bash
    exec schroot -p -c sid32 -q -- "/opt/AVR32/avr32studio/avr32studio" "$@"
    Be sure to bind-mount /home, /tmp, /dev, /proc, /sys, /opt and /var to some directory inside chroot environment.
  6. It comes handy to have a shell in the 32bit chroot system as well to be able to manually launch avr32program and avr32-gcc. I wrote avr32xterm for this:
    #!/bin/bash
    exec xterm -ls -e schroot -p -c sid32 -q -- /bin/bash -l
  7. Lauch avr32studio. It should start up, ask for the workspace directory and report that it found the avr32 compiler, debugger and so on. Alternatively (for those preferring terminal, text editor and Makefiles), launch avr32xterm and try avr32program --version, avr32-gcc --version.

Setting up the JTAG Adapter: AVR JTAGICE MKii

I'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:

  • -finternal@0x80000000 specifies to use the internal flash memory of the AT32UC3xxxx microcontroller which is mapped at start address 0x80000000.
  • -e -v tell the adapter to first erase the flash, then verify it after programming.
  • -R --run perform a reset of the microcontroller after programming and start run the new code.
  • -cint denotes to use as clock source the internal RC oscillator.
  • hello_world.elf of course specifies the file to be flashed onto the microcontroller.

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/Eclipse

It'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.


[home] [site map] [Impressum] [Datenschutz/privacy policy]
Valid HTML 4.01!
Copyright © 2008-2012 by Wolfgang Wieser
Last modified: 2012-09-22 00:25:15