AVR32 Linux Development/Getting started with AVR32 Linux Development

From AVRFreaks Wiki

Jump to: navigation, search

Contents

Introduction

The intention of this guide is to help users getting started with the AVR32 1000 Linux development. It is a quick reference on how to use Linux together with the AVR32. Users who want to develop applications without any operation system should read Getting started with AVR32 embedded development.

NOTE: Make sure to install all tools before using this guide.


Hardware setup

This section describes how to set up your STK1000/1002 kit for running AVR32 Linux.

STK1002 daughter board jumper settings

In order to run Linux on the STK1000/STK1002, the following jumpers must be set:

  • SW1: Set to SPI0
  • SW2: Set to PS2A/MMCI/USART1
  • SW3: Set to SSC0/PWM[0,1]/GCLK
  • SW4: N/A
  • SW5: Set to LCDC
  • SW6: Set to MACB0/DMAC

STK1000 jumper settings

  • To be able to communicate with the bootloader (Das U-Boot) and the Linux console, the JP6 (UARTA RXD) jumper should be set to DB9.
  • To use the AT73C213 external DAC with Linux, ensure JP4 and JP5 both are set for EXT. DAC


Starting a Linux session

This section describes two ways of connecting to the Linux environment: using the serial console or using the telnet protocol.

Connecting to the serial console

The Linux console is available on the UART_A connector on STK1000. To connect to it, use a terminal program such as HyperTerminal in Windows, or minicom in Linux, and set the communication parameters to 115200 bps, 8 databits, 1 stop bit, no parity (8N1).

If you connect to the console after having booted, you may need to press Enter to get a command prompt.

Connecting with telnet

If the STK1000 is properly connected to the network, and assigned an IP address (see "Finding your IP address" in the Linux on STK1000 chapter), you may use the telnet program to connect to the Linux environment.

In Windows, telnet is available as a command line interface program. Start the command line from the Start -> Accessories -> Command Prompt menu, and type telnet followed by the STK1000's IP address:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\joe>telnet 192.168.10.151

The STK1000's BusyBox command prompt should appear immediately:

BusyBox v1.1.0 (2006.06.22-12:19+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

Compilation

This section describes how to cross-compile a simple application for the AVR32 Linux platform using the GNU Compiler (GCC).

Single file compilation

On your build machine, create a single file called hello.c with the classical application "Hello Word":

#include <stdio.h>

int main(int argc, char** argv)
{
    printf("Hello World!\n");
    return 0;
}

Assuming your application consists of a single C source file called hello.c, use the avr32-linux-gcc command to compile and link the program in one operation:

$ avr32-linux-gcc -o hello.elf hello.c 

This will create an ELF executable suitable for running on AVR32 Linux called hello.elf.

If you wish to debug the application, you should specify the "-g" option which enables debugging symbols.

$ avr32-linux-gcc -g -o hello.elf hello.c 

A basic Makefile

Projects which consist of several files usually benefit from using a makefile to build the application. Here's a small example of a makefile that can be used as a template when creating applications for AVR32 Linux:

TARGET=hello.elf
OBJECTS=hello.o
CC=avr32-linux-gcc
CFLAGS=-Wall -g # warnings, debugging symbols
LDFLAGS=
LIBS=

.PHONY: all
all: $(TARGET) 

$(TARGET): $(OBJECTS)
        $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) 

.PHONY: clean
clean:
        -$(RM) $(TARGET) $(OBJECTS) 
 

With this makefile, the application can be built by issuing the "make" command:

$ make
avr32-linux-gcc -Wall -g -c -o hello.o hello.c
avr32-linux-gcc -o hello.elf hello.o
$

The executable and the object file(s) can be removed by calling "make clean".

$ make clean
rm -f hello.elf hello.o
$

Uploading

Once you have cross-compiled and linked your application on the build host, it needs to be transferred to the AVR32 in order to executed and debugged. It is most practical to do this using the network: by uploading with FTP; or retrieving it from a web server using wget.

It is also possible to copy the application to the SD card, either directly if you can access the Linux file system on your build host (easy if you are running Linux yourself, possible with an ext2fs driver in Windows), or by copying to a filesystem directory which you then use to create an SD card image with e2fsimage. More on this below.


Uploading via FTP

The AVR32 Linux BSP comes default with an FTP server which allows anonymous uploading of files. Using an FTP client on your build host, you may connect to the target's IP address and upload your executable into the /home/ftp directory on the SD card.

After the file has been uploaded, the permissions must be set so that it can be executed. Since the FTP server does not allow files in /home/ftp to be overwritten, it's a good idea to move the application to another location before executing or debugging it.

~ # mv /home/ftp/hello.elf .
~ # chmod 755 hello.elf
~ # ./hello.elf
Hello World!
~ # 

Retrieving files via HTTP (wget)

The wget command which is available as part of the AVR32 Linux environment can be used to retrieve data (e.g applications) from a HTTP URL. If you are running a local web server on your build host, or can otherwise make files available via HTTP, the file can be downloaded onto the target filesystem with wget.

After downloading the file, its permissions must be changed in order to execute it.

~ # wget http://192.168.10.151/hello.elf
Connecting to 192.168.10.151[192.168.10.151]:80
hello.elf            100% |*****************************|  3998       00:00 ETA
~ # chmod 755 hello.elf
~ # ./hello.elf
Hello World!
~ #


Debugging

This section describes how to debug a Linux application running on target using the GDB debugger over the network.

Remote debugging with GDB consists of several programs communicating with each other: the application being debugged (the target application); gdbserver, which runs on the target and controls the target application; and avr32-linux-gdb, which talks to gdbserver over the network and provides a user interface for the developer.

An application should always be compiled without optimization and with debugging symbols in order to debug it. This means that you should make sure the "-g" option is used when compiling the application, and that no "-O", "-O2" or other optimization flags are enabled.

NOTE: Debugging shared applications currently do not work properly. When debugging, link statically by specifying the -static option to the linker. With the example Makefile, this option can be added to the LDFLAGS variable.

Using the "Hello World" application and accompanying makefile described in the previous section on compilation, here's how to set up an AVR32 Linux GDB debug session:

First, on target, start gdbserver to execute the "Hello World" application and listen for gdb clients on the network port 1024.

~ # gdbserver :1024 ./hello.elf
Process ./hello.elf created; pid = 194
Listening on port 1024

Next, on the build host, start avr32-linux-gdb and instruct it to connect to the gdbserver process on target.

$ avr32-linux-gdb hello.elf
GNU gdb 6.4
...
(gdb) target remote 192.168.10.152:1024
Remote debugging using 192.168.10.152:1024
0x000010dc in _start ()
(gdb)
Static version created: 2007-03-07
Copyright (c) 2007 Atmel Corporation