-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
USBMIDI crashes on XIAO BLE Sense (mbed enabled core) when the board is powered but has no USB connection #1066
Comments
Ok, after poking around in the library I found out that the problem is in the backend: For example, the Adafruit_TinyUSB_USBDeviceMIDIBackend checks whether the USB device is mounted before the backend Fortunately, the backend class has inherited the connected() function. The code simply repeats sending a CC and flashes the onboard LED to check if the board is still running. #include <Arduino.h>
#include <Control_Surface.h>
struct MyUSBMIDIBackend {
using MIDIUSBPacket_t = AH::Array<uint8_t, 4>;
MIDIUSBPacket_t read() { return u32_to_bytes(backend.read()); }
void write(MIDIUSBPacket_t data) {
/* This checks whether there is a USB connection to the host before the backend can write data */
if (backend.connected()) {
backend.write(bytes_to_u32(data));
}
}
void sendNow() { backend.send_now(); }
bool preferImmediateSend() { return false; }
PluggableUSBMIDI backend;
};
struct MyUSBMIDI_Interface : GenericUSBMIDI_Interface<MyUSBMIDIBackend> {
MyUSBMIDI_Interface() = default;
using MIDIUSBPacket_t = MyUSBMIDIBackend::MIDIUSBPacket_t;
};
MyUSBMIDI_Interface midi_usb;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
midi_usb.begin();
}
void loop() {
static uint32_t testtime;
static boolean teststate;
if (millis() - testtime > 250) {
testtime = millis();
teststate = !teststate;
if (teststate) {
midi_usb.sendControlChange((1, Channel_1), 127);
digitalWrite(LED_BUILTIN, LOW);
} else {
midi_usb.sendControlChange((1, Channel_1), 0);
digitalWrite(LED_BUILTIN, HIGH);
}
midi_usb.update();
}
}
... |
I pushed a fix to the I'm leaving the issue open until the fix is merged. |
Very nice! I'm at work right now, but I'll check it tonight. |
Hello Pieter, your changes are correct. The library branch does the same as my little fix in the backend.
Since I have very limited knowledge of USB, I could only make assumptions here. But I'll stick with the problem and report back if I can figure something out. Best EDIT: What I can definitely say is that the board does not a reset at point 5. |
Thanks for the detailed description. The USB code could definitely use some improvements, cancellation and USB resets are not properly supported at the moment. It's on my TODO list, but I'm quite busy with other things, unfortunately. |
Hello,
I am using a XIAO BLE Sense (NRF52840) board to map IMU data into MIDI CC.
Yes I know this might be special topic because of the "core", so this is for information only.
Long story short. Except for one case, everything is working fine.
If the board is powered by an active USB hub but there is no PC on the other side,
then it hangs after a few attempts to send something.
The problem does not occur with the same code running on a Teensy LC for example.
So this is NOT a general problem with the library.
What I've already tried to do is figure out where it's hanging. If the code only runs update() without sendCC(), the problem does not occur. But that's probably because update() doesn't do anything if there's nothing to send...
The code simply repeats sending a CC and flashes the onboard LED to check if the board is still running.
If anyone out there knows how to prevent this, I would be very grateful :-)
The text was updated successfully, but these errors were encountered: