Stm32 & Usb: Roman Ludin
Stm32 & Usb: Roman Ludin
Roman Ludin
September 2014
Ver. 1.0
the Universal Serial Bus 3
• USB is a serial bus, using four shielded wires for the USB 2.0 variant:
• two for power (VBUS and GND),
• two for differential data signals (D+ and D-).
• USB specification provides the mechanical Standard, Mini, and Micro USB plugs.
and electrical specifications for the cables,
connectors
• The USB physical topology consists of
connecting the downstream hub port to
the upstream port of another hub or to a
device
http://www.usb.org
USB VID/PID sublicensing service 12
• Request details:
1) COMPANY NAME AUTHORZING USE TO :
2) Contact Name /Address and E-mail address:
3) Name/Sales type of the STMicrocontroller product name :
4) Name of USB end-product : { if possible USB device string Product}
• USB FS Device Library with intuitive USB device class drivers API
• Examples and demo based on a set of 6 classes (Audio, CCID, CDC, HID, VCP, MSC).
• Easy development of applications using USB full speed transfer types (control, interrupt, bulk and
isochronous).
• Provide the precise USB clock (48Mhz @ 0.25%) without any external
resonator. It uses the USB Start-of-Frame (SOF) sent by a host at
precise 1ms intervals (0.05% accurate), as a timing reference.
Note : to calcul the precision of the output, +/-0.1% of error must be added on top of the
reference signal precision. Ex : to reach 0.5% output, you need to have at worst 0.4%
reference input.
USB Battery Charging Detection 17
(USB BCD)
• Battery Charging Specification introduces new port definitions
• Standard downstream port (SDP) same port as defined by the USB 2.0 spec.
• Charging downstream port (CDP) normal port with extended current capability
• Dedicated charging port (DCP) car / wall charger, not able to enumerate
• STM32F0x2 identifies the nature of the USB host (SDP, CDP, DCP)
and its power source capability (…100mA, 500mA, 1.5A etc)
• LPM is a new power-saving state called “Sleep”, with fast entry and exit times,
compared to traditional “Suspend” mode.
• Benefits : Power consumption optimization across both the host and USB devices
while idle, and extend battery life of hand-held applications.
Entry : ~ 3ms
Exist : > 20 ms (Resume signaling)
+ 10 ms (Resume recovery)
The existing suspend/resume mechanisms have been proven to be inadequate for current and future generation mobile platforms.
The bus-imposed resume latencies are so long that the mechanism doesn’t support response times that are useful in many
applications, especially in hand-held platforms
Middleware – USB 19
Universal Serial Bus requires a dedicated software stack. This serial bus
is organized in a star topology with host and device roles, host
organizing the traffic. Several device classes are specified, in order to
ease communication in different application cases.
• ST provides a complete offer for STM32
Often seen acronyms
OTG On-The-Go: An OTG peripheral can switch host and device role on the fly
MS Mass storage: Protocols to interact with storage block devices (for files)
HID Human interface device: Protocols for peripherals interacting with human body (mouse, keyboard, etc.)
Communication device class: Protocols for serial communications, different sub-classes define details, for instance ACM for a
CDC standard COM port, or ECM for modems
Audio Defines what protocols to implement to build an audio application (microphone, headset, etc.)
Availability
Provider Solution name Model Cost
F1 F2 F3 F4 L1
CMX CMX-USB Device, Host Source License Y Y Y Y Y
EUROS USB Host & Device Binaries License Y Y Y Y Y
Express Logic USBX Source License Y Y Y Y Y
HCC HCC-USB Source License Y Y Y Y Y
Jungo USBware Source License + royalties On demand
Keil/ARM MDK-ARM USB Source License Y Y Y Y Y
Mentor Embedded Nucleus USB Source License Y Y Y Y Y
Micrium µC/USB Source License Y Y Y Y Y
Micro Digital smxUSB Source License Y Y Y Y Y
Quadros RTXCusb Source License Y Y Y Y N1
Rowebots Unison USB System Source License Y Y Y Y Y
SEGGER emUSB Source License Y Y Y Y Y
Availability
Provider Solution name Model Cost
F0 F1 F2 F3 F4 L0 L1
ST STM32Cube Source Free Y N Y Y Y Y N
Continua USB certified
ST Source Free N3 N3 N3 N3 N3 Y2
stack2
Thesycon Embedded USB Device Source License N1 Y N1 Y N1 N1
Device: HID, MS, CDC (ACM, ECM, RNDIS), Still Image, PTP, PictBridge
Express Logic USBX Host: HID, MS, CDC (ACM, ECM), Audio, Printer, HUB, Prolific
Device: HID, MS, CDC (ACM, ECM, RNDIS), Printer, Audio, Midi, MTP, Still Image
HCC HCC-USB Host: HID, MS, CDC (ACM, ECM, RNDIS), Audio, Midi, Printer, HUB
Device: HID, MS, CDC (ACM, ECM, RNDIS, WMC, OBEX), Audio, Video, SICD, PTP, MTP, PictBridge,
Jungo USBWare CCID, DFU
Host: HID, MS, CDC (ACM, ECM, EEM, NCM), Audio, Video, PTP, MTP, ICCD, iPod, HUB
Device: HID, MS, CDC (ACM, RNDIS, Single Interface and mult. ports), Audio, Video, Midi, PTP, MTP, DFU
Micro Digital smxUSB Host: HID, MS, CDC (ACM), Audio, Printer, HUB
USB PHDC Class (Personal Health Device Class), 11073-20601 = Base Framework.
ST Continua USB certified stack Agents: 1073-10417 = Glucose, 11073-10408 = Thermometer
Other Agents can be implemented on demand
Thesycon Embedded USB Device Device: HID, MS, CDC (ACM, ECM, NCM)
Software Development – STM32Cube 24
STM32CubeMX
Configuration tool on PC
User code
STM32Cube
Embedded software
Note: * configuration for all STM32. Code generation for all expect F1, L1
STM32Cube & USB – Let’s try it out!!! 25
STM32CubeMX
User code
STM32Cube
Middleware
USB – HID
HAL
STM32Cube & USB – Let’s try it out!!! 26
• Conditions
• Clock configuration
STM32Cube & USB – Let’s try it out!!! 29
• In IAR EWARM, Menu: Project -> Options -> ST-LINK (select SWD)
• Download the code: Ctrl+D or Menu: Project -> Download and Debug
STM32Cube & USB – Let’s try it out!!! 31
• After successful download of the code in IAR EWARM, close the debug
session by: Ctrl+Shift+D or Menu: Debug -> Stop Debugging
• As bonus you can change the Bus reported device description text to
any other one, e.g. ST is BEST
STM32072B_EVAL
STM32303C_EVAL
STM32373C_EVAL
STM324x9I_EVAL
STM322xG_EVAL
STM324xG_EVAL
STM32F302R8-
STM32L053C8-
STM32L053R8-
STM32F072B-
Discovery
Discovery
Discovery
STM32F3-
Nucleo
Nucleo
STM32 HW
development
boards
CDC Standalone X X X X X X
HID Standalone X X X X X X X X X X X
DFU Standalone X X X X X X X X X X X
MSC Standalone X X X X X
Audio Standalone X X X
DualCore Standalone X X
STM32 & USB out-of-box solutions 35
STM32F2 STM32F4
STM32Cube FW package
(v1.1.0) (v1.3.0)
STM324x9I_EVAL
STM322xG_EVAL
STM324xG_EVAL
STM32F429I-
STM32F401-
Discovery
Discovery
Discovery
STM32F4-
STM32 HW
development
boards
CDC Standalone X X X
Dynamic Switch Standalone X X
HID Standalone X X X
HID RTOS X X
MSC Standalone X X
MSC RTOS X X
USB Host
Audio Standalone X X
DualCore Standalone X X
FWupgrade Standalone X X X X
MTP Standalone X X X
Audio playback and record with USB disk X X X
Camera to USB disk X X X
FatFS with USB disk X X X X X X
FatFS with USB disk & RTOS X X X
FatFS with USB disk & RTOS multi access X X
LTDC Animated picture from USB disk X
Other STM32 USB related materials 36
http://www.youtube.com/watch?v=Kx7yWVi8kbU
Thank you 38