Missing USB packets (Midi)

Hi.

I'm currently working on a DUE based MIDI synth and have successfully got it running as a MIDI host and I can plug in various midi keyboards, it detects them and sort of works.

I'm using the standard USBHost library from arduino as well as the USBH_MIDI Due port (GitHub - bbx10/USBH_MIDI at due)

As I said, eveything works, although, for some reason I had to insert a one-time 100 microseconds delay in
USBHost::dispatchPkt, otherwise it just hits the NAK limit during configuration and the midi device will never be successfully initialized. This delay is not used once the device is configured though.

The problem I'm having is that midi packets from the device is just randomly lost, and I was wondering if anyone have more experience with this and could hint me in the right direction. I'm a bit uncertain about the polling speed, in what frequency I should request an InTransfer from the device. In the examples that comes with the midi library they seem to request data once every millisecond, so that's what I'm doing as well. I've tried both using their method of having a dynamic delay that subtracts the time already spent in the loop() function, as well as setting up a timer interrupt and request data in that callback, no difference.

If I shorten the delay too much I just don't get any data at all. The device I'm using is an M-Audio KeyRig49, and it's definitely not a fault with the device since it works flawlessly on windows.
I also tried with another midi device, and that one was even worse since it constantly sent some 0xFE midi system message, which caused almost all note on/off to be lost.

Another thing that puzzles me is that the device descriptor states that MaxPacketSize is 8 bytes, but the endpoint descriptor states 64 bytes. And I believe it's the 64 bytes limit that's being used by USBHost when I've skimmed the code. Dunno if something is amiss there.

Anyway, was hoping someone else had done similar things, and solved the problems, or could point me towards some good reading material. Reading though a 600 pages USB specification and get a full understanding of everything feels daunting for something that almost works, and it's not really my main objective here either :slight_smile:

I tried porting the USBH_MIDI driver to Arduino Zero/SAMD. I have not tried really high speed MIDI input though. I am not sure how different the Due vs. Zero USB host stacks are so this may not be useful at all.

In theory, the USB Host Shield 2.0 library for MAX3421E works on Due but I have never tried it. Perhaps it can do high speed MIDI.

Thanks, I'll check it out.

It's not that it's any high speed midi going on, the device is only full speed afaik. It just literally misses the occasional midi messages. It's more frequent if I press and release several keys at the same time, but I've had it happen quite frequently by just hitting the same note in a steady pace.

Well.

I wrote a new midi library which uses continuous IN token generation and catches all in data using interrupts instead, and that worked much better than polling for data.

So for future reference if anyone is interested, here it is: