USB Composite library MIDI Get Bytes without using Callbacks

Post here first, or if you can't find a relevant section!
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 »

USB has something called the 'single ended zero' - usb reset. i.e. pull both D+ / D- to gnd for 10ms
https://www.usbmadesimple.co.uk/ums_3.htm
resetting the mcu do not necessarily send the 'single ended zero'. so it may be a problem on the *host* side, i.e. the host 'remembers' the previous state and do not enumerate ports again.
a usual 'trick' is to enable or disable the device in windows, i'm not sure if there are other 'short cuts'
in linux there is a little piece of code that can do that usb reset
https://github.com/jkulesza/usbreset

it is possible to do this usb reset in your codes, e.g. in setup etc
e.g.

Code: Select all

pinMode(PA11, OUTPUT);
pinMode(PA12, OUTPUT);
digitalWrite(PA11, LOW);
digitalWrite(PA12, LOW);
delay(10);
pinMode(PA11, INPUT);
pinMode(PA12, INPUT);
the trouble here is actually this is incorrect, you need to restore the AFIO to USB after this.
it would be better to search in RM0008 for a proper means to do this usb reset

and you probably need to do this prior to calling usbComposite.begin() for that matter.
Last edited by ag123 on Sun Jan 16, 2022 10:50 pm, 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 »

fpiSTM wrote: Fri Jan 14, 2022 4:22 pm Maybe You can force to reenumerate in that case.
I don't understand what you mean :) I am a beginner with this arduino thing :mrgreen:

EDIT: Oh, I didn't see your other post as it was on a different page.

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 »

And I can try that and see if it works, it is simple enough. Thanks.

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: Fri Jan 14, 2022 4:33 pm

it is possible to do this usb reset in your codes, e.g. in setup etc
e.g.

Code: Select all

pintMode(PA11, OUTPUT);
pintMode(PA12, OUTPUT);
digitalWrite(PA11, LOW);
digitalWrite(PA12, LOW);
delay(10);
pintMode(PA11, INPUT);
pintMode(PA12, INPUT);
This seems to have worked, at least right after flashing the board while powering it via USB, it started immediately receiving MIDI over USB from my Windows PC. This didn't seem to happen before.

But "pintMode"???? :mrgreen: :mrgreen: :mrgreen:
I do like to be in "pint of beer Mode", specially in the evening ha ha :mrgreen:

Anyway, thank you, I will check this better. will flash now the Blue Pill board that is on the breadboard.

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 »

ok it must be getting late that time, so i just typed the codes away :lol:
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: Sun Jan 16, 2022 7:53 am ok it must be getting late that time, so i just typed the codes away :lol:
Could you please correct it? I have marked it as "Best Answer". Thank you.
It did the trick for me. It seems it always reconnect now if the board resets for some reason. I press reset, and it reconnects immediately without having to reboot it.

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..
yanisroy
Posts: 1
Joined: Tue Mar 01, 2022 8:20 am
Contact:

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by yanisroy »

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.
CharlesBottoms
Posts: 3
Joined: Mon Apr 11, 2022 8:46 pm

Re: USB Composite library MIDI Get Bytes without using Callbacks

Post by CharlesBottoms »

I encountered a similar problem, I will try to do as you advised, and I hope it works out. I really hope that I can recover all the data from the USB, because there are a lot of projects that I am working on. I'm still writing an article for a website with free summary samples for students. There's also a lot of personal information, so I'm really worried.
Post Reply

Return to “General discussion”