SPI.h error on Adafruit Neopixel Trinkey

Hi, I’m trying to build a TinyUSB based example on a Adafruit Neopixel Trinkey, and make it work to be sure that I don’t find any other problems with a project I’m trying to develop.
The problem is I can’t get rid of an error with SPI.h when I try to build the code.

Here’s the error

CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/adafruit_neotrinkey_m0.html
PLATFORM: Atmel SAM (8.2.0) > Adafruit NeoPixel Trinkey
HARDWARE: SAMD21E18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES: 
 - framework-arduino-samd-adafruit @ 1.7.13 
 - framework-cmsis @ 2.50400.181126 (5.4.0) 
 - framework-cmsis-atmel @ 1.2.2 
 - toolchain-gccarmnoneeabi @ 1.90301.200702 (9.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 16 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit TinyUSB Library @ 2.3.2
Building in release mode
Compiling .pio/build/busylight/libc1a/Adafruit_ZeroDMA/Adafruit_ZeroDMA.cpp.o
Compiling .pio/build/busylight/libc4d/SdFat - Adafruit Fork/FatLib/FatDbg.cpp.o
Compiling .pio/build/busylight/libc4d/SdFat - Adafruit Fork/FatLib/FatFile.cpp.o
Compiling .pio/build/busylight/libc4d/SdFat - Adafruit Fork/FatLib/FatFileLFN.cpp.o
Compiling .pio/build/busylight/libc4d/SdFat - Adafruit Fork/FatLib/FatFilePrint.cpp.o
In file included from .pio/libdeps/busylight/Adafruit TinyUSB Library/src/Adafruit_TinyUSB.h:76,
                 from /Users/gnammyx/.platformio/packages/framework-arduino-samd-adafruit/libraries/Adafruit_ZeroDMA/Adafruit_ZeroDMA.cpp:35:
.pio/libdeps/busylight/Adafruit TinyUSB Library/src/arduino/Adafruit_USBH_Host.h:30:10: fatal error: SPI.h: No such file or directory

*************************************************************
* Looking for SPI.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:SPI.h"
* Web  > https://registry.platformio.org/search?q=header:SPI.h
*
*************************************************************

   30 | #include <SPI.h>
      |          ^~~~~~~
compilation terminated.
Compiling .pio/build/busylight/libc4d/SdFat - Adafruit Fork/FatLib/FatFileSFN.cpp.o
Compiling .pio/build/busylight/libc4d/SdFat - Adafruit Fork/FatLib/FatFormatter.cpp.o
Compiling .pio/build/busylight/libc4d/SdFat - Adafruit Fork/FatLib/FatName.cpp.o
Compiling .pio/build/busylight/libc4d/SdFat - Adafruit Fork/FatLib/FatPartition.cpp.o
*** [.pio/build/busylight/libc1a/Adafruit_ZeroDMA/Adafruit_ZeroDMA.cpp.o] Error 1
Compiling .pio/build/busylight/libc4d/SdFat - Adafruit Fork/FatLib/FatVolume.cpp.o

The headers of my main.cpp file

#include <Arduino.h>
#include "Adafruit_TinyUSB.h"

And here is my platform.io file

[env:busylight]
platform = atmelsam
board = adafruit_neotrinkey_m0
framework = arduino
lib_deps=
    adafruit/Adafruit TinyUSB Library
lib_archive = no
build_flags=
    -DUSE_TINYUSB

What I’m doing wrong?

Thanks

  1. Misses version specifications, highly not recommended per https://registry.platformio.org/libraries/adafruit/Adafruit%20TinyUSB%20Library/installation
  2. Also add lib_ldf_mode = deep+ to the platformio.ini

Hi @maxgerhardt, sorry I forgot to put back the version in my many tries to get it work.
My platformio.ini file now look like this

[env:busylight]
platform = atmelsam
board = adafruit_neotrinkey_m0
framework = arduino
lib_deps=
    adafruit/Adafruit TinyUSB Library @ ^2.3.2
lib_archive = no
build_flags=
    -DUSE_TINYUSB
lib_ldf_mode = deep+

but the error is the same, I’ve tried also to perform a Clean of the project but nothing has changed

Thanks

Hm okay, something is definitely wrong here. I can reproduce the error.

One part is that it wrongly includes the “USBHost” library from the Arduino core when compiling the TinyUSB library, but that can be fixed with lib_ignore = USBHost. (Not nice, yes.).

The other part is really that it does not properly see the #include <SPI.h> in Adafruit_USBH_Host.h. And this line has only been added recently.

I also see lots of warnings when PlatformIO’s LDF tries to figure out the dependencies:

Warning! Classic Pre Processor is used for `C:\Users\Max\temp\trinkey\.pio\libdeps\busylight\Adafruit TinyUSB Library\src\arduino\Adafruit_TinyUSB_API.cpp`, advanced has failed with `Incorrect number of arguments to `TU_CHECK_MCU'`
Warning! Classic Pre Processor is used for `C:\Users\Max\temp\trinkey\.pio\libdeps\busylight\Adafruit TinyUSB Library\src\arduino\Adafruit_USBD_CDC.cpp`, advanced has failed with `Incorrect number of arguments to `TU_CHECK_MCU'`
Warning! Classic Pre Processor is used for `C:\Users\Max\temp\trinkey\.pio\libdeps\busylight\Adafruit TinyUSB Library\src\arduino\Adafruit_USBD_Device.cpp`, advanced has failed with `Incorrect number of arguments to `TU_CHECK_MCU'`
Warning! Classic Pre Processor is used for `C:\Users\Max\temp\trinkey\.pio\libdeps\busylight\Adafruit TinyUSB Library\src\arduino\Adafruit_USBH_Host.cpp`, advanced has failed with `Incorrect number of arguments to `TU_CHECK_MCU'`
...

It really seems to fail to recognize what the TU_CHECK_MCU macro does and consequently fails to do proper detection.

One workaround would be to downgrade the TinyUSB library version before the SPI.h line was included. Especially if you don’t have a USB Host chip in your project (USB Device is unaffected.)

Using v2.2.1,

[env:busylight]
platform = atmelsam
board = adafruit_neotrinkey_m0
framework = arduino
lib_deps=
    adafruit/Adafruit TinyUSB Library@2.2.1
lib_archive = no
build_flags=
    -DUSE_TINYUSB
lib_ldf_mode = deep+
lib_ignore = USBHost

the project compiles normally.

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.8% (used 3852 bytes from 32768 bytes)
Flash: [=         ]   8.1% (used 21108 bytes from 262144 bytes)
======== [SUCCESS] Took 42.62 seconds ========

Let me just check if maybe the newest PIO Core fixes this…

I tried to add the lib_ignore, same error, but with the file like this and downgrading the library the build is successfull

[env:busylight]
platform = atmelsam
board = adafruit_neotrinkey_m0
framework = arduino
lib_deps=
    adafruit/Adafruit TinyUSB Library @ 2.2.1
lib_archive = no
build_flags=
    -DUSE_TINYUSB

I consider this a bug in the core and have opened

accordingly.

Ok, thank you, I’ll track the issue on Github.
Have a nice day

Hi @gianmarco-mameli, is there a reason why you need a specific version of the Adafruit TinyUSB Library library instead of the revision bundled with the framework package?

Hi @valeros, no not particularily. My project is an experiment, trying to convert a Pi Pico based project to work on a neopixel trinkey but seems kind of hard, so I’m thinking to give up.
Maybe I can try use the tinyusb stack without insert the specific lib dep in platformio.ini file, only with ‘-DUSE_TINYUSB’ flag?
Thanks

I believe it should work, just don’t forget to delete the .pio folder after removing the lib_deps field.

the build is not completing successfully but now I have some error about multiple definitions of some functions.
This is because in the H and C files are present redefinitions of builtin functions from TinyUSB.
I’m a little stucked, anyway I’ll give it another try next days

Thanks