Optimization flags arduino 1.6.5

  1. I have been reading this:
    http://www.instructables.com/id/Arduino-IDE-16x-compiler-optimisations-faster-code/?ALLSTEPS

  2. Page 6 states that platform.txt exist in:
    C:\Users\XXXX\AppData\Roaming\Arduino15\packages\arduino\hardware\avr\1.6.x\platform.txt

However I have found that inside mu PC; C:\Users\XXXX\AppData\Roaming\Arduino15 , there is no folder name packages. I have searched in hidden files also.

  1. However I have found platform.txt file in:
    C:\Program Files\Arduino\hardware\arduino\avr

Not sure if I have to edit in this. I have attached a copy.

  1. There are three places where -Os is found, line 23,26 & 30.
    So should I change at these 3 places only depending on requirement:
    No optimization: -O0
    speed optimization: -O3
    size optimization: -Os
    balance optimization: -O2

platform.txt (5.72 KB)

So should I change at these 3 places only depending on requirement:
No optimization: -O0
speed optimization: -O3
size optimization: -Os
balance optimization: -O2

Why do you think you need to change the optimization level?

Vindhyachal_Takniki:
3. However I have found platform.txt file in:
C:\Program Files\Arduino\hardware\arduino\avr

Not sure if I have to edit in this. I have attached a copy.

Yes, platform.txt is the place to edit the optimization level for Arduino IDE versions 1.6.x

Before doing changes, better keep a copy of the unmodified platform.txt file.

But why do you want to change that? Want to create bigger executables?

  1. Want to learn abt optimization & test the result, how it changes the time/size in arduino.
    In final code, I may use default setting. But at learning stage I want to leran them.

  2. Since I have multiple files in my code, so should I replace "-Os" with "-fwhole-program -O3"?

  1. Since I have multiple files in my code, so should I replace "-Os" with "-fwhole-program -O3"?

What happened when you did that?

Vindhyachal_Takniki:
2. Since I have multiple files in my code, so should I replace "-Os" with "-fwhole-program -O3"?

As far as I know you can replace the occurances of "-Os" against "-O0" (no optimisation at all!), "-O1", "-O2" or "-O3".

But I never tried out.
And I know nothing about a "-fwhole-program" parameter.

  1. I have made 3 changes in platform.txt as present in: Line 23, 26 & 30.
    i.e changed O0,Os & O3
compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD
# -w flag added to avoid printing a wrong warning http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396
# This is fixed in gcc 4.8.3 and will be removed as soon as we update the toolchain
compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections
compiler.c.elf.cmd=avr-gcc
compiler.S.flags=-c -g -x assembler-with-cpp
compiler.cpp.cmd=avr-g++
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
  1. On new sketch (empty setup & loop), code builds without any warning on Os, O3. However when I changed it to O0 it shows warning in many compiled files. Why this error?
In file included from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\USBAPI.h:27:0,
                 from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\Arduino.h:225,
                 from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial2.cpp:25:
c:\program files\arduino\hardware\tools\avr\avr\include\util\delay.h:95:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
 # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
  1. Also my code has multiple .ino & .h files. So will chnaging only these three opt flag will include all files or I have to do something else.

Vindhyachal_Takniki:
i.e changed O0,Os & O3

LOL, I didn't know GCC has that option! :smiley:

You can prevent that from happening by using [nobbc]...[/nobbc].

LOL, what had just happened O0, O0 , O0

Final Code size by opt settings:

  1. Default -Os
    Sketch uses 22502 bytes (8%) of program storage space. Maximum is 253952 bytes.
    Global variables use 674 bytes (8%) of dynamic memory, leaving 7518 bytes for local variables. Maximum is 8192 bytes.

  2. Same code size generated for below thre options
    a) Replace -Os by -O3
    b) Replace -Os by -fwhole-program -O3
    c) Replace -Os by -flto -O3
    Sketch uses 44858 bytes (17%) of program storage space. Maximum is 253952 bytes.
    Global variables use 686 bytes (8%) of dynamic memory, leaving 7506 bytes for local variables. Maximum is 8192 bytes.

Havent tested on hardware yet. Will check. ordered new finger print module.