adafruit / Adafruit_TinyUSB_Arduino

Arduino library for TinyUSB
MIT License
487 stars 129 forks source link

Trying to compile midi_test on platform.io for esp32-s2 results in loads of warnings and errors #181

Closed derMart closed 2 years ago

derMart commented 2 years ago

Operating System

Linux

IDE version

platform.io vscodium extension Core 6.0.2 Home 3.4.2

Board

esp32-s2-saola-1

ArduinoCore version

using platform.io

TinyUSB Library version

adafruit/Adafruit TinyUSB Library@^1.13.2

Sketch

/*********************************************************************
 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit!

 MIT license, check LICENSE for more information
 Copyright (c) 2019 Ha Thach for Adafruit Industries
 All text above, and the splash screen below must be included in
 any redistribution
*********************************************************************/

/* This sketch is enumerated as USB MIDI device. 
 * Following library is required
 * - MIDI Library by Forty Seven Effects
 *   https://github.com/FortySevenEffects/arduino_midi_library
 */

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

// USB MIDI object
Adafruit_USBD_MIDI usb_midi;

// Create a new instance of the Arduino MIDI Library,
// and attach usb_midi as the transport.
MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);

// Variable that holds the current position in the sequence.
uint32_t position = 0;

// Store example melody as an array of note values
byte note_sequence[] = {
  74,78,81,86,90,93,98,102,57,61,66,69,73,78,81,85,88,92,97,100,97,92,88,85,81,78,
  74,69,66,62,57,62,66,69,74,78,81,86,90,93,97,102,97,93,90,85,81,78,73,68,64,61,
  56,61,64,68,74,78,81,86,90,93,98,102
};

void setup()
{
#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
  // Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
  TinyUSB_Device_Init(0);
#endif

  pinMode(LED_BUILTIN, OUTPUT);

  //usb_midi.setStringDescriptor("TinyUSB MIDI");

  // Initialize MIDI, and listen to all MIDI channels
  // This will also call usb_midi's begin()
  MIDI.begin(MIDI_CHANNEL_OMNI);

  // Attach the handleNoteOn function to the MIDI Library. It will
  // be called whenever the Bluefruit receives MIDI Note On messages.
  MIDI.setHandleNoteOn(handleNoteOn);

  // Do the same for MIDI Note Off messages.
  MIDI.setHandleNoteOff(handleNoteOff);

  Serial.begin(115200);

  // wait until device mounted
  while( !TinyUSBDevice.mounted() ) delay(1);
}

void loop()
{
  static uint32_t start_ms = 0;
  if ( millis() - start_ms > 266 )
  {
    start_ms += 266;

    // Setup variables for the current and previous
    // positions in the note sequence.
    int previous = position - 1;

    // If we currently are at position 0, set the
    // previous position to the last note in the sequence.
    if (previous < 0) {
      previous = sizeof(note_sequence) - 1;
    }

    // Send Note On for current position at full velocity (127) on channel 1.
    MIDI.sendNoteOn(note_sequence[position], 127, 1);

    // Send Note Off for previous note.
    MIDI.sendNoteOff(note_sequence[previous], 0, 1);

    // Increment position
    position++;

    // If we are at the end of the sequence, start over.
    if (position >= sizeof(note_sequence)) {
      position = 0;
    }
  }

  // read any new MIDI messages
  MIDI.read();  
}

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
  // Log when a note is pressed.
  Serial.print("Note on: channel = ");
  Serial.print(channel);

  Serial.print(" pitch = ");
  Serial.print(pitch);

  Serial.print(" velocity = ");
  Serial.println(velocity);
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
  // Log when a note is released.
  Serial.print("Note off: channel = ");
  Serial.print(channel);

  Serial.print(" pitch = ");
  Serial.print(pitch);

  Serial.print(" velocity = ");
  Serial.println(velocity);
}

What happened ?

Unable to compile the midi_test example in platform.io. This is my platformio.ini

[env:esp32-s2-saola-1]
platform = espressif32
board = esp32-s2-saola-1
framework = arduino
monitor_speed = 115200
upload_port = /dev/ttyUSB0
lib_deps = 
    adafruit/Adafruit TinyUSB Library@^1.13.2
build_flags =

this is the log output:

> Executing task in folder midi-usb: platformio run <

Processing esp32-s2-saola-1 (platform: espressif32; board: esp32-s2-saola-1; framework: arduino)
--------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s2-saola-1.html
PLATFORM: Espressif 32 (4.4.0) > Espressif ESP32-S2-Saola-1
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20003.0 (2.0.3) 
 - tool-esptoolpy @ 1.30300.0 (3.3.0) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch3 
 - toolchain-xtensa-esp32s2 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 37 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit TinyUSB Library @ 1.13.2
