Difference between revisions of "Atmel STK500 on Linux"

From Klaus' wiki
Jump to: navigation, search
(Using Assembler language)
(Using Assembler language)
 
Line 109: Line 109:
 
#
 
#
 
# Simple Makefile for programming Atmel AVR MCUs using avra and avrdude
 
# Simple Makefile for programming Atmel AVR MCUs using avra and avrdude
# written by Sebastian Falbesoner in February 2009
+
# written by Sebastian Falbesoner in February 2009  
 +
# Modified by Klaus Kolle in January 2013 to suit AU ASE lab exercises.
 
#
 
#
 
# Assemble with 'make', flash hexfile to microcontroller with 'make flash'.
 
# Assemble with 'make', flash hexfile to microcontroller with 'make flash'.

Latest revision as of 11:52, 25 January 2013

In order to develop on the STK500 beginners board on a Fedora (in this case 17) follow these instructions.

Eclipse

Inspired by [this] link.

Install Eclipse CDT in its latest version. Remember to choose the 32 or 64 bit edition that suits your OS. Place it in a separate directory in order to keep it clean of all other plugins you are using.

Start eclipse and in the Help menu select Install new software. In the Work with enter http://avr-eclipse.sourceforge.net/updatesite/ and press enter. Select the AVR plugin and install it. Takes a while, be patient.

Bin-utils

Using yum install support for the AVR devices,

$ yum install avrdude avr-gcc* avrice avr-binutils avr-gdb avra avrdude uisp

Attach your USB2serial converter (assuming that there is no serial port on your brand new laptop).

To detect which tty the port is assigned to issue:

$ ll /dev/ttyU*

typical output are

$ ll /dev/ttyU*
crw-rw----. 1 root dialout 188, 0 Jan 21 11:22 /dev/ttyUSB0

Because of the default access rights an ordinary user cannot access the port. There are two solutions to this. Change the access rights issuing:

$ chmod 666 /dev/ttyUSB0

if you are root - otherwise prepend with a sudo.

This have to be done everytime you connect the USB2serial converter.

The other option is to become a member of the dialout group. This is a permanent solution.

$  usermod -a -G dialout <your-loginname>

Now connect the serial cable to the RS232 CTRL connector on the STK500 board. Attach power. Remember do it like this in the future; the STK board can be very sensitive to connecting and disconnecting cables while powered.

Issue this command to test the connection to the board (only the first line is the command, the rest is the output):

$ avrdude -c stk500 -p m32 -P /dev/ttyUSB0
 
avrdude: AVR device initialized and ready to accept instructions
 
Reading | ################################################## | 100% 0.01s
 
avrdude: Device signature = 0x1e9502
 
avrdude: safemode: Fuses OK
 
avrdude done.  Thank you.

Configuring Eclipse

Next thing is to configure Eclipse to work with avrdude and the rest of the utils.

First open the Window->Preferences dialogue.

Select and expand the AVR entry.

AVRDude.png

The AVRDude configuration dialogue

Click Add and select Atmel STK500v2, name the configuration and enter in the Override default port (-P) field /dev/ttyUSB0, if this was the port you found a little while ago.

AVRDude1.png

The STK500 configuration has been selected

Click OK and Apply when back in the main Preferences dialogue.

Now click on the Path entry. BE PATIENT. It may take many, many minutes if not hours, but let it run until the dialogue shows up. Ensure that the Disable search for system paths at startup is checked. You can at any time adjust the paths if needed.

AVRDude2.png

The Path configuration dialogue

Now Eclipse is ready for programming.

Continue from the section Creating your first AVR project here.

Note: In order to use the Debug configuration in the project properties check the Generate HEX file for flash memory.

AVRDude3.png

Using Assembler language

It is possible to use assembler language to program the STK500 kit. It is although not recommendable to use Eclipse - use the commandline instead.

First you need to define a makefile suitable for convert the assembler mnemonics to machine code.

#
# Simple Makefile for programming Atmel AVR MCUs using avra and avrdude
# written by Sebastian Falbesoner in February 2009 
# Modified by Klaus Kolle in January 2013 to suit AU ASE lab exercises. 
#
# Assemble with 'make', flash hexfile to microcontroller with 'make flash'.
#
# Configuration:
#
# MCU     -> name of microcontroller to program (see 'avrdude -p ?' for a list)
# TARGET  -> target board/programmer to use (see 'avrdude -c ?' for a list)
# DEVICE  -> linux device file refering to the interface your programmer is plugged in to
# INCPATH -> path to the AVR include files (must be copied from AVR Studio for Windows!)
# SRCFILE -> single assembler file that contains the source
#
 
MCU = m32
TARGET = stk500v2
DEVICE = /dev/ttyUSB0
INCPATH = /usr/share/avra-1.2.3
SRCFILE = lab1.S
 
$(SRCFILE).hex: $(SRCFILE)
	avra -I $(INCPATH) $(SRCFILE)
 
flash:
	avrdude -c $(TARGET) -p $(MCU) -P $(DEVICE) -U flash:w:$(SRCFILE).hex:i
 
showfuses:
	avrdude -c $(TARGET) -p $(MCU) -P $(DEVICE) -v 2> stdout | grep "fuse reads" | tail -n2
 
clean:
	rm -f $(SRCFILE).hex $(SRCFILE).obj $(SRCFILE).cof

be sure to edit your tty-port and if the avra assemblers include path.

For each project change (and maybe add) the SRCFILE line to suit your needs.

Invoke it by typing:

$ make
avra -I /usr/share/avra-1.2.3 lab1.S
AVRA: advanced AVR macro assembler Version 1.2.3 Build 1 (15. November 2007)
Copyright (C) 1998-2007. Check out README file for more info
 
   AVRA is an open source assembler for Atmel AVR microcontroller family
   It can be used as a replacement of 'AVRASM32.EXE' the original assembler
   shipped with AVR Studio. We do not guarantee full compatibility for avra.
 
   AVRA comes with NO WARRANTY, to the extent permitted by law.
   You may redistribute copies of avra under the terms
   of the GNU General Public License.
   For more information about these matters, see the files named COPYING.
 
Pass 1...
Pass 2...
done
 
Used memory blocks:
   Code      :  Start = 0x0000, End = 0x001A, Length = 0x001B
 
Assembly complete with no errors.
Segment usage:
   Code      :        27 words (54 bytes)
   Data      :         0 bytes
   EEPROM    :         0 bytes

Flash the STK500 by typing

$ make flash
avrdude -c stk500v2 -p m32 -P /dev/ttyUSB0 -U flash:w:lab1.S.hex:i
 
avrdude: AVR device initialized and ready to accept instructions
 
Reading | ################################################## | 100% 0.01s
 
avrdude: Device signature = 0x1e9502
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "lab1.S.hex"
avrdude: writing flash (54 bytes):
 
Writing | ################################################## | 100% 0.08s
 
avrdude: 54 bytes of flash written
avrdude: verifying flash memory against lab1.S.hex:
avrdude: load data flash data from input file lab1.S.hex:
avrdude: input file lab1.S.hex contains 54 bytes
avrdude: reading on-chip flash data:
 
Reading | ################################################## | 100% 0.07s
 
avrdude: verifying ...
avrdude: 54 bytes of flash verified
 
avrdude: safemode: Fuses OK
 
avrdude done.  Thank you.