optimising for size

I am working with Jamie Allen on the next generation of the Pduino firmware that is meant to be used for all sorts of software packages. We want to include software PWM, pulseIn, and servo logic, but its looking like its going to be tough to fit all that into the ATMega8's code space.

Does anyone have any advice as to how to reduce the size? Does Arduino already use the -Os gcc flag (optimize for size)?

You can see the code in question here:


Hello hans

I'm glad you're working on pduino "next generation" :)

arduino has the -Os flag but there is some strange issue with linking that we are still investigating.

We could just shift to plain c for the pduino firmware... i see it as something you provide pre complied and people find it pre installed on any arduino they buy. we can add a menu item to arduino 0005 that will download the firmware into the board in case it is erased.

this way we can squeeze much more out of it.

what do you think?


I am still thinking that we can get this to work in Arduino code. Then maybe some assembly hacker can make it really fast. But the plans you mention above sound good.

Also, the Arduino core should be much smaller in Arduino 0005, as we've cut some of the fat out.

could someone post coomands for compiling linking and building!

tools/avr/bin/avr-gcc -c -g -Os -IC:\Programiranje\arduino-0004\lib\targets\arduino -w -mmcu=atmega8 -DF_CPU=16000000L C:\Programiranje\arduino-0004\lib\targets\arduino\buffer.c -oC:\DOCUME~1\Janez\LOCALS~1\Temp\build48482.tmp\buffer.c.o

I did find only those! Why I need them? Someone would ask! I need them for buildng my own IDE for Arduino. Work is allmost done i just need compiling commands becouse i don't want to use make! Thanks for help!

I posted some here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1157400799 and am in the process of creating a proper tutorial (and Makefile) for building and uploading Arduino sketches from the command line.

Wolf Paulus mentions a small hack to save 450 bytes - remove the legacy serial code support in arduino/lib/targets/arduino/wiring.c

Arduino's standard library still supports some legacy serial code, which can be removed by editing arduino/lib/targets/arduino/wiring.c (Arduino Version 0006): Start commenting out code at line 241, insert /* just before void beginSerial(long baud) This will reduce the size of a deployable program and increase the available memory for custom code by 450 Bytes, which doesn't sound like much but is equivalent to 6.3%.

-- http://wolfpaulus.com/journal/embedded/arduino.html

Not really so relevant for you guys working on pduino, but for us beginners reading this thread it's a nice tip.

also, check out this post, it might help.
saved me almost 1k…

Impressive ! Using a combination of the patch and removing the legacy serial code, my code went from 4.4KB to 1.8KB. And it still works, bonus.

Thanks guys, Lion.