One project, two boards, two codebases with src_filter

Hi all,

I’ve got a project where I have two teensies communicating via serial, and they need separate code (one’s master, one’s slave). Trying to figure out how to set this up in platformio. My file structure is:

├── include
│   └── README
├── lib
│   └── README
├── platformio.ini
├── src
│   ├── primary.ino
│   └── secondary.ino
└── test

my platformio.ini is:

[env:one]
platform = teensy
board = teensy36
framework = arduino
upload_protocol = teensy-gui
src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<secondary.ino*>

[env:two]
platform = teensy
board = teensy41
framework = arduino
upload_protocol = teensy-gui
src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<primary.ino*>

primary.ino and secondary.ino are glorified blink sketches: [edit: I should add that eventually, these will be different sketches, just testing for now]

int led = LED_BUILTIN;

void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  while(!Serial && millis() < 4000);
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
}

void loop() {
  digitalWrite(led, HIGH);
  delay(100);
  digitalWrite(led, LOW);
  delay(200);
}

When I try and build, env one can’t find any source files, and env two tries to build both.

What am I doing wrong here?

I found this thread, but adding the wildcards didn’t seem to have any effect.

Here’s the full compilation output:

Summary
Processing one (platform: teensy; board: teensy36; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy36.html
PLATFORM: Teensy (4.13.1) > Teensy 3.6
HARDWARE: MK66FX1M0 180MHz, 256KB RAM, 1MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
 - framework-arduinoteensy 1.154.0 (1.54)
 - toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
Converting secondary.ino
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
No dependencies
Error: Nothing to build. Please put your source code files to '/Users/sam/code/arduino/fountain_v4/src' folder
======================================================================================================== [FAILED] Took 0.48 seconds ========================================================================================================

Processing two (platform: teensy; board: teensy41; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy41.html
PLATFORM: Teensy (4.13.1) > Teensy 4.1
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 7.75MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
 - framework-arduinoteensy 1.154.0 (1.54)
 - tool-teensy 1.154.210805 (1.54)
 - toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
Converting secondary.ino
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/two/src/secondary.ino.cpp.o
Compiling .pio/build/two/FrameworkArduino/IntervalTimer.cpp.o
Compiling .pio/build/two/FrameworkArduino/Print.cpp.o
Compiling .pio/build/two/FrameworkArduino/Stream.cpp.o
Compiling .pio/build/two/FrameworkArduino/Tone.cpp.o
Compiling .pio/build/two/FrameworkArduino/WMath.cpp.o
Compiling .pio/build/two/FrameworkArduino/WString.cpp.o
Compiling .pio/build/two/FrameworkArduino/analog.c.o
/Users/sam/code/arduino/fountain_v4/src/primary.ino:1:5: error: redefinition of 'int led'
 int led = LED_BUILTIN;
     ^
/Users/sam/code/arduino/fountain_v4/src/secondary.ino:1:5: note: 'int led' previously defined here
 int led = LED_BUILTIN;
     ^
/Users/sam/code/arduino/fountain_v4/src/primary.ino: In function 'void setup()':
/Users/sam/code/arduino/fountain_v4/src/primary.ino:4:6: error: redefinition of 'void setup()'
 void setup() {
      ^
/Users/sam/code/arduino/fountain_v4/src/secondary.ino:4:6: note: 'void setup()' previously defined here
 void setup() {
      ^
/Users/sam/code/arduino/fountain_v4/src/primary.ino: In function 'void loop()':
/Users/sam/code/arduino/fountain_v4/src/primary.ino:14:6: error: redefinition of 'void loop()'
 void loop() {
      ^
/Users/sam/code/arduino/fountain_v4/src/secondary.ino:14:6: note: 'void loop()' previously defined here
 void loop() {
      ^
Compiling .pio/build/two/FrameworkArduino/bootdata.c.o
Compiling .pio/build/two/FrameworkArduino/clockspeed.c.o
Compiling .pio/build/two/FrameworkArduino/debugprintf.c.o
Compiling .pio/build/two/FrameworkArduino/delay.c.o
Compiling .pio/build/two/FrameworkArduino/digital.c.o
Compiling .pio/build/two/FrameworkArduino/eeprom.c.o
Compiling .pio/build/two/FrameworkArduino/extmem.c.o
*** [.pio/build/two/src/secondary.ino.cpp.o] Error 1
Compiling .pio/build/two/FrameworkArduino/interrupt.c.o
======================================================================================================== [FAILED] Took 1.02 seconds ========================================================================================================

Environment    Status    Duration
-------------  --------  ------------
one            FAILED    00:00:00.483
two            FAILED    00:00:01.017
================================================================================================== 2 failed, 0 succeeded in 00:00:01.500 ==================================================================================================

Any help appreciated! I’m sure I’m missing something trivial.

Have you tried converting them to real C++ files and seeing if the filters then work (when adapted to .cpp)? The needed conversion process might be interfering here.

1 Like

That was it, thanks!

I suppose, wishlist feature, it’d be cool if this worked on .ino files as well, since the process of importing a project from the arduino IDE otherwise works so well =)

Running into another issue here – I can make a new thread if it’s too unrelated but it seems close enough…

according to the pio compilation, everything uploads correctly to the two boards (a teensy 4.1 and 3.6):

Environment    Status    Duration
-------------  --------  ------------
one            SUCCESS   00:00:02.747
two            SUCCESS   00:00:02.938

the 4.1 is uploading fine, but the 3.6 gets stuck in bootloader. it seems like the 3.6 is compiling for 4.1 (despite what it says in the compilation, below). I only discovered this after switching from upload_protocol = teensy-cli to teensy-gui, and it popped up this warning:

Screen Shot 2021-09-22 at 10.14.14

Any thoughts? here’s the whole output:

Summary
Processing one (platform: teensy; board: teensy36; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy36.html
PLATFORM: Teensy (4.13.1) > Teensy 3.6
HARDWARE: MK66FX1M0 180MHz, 256KB RAM, 1MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES: 
 - framework-arduinoteensy 1.154.0 (1.54) 
 - tool-teensy 1.154.210805 (1.54) 
 - toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Linking .pio/build/one/firmware.elf
Checking size .pio/build/one/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   1.6% (used 4204 bytes from 262144 bytes)
Flash: [          ]   1.2% (used 12628 bytes from 1048576 bytes)
Building .pio/build/one/firmware.hex
Configuring upload protocol...
AVAILABLE: jlink, teensy-cli, teensy-gui
CURRENT: upload_protocol = teensy-gui
Uploading .pio/build/one/firmware.hex
Found 2 Teensy boards, but using auto-search to find board for upload.
Please use Tools > Ports(Teensy) to select the specific board.
======================================================================================================================= [SUCCESS] Took 2.07 seconds =======================================================================================================================

Processing two (platform: teensy; board: teensy41; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy41.html
PLATFORM: Teensy (4.13.1) > Teensy 4.1
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 7.75MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES: 
 - framework-arduinoteensy 1.154.0 (1.54) 
 - tool-teensy 1.154.210805 (1.54) 
 - toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Linking .pio/build/two/firmware.elf
Checking size .pio/build/two/firmware.elf
Building .pio/build/two/firmware.hex
Configuring upload protocol...
AVAILABLE: jlink, teensy-cli, teensy-gui
CURRENT: upload_protocol = teensy-gui
Uploading .pio/build/two/firmware.hex
Found 2 Teensy boards, but using auto-search to find board for upload.
Please use Tools > Ports(Teensy) to select the specific board.
======================================================================================================================= [SUCCESS] Took 1.32 seconds =======================================================================================================================

Environment    Status    Duration
-------------  --------  ------------
one            SUCCESS   00:00:02.065
two            SUCCESS   00:00:01.321
======================================================================================================================= 2 succeeded in 00:00:03.387 =======================================================================================================================

I don’t think the GUI program can auto-detect the correct target upload board when there is more than 1 board connected. Or PlatformIO is not invoking it with a flag that might give it a hind. Best to stick to teensy-cli if that worked for you.

You can open an issue about the GUI in Issues · platformio/platform-teensy · GitHub but if the program is missing the feature, fundamentally the program comes from the Teensy people and they need to adapt it.

Yeah sadly it’s the same deal with the teensy-cli – same thing happens even if I specifically target individual boards via upload_port (the 4.1 works fine but the 3.6 gets stuck in bootloader).

The only reason I mention the GUI is that I thought maybe that modal would be a clue as to why it’s not uploading properly.

It’s possible that yes, this is an issue with teensy. But I kind of doubt it, since if I don’t specify a port in the teensyduino IDE, the GUI correctly finds the appropriate port based on which board is selected.

Here’s the output with a more explicit platformio.ini and teensy-cli:

[env:one]
platform = teensy
board = teensy36
framework = arduino
upload_protocol = teensy-cli
upload_port = /dev/cu.usbmodem102538701 ; the 3.6 is on this port
src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<secondary.cpp*>

[env:two]
platform = teensy
board = teensy41
framework = arduino
upload_protocol = teensy-cli
upload_port = /dev/cu.usbmodem89957801 ; the 4.1 is on this port
src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<primary.cpp*>
Summary
Processing one (platform: teensy; board: teensy36; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy36.html
PLATFORM: Teensy (4.13.1) > Teensy 3.6
HARDWARE: MK66FX1M0 180MHz, 256KB RAM, 1MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES: 
 - framework-arduinoteensy 1.154.0 (1.54) 
 - tool-teensy 1.154.210805 (1.54) 
 - toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Linking .pio/build/one/firmware.elf
Checking size .pio/build/one/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   1.6% (used 4204 bytes from 262144 bytes)
Flash: [          ]   1.2% (used 12624 bytes from 1048576 bytes)
Building .pio/build/one/firmware.hex
Configuring upload protocol...
AVAILABLE: jlink, teensy-cli, teensy-gui
CURRENT: upload_protocol = teensy-cli
Rebooting...
Uploading .pio/build/one/firmware.hex
Teensy Loader, Command Line, Version 2.2
Read ".pio/build/one/firmware.hex": 12628 bytes, 1.2% usage
Error opening USB device: Operation timed out
Waiting for Teensy device...
 (hint: press the reset button)
Found HalfKay Bootloader
Read ".pio/build/one/firmware.hex": 12628 bytes, 1.2% usage
Programming.............
Booting
======================================================================================================================= [SUCCESS] Took 4.96 seconds =======================================================================================================================

Processing two (platform: teensy; board: teensy41; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy41.html
PLATFORM: Teensy (4.13.1) > Teensy 4.1
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 7.75MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES: 
 - framework-arduinoteensy 1.154.0 (1.54) 
 - tool-teensy 1.154.210805 (1.54) 
 - toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Linking .pio/build/two/firmware.elf
Checking size .pio/build/two/firmware.elf
Building .pio/build/two/firmware.hex
Configuring upload protocol...
AVAILABLE: jlink, teensy-cli, teensy-gui
CURRENT: upload_protocol = teensy-cli
Rebooting...
Uploading .pio/build/two/firmware.hex
Teensy Loader, Command Line, Version 2.2
Read ".pio/build/two/firmware.hex": 22528 bytes, 1.1% usage
Found HalfKay Bootloader
Programming...................
Booting
======================================================================================================================= [SUCCESS] Took 1.08 seconds =======================================================================================================================

Environment    Status    Duration
-------------  --------  ------------
one            SUCCESS   00:00:04.963
two            SUCCESS   00:00:01.084
======================================================================================================================= 2 succeeded in 00:00:06.048 =======================================================================================================================

Actually a workaround by using a different upload that has a select capability is outlined at --upload-port flag has no effect · Issue #44 · platformio/platform-teensy · GitHub

A PR to add board selection is still open at Enable the user to specify the serial number by hmaarrfk · Pull Request #57 · PaulStoffregen/teensy_loader_cli · GitHub… because COVID.

Actually this is bug-worthy – please open an issue in Issues · platformio/platformio-core · GitHub.

1 Like

done, thanks for your help @maxgerhardt

You can override the upload command via: