Skip to content

Including SPI and/or EEPROM seems to force Adafruit TinyUSB stack #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Doridian opened this issue Feb 10, 2022 · 7 comments
Closed

Including SPI and/or EEPROM seems to force Adafruit TinyUSB stack #477

Doridian opened this issue Feb 10, 2022 · 7 comments
Labels
platformio Platform.IO support

Comments

@Doridian
Copy link

Doridian commented Feb 10, 2022

I have started using this in PlatformIO using the steps documented on the readthedocs website.
Everything seems to be working fine, except that as soon as I use SPI, it forces me to swap to the Adafruit TinyUSB stack.

As can be seen by the dependency graph below, it seems SPI depends on it somehow? As does EEPROM?

Scanning dependencies...
Dependency Graph
|-- <SPI> 1.0
|   |-- <Adafruit TinyUSB Library> 1.9.2
|-- <Adafruit TinyUSB Library> 1.9.2
|-- <EEPROM> 1.0
|   |-- <Adafruit TinyUSB Library> 1.9.2

Did I set up something wrong or is that library required to operate EEPROM or SPI?

(I tested and it actually fails to compile if I select a different USB stack, as in, the default one)

@earlephilhower
Copy link
Owner

The TinyUSB include is #ifdef'd out of normal compilation. Looks like the PIO preprocessor isn't honoring that.

#ifdef USE_TINYUSB
// For Serial when selecting TinyUSB. Can't include in the core because Arduino IDE
// will not link in libraries called from the core. Instead, add the header to all
// the standard libraries in the hope it will still catch some user cases where they
// use these libraries.
// See https://github.com/earlephilhower/arduino-pico/issues/167#issuecomment-848622174
#include <Adafruit_TinyUSB.h>
#endif

In theory, nothing should link to the TinyUSB library even if it compiled, w/o that USE_TINYUSB so unless you're finding it is (and crashing/etc.), I would not worry about it.

@Doridian
Copy link
Author

Doridian commented Feb 10, 2022

The TinyUSB include is #ifdef'd out of normal compilation. Looks like the PIO preprocessor isn't honoring that.

#ifdef USE_TINYUSB
// For Serial when selecting TinyUSB. Can't include in the core because Arduino IDE
// will not link in libraries called from the core. Instead, add the header to all
// the standard libraries in the hope it will still catch some user cases where they
// use these libraries.
// See https://github.com/earlephilhower/arduino-pico/issues/167#issuecomment-848622174
#include <Adafruit_TinyUSB.h>
#endif

In theory, nothing should link to the TinyUSB library even if it compiled, w/o that USE_TINYUSB so unless you're finding it is (and crashing/etc.), I would not worry about it.

The problem I have is the following is causing it to not even compile unless I explicitly tell it to use the TinyUSB stack (by adding said define to platformio.ini)

In file included from C:\Users\Doridian\.platformio\packages\framework-arduinopico\libraries\Adafruit_TinyUSB_Arduino\src\arduino\Adafruit_TinyUSB_API.cpp:30:
C:\Users\Doridian\.platformio\packages\framework-arduinopico\libraries\Adafruit_TinyUSB_Arduino\src/Adafruit_TinyUSB.h:31:2: error: #error TinyUSB is not selected, please select it in "Tools->Menu->USB Stack"
   31 | #error TinyUSB is not selected, please select it in "Tools->Menu->USB Stack"
      |  ^~~~~

@earlephilhower
Copy link
Owner

I'm not familiar with P.IO, unfortunately. I seem to remember there being a "deep mode." Maybe that would actually make it obey the #ifdefs?

OTW, maybe @maxgerhardt has an idea?

@Doridian
Copy link
Author

@earlephilhower Thanks for the pointer, with your suggestion I immeditely found a workaround.
Setting lib_ldf_mode = chain+ (the default is chain without the +) it will respect preproc definitions. (Docs: https://docs.platformio.org/en/latest/librarymanager/ldf.html)

@maxgerhardt
Copy link
Contributor

maxgerhardt commented Feb 10, 2022

Correct, PlatformIO's library dependency finder (LDF) seems to detect the dependency on Adafruit_TinyUSB.h even though the #ifdef USE_TINYUSB block isn't actiavted. That's the behavior of the default lib_ldf_mode.

A more correct fix would be to add a library.json to each of the framework's built in libraries declaring this libLDFMode or somehow setting this as the default setting in the PlatformIO builder script (tools/platformio-build.py) for all projects using this core. I'll look into it.

@mtfurlan
Copy link

Setting lib_ldf_mode = chain+ in the platformio.ini didn't work for me, but lib_ignore = Adafruit TinyUSB Library did.

@earlephilhower
Copy link
Owner

Fixed with #513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platformio Platform.IO support
Projects
None yet
Development

No branches or pull requests

4 participants