Problems compiling Teensy for different USB endpoint type (with solution)

The Teensy can be configured as a number of different types of USB device. I am particularly interested in running it as USB Audio, to use with the Audio Library. I had a lot of trouble getting this working, and I wanted to share this solution with other users, and ask for the docs updated.

As described in the Teensy platform docs, you need to define the appropriate option for the USB endpoint type you wish the teensy to appear as. This is equivalent to choosing one of the menu options in the Arduino IDE (as is mentioned in many of the tutorials). The option -DUSB_AUDIO is needed for audio applications, and is not currently included in this list.

However, all of these options clash with the preconfigured option -DUSB_SERIAL, which is included in the Makefile. As can be seen in usb_desc.h, the different options are defined with #elif, therefore only one can be defined at a time, and the serial option needs to be undefined.

So in the case of USB audio, the solution is to add the following line to platformio.ini

build_flags = -DUSB_AUDIO -UUSB_SERIAL

Thanks a lot for the report!

You don’t need to do -UUSB_SERIAL. Could you try build_flags = -DUSB_AUDIO?

I initially tried only build_flags = -DUSB_AUDIO, and I spent a frustratingly long time wondering why it didn’t work. If you look at the usb_desc.h file, you will see that if USB_SERIAL is defined, the preprocessor will never check if USB_AUDIO is defined, because of the cascading series of #elifs.

Furthermore, unbuild_flags = -DUSB_SERIAL didn’t help either, because it is declared within the Makefile, rather than by the platformio system.

This our bug and I’ve just fixed it in v1.2.1:

Please run pio update and use only build_flags = -DUSB_AUDIO.

P.S: I’ll update docs. Thanks.

Thanks, I confirmed that your fix works.

1 Like