Trying to replace the #define for build

I use Arduino for STM32. I need to place interrupt vectors table at a different address to use my firmware with bootloader.
For moving the interrupt vectors table, I need to change the preprocessor #define VECT_TAB_ADDR which is defined in platforms\ststm32\builder\frameworks\arduino\maple\

Supplying new value was easy - just add -D VECT_TAB_ADDR=whatever to build_flags. But the compiler throws a warning that preprocessor symbol was redefined. If I enable verbose compiler output, I see that VECT_TAB_ADDR is defined on the command line twice.

So, the removing of old symbol value is where I’m stuck.

I tried build_unflags - doesn’t work.
I tried adding extra_scripts = to platformio.ini. The contents of are:

env.Replace(CPPDEFINES=[d for d in env['CPPDEFINES'] if d != ('VECT_TAB_ADDR', 134217728)])

So that it should remove the definition. Doesn’t work! The firmware is built with old value of VECT_TAB_ADDR. Looks like the CPPDEFINES are already cached somewhere else at the time my extra script is run, and changing them doesn’t influence anything.

How can it be done without editing deep in STM32 platform tree?

Thanks again! Fixed in

Please pio upgrade --dev and try

env.Append(CPPDEFINES=("VECT_TAB_ADDR", whatever))

It’s now broken again :frowning:

The correct script now should be

env.Append(CPPDEFINES=("VECT_TAB_ADDR", whatever))


env.Replace(CPPDEFINES=[d for d in env['CPPDEFINES'] if d != ('VECT_TAB_ADDR', 134217728)])
env.Replace(CPPDEFINES=[d for d in env['CPPDEFINES']] + [('VECT_TAB_ADDR', 0x8005000)])

Looks like both variants work for me.

Could you reproduce it again in the latest version of PIO Core?

Yes, I can reproduce it. But I think the way it works now is even better in some aspects. It allows to specifically undefine a build flag with specific content, whereas previously it undefined a build flag with certain name regardless of its content.
Maybe it’s possible to keep both variants of env.ProcessUnFlags?

The previous behavior was incorrect. We should handle macro as a pair of name and value. If you need to remove all macros by name, the env.Replace(CPPDEFINES) is a right way.

Please note that the last PIO Core 3.5.4+ has 2 different build environment: global env and projenv which is isolated from frameworks, etc. We use it to build especially project source file.

Import("env", "projenv")

See Redirecting...