Teensy USB Compile Issue

I’m using PlatformIO on a Mac, and trying to compile a ‘hello world’ using usb midi.

My platformio.ini is:

[env:teensy32]
platform = teensy
board = teensy31
framework = arduino
build_flags = -DUSB_MIDI

And the main.cpp is:

#include <Arduino.h>

void setup() {
  usbMIDI.begin();
}

void loop() {
}

When I build, I get the following:

Processing teensy32 (platform: teensy; board: teensy31; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy31.html
PLATFORM: Teensy (1.6.0) > Teensy 3.1 / 3.2
HARDWARE: MK20DX256 72MHz, 64KB RAM, 256KB Flash
PACKAGES: 
 - framework-arduinoteensy @ 1.135.0 (1.35) 
 - toolchain-gccarmnoneeabi @ 1.40804.0 (4.8.4)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 90 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/teensy32/src/main.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/AudioStream.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/DMAChannel.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/HardwareSerial1.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/HardwareSerial2.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/HardwareSerial3.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/HardwareSerial4.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/HardwareSerial5.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/HardwareSerial6.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/IPAddress.cpp.o
Compiling .pio/build/teensy32/FrameworkArduino/IntervalTimer.cpp.o
src/main.cpp: In function 'void setup()':
src/main.cpp:4:3: error: 'usbMIDI' was not declared in this scope
   usbMIDI.begin();
   ^
*** [.pio/build/teensy32/src/main.cpp.o] Error 1

Any ideas what I’m doing wrong?

Figured it out. For some reason USB_SERIAL is being defined even though it’s not included in my platformio.ini. I changed it to:

[env:teensy32]
platform = teensy
board = teensy31
framework = arduino
build_flags = -DUSB_MIDI_SERIAL -UUSB_SERIAL

And now it builds fine.

Documented behavior.

It may work directly with just build_flags = -D USB_MIDI

Hi,

The documentation says USB_SERIAL is defined if no other USB define is set, but that’s not what I’m seeing. If you look at my original post, I’m defining only USB_MIDI and the resulting flags contain both definitions, which seems like a bug.

I need to explicitly undefined USB_SERIAL to work around this.