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).
Below an alternative Veroboard add-on for the STM32L053-, STM32F411-, STM32F446- and STM32L476 Nucleo-64 boards is presented.

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 58x30mm.

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 (total current about 26 mA).

The basic mode of operation is bidirectional transfer of a "transparent" MIDI message stream between USB and the MIDI connectors (respectively RS-232 byte stream). A simple combined MIDI and RS-232 port hardware is provided on the board with separately wired connectors. An interesting feature is the fully 3.3V compatible MIDI interface. A dual red/green LED signals presence of power and data flow.

The middle part was originally designed as a kind of "STM32 Stamp" with all IO pins put at two rows of socket arrays (or pinheads, as user prefers). This part still can be cut out and be used standalone, on a breadboard for example.

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.

In RS-232 operation, a special setup mode can be activated. Here for the serial connectors baud rates 9600, 19200, 38400 ,57600, 115200, 230400 and 31250(=MIDI) are user configurable. New as of April 2017: 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 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 the board can be programmed with ST-LINK, which is connected to the pin quadruple next to the USB connector.

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 (HFE clock), 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-17 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 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-usbmidicom13.hex" for the small STM32F042 board (Version 1.3 , 05 April 2017)

Firmware "L053-usbmidicom13.hex" for the Nucleo "base board" (Version 1.3 , 05 April 2017)

Firmware "f411-usbmidicom23.hex" for the Nucleo "base board" (Version 2.3 , 05 April 2017)

Firmware "f446-usbmidicom22.hex" for the Nucleo "base board" (Version 2.2 , 05 April 2017)

Firmware "L476-usbmidicom24.hex" for the Nucleo "base board" (Version 2.4 , 05 April 2017)

Source code "f042-usbmidicom.zip" for the small STM32F042 board (status 05 April 2017)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 550 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 April 2017)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 454 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 April 2017)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 734 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 o5 April 2017)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 581 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 April 2017)
This source code is provided as complete "EmBitz1.11" project (ZIP file, 781 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.)
Because the STM32L476 processor is not yet directly supported by EmBitz, this download is quite well suitable as an Embitz project template for further own development.



* State of information April 2017.
* 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.