Let's take a look at one option in the "Optimize" custom board option menu (menu ID opt
):
https://github.com/stm32duino/Arduino_Core_STM32/blob/2.3.0/boards.txt#L7300
GenF1.menu.opt.ogstd=Debug (-Og)
This line adds a "Debug (-Og)" option to the Tools > Optimize menu in Arduino IDE.
https://github.com/stm32duino/Arduino_Core_STM32/blob/2.3.0/boards.txt#L7301
GenF1.menu.opt.ogstd.build.flags.optimize=-Og
This line causes a build property named build.flags.optimize
to be defined and set to the value -Og
when the user selects Tools > Optimize > Debug (-Og) from the Arduino IDE menus.
This build.flags.optimize
is only an arbitrary property. Defining it doesn't do anything on its own. The property must be used somewhere. You can see one of the places it is used here:
https://github.com/stm32duino/Arduino_Core_STM32/blob/2.3.0/platform.txt#L37
compiler.cpp.flags={compiler.extra_flags} -c {build.flags.optimize} {build.flags.debug} {compiler.warning_flags} -std={compiler.cpp.std} -ffunction-sections -fdata-sections -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -fno-use-cxa-atexit -MMD {compiler.stm.extra_include}
(note the {build.flags.optimize}
property reference in that line)
This property reference is being used as part of the definition of yet another build property: compiler.cpp.flags
. Once again, defining that property doesn't have any effect on its own if it is not used somewhere. You can see it being used here:
https://github.com/stm32duino/Arduino_Core_STM32/blob/2.3.0/platform.txt#L129
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {build.info.flags} {compiler.cpp.extra_flags} {build.st_extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
(note the {compiler.cpp.flags}
property reference in that line)
The previous build properties were only arbitrary properties, which the platform developer can define as many as they like with any name, and reference them as they like. There are also some properties that have special significance in the Arduino boards platform framework. recipe.cpp.o.pattern
is one of them. This defines the "pattern" (i.e., template) used to generate one of the commands Arduino IDE runs during the compilation:
https://arduino.github.io/arduino-cli/latest/platform-specification/#recipes-to-compile-source-code
So the combination of setting the property in boards.txt
and then referencing it (indirectly) in the recipe.cpp.o.pattern
causes the -Og
flag to be added to the compilation command.
This is likely because you aren't referencing the {build.flags.optimize}
property in the appropriate places in your platform.txt
file.