arpruss / USBComposite_stm32f1

USB Composite library for STM32F1 (HID, Serial, MIDI and XBox360 controller)
Other
383 stars 76 forks source link

USBComposite never loaded #100

Open epson121 opened 3 years ago

epson121 commented 3 years ago

Hey, I'm having an issue with setting up midiout.ino sketch to work properly.

It gets uploaded to the STM board (black pill, STM32F103C Generic), but USBComposite never gets ready, and program is not functioning correctly.

I've slightly modified the midiout.ino to show the issue:

#include <USBComposite.h>

const uint8_t notes[] = {60, 62, 64, 65, 67, 69, 71, 72, 61, 63, 66, 68, 70};
const int numNotes = sizeof(notes)/sizeof(*notes);

USBMIDI midi;

void setup() {
    Serial.begin(9600);
    USBComposite.setProductId(0x0031);
    midi.begin();
    while (!Serial);
    while (!USBComposite) {
      Serial.println("Waiting for USBComposite");
    }
}

void loop() {
  for (int i=0;i<numNotes;i++) {
    midi.sendNoteOn(0, notes[i], 127);
    delay(200);
    midi.sendNoteOff(0, notes[i], 127);
  }
}

And the console output is:

16:22:04.644 -> Waiting for USBComposite
16:22:04.677 -> Waiting for USBComposite
16:22:04.677 -> Waiting for USBComposite
16:22:04.710 -> Waiting for USBComposite
16:22:04.743 -> Waiting for USBComposite
16:22:04.777 -> Waiting for USBComposite
16:22:04.810 -> Waiting for USBComposite
16:22:04.810 -> Waiting for USBComposite
16:22:04.843 -> Waiting for USBComposite
16:22:04.876 -> Waiting for USBComposite
16:22:04.909 -> Waiting for USBComposite
16:22:04.943 -> Waiting for USBComposite
16:22:04.976 -> Waiting for USBComposite
16:22:04.976 -> Waiting for USBComposite
16:22:05.009 -> Waiting for USBComposite
16:22:05.042 -> Waiting for USBComposite
16:22:05.075 -> Waiting for USBComposite
16:22:05.108 -> Waiting for USBComposite
16:22:05.108 -> Waiting for USBComposite
16:22:05.142 -> Waiting for USBComposite
16:22:05.175 -> Waiting for USBComposite
16:22:05.208 -> Waiting for USBComposite
16:22:05.241 -> Waiting for USBComposite
16:22:05.274 -> Waiting for USBComposite
16:22:05.274 -> Waiting for USBComposite
16:22:05.307 -> Waiting for USBComposite
16:22:05.341 -> Waiting for USBComposite
16:22:05.374 -> Waiting for USBComposite
16:22:05.407 -> Waiting for USBComposite
16:22:05.407 -> Waiting for USBComposite
16:22:05.441 -> Waiting for USBComposite
16:22:05.474 -> Waiting for USBComposite
16:22:05.507 -> Waiting for USBComposite
16:22:05.540 -> Waiting for USBComposite
16:22:05.540 -> Waiting for USBComposite
16:22:05.573 -> Waiting for USBComposite
16:22:05.606 -> Waiting for USBComposite
16:22:05.640 -> Waiting for USBComposite
16:22:05.673 -> Waiting for USBComposite
16:22:05.706 -> Waiting for USBComposite
16:22:05.706 -> Waiting for USBComposite
16:22:05.739 -> Waiting for USBComposite
16:22:05.772 -> Waiting for USBComposite
16:22:05.805 -> Waiting for USBComposite

Any ideas what might be causing this? STM is connected via USB to computer (not directly, but using an UART).

I've tested this on linux and windows, same result.

EDIT: also, I'm having to use Upload method: Serial (in Arduino IDE), because STM32Duino bootloader is throwing DFU issues:

Can't open /dev/ttyUSB0: Input/output error
Can't open serial /dev/ttyUSB0
dfu-util 0.8

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2014 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

the selected serial port 
 does not exist or your board is not connected

*** autoreset failed; you need to use RESET button
dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
dfu-util: No DFU capable USB device available

Upload failed :(
processing.app.SerialException: Error opening serial port '/dev/ttyUSB0'.
    at processing.app.Serial.<init>(Serial.java:152)
    at processing.app.Serial.<init>(Serial.java:82)
    at processing.app.SerialMonitor$2.<init>(SerialMonitor.java:132)
    at processing.app.SerialMonitor.open(SerialMonitor.java:132)
    at processing.app.AbstractMonitor.resume(AbstractMonitor.java:132)
    at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2120)
    at processing.app.Editor.access$1300(Editor.java:117)
    at processing.app.Editor$UploadHandler.run(Editor.java:2089)
    at java.lang.Thread.run(Thread.java:748)
Caused by: jssc.SerialPortException: Port name - /dev/ttyUSB0; Method name - openPort(); Exception type - Port not found.
    at jssc.SerialPort.openPort(SerialPort.java:167)
    at processing.app.Serial.<init>(Serial.java:141)
    ... 8 more
Error opening serial port '/dev/ttyUSB0'.
W3AXL commented 2 months ago

Seeing the same issue, USBComposite never returns true and USB does not function. This is using an STM32F103C8 blue pill and the latest arduino/Arduino_STM32 libraries.

#include <USBComposite.h>

// USB HID device
USBHID HID;

// Keyboard
HIDKeyboard Kbd(HID);

// USB Serial Device
USBCompositeSerial Vcp;

void setup() {
  pinMode(PC13, OUTPUT);
  digitalWrite(PC13, HIGH);
  HID.begin(Vcp, HID_KEYBOARD);
  while (!USBComposite);
  Kbd.begin();
}

void loop() {
  Vcp.println("Ping!");
  digitalWrite(PC13, LOW);
  delay(100);
  digitalWrite(PC13, HIGH);
  delay(900);
}
W3AXL commented 2 months ago

Aha!

I think it may be a fake STM32F1 issue - I switched to the Generic STM32F103C/fake STM32F103C8 board in Arduino and now the above code works.