cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with STM32F4 USB bulk transfer (MIDI)

ron239955_stm1
Associate III
Posted on December 07, 2012 at 18:47

Hi all,

I'm working on an application for the STM32F4 where I need a USB MIDI device class. I've started with the STM USB library and, looking at the CDC and Audio class examples, have come up with a MIDI device that runs on the OTG FS core. It successfully goes through enumeration and is recognized by the connected computer as a MIDI device.

The problem comes in when I try to send data (an IN transaction). I have traced this through all the way to the USB_OTG_WritePacket routine, where it writes data to the endpoint's transmit FIFO. I am writing a valid MIDI packet to the FIFO (0x0b 0xb0 0x3f 0x7f), but the moment the FIFO is written, the output on the bus (monitored with a USB analyzer) is something completely different (0x4a 0x4a). I've checked how the registers to make sure it has the correct transmit size, FIFO number, etc. but can't for the life of me figure out how the outgoing data is so different than what's being placed in the FIFO. 

Does anyone have any experience with this? Any tips on what to look at would be most appreciated.

 

#stm32f4-usb-midi
11 REPLIES 11
ron239955_stm1
Associate III
Posted on December 09, 2012 at 21:32

Found it! It turns out that my FIFO configuration was incorrect. The FIFO size definitions in usb_conf.h were too large, pushing EP2's TX FIFO outside the valid range of addresses. It would be a good idea to add some preprocessor error checking of these values in the USB library.

When setting FIFO sizes, remember that sizes are in words, not bytes, and you have only 320 words of FIFO. The RX FIFO and TX FIFO sizes for each active endpoint need to add up to 320 or less.

M0NKA
Senior
Posted on June 27, 2013 at 20:02

Thank you! Saved me few days of hairs pulling

BR
benjamin
Associate II
Posted on July 15, 2013 at 11:12

Hello,

I am a bachelor student who is trying to use the STM32F4-Discovery as a midi console controler as a fun project :-). I was wondering how you were able to make the usb-midi interface code. I have found no usefull sites for this, most people use the  midi box from st which has almost everything you need for this kind of application, but I wanted to learn hoz to use this board for another project i want to do (yes I am a geek :p). If you have some tips on how to do it or where to find it, I would be very gratefull.

Thank you in advance,

tsuneo
Senior
Posted on July 17, 2013 at 00:18

Hi benjamin,

USB-MIDI is a good start point to learn class implementation on a USB device stack, because its USB protocol is simple. Also, many host applications/utilities are available, without writing any test code on PC. If you would like to make one, I'll help you.

A. Overview of USB-MIDI spec

Here is the USB-MIDI spec,

USB MIDI Device spec 1.0

http://www.usb.org/developers/devclass_docs/midi10.pdf

In general, USB class implementation consists of these three steps,

1) Descriptors

Like usual audio device, MIDI device has two interfaces,

- Audio control interface (AC)

- Audio streaming interface (AS)

On the AC interface, input/output MIDI jacks are declared.

You may define 16-IN/16-OUT MIDI jacks

In this post, we discussed implementation of multiple IN/OUT jacks.

http://www.microchip.com/forums/fb.ashx?m=493422

AS interface declares bulk endpoint(s) to exchange USB-MIDI packets.

In this section of the USB-MIDI spec, you'll find typical descriptors.

Appendix B. Example: Simple MIDI Adapter (p37, midi10.pdf)

2) Class-specific requests

As Windows don't support control of MIDI elements over USB protocol, implementation of class-specific requests is not required.

3) Protocol over endpoint(s)

MIDI device exchanges USB-MIDI packets over bulk endpoints

- Bulk IN endpoint sends USB-MIDI packets to host

- Bulk OUT endpoint receives USB-MIDI packets from host

MIDI device may have either one or both endpoints, by its purpose.

USB-MIDI packet consists of 4 bytes, one byte prefix + usual 3 bytes MIDI packet.

The prefix byte contains channel (jack) number, so that single bulk endpoint can exchange MIDI packets of multiple jacks.

Single (64 bytes) USB bulk packet can hold 16 USB-MIDI packets.

The details of USB-MIDI packet is described in this section of MIDI spec,

4 USB-MIDI Event Packets (p16, midi10.pdf)

B. Implementation on ST's stack

As the starting example, any device example will do. We pick up VCP (CDC) one.

STM32_USB-Host-Device_Lib_V2.1.0 (STSW-STM32046)

http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257882

Copy this file to your project,

STM32_USB-Host-Device_Lib_V2.1.0\Libraries\STM32_USB_Device_Library\Class\cdc\src\usbd_cdc_core.c

To be continued..

Tsuneo

pradeepa
Associate II
Posted on September 07, 2013 at 08:28

Hello,

I've been working with the  Discovery board for a few weeks now. I have implemented the bulk transfers successfully. But recently, accidentally I ran into a small issue. 

It's that if I call 'dcd_ep_tx' multiple times without sending an IN token from the host, I can store up to 320 bytes. But my TxFIFO size is set to 128. I can't understand how the device store 320 bytes without considering the FIFO size. If you have any idea please shed some light.

Thank you.

jean_prieur
Associate III
Posted on October 16, 2013 at 18:03

Hello,

I'm also trying to configure the MIDI USB class implementation on STM32F4.

I experienced some problems with this driver...

derouineau.benjamin are you still on it ?

Thanks !

Jean

gory-mail
Associate II
Posted on November 28, 2014 at 15:04

I'm experiencing the same problem with the Write_Packet and with the new STM32Cube F4 library. I haven't checked the FIFO sizes yet. I'm using an audio isochronous out endpoint besides my MIDI in and MIDI out endpoints.

I'm calling the USB_LL_Transmit, but it stucks in an interrupt somewhere. I cannot even generate an external push button interrupt after I invoked the low level transfer function.

tsuneo
Senior
Posted on November 29, 2014 at 20:29

Sound like you are mixing up STM32F2/4 FIFO with double buffers of STM32F103 or other USB SIE.

> It's that if I call 'dcd_ep_tx' multiple times without sending an IN token from the host

 

> I'm experiencing the same problem with the Write_Packet

 

You can't use dcd_ep_tx / Write_Packet in this way.

These routines put the ''transfer'' data to the FIFO, and register a ''transfer'' to the endpoint.

STM32F2/4 endpoint can't hold multiple ''transfers'' at a time. Just single one.

Usual ''double buffers'' may hold up to two transactions.

Tsuneo

gory-mail
Associate II
Posted on December 05, 2014 at 14:34

I solved my problem. I only forgot to set the TX FIFO for the specific endpoint. My fault.

----

http://turntablecontrol.wordpress.com/