Assignment 22 - MIDI out to STM32 Device
USB Setup Forum That Helped a Bit
- Experiment Design: Take in a USB input data, say MIDI data, from an external source (PC/Laptop/MIDI Device) and output
The device (STM) to be a USB Host, but what is a USB host?
Main Points on USB Hosting
There are multiple USB host types. Since we are doing a USB-type B from our device, and USB-type A to our STM, we want our STM to be an OTG A-host
.
Some behaviors to note are that:
- The STM has a
OTG_HPRT
status register for host port control, that - ... (really a lot of the behaviors are "as you need them" so follow the
OTG_FS
programming model for whatever you need, and look up stuff as you go).
Initialization
When connecting:
- If an "A" plug is connected, then the device enters host mode, if "B" then enters device mode.
- You must follow the following to initialize the device in this way
OTG_GAHBCFG
:- Global interrupt mask bit
OTG_GINTMSK = 1
- Empty the FIFO Rx bit via
RXFLVL
within theOTG_GINTSTS
register. - Program the same Tx bit
TXFLVL
in the same register.
- Global interrupt mask bit
OTG_GUSBCFG
:- Enable some of
HNP, SRP
OTG_FS
timeout calibration field- USB turnaround time field (in
OTG_GUSBCFG
)
- Enable some of
- Unmask
OTG_GINMSK
and either choose to mask or not theOTG
interrupt and mode mismatch interrupt masks - Read from the
CMOD
bit inOTG_GINSTS
to confirm that we are in the host mode (or device mode if you want that)
Host Initialization
You must:
- Program
HPRTINT
in theOTG_GINTMSK
register to unmask - Set
OTG_HCFG
register to select full-speed host - Set
OTG_HPRT
to 1, to driveV_BUS
on the USB (we want to power it from here). - (continue from pg. 1782)
Channel Initialization
You'll need to setup a USB channel in order to read and write data over. See pg. 1783 for that.
Receiving Data Packets
See pg. 1784 and 1785 for read and write access to FIFOs per channel. The programming flowchart is essentially what code you want to have to setup your USB read/write functions.
Setting up GPIO
By ![[datasheet_stm32l476rg.pdf#page=99]]
use the PA10-13
pins for connecting the USB-A side pins to, rather than the onboard usb (that's the debug USB). Via ![[datasheet_stm32l476rg.pdf#page=99]]
,