Arduino IDE 2.0 and gcc optimization

How can I force gcc to compile with -O3 in Arduino IDE 2.0? In previous version it was easy -- editing platform.txt was enough.

Hi @prezi. The Arduino boards platform configuration system works exactly the same in Arduino IDE 2.x as in the classic Arduino IDE.

There is one difference which might trip you up, but actually makes this process less confusing: A copy of the "Arduino AVR Boards" platform (Uno, Mega, Leonardo, etc.) came preinstalled with every installation of the classic Arduino IDE. This was located under the hardware subfolder of the Arduino IDE installation folder.

You will find that Arduino IDE 2.x does not have this hardware subfolder. The reason is because there are no boards platforms bundled with the Arduino IDE 2.x installation. Instead, Arduino IDE 2.x uses the Boards Manager system to install all boards platforms, including "Arduino AVR Boards". These are installed to a different location on your computer.

This might be confusing if you are following an outdated tutorial from before the Boards Manager feature was added, which will assume that boards platforms are always installed in the hardware subfolder of the Arduino IDE installation folder. But that assumption was not even safe when using any modern version of the classic Arduino IDE because it also has a Boards Manager feature which installs boards platforms to the same location Arduino IDE 2.x uses. This meant that the copy of Arduino AVR Boards bundled with the classic IDE might not even be the active copy, which results in a very confusing situation if you are edit the inactive platform's files!

So you first need to find the location of the boards platform you want to modify. You can do that by following these instructions:

  1. Start the Arduino IDE.
  2. Select File > Preferences from the Arduino IDE menus.
  3. Check the box next to Show verbose output during: compilation.
  4. Click the OK button.
  5. Select any board of the boards platform you want to modify from the Tools > Board menu in the Arduino IDE.
  6. Select Sketch > Verify/Compile from the Arduino IDE menus.
    It doesn't matter which sketch you compile.
  7. Wait for the compilation to finish.
  8. Scroll the black console pane at the bottom of the Arduino IDE window all the way to the top.

You will now see a line in the output that looks something like:

Using board 'uno' from platform in folder: C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3

This is the path of the platform of that board. You can then edit the platform.txt file you find in that folder. Note that it is under a hidden folder, so you will need to configure your file browser software to show hidden folders in order to see it.

Make sure to close all Arduino IDE windows and then start the Arduino IDE again whenever you make a modification to a boards platform configuration file like platform.txt. The Arduino IDE loads these files on start up, so changes you make to the files after that won't have any effect until after you have restarted the IDE.