PlatformIO Community

Can't compile midi program for teensy2++

I am trying to compile a midi controller type program for the teensy using platformio. I was able to do this with the arduino IDE and get it uploaded without issues. I have never used platformio before so I thought I would try it. I am using the platformio plugin with clion.

Here is my .ini file:

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

lib_deps =
    paulstoffregen/Encoder @ ^1.4.1
    tttapa/Control Surface @ 1.2.0-4

and here is the main.cpp

#include <Encoder.h>
#include <Control_Surface.h>

// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;

// Instantiate a CCRotaryEncoder object
CCRotaryEncoder enc = {
        {32, 33},       // pins
        {14}, // MIDI address (CC number + optional channel)
        1,            // optional multiplier if the control isn't fast enough
};
void setup() {

    RelativeCCSender::setMode(relativeCCmode::TWOS_COMPLEMENT);
    Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
    Control_Surface.loop(); // Update the Control Surface
}

The first error I get is In file included from .pio/libdeps/teensy2pp/MIDIUSB/src/MIDIUSB.cpp:17:0: .pio/libdeps/teensy2pp/MIDIUSB/src/MIDIUSB.h:74:2: error: #error "Unsupported architecture"

followed by a lot more errors from the same MIDIUSB.h file
This code compiles and was uploaded using the arduino IDE and the teensy loader.

I am using a teensy2++.

Any help is greatly appreciated.

I’ve looked at the compilation process and it seems PlatformIO includes some wrong libraries. MIDIUSB e.g. is recognized as some Arduino library written for AVR and SAM(D) processors and not the one in the core directory.

To correct that, add the line

lib_ignore = MIDIUSB, Audio

to the platformio.ini and retry.

EDIT: Also, the project should be cleaned to remove old build artifacts and libraries, e.g. using pio run -t clean or “Clean” in VSCode.

thank you. that got rid of the USBMidi errors. However Now I have

/tmp/ccYJWZkO.s: Assembler messages:
/tmp/ccYJWZkO.s:506: Error: register r24, r26, r28 or r30 required
/tmp/ccYJWZkO.s:567: Error: register r24, r26, r28 or r30 required
*** [.pio/build/teensy2pp/libe99/SoftwareSerial/SoftwareSerial.cpp.o] Error 1

For that path is .pio\build\teensy2pp\libe68\SoftwareSerial\SoftwareSerial.cpp.o. Maybe again a different library is used (based on my 0xe68 and your 0xe99). Do you have maybe have a Arduino-AVR version of SoftwareSerial globally installed in ~/.platformio/lib? If yes, delete it.

Compilation goes through for me.

Checking size .pio\build\teensy2pp\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  10.2% (used 837 bytes from 8192 bytes)    
Flash: [=         ]   9.5% (used 12350 bytes from 130048 bytes)
====================== [SUCCESS] Took 5.55 seconds =============

Ah, that can be checked easily. Please run the “Verbose Build” task (or pio run -v). The dependency graph will then show the full paths.

Dependency Graph
|-- <Encoder> 1.4.1 (C:\Users\Maxi\Documents\PlatformIO\Projects\esp_test\.pio\libdeps\teensy2pp\Encoder)
|-- <Control Surface> 1.2.0-4 (C:\Users\Maxi\Documents\PlatformIO\Projects\esp_test\.pio\libdeps\teensy2pp\Control Surface)
|   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoteensy\libraries\SPI)
|   |-- <Encoder> 1.4.1 (C:\Users\Maxi\Documents\PlatformIO\Projects\esp_test\.pio\libdeps\teensy2pp\Encoder)
|   |-- <FastLED> 3.3.3 (C:\Users\Maxi\.platformio\packages\framework-arduinoteensy\libraries\FastLED)
|   |   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoteensy\libraries\SPI)
|   |   |-- <SoftwareSerial> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoteensy\libraries\SoftwareSerial)     
|   |   |-- <DmxSimple> 3.1 (C:\Users\Maxi\.platformio\packages\framework-arduinoteensy\libraries\DmxSimple)
|   |-- <SoftwareSerial> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoteensy\libraries\SoftwareSerial)

If SoftwareSerial doesn’t point to framework-arduinoteensy\libraries\SoftwareSerial, that’s an error. What does your output say?

the dependency graph shows

-- <SoftwareSerial> 1.0 (/home/stone/.platformio/packages/framework-arduinoteensy/libraries/SoftwareSerial)

I’m unable to reproduce your issue on Ubuntu 20.04LTS with pio --version latest 5.0.2b2 (via pio upgrade --dev) and the latest Teensy package.

My verbose compilation log is at https://pastebin.com/FjiFXKwS for you to compare versions and invocations against.

Some steps I can recommend:

  • pio run -t clean in the project to clean it
  • removal of .pio folder in the project (build and library artifacts) and recompile
  • pio platform update to make sure you’re on the latest version
  • pio upgrade --dev for bleeding edge PIO version
  • rm -rf ~/.platformio/packages/toolchain-atmelavr* to delete the compiler package (will be freshly redownloaded on next compile)
  • rm -rf ~/.platformio/packages/framework-arduinoteensy
  • adding the line platform_packages = toolchain-atmelavr@https://bintray.com/platformio/tool-packages/download_file?file_path=cc65b2c-toolchain-atmelavr-linux_x86_64-1.70300.191015.tar.gz to the platformio.ini to force usage of a 7.3.0 GCC instead of the 5.4.0, if the compiler is really at fault here (but somehow not on my system)
  • try on different system?

im on 20.04 as well. I will give your suggestions a try and report back

looks like cleaning worked. It compiled and uploaded. Thank you!

1 Like