STM32 based USB to MIDI or RS-232 Interface
This is a DIY construction manual for a small USB to MIDI (or RS-232) interface based on the STM32F042F6 microcontroller (20 pin TSSOP).
An alternative Veroboard add-on for the STM32L053-, STM32F411-, STM32F446- and STM32L476 Nucleo-64 boards is presented below on this page.
Though a number of SMD parts is used, technology is held as simple as possible. Prototype boards are bathroom made and freehand assembled.
Assembly of the small STM32F042 interface (solder and top side view). Board size is 70x25mm.
The interface is "full speed USB2.0" grade. USB class selection between MIDI and RS-232 is made by a jumper near the USB socket (may be connected to a switch). The 5V supply is scaled down by a linear low drop regulator to 3.3V which supplies the complete board except the serial output driver (total current about 26-30 mA, depending on operating conditions).
The basic mode of operation is "transparent" bidirectional transfer of a byte stream. A simple combined MIDI and RS-232 port hardware is provided on the board with separately wired connectors. This way, depending on the activated USB class, the device works as a standard MIDI interface or as an external RS-232 port. The combined MIDI/RS-232 OUT of the revised PCB is equiped with a 74LVC2G14 push-pull driver. This minimizes crosstalk from the serial input to the output, which was sometimes observed with the high-side driver of previous board versions. It works reliably together with standard MIDI inputs as well as up to 230.4 kBaud. A dual red/green LED signals presence of power and data flow.
Two rows of pinheads (or socket arrays, as user prefers) are provided in the middle of the PCB, which break out all I/O pins of the microcontroller for additional tasks or "shields".
The board can be assembled without or with a quartz oscillator, see different firmware versions. Without quartz, the STM32F042 HSI oscillator is active USB synchronized. The STM32F070 does not have this feature. With quartz, the board can be operated standalone as a MIDI stompbox with pushbuttons and pots. No USB data connection is necessary, instead it is powered by a USB power bank or similar d.c. source 4 Volt up to max 5.5 Volt.
During RS-232 operation, a special setup mode can be activated. For the serial connectors baud rates 9600, 19200, 38400 ,57600, 115200, 230400 and 31250(=MIDI) are user configurable. The baud rate for each USB mode of operation (virtual COM port or MIDI) is configured individually. This way, the device may work as a data bridge between MIDI and RS-232 "worlds". Furthermore user specific USB Vid/Pid and MIDI messages to be triggered by pushbuttons or potentiometers are user configurable. The user setup is stored nonvolatile in the microcontroller flash.
The module can be programmed with ST-LINK, which is connected to the pin array next to the USB connector. Alternatively but much less comfortably it can be programmed with the STM FlashLoader via the on board RS232 connector. Unfortunately the loader supports only USART1, which is not directly available because USB is mapped on these pins. A workaround is shown in the PDF construction manual.
Alternatively a functionally equivalent device can be built on a Veroboard as a kind of shield (or better say "base board") for the STM32L053 Nucleo-64, for the STM32F411 Nucleo-64, for the STM32F446 Nucleo-64 or for the STM32L476 Nucleo-64 modules.
This solution is less compact but takes less "technological skills". USB class and transmission of user triggered MIDI messages is selected with a dual DIP switch. The device may be operated USB bus powered or with an external power supply as it is supported by the Nucleo hardware. The supply current is in the order of 60 to 80 mA including the ST-LINK part and 28 to 35 mA when it is cut off. Particularly each LED of the ST-LINK part uses about 10mA! The MIDI and RS-232 interface hardware on this board is powered with 5 Volt.
The "base board" hardware, programming and operation is the same for all four Nucleo versions, though firmwares differ significantly. The firmware is programmed straightforward on register level, no "libraries" are used. Especially the USB implementation is totally different for the Cortex M4 microcontrollers (USB_OTG vs. USB_FS for STM32F0xx,L0xx).
The STM32L053, STM32F411 and the STM32F446 use a quartz clock oscillator (HSE clock, provided by the ST-LINK part or 8Mhz quartz assembled by the user), whereas the STM32L476 is driven by a free running oscillator (MSI clock) which is locked with the 32kHz quartz crystal available on the Nucleo board (LSE clock) and provides very good stability.
Assembly of the Nucleo Veroboard (top and solder side view).
For triggering user programmed MIDI messages, up to 4 potentiometers and 4 pushbuttons (or no potentiometers and 9 pushbuttons) can be attached at the long brown connector in the middle of the board.
The ST-LINK module on the Nucleo provides a serial port, too. But its baud rate is restricted to 115200 baud, it is not useable as MIDI interface and needs a specifically compiled firmware (uses USART2 instead of default USART1). For practical use, the ST-LINK part can be cut off the Nucleo board. On the Veroboard a connector for an external ST-LINK (e.g. the cut part from the Nucleo) is provided.
PCB layout for the small STM32F042 / STM32F070 interface (1:1 TIF format, view "from component side")
Veroboard layout for STM32L053-, STM32F411-, STM32F446 and STM32L476 Nucleo "base board"
Firmware "f042-hse8mhz37.hex" for the small STM32F042 / STM32F070 board with 8 Mhz quartz oscillator (Version 3.7 , 05 June 2018)
Firmware "f042-hse8mhz37-inv.hex" for the small STM32F042 / STM32F070 board with 8 Mhz quartz oscillator LED levels inverted: i.e. power presence not monitored, LEDs on when data transfer (Version 3.7 , 05 June 2018)
Firmware "f042-hsiusb37.hex" for the small STM32F042 board with USB synchronized HSI oscillator
Firmware "L053-usbmidicom17.hex" for the Nucleo "base board" with unmodified Nucleo board (Version 1.7 , 05 June 2018)
Firmware "L053-usbmidicom17-cutoff.hex" for the Nucleo "base board" when the ST-LINK part is cut off and an 8 MHz quartz oscillator is assembled on the Nucleo board (Version 1.7 , 05 June 2018)
Firmware "f411-usbmidicom27.hex" for the Nucleo "base board" (Version 2.7 , 05 June 2018)
Firmware "f446-usbmidicom27.hex" for the Nucleo "base board" (Version 2.7 , 05 June 2018)
Firmware "L476-usbmidicom27.hex" for the Nucleo "base board" (Version 2.7 , 05 June 2018)
Source code "f042-usbmidicom.zip" for the small STM32F042 board (status 05 June 2018)
Source code "L053-usbmidicom.zip" for the Nucleo "base board" (status 05 June 2018)
Source code "f411-usbmidicom.zip" for the Nucleo "base board" (status 05 June 2018)
Source code "f446-usbmidicom.zip" for the Nucleo "base board" (status 05 June 2018)
Source code "L476-usbmidicom.zip" for the Nucleo "base board" (status 05 June 2018)
* State of information June 2018.
* Right of technical modifications reserved. Provided 'as is' - without any warranty. Any responsibility is excluded.
* This description is for information only. No product specifications are assured in juridical sense.
* Trademarks and product names cited in this text are property of their respective owners.