Arduinio build/upload different binaries

Hi forum,

I try to build a simple project with two files in src folder. File one is my main application, file two is, say a ‘check the hardware’ program.

Normally Iḿ willing to build and upload my ‘main application’ but from time I will upload my ‘check the hardware program’.

How can I setup this simple behaviour in platformio?
I played around with ±<src_files> and different env but without success.

Please re-phrase, I can’t understand what do you need :frowning:

If I got it right, the OP wants to set up different “configurations” in their source code, such that the main() function or other functions have a different behavior. And choose which configuration to use when building & uploading the code.

A possible solution: define multiple environments that specify the same platform/framework/board, but with different build flags that define a different preprocessor constant. Then use that constant to enable/disable parts of code.

For example, a platform.ini like

[platformio]
env_default = main

[env:main]
platform = atmelavr
board = micro
framework = arduino
build_flags =
  -DCONFIG_MAIN

[env:hwtest]
platform = atmelavr
board = micro
framework = arduino
build_flags =
  -DCONFIG_HWTEST

Then in your main.cpp:

#ifdef CONFIG_HWTEST
void setup() {
  setupForHardwareTest();
}
#endif

#ifdef CONFIG_MAIN
void setup() {
  regularSetup();
}
#endif

When you want to build/run your hardware test app, type pio build -e hwtest.

Hope this helps.
Kind regards,
Enrico

Okay, I try it

one: $(OBJECTS)
$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@

two: $(OBJECTS2)
$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@

In a make centric world you build your main application with make one.

Occasionally you want to build the binary ‘two’ with make two

All the sources lie in the same source directory, but ‘two’ is completely independent from ‘one’ but can use source code from ‘one’.

The suggestion from ris8_allo_zen0 makes me not happy. It’ s not more than a workaround,

Indeed it’s more of a workaround. And like you I’m also looking for a proper solution.

You need Redirecting...