|-- MIDI Library @ 5.0.2
Building in release mode
Compiling .pio/build/esp32-s2-saola-1/src/main.cpp.o
In file included from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/tusb_option.h:179,
                 from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/Adafruit_TinyUSB.h:34,
                 from src/main.cpp:19:
.pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/common/tusb_mcu.h:275:4: warning: #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8" [-Wcpp]
   #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
    ^~~~~~~
src/main.cpp:23:1: error: 'Adafruit_USBD_MIDI' does not name a type
 Adafruit_USBD_MIDI usb_midi;
 ^~~~~~~~~~~~~~~~~~
In file included from .pio/libdeps/esp32-s2-saola-1/MIDI Library/src/MIDI.h:35,
                 from src/main.cpp:20:
src/main.cpp:27:22: error: 'Adafruit_USBD_MIDI' was not declared in this scope
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
                      ^~~~~~~~~~~~~~~~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:100:32: note: in definition of macro 'MIDI_CREATE_INSTANCE'
     MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
                                ^~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:100:36: error: template argument 1 is invalid
     MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
                                    ^
src/main.cpp:27:1: note: in expansion of macro 'MIDI_CREATE_INSTANCE'
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
 ^~~~~~~~~~~~~~~~~~~~
src/main.cpp:27:42: error: 'usb_midi' was not declared in this scope
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
                                          ^~~~~~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:100:51: note: in definition of macro 'MIDI_CREATE_INSTANCE'
     MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
                                                   ^~~~~~~~~~
src/main.cpp:27:42: note: suggested alternative: 'midi'
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
                                          ^~~~~~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:100:51: note: in definition of macro 'MIDI_CREATE_INSTANCE'
     MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
                                                   ^~~~~~~~~~
src/main.cpp:27:22: error: 'Adafruit_USBD_MIDI' was not declared in this scope
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
                      ^~~~~~~~~~~~~~~~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:101:62: note: in definition of macro 'MIDI_CREATE_INSTANCE'
     MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
                                                              ^~~~
Compiling .pio/build/esp32-s2-saola-1/lib5a4/Adafruit TinyUSB Library/device/usbd.c.o
src/main.cpp:27:22: error: template argument 1 is invalid
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
                      ^~~~~~~~~~~~~~~~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:101:62: note: in definition of macro 'MIDI_CREATE_INSTANCE'
     MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
                                                              ^~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:101:66: error: template argument 1 is invalid
     MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
                                                                  ^~
src/main.cpp:27:1: note: in expansion of macro 'MIDI_CREATE_INSTANCE'
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
 ^~~~~~~~~~~~~~~~~~~~
src/main.cpp:27:22: error: 'Adafruit_USBD_MIDI' was not declared in this scope
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
                      ^~~~~~~~~~~~~~~~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:101:102: note: in definition of macro 'MIDI_CREATE_INSTANCE'
     MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
                                                                                                      ^~~~
Compiling .pio/build/esp32-s2-saola-1/lib5a4/Adafruit TinyUSB Library/device/usbd_control.c.o
In file included from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/tusb_option.h:179,
                 from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/device/usbd.c:27:
.pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/common/tusb_mcu.h:275:4: warning: #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8" [-Wcpp]
   #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
    ^~~~~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:101:106: error: template argument 1 is invalid
     MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
                                                                                                          ^
src/main.cpp:27:1: note: in expansion of macro 'MIDI_CREATE_INSTANCE'
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
 ^~~~~~~~~~~~~~~~~~~~
.pio/libdeps/esp32-s2-saola-1/MIDI Library/src/serialMIDI.h:101:108: error: expected primary-expression before ')' token
     MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
                                                                                                            ^
src/main.cpp:27:1: note: in expansion of macro 'MIDI_CREATE_INSTANCE'
 MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
 ^~~~~~~~~~~~~~~~~~~~
src/main.cpp: In function 'void setup()':
src/main.cpp:46:11: error: 'LED_BUILTIN' was not declared in this scope
   pinMode(LED_BUILTIN, OUTPUT);
           ^~~~~~~~~~~
Compiling .pio/build/esp32-s2-saola-1/lib5a4/Adafruit TinyUSB Library/host/hub.c.o
src/main.cpp:52:8: error: request for member 'begin' in 'MIDI', which is of non-class type 'int'
   MIDI.begin(MIDI_CHANNEL_OMNI);
        ^~~~~
src/main.cpp:56:8: error: request for member 'setHandleNoteOn' in 'MIDI', which is of non-class type 'int'
   MIDI.setHandleNoteOn(handleNoteOn);
        ^~~~~~~~~~~~~~~
