New Arduino IDE with an external AVR toolchain and compiler/linker options

I had a bug with the current 0022 compiler so I modified Compiler.java to accept an external AVR toolchain. It also allows you to optionally specify new compiler/linker options. Useful if you want to turn on warnings or spec a little better optimization. All options are specified in the preference.txt file and if left out the IDE reverts to the internal compiler and options.

Prebuilt IDEs with a readme along with the modified Compiler.java can be found here MostlySoftware.com is for sale | HugeDomains

I hope the Arduino team guys take notice of this.
This is a very simple update that could be tossed into the next release to offer tool options,
which many people have been requesting for quite some time.

I don't know the issues list # for it, but it would be great if you could track it down
(or any issue that asks for compiler or linker options) and
put a link to this thread in it.

That way this update is not forgotten.

--- bill

Call me a Java noob, but I can't work out where to put Compiler.java. There isn't a file of that name, as far as I can see, in the existing IDE folder (this is OS/X).

But thanks for the great tool! If I can get it to work, it is exactly what I wanted.

You have to get the source code and use ant to rebuild the IDE. Look here for instructions Google Code Archive - Long-term storage for Google Code Project Hosting.. Replace the existing Compiler.java with my new one.

Alternately you could just download one of the prebuilt IDEs from my site.

Hi, thanks for this!

I DLed it from your site and extracted it to my desktop. I called up the "Bare Minimum" example (or whatever its called) and hit "verify" holding down shift to get verbose output. The first line was this:

C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\tools\avr\bin\avr-g++ -c -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=22 -O3 -IC:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino

I was thrilled to see the -O3 because that's what I was after. And, as a sort of conformation, the compiled app is several hundred bytes larger than when compiled with the 0022 distro (like 630 vs 400).

But, I also saw a pile of warnings like those pasted below. Is this just a matter of you having higher warning reporting on by default (as opposed to the standard 0022 distro) or is there something amiss here?

Thanks...

In file included from C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\/wiring_private.h:30,
                 from C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:26:
c:/documents and settings/jim/desktop/arduino-aq22/hardware/tools/avr/lib/gcc/../../avr/include/avr/delay.h:36:2: warning: #warning "This file has been moved to <util/delay.h>."
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:361: warning: initialization makes integer from pointer without a cast
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:362: warning: initialization makes integer from pointer without a cast
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:363: warning: initialization makes integer from pointer without a cast
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:369: warning: initialization makes integer from pointer without a cast
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:370: warning: initialization makes integer from pointer without a cast
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:371: warning: initialization makes integer from pointer without a cast
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:377: warning: initialization makes integer from pointer without a cast
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:378: warning: initialization makes integer from pointer without a cast
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\pins_arduino.c:379: warning: initialization makes integer from pointer without a cast
C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\tools\avr\bin\avr-gcc -c -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=22 -O3 -IC:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\WInterrupts.c -oC:\DOCUME~1\Jim\LOCALS~1\Temp\build7948476801286890297.tmp\WInterrupts.c.o 
In file included from C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\/wiring_private.h:30,
                 from C:\Documents and Settings\Jim\Desktop\arduino-AQ22\hardware\arduino\cores\arduino\WInterrupts.c:34:
c:/documents and settings/jim/desktop/arduino-aq22/hardware/tools/avr/lib/gcc/../../avr/include/avr/delay.h:36:2: warning: #warning "This file has been moved to <util/delay.h>."

I'm not surprised to see a few warnings. And if they appeared more often the library developers would be motivated to fix the problems they report, minor though they may be.

@skyjumper, your welcome!

When you turn on warnings either by default or with a -Wall option the arduino core libs will output some warnings. As Nick said the warnings you are seeing really shouldn't be there but then the stock IDE uses -w to turn off all warnings so you don't usually see them.

Getting warnings back was one of the features that motivated me to change to IDE.

Thanks guys! As long as the warnings are normal and don't mean I installed your new IDE wrong, then I am fine with that. There were a bunch so I was concerned I did somethign wrong.

May I make a suggestion? The window where errors and warnings are dumped is very small. Perhaps there could be a switch to enable a popup window or a new tab? Warnings / errors are of course important, but its sure hard to weed through them in such a tiny window.

Thanks again! I have really been wanting to optomize for speed, now I can easily so it!

The best way (easiest) to enlarge the output window (where the errors appear) is to enlarge the IDE and then drag the upper edge of the output window up.

Okay I'll try that, thanks!

And I am correct in seeing that you guys do -O3 by default?

I use the standard IDE, with whatever optimization it gives me. It seems to work OK. As a general rule, the amount you will save with different optimization would be less than what you save with careful design, such as using strings from program memory. In fact their choice of -Os (optimize for size but not at the expense of speed) is probably a good choice.

Nick, I respectfully disagree. I was to optomize for speed. The compiler can make big wins here. My chip has 128k of flash, and leaving most of it empty gains me nothing. If the compiler can make the code faster (and it can) using -O2 or -O3, I'll take it.

Absolutely. Every design is a trade-off, and if in your case you have plenty of program memory, but want lots of speed, certainly optimize for speed. A lot of people however are trying to do stuff like lots of user interaction (which takes program space) but as long as the program responds in a few tenths of a second the speed is fine.

What I would really like is access to the compiler switches from the IDE. That includes warnings, if you want to see them, and customized optimizations.

Is there a way to specify the compiler and/or linker options int eh preferences file, or some other easily modified file?

[quote author=Nick Gammon link=topic=54456.msg443674#msg443674 date=1305606046]What I would really like is access to the compiler switches from the IDE. That includes warnings, if you want to see them, and customized optimizations.
[/quote]

Me too!

skyjumper:
Is there a way to specify the compiler and/or linker options int eh preferences file, or some other easily modified file?

Found it int eh .java file:

In the preferences.txt file, add:

avr-gcc.options = -O2
avr-g++.options = -O2
avr-link.options = -O2

Where -O2 is your preferred options

Oh! Like the big note at the top of the preferences.txt file says, be sure to modify the correct file! You need to modify the local copy. Where the local copy is depends on your operating system but its not hard to find.

skyjumper:
Is there a way to specify the compiler and/or linker options int eh preferences file, or some other easily modified file?

It's all covered in the "readme.txt" file in the same place as you obtained the IDE.

If you are looking to save memory space these optimizations go a lot further to conserve ram than the standard IDE:

-g -Os -Wall -ffunction-sections -fdata-sections -funsigned-char -mcall-prologues -Wl,--relax,--gc-sections -funsigned-bitfields -fpack-struct -fno-inline-small-functions -fno-split-wide-types

Good linker options:
-Os -Wl,--relax,--gc-sections

By the way, the latest github Arduino source has a lot less warnings, including many of the ones fixed in earlier posts on this thread. Plus I just submitted a patch that clear up all of the warnings I run into, so hopefully soon it will be silent. Yay!