Choose USB stack as tiny Usb

Hi everyone,
I want to use my Matrix portal m4(SAMD51) as a USB mass storage device running in platformio, which requires select USB Stack as TinyUSB.
After some searches, I have added the build_flags = -D USE_TINYUSB.
But somehow, with build_flags = -D USE_TINYUSB added. No matter what code I uploaded, the board just no longer shows up under Ports and I can’t upload code or open serial monitor anymore.

Platformio.init:
image

I am not sure if this is the right way to select TinyUSB as the USB stack.

It would be very appreciated if anyone can offer any help!

Leo

Don’t add the TinyUSB library to lib_deps. The core already has the right version of the library built-in.

You are right that the USE_TINYUSB macro activates the TinyUSB stack.

As a first check, you should see if simple USB sketches, e.g. the built-in USB serial, works. That is,

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

void setup() {
   Serial.begin(115200);
   while(!Serial) {}
}

void loop() {
  Serial.println("Test");
  delay(1000);
}
[env:adafruit_matrix_portal_m4]
platform = atmelsam
board = adafruit_matrix_portal_m4
framework = arduino
build_flags =
   -DUSE_TINYUSB

Before compilation, remove the .pio folder of the project to delete the old set of libraries.

If that simple sketch with the correct library is not working, there’s a problem. But test that first.

Hi there,

Thanks for the reply.

I’ve removed the TinyUSB from lib_deps and uploaded the USB serial sketches. The board still disappeared under COM ports after uploading the sketch. I also tried uploading the blink led sketch without Serial. The board still disappeared after, but the led blink sketch is working.

TinyUSB lib under core also seems to be outdated.

TinyUSB 1.0.3 is expected for the latest stable core version, as I’ve linked above.

I’ll try and test this on a SAMD21 chip and see if I can reproduce that result of it not working.

I could reproduce the error. The problem is the library linkage. The library is built as .a archive and linked in the final executable, this however creates problems when interrupt handlers with weak linking want to be overwritten by the library. For that, they must be linked as individual object files. Known per e.g. Translating make file for freeRTOS, libopencm3 to platformio.ini - #12 by maxgerhardt and STM32FreeRTOS vTaskDelay() not returning - #2 by maxgerhardt

Add

lib_archive = no

(docs) the platformio.ini and it will likely work for you too.

1 Like

Thanks a lot! It worked like a charm.