Atmel AVR and STK500 devboard with Linux

   

STK500 Development Board. The Atmel AVR series of 8-bit RISC microprocessors are used in a wide range of real applications. There are also a lot of individuals who use it for controlling experimental designs, mostly for the AVR:s ease of use and low cost.

References:

AVR 8-bit RISC
Atmel Corporation official site.
AVR Freaks
lots of useful information, tools, documentation.

This is just a small HOWTO on using the STK500 development board with Linux (in this case, Debian/GNU Linux). Provided with the STK500 package is a Windows development environment, so if you run Windows you should really have no problems.

Note that this is just the first steps, if you want to be more advanced there are other things to consider, like compiler flags and special instructions for uisp.

1. Install gcc-avr (package name in Debian).

2. Install avr-libc (package name in Debian).

3. Example Makefile:

# Example Makefile for demo project
# Copied from http://www.enteract.com/~rneswold/avr/x421.html
# with "clean" added.

CC=avr-gcc
OBJCOPY=avr-objcopy

CFLAGS=-g -mmcu=at90s8515

rom.hex : demo.out
        $(OBJCOPY) -j .text -O ihex demo.out rom.hex

demo.out : demo.o
        $(CC) $(CFLAGS) -o demo.out -Wl,-Map,demo.map demo.o

demo.o : demo.c
        $(CC) $(CFLAGS) -Os -c demo.c

clean:
        rm -f *.o *.out *.map *.hex

Change mcu if using other than default mcu. Replace "demo" with whatever name you're using (maybe example.c for C file).

4. Example code:

/*
    Title:    AVR-GCC test program #1 for the STK200 eva board
              (modified by Rolf Johansson <rojo (at) nocrew.org>)
    Author:   Volker Oth
    Date:     4/1999
    Purpose:  Flashes the LEDs on Port B with a hard coded delay loop
    needed
    Software: AVR-GCC
    needed
    Hardware: ATS90S8515/8535/2313/mega on STK200/STK300 board
    Note:     To contact me, mail to
                  volkeroth (at) gmx.de
              You might find more AVR related stuff at my homepage:
                  http://members.xoom.com/volkeroth
*/

#include <io.h>

typedef unsigned char  u08;

int main( void )
{
   u08 led, i, j, k, l, dc, run, rundc;

   outp(0xff,DDRB);            /* use all pins on PortB for output */

   led = 1;                  /* init variable representing the LED state */
   dc = 1;                     /* Init the direction (dc) */
   run = 1;
   rundc = 0;
   
   for (;;) {
       outp(~led, PORTB);      /* invert the output since a zero means: LED on */
       if (dc==0)
         led >>= 1;              /* move to next LED */
       if (dc==1)
         led <<= 1;              /* move to next LED */
       if (!led) {             /* overflow: start with Port B0 again */
         if (dc == 0) {
           led = 1;
           dc = 1;
         }
         else {
           led = 128;
           dc = 0;
         }
         if (rundc == 0)
           run++;
         if (rundc == 1)
           run--;
       }
       if (run == 1)
         rundc = 0;
       if (run == 255)
         rundc = 1;
       for (i=0; i<run; i++)     /* outer delay loop */
          for (j=0; j<run;j++)   /* inner delay loop */
             for (l=0; l<16;l++) /* inner inner delay loop */
                k++;                /* just do something - could also be a NOP */
   }
}

5. Type "make" to make the rom.hex file.

6. Programming the STK500.

Make sure the programming cable is connected from RS232 CTRL to the computer's serial port.

Install the latest release of "uisp" (Micro In-System Programmer for Atmel's AVR MCUs).

When compiled and installed, run uisp with the right parameters (check the serial port and chip model):

uisp -dprog=stk500 -dserial=/dev/ttyS0 -dpart=AT90S8515\
 --erase --upload --verify if=rom.hex

Example output from my computer:

Vendor Code: 0x1e
Part Family: 0x93
Part Number: 0x01
Atmel AVR AT90S8515 is found.
Page Write Disabled
FLASH Write Delay (t_wd_flash): 11111 us
EEPROM Write Delay (t_wd_eeprom): 11111 us
Uploading: flash
#######
(total 198 bytes transferred in 0.90 s (221 bytes/s)
Verifying: flash
#######
(total 198 bytes transferred in 3.06 s (65 bytes/s)

The program is transfered to the AVR micro processor. Good luck.

Updated