src/main.cpp:56:24: error: 'handleNoteOn' was not declared in this scope
   MIDI.setHandleNoteOn(handleNoteOn);
                        ^~~~~~~~~~~~
src/main.cpp:59:8: error: request for member 'setHandleNoteOff' in 'MIDI', which is of non-class type 'int'
   MIDI.setHandleNoteOff(handleNoteOff);
        ^~~~~~~~~~~~~~~~
src/main.cpp:59:25: error: 'handleNoteOff' was not declared in this scope
   MIDI.setHandleNoteOff(handleNoteOff);
                         ^~~~~~~~~~~~~
In file included from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/tusb_option.h:179,
                 from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/device/usbd_control.c:27:
.pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/common/tusb_mcu.h:275:4: warning: #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8" [-Wcpp]
   #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
    ^~~~~~~
Compiling .pio/build/esp32-s2-saola-1/lib5a4/Adafruit TinyUSB Library/host/usbh.c.o
src/main.cpp:64:11: error: 'TinyUSBDevice' was not declared in this scope
   while( !TinyUSBDevice.mounted() ) delay(1);
           ^~~~~~~~~~~~~
In file included from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/tusb_option.h:179,
                 from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/host/hub.c:27:
.pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/common/tusb_mcu.h:275:4: warning: #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8" [-Wcpp]
   #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
    ^~~~~~~
src/main.cpp: In function 'void loop()':
src/main.cpp:85:10: error: request for member 'sendNoteOn' in 'MIDI', which is of non-class type 'int'
     MIDI.sendNoteOn(note_sequence[position], 127, 1);
          ^~~~~~~~~~
src/main.cpp:88:10: error: request for member 'sendNoteOff' in 'MIDI', which is of non-class type 'int'
     MIDI.sendNoteOff(note_sequence[previous], 0, 1);
          ^~~~~~~~~~~
src/main.cpp:100:8: error: request for member 'read' in 'MIDI', which is of non-class type 'int'
   MIDI.read();
        ^~~~
In file included from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/tusb_option.h:179,
                 from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/host/usbh.c:27:
.pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/common/tusb_mcu.h:275:4: warning: #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8" [-Wcpp]
   #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
    ^~~~~~~
Compiling .pio/build/esp32-s2-saola-1/lib5a4/Adafruit TinyUSB Library/portable/chipidea/ci_hs/dcd_ci_hs.c.o
Compiling .pio/build/esp32-s2-saola-1/lib5a4/Adafruit TinyUSB Library/portable/chipidea/ci_hs/hcd_ci_hs.c.o
In file included from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/tusb_option.h:179,
                 from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/portable/chipidea/ci_hs/dcd_ci_hs.c:27:
.pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/common/tusb_mcu.h:275:4: warning: #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8" [-Wcpp]
   #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
    ^~~~~~~
In file included from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/tusb_option.h:179,
                 from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/portable/chipidea/ci_hs/hcd_ci_hs.c:27:
.pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/common/tusb_mcu.h:275:4: warning: #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8" [-Wcpp]
   #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
    ^~~~~~~
Compiling .pio/build/esp32-s2-saola-1/lib5a4/Adafruit TinyUSB Library/portable/espressif/esp32sx/dcd_esp32sx.c.o
In file included from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/tusb_option.h:179,
                 from .pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/portable/espressif/esp32sx/dcd_esp32sx.c:29:
.pio/libdeps/esp32-s2-saola-1/Adafruit TinyUSB Library/src/common/tusb_mcu.h:275:4: warning: #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8" [-Wcpp]
   #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
    ^~~~~~~
*** [.pio/build/esp32-s2-saola-1/src/main.cpp.o] Error 1
========================================= [FAILED] Took 2.98 seconds =========================================
The terminal process "platformio 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

so it seems Adafruit_USBD_MIDI is not defined. What am I doing wrong?

How to reproduce ?

Try to compile midi_test (as main.cpp) using the platform.io extension.

Debug Log

No response

Screenshots

No response

hathach commented 2 years ago

I don't use PIO and don't know how to reproduce or fix this. Try the Arduino IDE to see if that work. If not you could open an new issue again, though please ATTACH both sketch and warnings as txt file instead of pasting it her.

derMart commented 2 years ago

Well I am not using the Arduino IDE (not intending to). This issue also is not about the Arduino IDE, but about using this library within platformio, so please stick to the topic. Why are you not able to reproduce this? Just download vscode / vscodium install the platformio extension and try for yourself, it is not complicated. For your convenience, I am happy to generate a repository with all the necessary files which you just can try to build out of the box with platformio (either using the cli or using the vscode extension). Please reopen until resolved. This issue is not complete. EDIT: If you @hathach are not able to fix the issue, please assign this issue to somebody who is. Thanks alot.