Compiler optimisation for due board

Hi,

How to change the compiler options for arduino due (arduino -1.5.7) running on linux machine?

Is there a particular reason you're using Arduino IDE 1.5.7? That is a very outdated version that was only ever considered a beta.

Hi,

Yeah its beta version only.
In the arduino 1.8.5 ,i am unable to find find option for arduino due board.So, i am using arduino-1.5.7

They stopped bundling the hardware package for the Due (Arduino SAM Boards) in recent versions of the Arduino IDE but it's quite easy to install it:

  • Tools > Board > Boards Manager
  • Wait for downloads to finish.
  • Click on "Arduino SAM Boards".
  • Click "Install".
  • Wait for installation to finish.
  • Click "Close".

There has been a lot of development on the Arduino IDE since 1.5.7 so you might find it useful to update but the choice is yours of course.

As for the compiler options. These are set in the file platform.txt. Each hardware package has its own platform.txt so you will notice there is one for Arduino AVR Boards and another for Arduino SAM Boards. In your Arduino IDE 1.5.7 installation you will find the Arduino SAM Boards platform.txt at {Arduino IDE instatallation folder}/hardware/arduino/sam/platform.txt.

To make changes to the flags you can edit that file directly. The Arduino IDE only scans platform.txt on startup so you need to close all Arduino IDE windows and then start the IDE again before changes you make to platform.txt will take effect.

There are also some options to add custom compilation flags without editing platform.txt.

You can create a file named platform.local.txt and in that file define any of these properties:

  • compiler.c.extra_flags
  • compiler.c.elf.extra_flags
  • compiler.cpp.extra_flags
  • compiler.ar.extra_flags
  • compiler.elf2hex.extra_flags

You can examine platform.txt to see exactly where those properties will be expanded in the compilation recipes. For example:

recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}"

The same requirement of restarting the IDE applies for platform.local.txt.

There is also the possibility to pass these properties from the command line if you're using the Arduino IDE CLI. For example:

arduino --pref compiler.cpp.extra_flags=-O0 --upload --board arduino:sam:arduino_due_x_dbg foobar.ino

Unfortunately it's only possible to do this when compiling from the command line. You can't set the compiler flags as used by compilation in the Arduino IDE GUI from the command line.

More information on the Arduino IDE CLI:

I should mention if you do update to a recent IDE version that requires you to install Arduino SAM Boards then the platform.txt will be found in a different location on your computer. I can provide instructions for finding that.

hI,

Thank you so much for your reply.
But in arduino-1.8.5, Tools->Boards->BoardManager ,no options are there to install Arduino SAM Boards.

When you select Tools > Type of boards > Board manager, what do you see ( attach an hard copy of your screen)

Hello I have the same problem. No SAM directory present in the ...\Program Files (x86)\Arduino\hardware\arduino. Only avr directory is present.

bobes131:
Hello I have the same problem. No SAM directory present in the ...\Program Files (x86)\Arduino\hardware\arduino. Only avr directory is present.

This is normal and expected. That path is where the copy of Arduino AVR Boards bundled with the Arduino IDE is located. Arduino SAM Boards has not been bundled with the Arduino IDE for years. When you install a boards platform via Boards Manager, it is installed to a different location. You can find it by clicking the link at the line following File > Preferences > More preferences can be edited directly in the file, then navigating from there to the packages/arduino/hardware/sam/1.6.12 folder.