Adafruit Arcada with Clue (nrf52840) tries to build library for another platform (SAMD)

When attempting to build the arcada_clue_test for a nordicnrf52 (Adafruit Clue), it seems that PlatformIO is trying to compile the library Adafruit ZeroTimer which is for selected SAMD platforms.

My platformio.ini:

[env]
platform = nordicnrf52
board = adafruit_clue_nrf52840
framework = arduino
monitor_speed = 115200

[env:arcada_clue_test]
lib_deps=
    adafruit/Adafruit Arcada Library@^2.5.4
    adafruit/Adafruit BusIO@^1.14.1
build_src_filter = 
    +<arcada_clue_test.cpp> 

arcada_clue_test.ino is properly adapted to .cpp, I run pio run -e arcada_clue_test and all the libraries get properly installed with no missing dependencies but then I get a bunch of errors related to ZeroTimer, an extract of which is:

In file included from .pio/libdeps/arcada_clue_test/Adafruit ZeroTimer Library/Adafruit_ZeroTimer.cpp:13:0:
.pio/libdeps/arcada_clue_test/Adafruit ZeroTimer Library/Adafruit_ZeroTimer.h:14:29: error: 'TC_CTRLA_PRESCALER' was not declared in this scope
   TC_CLOCK_PRESCALER_DIV1 = TC_CTRLA_PRESCALER(0),
                             ^~~~~~~~~~~~~~~~~~
.pio/libdeps/arcada_clue_test/Adafruit ZeroTimer Library/Adafruit_ZeroTimer.h:14:29: note: suggested alternative: 'TPI_ACPR_PRESCALER_Msk'
   TC_CLOCK_PRESCALER_DIV1 = TC_CTRLA_PRESCALER(0),
                             ^~~~~~~~~~~~~~~~~~
                             TPI_ACPR_PRESCALER_Msk
.pio/libdeps/arcada_clue_test/Adafruit ZeroTimer Library/Adafruit_ZeroTimer.h:16:29: error: 'TC_CTRLA_PRESCALER' was not declared in this scope
   TC_CLOCK_PRESCALER_DIV2 = TC_CTRLA_PRESCALER(1),
                             ^~~~~~~~~~~~~~~~~~
.pio/libdeps/arcada_clue_test/Adafruit ZeroTimer Library/Adafruit_ZeroTimer.h:16:29: note: suggested alternative: 'TC_CLOCK_PRESCALER_DIV1'
   TC_CLOCK_PRESCALER_DIV2 = TC_CTRLA_PRESCALER(1),
                             ^~~~~~~~~~~~~~~~~~
                             TC_CLOCK_PRESCALER_DIV1
.pio/libdeps/arcada_clue_test/Adafruit ZeroTimer Library/Adafruit_ZeroTimer.h:18:29: error: 'TC_CTRLA_PRESCALER' was not declared in this scope
   TC_CLOCK_PRESCALER_DIV4 = TC_CTRLA_PRESCALER(2),
                             ^~~~~~~~~~~~~~~~~~
.pio/libdeps/arcada_clue_test/Adafruit ZeroTimer Library/Adafruit_ZeroTimer.h:18:29: note: suggested alternative: 'TC_CLOCK_PRESCALER_DIV2'
   TC_CLOCK_PRESCALER_DIV4 = TC_CTRLA_PRESCALER(2),
                             ^~~~~~~~~~~~~~~~~~
                             TC_CLOCK_PRESCALER_DIV2
.pio/libdeps/arcada_clue_test/Adafruit ZeroTimer Library/Adafruit_ZeroTimer.h:20:29: error: 'TC_CTRLA_PRESCALER' was not declared in this scope
   TC_CLOCK_PRESCALER_DIV8 = TC_CTRLA_PRESCALER(3),
                             ^~~~~~~~~~~~~~~~~~
.pio/libdeps/arcada_clue_test/Adafruit ZeroTimer Library/Adafruit_ZeroTimer.h:20:29: note: suggested alternative: 'TC_CLOCK_PRESCALER_DIV4'

The sketch builds fine in the Arduino IDE, and Arduino IDE correctly lists the examples for the ZeroTimer lib as incompatible with the selected board “Adafruit CLUE”.

Why would platformio build ZeroTimer, a SAMD compatible pltform, when my current specified platform is nordic52?

And how could I prevent this from happening?

The library does use conditional includes depending on the chip series

So per documentation you need to set the library dependency finder mode to something that evaluates these macros, after which the LDF should exclude the library from the build (since it’s neither SAMD51 or SAMD21).

For example, add in the platformio.ini

lib_ldf_mode = chain+

Maximilian, thanks for the hint, but adding the option

lib_ldf_mode = chain+

didn’t change anything, the errors are exactly the same.

And since platformio.ini clearly specifies the platform, why would the user have to tweak the LDF (library dependency finder)?
What is strange is that since that Adafruit_ZeroTimer.h is actually included, we could think that _SAMD21_ or __SAMD51__ are defined somewhere (see @maxgerhardt Adafruit_Arcada.h#L13-L15 above). Or, and that would require more digging, Adafruit_ZeroTimer.h is included from somewhere else. Anyway, platformIO here is missing something that we have yet to find out.

I managed to get it to build successfully but it’s not a clean way.
It will require to add a library

  1. clean up the .pio directory (delete it).
  2. do a dry run: pio run -e arcada_clue_test, which will download all the necessary dependencies, it will fail with the error mentioned in the first post.
  3. edit:
.pio/libdeps/arcada_clue_test/Adafruit Arcada Library/Adafruit_Arcad.h

and comment out line L14 responsible for the include of the troublesome library.
4) rebuild, it will complain that Adafruit EPD library is missing, add it to platformio.ini:

[env]
platform = nordicnrf52
board = adafruit_clue_nrf52840
framework = arduino
monitor_speed = 115200

[env:arcada_clue_test]
lib_deps=
    adafruit/Adafruit Arcada Library@^2.5.4
    adafruit/Adafruit BusIO@^1.14.1
    adafruit/Adafruit EPD@^4.5.0
build_src_filter = 
    +<arcada_clue_test.cpp> 

(there is no need for lib_ldf_mode = chain+)
5) rebuild

And it builds successfully.