I just recently purchased a 3pi robot and so far it has been a lot of fun to learning about the world of small microcontrollers. It is quite a bit different from creating a program for an average PC and certainly presents a challenge when working with limited memory resources and microcontroller clock cycles. This leads into the question for this post.
When I create a new project in AVR Studio 4 and copy and paste code from the examples in the Pololu AVR Library, the compiled code in my new project is about 10% larger then the example code. Even the .hex files are larger by about 10 kilobytes. I know 10kb is not that much of a difference in the world of PCs, but when you are limited to a total of 32kb, 10kb is a big difference. I tried going through the configuration options for the project and matched each projects settings, but they are still larger. Here is the compiler output for each project:
(The code used is from the 3pi-linefollower-pid example: Pololu AVR Library\libpololu-avr\examples\atmega328p\3pi-linefollower-pid)
My new project output:
Build started 14.3.2010 at 08:37:21 avr-gcc -mmcu=atmega328p -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT Main.o -MF dep/Main.o.d -c ../Main.c avr-gcc -mmcu=atmega328p -Wl,-Map=TestLineFollow.map Main.o -lpololu_atmega328p -o TestLineFollow.elf avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature TestLineFollow.elf TestLineFollow.hex avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex TestLineFollow.elf TestLineFollow.eep || exit 0 avr-objdump -h -S TestLineFollow.elf > TestLineFollow.lss AVR Memory Usage ---------------- Device: atmega328p Program: 12280 bytes (37.5% Full) (.text + .data + .bootloader) Data: 133 bytes (6.5% Full) (.data + .bss + .noinit) Build succeeded with 0 Warnings...
Pololu AVR Library example output:
Build started 14.3.2010 at 08:36:24 avr-gcc -mmcu=atmega328p -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT test.o -MF dep/test.o.d -c ../test.c avr-gcc -mmcu=atmega328p -Wl,-gc-sections -Wl,-Map=test.map test.o -lpololu_atmega328p -o test.elf avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature test.elf test.hex avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex test.elf test.eep || exit 0 avr-objdump -h -S test.elf > test.lss AVR Memory Usage ---------------- Device: atmega328p Program: 9182 bytes (28.0% Full) (.text + .data + .bootloader) Data: 127 bytes (6.2% Full) (.data + .bss + .noinit) Build succeeded with 0 Warnings...
If you look at the AVR Memory Usage output / Program, it is different by ~2000kb. I was wondering, does anyone know why my program size is bigger, even though the amount of code is the same? Could it be possible when I create a new project, AVR Studio 4 is automatically importing an external library?