USB Composite library MIDI Get Bytes without using Callbacks

Post here first, or if you can't find a relevant section!
jhsa
Posts: 26
Joined: Sat Jan 08, 2022 12:10 am

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by jhsa »

Bakisha wrote: Wed Jan 12, 2022 9:22 pm IMHO, yes, you'll need to program every event when received from or send to USB.
Whole purpose of USB Composite library is that it can be detected to computer as midi device (for receiving and sending) and virtual com port at the same time. Maybe even HID device? I forgot the limitations...
You can see what functions is available in USBMIDI.h in USB Composite library's folder.
I'm guessing that you are using arduino_midi_library, but i'm not familiar with it, nor it's syntax.
jhsa wrote: Wed Jan 12, 2022 7:33 pm And this will complicate more when I get to send the USB input to the others, as I will have to code it inside the callback functions for each event
Yes, basically, that's what you have to do with USB Composite library.
And this is what I ended up doing. It was a lot of work and added some extra 500 lines of code (guessing here ;) ), but I think it was the only option I had. Had to account for every single Midi event. Found some that I cannot make work even after checking the library files for documentation. One id "Pitch" and the other is the System Exclusive (Sysex)". All the rest seems to be working.

João
jhsa
Posts: 26
Joined: Sat Jan 08, 2022 12:10 am

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by jhsa »

ag123 wrote: Thu Jan 13, 2022 7:35 am Another possible implementation is to use USB Serial rather than HID for the midi router implementation.
My guess is that this would be simpler, and it saves having to deal with a HID implementation.
it makes the codes a lot simpler as you could use Serial.print() and Serial.read()
I'd guess you may still need to deal with each event say in an if - else switch or switch - case setup, this in part as there would otherwise be little means of telling apart the devices.
Of course, but then the device would show up as a USB To Serial device, right? That would work with a computer, but not with other Midi USB devices with host capabilities. I need it to be true USB Midi. But thank you for the idea. A couple serial to USB is also on my list as I always need them. I use those small red ones with the FTDI chip, but I like to build my own stuff :) Just lack some knowledge sometimes. :)

João
jhsa
Posts: 26
Joined: Sat Jan 08, 2022 12:10 am

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by jhsa »

Thank you all for your replies, I think I got it working and will do some serious testing now :)
I do have a little problem though. If I reset the board via the reset pin, the F103 resets but the USB Midi stops working until I really reboot the device completely. I think the device is still connected to the PC, just the Midi stops working. Any ideas why this would happen? Thanks.

João
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by Bakisha »

I can't say why sysex is not working, you could check if there is any updates of library.
As for USB, try not to press reset :D
Close any program that is using Maple midi-out, compile and flash, disconnect and reconnect USB cable, wait until computer recognize it and start program again.
jhsa
Posts: 26
Joined: Sat Jan 08, 2022 12:10 am

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by jhsa »

Thanks, the problem is that if the board resets itself for some reason in the middle of a song, I am left with no MIDI. That is unlikely to happen, but you know, when your gig depends on stuff being reliable, you want to make sure it doesn't happen :)
I have built most of my guitar effects and I used this library already on other projects, and it is great..
Thank you all for your help and advice. :)

João
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by ag123 »

stm32f103 has 20k sram, i've more than one occasion an app freezes / hang in the midst of logging to an sd card.
runs out of memory, most likely the stack overwrites the global variables.
only a manual reset would recover.

if the board resets in the middle of it, it may be due to other reasons.
you could try to find out if a watchdog implementation could have been done in your codes or library.
if the watchdog is configured, it could trigger the reset when the freeze / hang as like above happens.

if it is simply memory it may help getting a bigger chip
https://www.st.com/en/microcontrollers- ... 2f103.html
e.g. those with RC or RE suffix which has both more flash and ram - and more pins and peripherals.
some vendors do ship boards with that
https://www.aliexpress.com/wholesale?ca ... 32f103rct6

edit:
you would need to edit the ld script file in the variant to use that ram and flash
Last edited by ag123 on Fri Jan 14, 2022 8:49 am, edited 1 time in total.
jhsa
Posts: 26
Joined: Sat Jan 08, 2022 12:10 am

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by jhsa »

Memory is ok.. My code is using only about 30% of RAM..
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by Bakisha »

As ag123 mention it, maybe st-link debugger can be helpfull. I personally don't know how to use it, most of the time i use digital analyser for debugging and pin toggling. USB stuff is very complex for me to understand, i like simple predictable protocols, like serial or spi :D
I had experienced crashing with this library, and i fix it by declaring volatiles any variables that are shared between main loop and virtual voids of USB composite library.
I don't know will it help, try to set "Send_A_To" and others as global volatile variables.
jhsa
Posts: 26
Joined: Sat Jan 08, 2022 12:10 am

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by jhsa »

Bakisha wrote: Fri Jan 14, 2022 7:20 am As ag123 mention it, maybe st-link debugger can be helpfull. I personally don't know how to use it, most of the time i use digital analyser for debugging and pin toggling. USB stuff is very complex for me to understand, i like simple predictable protocols, like serial or spi :D
I had experienced crashing with this library, and i fix it by declaring volatiles any variables that are shared between main loop and virtual voids of USB composite library.
I don't know will it help, try to set "Send_A_To" and others as global volatile variables.
Thanks, I can try that, but my problem is not the code crashing, it is the midi not working if I reset the board using the reset button. Only if reset by powering it off and on again. Hmm, perhaps it needs a delay somewhere in setup :) :D

João
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by fpiSTM »

Maybe You can force to reenumerate in that case.
Post Reply

Return to “General discussion”