STM32 based USB to MIDI or RS-232 Interface


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).
Hard - and firmware fit for STM32F070F6 (20 pin TSSOP) processors too, except the USB synchronized system clock (no quartz).

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.

STMF042 board assembly photo
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".
Supported by the provided firmware, up to 6 potentiometers and 1 pushbutton (or no potentiometers and 7 pushbuttons) can be installed there to trigger user programmable MIDI messages laid over the transparent data transfer.

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.

A detailled construction- and operation manual for both versions is provided here (PDF file).


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 actual firmware supports Vusb sensing for the M4 boards, but this is not supported for the STM32F053 board. To keep the Veroboard usable for all versions, jumper J1 has been added to select Vusb sensing wiring or not (see the green jumper on the photo below, which is set in Vusb sensing position).

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.

Nucleo Veroboard assembly photo
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.

Downloads:
The subsequently downloadable material is copyrighted (c)2016-18 by Wolfgang Schemmert.
Assembly and use of the devices is permitted for free by everybody for any purpose ("freeware").
All information is based on best knowledge, but "as is" and without any warranty. Any responsibility is excluded.

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"
(1:1 TIF format, view "from component side". May be etched as PCB too)

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
(Version 3.7 , 05 June 2018) Not useable for STM32F070 !!

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)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 608 kB. Parts published by EmBitz are under license of Embitz, parts published by STM are under license of STM, parts programmed by me are provided under GNU GPL3 license.)

Source code "L053-usbmidicom.zip" for the Nucleo "base board" (status 05 June 2018)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 540 kB. Parts published by EmBitz are under license of Embitz, parts published by STM are under license of STM, parts programmed by me are provided under GNU GPL3 license.)

Source code "f411-usbmidicom.zip" for the Nucleo "base board" (status 05 June 2018)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 692 kB. Parts published by EmBitz are under license of Embitz, parts published by STM are under license of STM, parts programmed by me are provided under GNU GPL3 license.)

Source code "f446-usbmidicom.zip" for the Nucleo "base board" (status 05 June 2018)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 691 kB. Parts published by EmBitz are under license of Embitz, parts published by STM are under license of STM, parts programmed by me are provided under GNU GPL3 license.)

Source code "L476-usbmidicom.zip" for the Nucleo "base board" (status 05 June 2018)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 919 kB. Parts published by EmBitz are under license of Embitz, parts published by STM are under license of STM, parts programmed by Atollic AB are under license of Atollic, parts programmed by me are provided under GNU GPL3 license.)



* 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.