STM32 based USB to MIDI or RS-232 Interface

back to menue

STM32 based USB to MIDI or RS-232 Interface

A DIY project is described for a small USB to MIDI (or RS-232) interface based on the STM32F042F6 microcontroller (20 pin TSSOP). Hard - and firmware are compatible with STM32F070F6 (20 pin TSSOP) processors too.

Almost the same circuit mounted on a Veroboard compatible PCB (is bigger but takes less "technology" for reproduction) and an alternative version for the STM32 Nucleo-L476 is described in parallel at this website.

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. 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. By default, the interface works as a virtual COM port seen by the PC. When a jumper or switch is placed between microcontroller port pin PA14 and Ground, it works as a native USB/MIDI interface.
A simple combined MIDI and RS-232 port hardware is provided on the board with separately wired connectors. The combined MIDI/RS-232 OUT of the PCB is equiped with a 74LVC2G14 push-pull driver. It works reliably together with standard MIDI inputs as well as up to 115200 Baud. 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 freely available I/O pins of the microcontroller for additional tasks or "shields".
Supported by the provided firmware, up to 6 potentiometers or pushbuttons can be installed there to trigger user programmable MIDI or ASCII text input change messages merged over the transparent data transfer. This feature is switched ON and OFF with a jumper or switch between pin PA13 (programming connector) and Ground.

Individual USB Vid/Pid, baud rates and format of input change messages are user configurable. During RS-232 operation, a special configuration mode gets activated with fast keyboard sequence '+++'. For the serial connectors baud rates 9600, 19200, 38400 ,57600, 115200 and 31250(=MIDI) are user configurable. The baud rate for each 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".
The user setup can be 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 manual and an operation manual is available (PDF files).


Downloads:
The subsequently downloadable material is copyrighted (c)2016-21 by Wolfgang Schemmert.
Assembly of the devices, programming and use of the software is permitted for free by everybody for any purpose ("freeware"). For commercial use, restrictions of third-party software contributors (Segger GmbH, STM) must be respected.
All information is based on best knowledge, but "as is" and without any warranty. Any responsibility is excluded. Use for dangerous, life-threatening and medical applications is forbidden.

PCB layout for the small STM32F042 / STM32F070 interface
(1:1 TIF format, view "from component side")

Firmware "usbmidicom-f042-small.hex" for the small STM32F042 / STM32F070 board
(06 December 2021)

Firmware "usbmidicom-f042-invled.hex" for the small STM32F042 / STM32F070 board
LED levels inverted: i.e. power presence not monitored, LEDs on when data transfer (06 december 2021)

Source code "usbmidicom-f042v9.zip" for the STM32F042 USB to MIDI or RS232 converter
(state 06 December 2021) This source code is provided as complete "Segger Embedded Studio" project (ZIP file, 306 kB).
Parts published by Segger GmbH are under license of Segger&|Rowley, parts published by STM are under license of STM, parts programmed by me are provided under GNU GPL3 license.


back to menue


* State of information December 2021.
* 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.