gdsports / USB_Host_Library_SAMD

USB host library 2.0 for Zero/M0/SAMD
126 stars 39 forks source link

Recvbuf needs to be aligned #13

Open studiohsoftware opened 3 years ago

studiohsoftware commented 3 years ago

Hi the datasheet for the SAMD21 here https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Atmel-42181-SAM-D21_Datasheet.pdf page 836, says that the ADDR value must be aligned with the two least significant bits zero.

So in USBH_MIDI_dump.ino the bufMidi declaration should be uint8t bufMidi[64] __attribute_\ ((aligned (4)));

Similarly, looking at USB_MIDI_converter_multi.ino, this leads to the declaration in usbh_midi.h uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE]; This also needs to be aligned per the datasheet.

I am not sure the implications of this. I am doing a deep dive on this code to sort out the dropped MIDI message problem, and just stumbled on it.

todbot commented 3 years ago

I was really hopeful your hypothesis that the alignment ofbufMidi and recvBuf would address the message loss I'm seeing (described in #8). But I dusted off my test setup and tried it out: nope. Still seeing missing MIDI messages. But this is the kind of issue I'm suspecting is the problem.

studiohsoftware commented 3 years ago

yeah I know. seems to make no difference. I am just about done with an interrupt based multi midi ino example.

I did find as well that interval set to zero throws reset errors but while using a 1 there in the interrupt case fixes it, there is no benefit to the polling approach used in the examples.

Short version is that the polling approach is just horrible.