Time goes fast, new and more powerful microprocessors are introduced, and the favourites of a year ago are fading and starts to collect dust in a draver filled with useful but not quite exciting boards. These days the Cortex M3 of the Maple board feels a bit old, the Teensy 3.1 is a great board and the Arduino type libraries and support is superb, but it has a bit limited memory and no hardware floating point.The boards I use mostly for audio generation at the moment are the Netduino plus 2, without the Netduino bootloader and .Net libraries, the STM32F4 Discovery and the XMC4500 Relax Kit Lite. All of these have Cortex-M4F processors, more than 128KB RAM and 1024KB of flash, they are all cheap and good value for money.
I need stable USB MIDI and after wrangling with the device libraries and development platforms, endless hierachies of folders and files that are usually targeted at Windows and often lacking USB MIDI, I decided to write yet another lightweight USB implementation. I know this might sound stupid and a waste of effort but having some time free due to vacation times and a bit of rainy summer I went ahead.
The code is written from scratch and uses only some MCU specific header files borrowed unchanged from the manufaturer supplied code libraries. When time allows and I have done some more testing a few minimal example programs will be added.
I have uploaded the code to my Cortal Dendrites repository on Github:
https://github.com/mlu/cortal_dendrites/tree/master/cortex_m/usblib
Happy Coding :)
Showing posts with label USB. Show all posts
Showing posts with label USB. Show all posts
Monday, August 10, 2015
Saturday, April 6, 2013
MIDI USB Class for the Maple board
I got myself an OpenPipe breakout board and want to use a Maple board
to connect it to a soft synth on my computer or a hardware synth. For
this I want the Maple to implement a MIDI USB class device.
The
Maple has as standard a USB serial device that gets setup and loaded as
part of building a sketch and its then available as SerialUSB object. The MIDI USB will replace the Serial USB, and register the device as a MIDI class compliant device. The Maple bootloader is not affected, but the remote reset into bootloader is not implemented, so a manual reset is needed to get into the bootloader, I can live with that.
The MIDI USB needs a few things to setup
- USB Setup and handling of Control Requests
- A MIDI USB device descriptor to present itself to a host computer as a MIDI USB device
- Bulk IN and OUT endpoints for MIDI USB packets, 32 bit/4 byte blocks of data
- Code that interprets the MIDI USB packets as standard MIDI events.
Building
the MIDI USB class as a variant of the existing USB serial code, the
first and third parts are almost identical for MIDI and Serial, actually
easier for MIDI since no modem control line handling is necessary and
no management endpoint is needed.
The device descriptor is bit harder, but its a static datastructure and just following the MIDI USB documentation carefully will get you through this.
The USB MIDI package handling is standard MIDI code, and does not depend on the details of the USB transport layer.
The device descriptor is bit harder, but its a static datastructure and just following the MIDI USB documentation carefully will get you through this.
The USB MIDI package handling is standard MIDI code, and does not depend on the details of the USB transport layer.
The code has been tested and registers as a MIDI device both under OSX and Android, and seems to be working.
A git repository can be found at https://github.com/mlu/maple-ide
The MIDI USB is built from the following files:
- usb_midi.cpp
- include/wirish/usb_midi.h
- stm32f1/usb_midi_device.c
- include/libmaple/usb_midi_device.h
The development is done on a modified Maple-IDE that uses a current arm toolchain and a libmaple layout that is closer to the present libmaple layout so the files are placed in different locations than the standard Maple-IDE file layout.
UPDATE 2013/0412
The descriptor definitions have been factored out of usb_midi_device and placed into usb_midi_descr.c/h . A working copy of the libmaple git repository with the midi usb files placed in their proper place in the hierarchy can be found at https://github.com/mlu/libmaple .
Friday, July 31, 2009
MIDI7S - a flexible USB - MIDI interface
MIDI7S - a flexible USB - MIDI interface
This page is work in progress and will be updated with more precise documentation when that is available.
Update june 2013
All the images had vanished from the blog, thanks blogger, but now I have restored them. My work with midi has mostly moved on to use Maple boards and STM4FDiscovery board. The Teensy 3 board have midi implemented as standard and uses Arduino IDE for coding and programming making things much simpler.
System Components
Processor board
The AT91SAM7S64 processor has 3 uarts that can be used as MIDI ports and a USB interface. The Olimex SAM7-P64 board also has header for most uP pins, power supply and mmc card connector. This makes it a cheap and powerful platform for a USB MIDI system.
This processor is a bit old, but it is still a nice processor and I had this board and did not use for anything else. Today I would probably use something like a Olimex STM32-P103 board or design my own board for a STM32F103 processor.
MIDI interface board
MIDI out is driven directly from the microprocessor uart tx pin. Only one 220Ohm resistor is used , there should be two according to reference implementations. When driving MIDI from a 3.3 V source 2x70 Ohm is probably the best, for a typical VF in the optocoupler of 1.5V and series resistance of 220 Ohms in the receiver this gives I=(3.3-1.5)/360 = 5mA. The short curcuit current, 47 mA is a little bit high but not exceptional. The MIDI receivers uses 6N137 optoisolatorsMIDI 1 IN / OUT
MIDI 2 IN / OUT
Schematic (one channel):
Board layout (one channel)
The actual construction was built on a strip-board
DOG-ME Display board
This a 2x20 character LCD display using serial communicationsCommunication Interfaces
USBMIDI
The USBMIDI configuration uses two logical USB MIDI Cables connected to the physical MIDI ports/* MIDI IN JACK 1 receives data from the USB interface Ep 1 */
/* MIDI IN JACK 2 receives data from the serial uartmidi[0] */
/* MIDI OUT JACK 3 transmits data to the USB interface Ep 82 */
/* MIDI OUT JACK 4 transmits data to the serial uartmidi[0] */
/* MIDI OUT JACK 8 transmits data to the serial uartmidi[1] */
The sending of USB MIDI data through MIDI OUT JACK 3 using USB IN endpoint Ep82 needs work for buffering and handling of many small write requests
Serial MIDI
The serial MIDI interfaces are connected to USART0 and DEBUGUSART. USART1 is connected to a RS232 level shifter an can be used for "standard" serial communications.Dog-ME Display interface (SPI 3.3V)
PA13 MOSIPA14 SPCK
PA30 IRQ1/NPCS2 DOG_LCD_SELECT_PIN
PA31 NPCS1/PCK2 DOG_LCD_RS_PIN
Code
The code is written in C++ using a minimal profile for small embedded systems, no dynamic object creation, no exceptions.USB MIDI device descriptor
http://www.usb.org/developers/devclass_docs/midi10.pdfUSB MIDI device descriptors as C code, corresponding header file
Transmission buffers
All uart communications uses buffered DMA transactionsspi to the display should also use DMA but with a DLYBCT of 50 giving a character spacing of approximatly 33us, the serial:: transmission logic can be reused (subclassed) here.
The AT91SAM7 variable chipselects and chipselect decode mode together with 32 bit DMA SPI transmissions allows us to control both data bits and the RS line with automatic transfers to the Dog-Me display.
Testing
The system has been used as an USB to MIDI inteface betwen a Linux computer and a U220 synth module. The usb midi ports are autodetected and added as Alsa MIDI ports. Some USB communication gliches has been observed, but not frequent and not yet reproducible. Loopback tests with a standard MIDI cable connected from MIDI out to MIDI in works well.Round trip times on PC running Linux, Fedora 10, PC(Alsa MIDI)->USB MIDI IN->MIDI OUT->MIDI IN->USB MIDI OUT->PC are 1.5 - 3 ms (/home/lundin/delad/arbete/mikrop/usbmidi/miditest.c) with processing times up to 130uS using single message pings (090531 r357)
Direct echo within the module , no serial MIDI, gives times of .8 to 2 ms
Future
With the basic USB and MIDI communications working, it is possible to expand the capabilities of the system.
The analog and digital inputs can be used to generate MIDI events from different sensors and there is spare processor capacity for MIDI processing.
TWI EEPROM For settings
Control panel
I/O Extender
MIDI file player
Sensor to midi event generation
Labels:
ARM,
at91sam7s,
MIDI interface,
midi usb,
USB
Location:
Southern Europe
Friday, August 8, 2008
Using Python and XML for parsing USB descriptor structures to C
This project consists of a Python script that parses an XML description of USB descriptors and generates C code structures that can be included in a C firmware program for a USB device. This tool is primarily intended for developers of USB devices on embedded platforms. The XML representation of the descriptors gives a good view of the structure and the Python parser generates correct bDescriptorType values, bLength values and calculates total lengths. For elements with a variable number of child elements, such as bNumEndpoints in the Interface descriptor, the correct value is inferred from the XML structure. Most elements have a default value that is inserted in the generated C data structure. Symbolic values can be used for field values through XML entities defined in a DTD.
Related work
This project is part of a set of tools written in Python to simplify work with embedded development and USB. Most of the development work is done under Linux. Other components in this effort are:- usbmodule: A Python module that wraps libusb and gives raw access to USB devices, with experimental thread code to download and buffer incoming data before the application requests it, this works (for me) but it is unstructured, uncleaned and probable a bit buggy. This is similar to PyUSB http://pyusb.berlios.de/ , I have not had time to really check out this project, perhaps we should merge ....
- A python GUI application for firmware downloads to embedded systems, first written to program Parallax Javelin systems from Linux, then extended to talk to serial monitors on LPC2xxx and AT91SAM7 arm processors. Today it is mostly used for SPI flashing of Atmel AVR8 processors using an FT232 interface in bitbang mode (this is where the USB from Python is used)
Example
An example XML representation of a device dsecriptor<USB_Device_Descriptor name="devDescriptor" bcdUSB="0110" bDeviceClass="0" bDeviceSubclass="0" bDeviceProtocol="0" idVendor="EB03" idProduct="2463" bcdDevice="0000" iManufacturer="1" iProduct="2" iSerialNumber="3" bNumConfigs="1"/>and the output in C code format that is generated
const char devDescriptor [] = {
// Device Descriptor
/* 0 */ 0x12, //bLength
/* 1 */ 0x1, //bDescriptorType
/* 2 */ 0x10, //bcdUSB
/* 2 */ 0x1,
/* 4 */ 0x0, //bDeviceClass
/* 5 */ 0x0, //bDeviceSubclass
/* 6 */ 0x0, //bDeviceProtocol
/* 7 */ 0x8, //bMaxPacketSize0
/* 8 */ 0x3, //idVendor
/* 8 */ 0xeb,
/* 10 */ 0x63, //idProduct
/* 10 */ 0x24,
/* 12 */ 0x0, //bcdDevice
/* 12 */ 0x0,
/* 14 */ 0x1, //iManufacturer
/* 15 */ 0x2, //iProduct
/* 16 */ 0x3, //iSerialNumber
/* 17 */ 0x1 //bNumConfigs
};
Status
Currently the tool can generate what looks as correct C code structures, with examples from USB specification. The output has not been tested and used as descriptor structures in actual USB firmware. The Python code can be run as a simple command line tool. There is a lack of documentation for the XML tags and attributes used. Future work devoted to this will depend on the testing and also interest from third parties-Future work
Use the output from this tool as descriptors for a MIDI interface implemented on an AT91SAM7S development board. Use the output from this tool as descriptors for a HID device implemented on an AT91SAM7S development board connected to . This document/page will also be updated and made more complete depending on external feedback.Contact
Magnus Lundin If you are interested in this project contact me at: lundin at mlu dot mine dot nu
Subscribe to:
Posts (Atom)