I'm currently running Ubuntu 6.10, named (unfortunately) "Edgy Eft," and I had installed the Ubuntu package "avr-gcc" which is version 4.1.0 of the compiler. Attempting to compile usbtinyisp gave the error message:
"ERROR: Flash size limit exceeded by 50 bytes."
That's been mentioned several places on the site. In fact, it's a documented bug in gcc:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30908
According to the developers, it isn't just a matter of size optimization "not working as well" in newer versions. It's actually known to be making wrong decisions about when to inline functions versus calling them in place. It is still an open bug as of writing and it looks like it's been observed in all 4.x.x versions.
So I de-install my avr-gcc package and download the gcc-3.4.6, gcc-core-3.4.6, and gcc-g++-3.4.6 source packages from http://gcc.gnu.org/mirrors.html. I un-tar them into a single directory, create another directory called "build-gcc" and cd into it (per the instructions in the INSTALL file) and execute:
Code: Select all
../gcc-3.4.6/configure --target=avr --program-prefix="avr-" --enable-languages=c,c++
One other Ubuntu hitch: The build failed with an error that it couldn't find the header file "sys/types.h". This seems to result from Ubuntu putting AVR-related files in /usr/avr, while I wanted to use the more common location /usr/local/avr. The solution was to add (as superuser) a symbolic link to make everyone happy:
Code: Select all
ln -s /usr/avr /usr/local/avr
"unknown MCU `attiny2313' specified"
It's not a case of my gcc version being so incredibly old that ATTiny2313 chips didn't even exist yet, because version 3.4.6 wasn't released all that long ago.
A long and involved thrash follows. If no 3.x.x version supports ATTiny2313 then I thought that maybe the bug report was wrong and a newer version had fixed it. So I downloaded and built the most recent posted version, which is gcc-4.2.2. (Gotta add "--disable-libssp" to the configure command line now. Another 15 or 20 minutes gone finding that one.)
I build, install, and test, and the size margin was a few bytes different, but the code is still too big for the chip.
I figure that Ladyada must have used some release of WinAVR, so perhaps some of their 3.x.x releases had patches applied to add ATTiny2313 support. (Getting warmer here!) I made several attempts at trying to run WinAVR using the Wine MSWindows emulator, but I could never convince avr-gcc to run on top of Wine.
But I found some patch files in the CVS archive on the WinAVR SourceForge site. Only the most recent ones were available there, none applying to pre-4 gcc versions, but they put me on the right track. Via exhaustive googling, I eventually found a FreeBSD site with all of their avr-gcc patches, including one that adds support for more recent devices to version 3.4.6 by changing the files "avr.c", "avr.h", and "t-avr" in the directory "gcc/config/avr". Bingo.
That patch is described here:
http://www.freebsd.org/cgi/cvsweb.cgi/p ... es#rev1.10
and I got the actual file from here:
http://www.freebsd.org/cgi/cvsweb.cgi/~ ... xt%2Fplain
I emptied out my "build-gcc" directory, re-ran the "configure", "make", and "make install" commands, and voila all was right in the world again. Usbtinyisp v.2 built successfully:
Code: Select all
timv@zabel:~/ladyada/usbtinyisp/spi$ make
avr-gcc -Os -g -Wall -I. -I../usbtiny -mmcu=attiny2313 -c ../usbtiny/crc.S
avr-gcc -Os -g -Wall -I. -I../usbtiny -mmcu=attiny2313 -c ../usbtiny/int.S
avr-gcc -Os -g -Wall -I. -I../usbtiny -mmcu=attiny2313 -c ../usbtiny/usb.c
avr-gcc -Os -g -Wall -I. -I../usbtiny -mmcu=attiny2313 -c -o main.o main.c
avr-gcc -g -mmcu=attiny2313 -o main.elf crc.o int.o usb.o main.o
text: 2044, data: 2, bss: 60
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
I hope this helps someone else avoid having to go through all of this again.