MIDI interface using STM32 microcontroller

hexreader

Joined Apr 16, 2011
581
In post #2 I gave a link to a device (out of stock) that will convert USB MIDI to serial.

Once you have serial MIDI, there are many resources that can be Googled to find MIDI serial protocols.

You still need to write your own code to handle MIDI messages even when you have solved the USB to serial problem.

You will do better to plug your keyboard straight into a Windows PC and use PC applications to do all of the clever MIDI things.

Not sure why you would want to connect MIDI keyboard to an MCU.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Thank you all for help. Could you explain me a little bit why it would not work if I use an USB to midi cable and then design a circuit like this:


I know you mentioned that this wont work, but I am struggling to understand why?
 

hexreader

Joined Apr 16, 2011
581
USB requires that a USB device is connected to a USB host.

Host to host will not work
Device to device will not work.

Your MIDI keyboard is a USB device.
Your MIDI cable is a USB device. (assuming the cable in post #16)

A device cannot talk to a device.
 

hexreader

Joined Apr 16, 2011
581
Yes, STM32F4 has USB Host capability and in theory could interface with your keyboard.

You will need to find driver firmware for STM32F4 to suit your keyboard. My guess is that no such driver firmware is readily available, but I have not checked and I could be wrong.

I sense that you do not have the skills or experience to write your own driver firmware for STM32F4.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
I will not have to do software - thats my colleague job. Hes more experienced than I am so I believe he will know what he need to do.

Having read more about STM32F4 as a USB host, I came across this website:
https://electronics.stackexchange.c...sb-2-0-have-5-pins-when-the-a-type-only-has-4

I was planning to use USB type A to micro USB cable to connect the device and my microcontroller together.
My microcontroller has USB_FS_ID , USB_FS_VBUS, USB_FS_DM and USB_FS_DP pins which I will try to use to connect my microcontroller to my MIDI device.

Based on the information i have gathered from the website, it can be determined which device is host or a slave based on the ID pin. So if I ground the ID pin on my microconttoller side, it should act as a host?

But the confusing thing for me is how does it work on a USB A? It does not have ID pin so how is the device going to know whether to act as a host or a device?
 

hexreader

Joined Apr 16, 2011
581
I googled "USB ID pin" and my understanding is that you ground the ID pin on STM32 to indicate host, then connect 4 USB pins (2 data, 2 power) to type A socket and plug in your keyboard.

The "device" is your keyboard and it does not need to know whether to be host or device, as it can only ever be a device.

I only build micro-controller projects as a hobby, so I am no expert and could be wrong
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
I was thinking about using USB micro type A on my microcontroller side which would save me some space instead of using big old USB A.

I have uploaded a quick sketch.

Thank you for all your help anyways! I think we got there in the end.
 

Attachments

Thread Starter

zazas321

Joined Nov 29, 2015
936
Hey.. I have few more questions:
In this paper: https://pdfserv.maximintegrated.com/en/an/AN1822.pdf
I have found a lot of information about the implementation of USB host.
upload_2019-7-8_12-19-14.png

1. It is mentioned, that for host configuration, 15kOhm pulldowns are requried for D+ and D-. I cant really understand why?

2. I need to power my MIDI keyboard device through VBUS. I assume it has to be +5V. There is an example schematic given:
upload_2019-7-8_12-21-9.png
I cant quite understand how this current limiter power switch supplies +5V from +3.3V. Do I have to use VBUS pin on my microcontroller or I can use external +5V supply to power the MIDI device?
 

Attachments

hexreader

Joined Apr 16, 2011
581
Out of my depth now - over to someone else who knows more than I do....

... though I do notice that Host-only mode does not require any USB_ID signal to be provided.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Thanks. I am trying to design a 5V supply for my MIDI device: AKAI Professional MPK Mini MKII. However, I cant seem to find the spec which would say how much current do I need to pwer the device.
 

chrisw63

Joined Apr 26, 2020
5
I realize this is over six months old, but there are several microcontrollers and modules that can act as a USB host. The Teensy line of Arduino compatible micro boards are great for this, and most less than $30. Adafruit's Feather line (most based on the STM line mentioned by the OP) has several as well, but best of all, in my opinion, is the ESP32 line, as boards with power management and a USB connector are available under $10 (US).

Just about any good microcontroller can act as a USB Host, but the STM32 line has that functionality built in, and boards like the Feather series (and many copycats that are cheaper!) make programming a USB Host easy. From there, it's just a matter of adding the USB MIDI part.
 
Top