Page 1 of 1

avr-gcc-4 vs avr-gcc-3

Posted: Fri Apr 27, 2012 10:16 pm
by Coda
I have been away from avr development for a while, and I recently came back to start a new project. I also gained a new mac from work since, and I decided I would do development on it, instead of my older and trusty leopard based machine which I haven't got around to updating yet. So, I went to download Crosspack (also from Objective Development -its a nice pre-packaged avr toolkit, thank you OD) and saw there was a new version. Cool!

Only thing is, I just started looking at some of the V-USB based projects, some of which are supposed to be able to fit onto a device with 2k of flash (there's a few Attiny2313 projects out there). Even the main V-USB hardware page mentions 2k of flash as a minimum requirement. However all of the projects I have downloaded and have lazily typed 'make all' on came in well over 2k in code size. This is important to me - I want to develop a dongle for a certain serial protocol keyboard - it wants to be in a smallish package, and wants a hardware UART. Attiny2313 fits the bill, but hey it's only got 2k Flash... I know the attiny85 has 8k but theres no harware UART... :cry:

Anyway - I checked the compiler version and noticed gcc v4 was being used. I tried to change it to v3.x and then I noticed that v3 was no longer available in Crosspack - it has been removed, so I downloaded the previous version, changed gcc version to 3 and rebuilt a project I've been hacking around with the last few days. PS2USB.

I use the basic 3.6v zener diode interface hooked up directly to my Atmel STK500 dev board, and plugged in a spare atmega88. I have removed the code for the second pad. Its made the code smaller, but even so, look at the results:


Code: Select all

$ make clean; make all
rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s
avr-gcc -Wall -Os -DF_CPU=12000000    -Iusbdrv -I. -DDEBUG_LEVEL=0 -mmcu=atmega88 -c usbdrv/usbdrv.c -o usbdrv/usbdrv.o
avr-gcc -Wall -Os -DF_CPU=12000000    -Iusbdrv -I. -DDEBUG_LEVEL=0 -mmcu=atmega88 -x assembler-with-cpp -c usbdrv/usbdrvasm.S -o usbdrv/usbdrvasm.o
avr-gcc -Wall -Os -DF_CPU=12000000    -Iusbdrv -I. -DDEBUG_LEVEL=0 -mmcu=atmega88 -c usbdrv/oddebug.c -o usbdrv/oddebug.o
avr-gcc -Wall -Os -DF_CPU=12000000    -Iusbdrv -I. -DDEBUG_LEVEL=0 -mmcu=atmega88 -c main.c -o main.o
main.c: In function 'main':
main.c:483: warning: unused variable 'idleCounter'
main.c: At top level:
main.c:15: warning: 'outBuffer2' defined but not used
avr-gcc -Wall -Os -DF_CPU=12000000    -Iusbdrv -I. -DDEBUG_LEVEL=0 -mmcu=atmega88 -o main.elf usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
rm -f main.hex main.eep.hex
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
avr-size main.hex
   text      data       bss       dec       hex   filename
      0      3034         0      3034       bda   main.hex


avr-gcc v4: 3034 bytes
avr_gcc v3: 2712 bytes

That's a whopping difference. At this rate I'd be hard pushed to fit my own project on a 4k device, never mind a 2k one. I was wondering if I can remove the debug code and see what, if anything it does to reduce the code size. Is there anything else I could be missing?

Size is everything in this world, right guys? :P

Re: avr-gcc-4 vs avr-gcc-3

Posted: Sun Apr 29, 2012 10:29 am
by Coda
I've built a new program for attaching an Atari Keyboard (TT/Mega ST(e) etc) to USB, and so far it's working with basic functionality (simple key-presses, no modifiers work, and no attached mouse/joystick reports which would be cool). Code size is 1952 bytes with v3, and 2018 with v4. I'm going to need a few more bytes to make it properly functional (at least support the modifier keys). If it gets too much bigger then at least I can try to find a Attiny4313, or maybe use the physically bigger Atmega48.

Re: avr-gcc-4 vs avr-gcc-3

Posted: Sun Apr 29, 2012 9:37 pm
by xiangrui
It is always good to have some extra space. Try to use a chip with larger flash. It is quite common that you may like to add something in the future.

Re: avr-gcc-4 vs avr-gcc-3

Posted: Mon Sep 10, 2012 2:14 pm
by horo
xiangrui wrote:It is always good to have some extra space. Try to use a chip with larger flash. It is quite common that you may like to add something in the future.

You're right - BUT - when you want to use USBaspLoader located in the boot block you're limited to 2K boot block size on ATmega8, 88, 16, 168 even with 8 or 16K flash.

Ciao, Martin

Re: avr-gcc-4 vs avr-gcc-3

Posted: Mon Sep 10, 2012 5:49 pm
by ulao
horo, I dont see where the OP was talking about the bootloader code size? Though this is a good point to make, bigger chips will not change that. If you need a chip with a lot of flash get the atmeg328. I use this with my v-usb project and I still have not used it up. my adapter support every controller out there including the atari keyboard, so it have to be big enough.

Re: avr-gcc-4 vs avr-gcc-3

Posted: Mon Sep 10, 2012 11:36 pm
by Coda
ulao wrote:horo, I dont see where the OP was talking about the bootloader code size? Though this is a good point to make, bigger chips will not change that. If you need a chip with a lot of flash get the atmeg328.

Right, the OP (me) wasn't talking about bootloader but it is a valid point as I've been thinking about it recently. Anyhow, for physical space reasons I didn't want to go bigger than a ATtiny2313, certainly not to the 28pin parts like the mega48-328 range. Anyway, I managed to get a 25 strip of 4313 so I'm ok now with 4K flash. I couldn't find these in EU so I had to order them from the States.
ulao wrote:...my adapter support every controller out there including the atari keyboard, so it have to be big enough.

Which adapter? Which Atari keyboard? BTW I'm also working on a Mac ADB keyboard adapter (I have an Apple Extended II) so I have something good for writing my next book on, but the ADB protocol (which is similar to PS/2) is a bit of a pain and needs some clever solution. I hope that this one can be done on a tiny85, as it needs to physically fit inside the case.

Re: avr-gcc-4 vs avr-gcc-3

Posted: Tue Sep 11, 2012 9:24 am
by horo
Coda wrote:Anyway, I managed to get a 25 strip of 4313 so I'm ok now with 4K flash. I couldn't find these in EU so I had to order them from the States.

According to their online catalog segor in Berlin has them on stock as DIP and SO:
ATtiny4313-PU: 3.40€ (10+: 2.72€)
ATtiny4313-SU: 3.60€ (10+: 2.88€, 37+:2.17€, 111+: 1.94€)

Ciao, Martin

Re: avr-gcc-4 vs avr-gcc-3

Posted: Tue Sep 11, 2012 9:43 am
by Coda
Thanks, didn't know about them. I got them them from Digikey, I think I paid about $1 each for 25 I'll have to check though.

Re: avr-gcc-4 vs avr-gcc-3

Posted: Tue Sep 11, 2012 4:01 pm
by ulao
"Which Atari keyboard?" it just occurred to me you are talking the ST(e) "keyboard" for some reason I was thinking the key pad. Big difference, my fault. My adapter is for the console atari's.