Programming ATMega2560

Andreas Höschler <[email protected]>
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
HI all,

I have programmed ATMega8 in the past (worked great). I have purchased a ATMega2560 board now and am trying to get my avr gcc tool chain to accept this chip:

Makefile
==================
# AVR-GCC Makefile
PROJECT=toggle_led
SOURCES=main.c 
HEADERS=
CC=avr-gcc
OBJCOPY=avr-objcopy
MMCU=atmega2560
 
CFLAGS=-mmcu=$(MMCU) -Wall -O2 -I /usr/local/avr/include

$(PROJECT).hex: $(PROJECT).out
	$(OBJCOPY) -j .text -O ihex $(PROJECT).out $(PROJECT).hex
 
$(PROJECT).out: $(SOURCES)
	$(CC) $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES)
 
program: $(PROJECT).hex
	avrdude  -p $(MMCU) -c avrispmkII -P usb -e -U flash:w:$(PROJECT).hex
clean:
	rm -f $(PROJECT).out
	rm -f $(PROJECT).hex

main.c
==================
#define F_CPU 16000000UL  /* 16 MHz CPU clock */
#include <util/delay.h>
#define OUTPUTPORT PORTB   
#define OUTPUTPIN PB7   
int main (void)
  {
   DDRB = 0xff;          // all outputs
   while (1)                       /* loop forever */
     {            
      if ((PORTB & _BV(PB7)) > 0) PORTB &= ~_BV(PB7);
      else PORTB |= _BV(PB7);      
      delay_ms(500);      
     }   
      return (0);
  }

When I try to make this project I get

-bash-3.2$ make
avr-gcc -mmcu=atmega2560 -Wall -O2 -I /usr/local/avr/include -I./ -o toggle_led.out main.c 
unknown MCU 'atmega2560' specified
Known MCU names:
   avr2
   at90s2313
...
   attiny12
   attiny15
   attiny28
main.c:1: error: MCU 'atmega2560' supported for assembler only
main.c: In function 'toggleOutput':
main.c:19: error: 'PORTB' undeclared (first use in this function)
main.c:19: error: (Each undeclared identifier is reported only once
main.c:19: error: for each function it appears in.)
main.c:19: warning: implicit declaration of function '_BV'
main.c:19: error: 'PB7' undeclared (first use in this function)
main.c: In function 'main':
main.c:34: error: 'DDRB' undeclared (first use in this function)
main.c:45: error: 'PORTB' undeclared (first use in this function)
main.c:45: error: 'PB7' undeclared (first use in this function)
make: *** [toggle_led.out] Error 1

The chip atmega2560 indeed is not in the offered list!? I built my tool chain as shown below! What am I missing? How can this be fixed?

Thanks a lot!!!

Andreas

********************************************************************************************************
We download http://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.gz:

	PREFIX=/usr/local/avr
	export PREFIX
	PATH=$PATH:$PREFIX/bin
	export PATH

	cd /usr/src
	mkdir avr
	cd avr
	scp [email protected]:/home/ahoesch/Downloads/binutils-2.24.tar.gz .
	gunzip binutils-2.24.tar.gz
	gtar xvf binutils-2.24.tar
	cd binutils-2.24
	./configure --target=avr --program-prefix="avr-" --prefix=$PREFIX
	make
	make install

We download http://gcc.cybermirror.org/releases/gcc-4.3.3/gcc-4.3.3.tar.bz2:

	cd /usr/src/
	gtar xvf mpfr-2.4.0.tar
	cd mpfr-2.4.0
	./configure
	make
	make install

	cd /usr/src/avr
	mkdir avrgcc
	scp [email protected]:/home/ahoesch/Downloads/gcc-4.3.3.tar.bz2 .
	bunzip2 gcc-4.3.3.tar.bz2
	gtar xvf gcc-4.3.3.tar
	cd avrgcc
	../gcc-4.3.3/configure --target=avr --prefix=/usr/local/avr --enable-languages=c --disable-libssp --disable-shared --disable-libada --disable-libssp --disable-nls --with-dwarf2 --with-gmp=/usr/local --with-mpfr=/usr/local --prefix=/usr/local/avr
	make 
	make install 

	pico /etc/default/login
	pico /etc/default/su

	PATH= ...:/usr/local/avr/bin
	SUPATH= ...:/usr/local/avr/bin

Relogin to get the new PATH value.

	which avr-gcc

We download http://download.savannah.gnu.org/releases/avr-libc/avr-libc-1.8.1.tar.bz2:

	cd /usr/src/avr
	scp [email protected]:/home/ahoesch/Downloads/avr-libc-1.8.1.tar.bz2 .
	bunzip2 avr-libc-1.8.1.tar.bz2
	gtar xvf avr-libc-1.8.1.tar
	cd avr-libc-1.8.1
	./configure --host=avr --prefix=/usr/local/avr
	make
	make install


We sync avrdude-5.8 and arduino.sh from the 192.168.1.2 

	rsync -avz -e ssh arduino.sh avrdude-5.8 [email protected]:/usr/src/avr

and build as follows:
	
	LIBUSB=/usr/sfw
	export CPPFLAGS="-I${LIBUSB}/include"
	export LDFLAGS="-L${LIBUSB}/lib"
	make 
	make install

This installs

	/usr/local/bin/avrdude
	/usr/local/etc/avrdude.conf

We can now do 

	avrdude -c avrispmkII -P usb -p atmega8
	...
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.