PlatformIO Community

How to use stm32duino (official STM32 core) build_opt.h in PlatformIO?

I would need to customize adc clock divider and sampling rate parameters and, as written in the official wiki, this should be done creating a “special” file named build_opt.h and putting there something like this:


Info about this is here:

and here, in the official wiki:

Now, as described in the wiki, when using Arduino IDE, put the file build_opt.h in the sketch folder and you should be done…but…what if one need to do the same thing in PlatformIO?

Any hint/help is very welcome!

The Arduino build system simply reads extra GCC option flags from this file and substitutes them in. See

Meaning this is 100% equivalent to what is already possible in PlatformIO via the build_flags. Your example would translate in

build_flags = 

added to the platformio.ini.

If you still do want to have it in a file, then as seen here, you can pass a -include <file> as a GCC flag and it will include it as the first line of every compilation unit. Thus you can exactly replicate the build_opt.h behaviour, alas more indirectly.

1 Like

Thank you @maxgerhardt, I already use build_flags for other definitions, I was not sure it could work also for this case, still, it did work a charm, thank you!

1 Like