Using TinyUSB to access onboard storage and log to serial at the same time

Long story short, I am want to be able to both access my contraption’s onboard SD card via the USB connection to the computer as well as use that same USB connection for logging.

I have had a look at the msc_sd.ino example in the Adafruit_TinyUSB library, and this compiles and works perfectly with the Arduino IDE. Trying to take this code into PlatformIO, however, has induced several days of headaches (4 so far), and I am no longer sure what is a PIO bug and what I am doing right or wrong. I understand that I need to use TinyUSB for this task, but that’s about it.

So, I’m just asking for guidance. I’ve been so bogged down with bugs and issues and circular library dependencies that I am no longer sure what I need to be doing or installing or uninstalling to reach my goal. Can anyone point me in the right direction?

So the msc_sd.ino compiles fine in the Arduino IDE, but you can’t get that exact piece of code to compile and work in PlatformIO?

What exactly is your platformio.ini?

[env:adafruit_feather_m4_can]
platform = atmelsam
board = adafruit_feather_m4_can
framework = arduino
lib_archive = false
lib_ldf_mode = deep+
lib_deps =
  SPI
  adafruit/Adafruit TinyUSB Library@3.3.1
  adafruit/Adafruit Zero DMA Library@^1.1.3
lib_ignore =
  USBHost ; needed per [https://community.platformio.org/t/moteinom0-adafruit-tinyusb-build-errors/36891](https://community.platformio.org/t/moteinom0-adafruit-tinyusb-build-errors/36891) to get Adafruit TinyUSB working
build_flags =
  -D USE_TINYUSB

a lot of those additions are to solve issues detailed in:

… and a few others, but i can only put 2 links in a single post

All these people only have these problems because they just had to get the very latest version of Adafruit TinyUSB. The Adafruit SAMD Arduino core has a builtin, matched version of Adafruit TInyUSB already, as is evident by looking into https://github.com/adafruit/ArduinoCore-samd/tree/1.7.16/libraries. Thus, the correct way is to absolutely not include TinyUSB in the lib_deps expression. PlatformIO will comfortably find it in the builtin libraries of the Arduino core.

The msc_sd.ino files compiles with the most simplistic platformio.ini just fine. Take a look at