adafruit / Adafruit_TinyUSB_Arduino

Arduino library for TinyUSB
MIT License
449 stars 119 forks source link

Arduino build error: undefined reference to `log_printf' when USB Stack is set to Adafruit TinyUSB Host #384

Closed rppicomidi closed 4 months ago

rppicomidi commented 4 months ago

Operating System

Linux

Arduino IDE version

2.3.0

Board

Raspberry Pi Pico

ArduinoCore version

3.7.0

TinyUSB Library version

3.0.0

Sketch as ATTACHED TXT

Sketch is usb_midi_host_example.ino

Compiled Log as ATTACHED TXT

BuildErrors.txt

What happened ?

I loaded the example sketch referenced above. If CFG_TUSB_DEBUG is 0, the sketch builds fine. If it is 1, 2, or 3, I get the errors described in the referenced BuildErrors.txt file.

How to reproduce ?

  1. Launch the Arduino IDE
  2. Install the Raspberry Pi Pico/RP2040 Arduino Core using the board manager
  3. Select board Raspberry Pi Pico
  4. Install the Adafruit_TinyUSB_Library and all of its dependencies
  5. Install the usb_midi_host library using the Library Manager
  6. File->Examples->usb_midi_host->arduino->usb_midi_host_example
  7. When the usb_midi_host_example.ino sketch opens, Tools->USB Stack: Adafruit TinyUSB Host
  8. Click the Verify checkmark icon.
  9. Observe the code builds with no errors and only the expected warnings.
  10. Using a text editor, change Arduino/libraries/Adafruit_TinyUSB_Library/src/arduino/ports/rp2040/tusb_config_rp2040.h line 68 from
    #define CFG_TUSB_DEBUG 0

    to

    #define CFG_TUSB_DEBUG 1
  11. Observe the build errors referenced above.

Note: If I try the above steps with sketch usb_midi_host_pio_example.ino but choose Tools->USB Stack: Adafruit TinyUSB, then everything build normally. The issue appears to be tied to selecting Adafruit TinyUSB Host.

Note: If I add the following code to my sketch, the code builds fine and the debug log works as expected

// Debugging
int log_printf(const char * format, ...)
{
  char outstr[256];
  va_list va;
  va_start(va, format);
  int ret = vsprintf(outstr, format, va);
  // Uncomment the next line to send the debug log to the Serial1 output
  return Serial1.print(outstr);
}

Debug Log

N/A

Screenshots

N/A