Hi,
I have a highly specific crash case that I'm looking for help to resolve.
I have a product that uses a Micromod Teensy 4 and the USBHost_t36 library to communicate with external MIDI devices. I've discovered a crash in my device when connected to a specific MIDI hardware device (Behringer BCF2000) but I have not seen similar crashes in other devices using the same code.
I'm just using Arduino IDE and the test programs below.
The issue lies with the call to: -
However, it only occurs when this call is made multiple times inside an interval timer.
Here's a worked-through example: -
This code works perfectly fine (when connected to the device)...
You can see I'm making 16 calls to stop all notes. One call for each MIDI channel. (Yes, I know, but bear with me).
(The stopwatch sw shows around 8000µs).
The following code does the same but from within a fairly slow-running interval timer loop.
If you set NO_OF_CHANNELS to 2, all works fine, and the stopwatch sw shows only 2µs. However, if you set NO_OF_CHANNELS to 3, the device crashes!
The behaviour is the same if I replace sendControlChange with sendNoteOff. It still crashes when setting the NO_OF_CHANNELS any higher than 2.
I've been through the USBHost_t36 midi.cpp code and nothing obvious jumps out. The USBHOST_PRINT_DEBUG debug flag is only showing the transmitted messages, there's nothing incoming.
If I connect other MIDI devices (e.g. Beatstep Pro) the code works fine, right up to 16 channels.
There's clearly something in the way the BCF device interacts with my device but I'm wondering how to debug it?
It is most confusing and any suggestions on what to try or how to dig deeper would be very much appreciated.
Thanks in advance.
Chris
I have a highly specific crash case that I'm looking for help to resolve.
I have a product that uses a Micromod Teensy 4 and the USBHost_t36 library to communicate with external MIDI devices. I've discovered a crash in my device when connected to a specific MIDI hardware device (Behringer BCF2000) but I have not seen similar crashes in other devices using the same code.
I'm just using Arduino IDE and the test programs below.
The issue lies with the call to: -
Code:
hostMIDI.sendControlChange(0x78, 0, channel);
However, it only occurs when this call is made multiple times inside an interval timer.
Here's a worked-through example: -
This code works perfectly fine (when connected to the device)...
Code:
#include <USBHost_t36.h>
USBHost usbHost;
MIDIDevice_BigBuffer hostMIDI(usbHost);
unsigned int sw;
int c = 0;
const int NO_OF_CHANNELS = 16;
void setup() {
Serial.begin(9600);
usbHost.begin();
}
void loop() {
Serial.println(c++);
sw = micros();
for (int channel = 1; channel <= NO_OF_CHANNELS; channel++) {
// send StopAllNotes msg
hostMIDI.sendControlChange(0x78, 0, channel);
}
Serial.print("Time: ");
Serial.println(micros() - sw);
}
You can see I'm making 16 calls to stop all notes. One call for each MIDI channel. (Yes, I know, but bear with me).
(The stopwatch sw shows around 8000µs).
The following code does the same but from within a fairly slow-running interval timer loop.
Code:
#include <USBHost_t36.h>
USBHost usbHost;
MIDIDevice_BigBuffer hostMIDI(usbHost);
IntervalTimer midiLoopTimer;
unsigned int sw;
const int NO_OF_CHANNELS = 2;
void setup() {
Serial.begin(9600);
usbHost.begin();
midiLoopTimer.begin(midiLoop, 1000000);
}
int c = 0;
void midiLoop()
{
Serial.println(c++);
sw = micros();
for (int channel = 1; channel <= NO_OF_CHANNELS; channel++) {
// send StopAllNotes msg
hostMIDI.sendControlChange(0x78, 0, channel);
}
Serial.print("Time: ");
Serial.println(micros() - sw);
}
void loop() {
}
If you set NO_OF_CHANNELS to 2, all works fine, and the stopwatch sw shows only 2µs. However, if you set NO_OF_CHANNELS to 3, the device crashes!
The behaviour is the same if I replace sendControlChange with sendNoteOff. It still crashes when setting the NO_OF_CHANNELS any higher than 2.
I've been through the USBHost_t36 midi.cpp code and nothing obvious jumps out. The USBHOST_PRINT_DEBUG debug flag is only showing the transmitted messages, there's nothing incoming.
If I connect other MIDI devices (e.g. Beatstep Pro) the code works fine, right up to 16 channels.
There's clearly something in the way the BCF device interacts with my device but I'm wondering how to debug it?
It is most confusing and any suggestions on what to try or how to dig deeper would be very much appreciated.
Thanks in advance.
Chris