100% found this document useful (1 vote)
183 views

Stm32 & Usb: Roman Ludin

The document discusses the Universal Serial Bus (USB) standard. It provides an overview of USB including its history and specifications for speed, power delivery, topology, and connectors. It also discusses USB device classes and profiles. Finally, it describes how USB is implemented on STM32 microcontrollers, including USB controllers, clock recovery, and middleware support.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
183 views

Stm32 & Usb: Roman Ludin

The document discusses the Universal Serial Bus (USB) standard. It provides an overview of USB including its history and specifications for speed, power delivery, topology, and connectors. It also discusses USB device classes and profiles. Finally, it describes how USB is implemented on STM32 microcontrollers, including USB controllers, clock recovery, and middleware support.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

STM32 & USB

Roman Ludin

September 2014
Ver. 1.0
the Universal Serial Bus 3

• The USB - Universal Serial Bus is an industry


standard developed in the mid-1990s that
defines
• Bus architecture
• Cables, Connectors, Electrical levels
• Communications protocols

• USB was designed to standardize the connection of computer


peripherals
• keyboards, pointing devices, digital cameras, printers, portable media players, disk
drives and network adapters

• It has become common interface on other devices, such as


smartphones, PDAs and video game consoles.

• USB has effectively replaced a variety of earlier interfaces, such as


serial and parallel ports.
the Universal Serial Bus 4

Hot pluggable YES


Protocol Serial, pooled, host centric
Bitrate 1.5/ 12/ 480/ 5,000/ 10,000
Mbit/s
Max Length 5m
Max Voltage 5V
Max Current 0.5A general
5A charging device
Max Devices 127
Pins 4
1 supply, 2 data, 1 ground
Topology Tired star
USB History 5

• The original USB 1.0 specification was introduced in January 1996


• Defined data transfer rates of 1.5 Mbit/s“ Low Speed" and 12 Mbit/s "Full Speed“
The first widely used version of USB was 1.1, was released in September 1998.

• The USB 2.0 specification was released in April 2000


• Develop a higher data transfer rate achieving 480 Mbit/s
• a 40-times increase over the original USB 1.1 specification

• The USB 3.0 specification was published on 12 November 2008.


• Increase the data transfer rate (up to 5 Gbit/s)
• decrease power consumption, increase power output
• backwards-compatible with USB 2.0. USB 3.0 includes a new, higher speed bus
called SuperSpeed in parallel with the USB 2.0 bus.

• The USB 3.1 specification was released on 31 July 2013


• Introducing a faster transfer mode called "SuperSpeed USB 10 Gbps"
www.usb.org 6

• USB Implementers Forum, Inc.


• is a non-profit corporation that developed the USB specification
• The Forum facilitates the development of high-quality
compatible USB peripherals (devices), and the quality of products
that have passed compliance testing. Some of the many
activities that the USB-IF supports include:
 USB Compliance Workshops and compliance test and tool
development
 USB Developer Conferences
 Assignment of a vendor ID
 www.usb.org Web site
 and many more...
Bus Topology 7

• The USB physical interconnect is a tiered star topology.


• The USB connects USB devices with the USB host.
• A hub is at the center of each star. Each wire segment is a
point-to-point connection.
• The maximum of 127 devices can be connected in the bus
• The maximum of 5 hubs can be connected in series
• The maximum number of tiers allowed is seven
• The maximum cable length is 5meter
Electrical 8

• 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-).

• Non-Return-to-Zero Inverted (NRZI) encoding scheme is used for


transferring data.
Mechanical 9

• 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

• “keyed connector” are used to


minimize end user termination problems
upstream towards downstream
the "host" system towards the
USB Device
USB over STM32 Family 10

MCU Core USB controller


STM32L0x2 Cortex-M0+ 1x Crystal less USB 2.0 FS device with Link Power
STM32L0x3 Managament (LPM) and Battery Charger detection (BCD)
STM32F0x2 Cortex-M0 1x Crystal less USB 2.0 FS device controller with Link Power
STM32F0x8 Managment (LPM) and Battery Charger detection (BCD)
STM32L1 Cortex-M3 1x USB 2.0 FS device with internal 48 MHz PLL

STM32F102/103 Cortex-M3 1x USB 2.0 FS device controller

STM32F105/107 Cortex-M3 1x USB 2.0 FS device/host/OTG controller with on-chip PHY


with 1.25 Kbytes of dedicated SRAM
STM32F2 Cortex-M3 1x USB 2.0 FS device/host/OTG controller with on-chip PHY
1x USB 2.0 FS/HS device/host/OTG controller with dedicated
DMA, on-chip full-speed PHY and ULP
STM32F3 Cortex-M4 1x USB 2.0 FS device controller and LPM

STM32F4 Cortex-M4 1x USB 2.0 FS device/host/OTG controller with on-chip PHY


1x USB 2.0 FS/HS device/host/OTG controller with dedicated
DMA, on-chip full-speed PHY and ULPI
STM32 on USB-IF integrators list 11

http://www.usb.org
USB VID/PID sublicensing service 12

Process & Schedule for PID request

• 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}

• PID Booked in an internal ST Database

• By end of each quarter


• ST send the approval list to the USB-IF
• Approval by USB-IF
• PID send to the customer with a “letter form Agreement”
USB peripheral (F0/L0) 13

• Crystal-less* USB 2.0 FS interface (12Mbit/s)


• Integrated on-chip 48 MHz oscillator with clock recovery system. No external resonator/ crystal
needed (cost saving is in range of 0.10$).
• Up to 16 mono-directional or 8 bidirectional configurable endpoints
• Up to 1024 Bytes of dedicated packet buffer memory SRAM

• Complies with Link Power Management feature (LPM) and Battery


Charging Detection (BCD) specification 1.2

• Device Firmware Upgrade on the field over USB (boot loader)

• 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).

• Free PID/VID program for end-product certification


(USB) Clock recovery principle 14

• 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.

• SOF timing reference allows to automatically trim the int 48 MHz RC


frequency based on the actual frequency error measured by a counter.

• HSI48 oscillator trimming step is 0.14% typical (0.2% max) to


guarantee with a good margin the 0.25% accuracy needed for USB.

• Other synchronization sources (LSE, ext pin or SW trigger) works too.

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)

• Typical use-case is to speed-up battery charging of portable devices


connected to the USB port.
USB Link Power Management (LPM) 18

• 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

HUB Defines what protocols to implement to build a hub application

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

Printer Defines what protocols to implement to build a printer application

Audio Defines what protocols to implement to build an audio application (microphone, headset, etc.)

DFU Device firmware upgrade: Protocols to implement firmware upgrade ability


STM32 – USB solutions (1/2) 20

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

1/ Available on customer request. Please contact supplier


STM32 – USB solutions (2/2) 21

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

1/ Available on customer request. Please contact supplier


2/ Available to Continua members only. Refer to your local ST sales office.
3/ Can be ported
STM32 – USB solutions details (1/2) 22

Provider Solution name Details


Device: HID, MS, CDC (ACM, ECM, RNDIS), Audio, Midi, MTP, PHDC
CMX CMX-USB Device, Host Host: HID, MS, CDC (ACM, ECM, RNDIS, OBEX), Audio, Midi, Printer, HUB

Device: HID, MS, CDC (ACM, ECM)


EUROS USB Host & Device Stack Host: HID, MS, CDC (ACM, ECM), HUB

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), Audio


Keil/ARM MDK-ARM USB Host: HID, MS

Device: HID, MS, CDC (ACM, ECM)


Mentor Embedded Nucleus USB Host: HID, MS, CDC (ACM, ECM), HUB

Device: HID, MS, CDC (ACM), Audio, PHDC (Medical)


Micrium µC/USB Host: HID, MS, CDC (ACM), Audio, Printer, PHDC (Medical)

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

Device: MS, CDC (ACM, ECM, RNDIS)


Quadros RTXCusb Host: HID, MS, CDC (ACM), HUB

Device: MS, CDC (ACM)


Rowebots Unison USB System Host: MS, CDC (ACM), HUB, others on demand (inc . PHDC)

Device: HID, MS, CDC (ACM), Printer


SEGGER emUSB Host: HID, MS, CDC (ACM), Printer
STM32 – USB solutions details (2/2) 23

Provider Solution name Details


Device: HID, MS, CDC (ACM), Audio, DFU,
ST STM32Cube Host: CDC, HID (RTOS), MSC (RTOS), Audio, DFU, MTP

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

• Get configuration code generated* from a tool with STM32Cube and


focus on your added-value software !
• 4 configuration wizards: pinout, clock, peripherals & middleware, power consumption
• Portable Hardware Abstraction layer, from one serie to another
• Middleware with RTOS, USB, TCP/IP, File System, Graphics

STM32CubeMX
Configuration tool on PC

User code

STM32Cube
Embedded software

Initialization C code Middleware


RTOS, USB, TCP/IP, Graphics...
generation
depending on user choices Hardware abstraction layer

Note: * configuration for all STM32. Code generation for all expect F1, L1
STM32Cube & USB – Let’s try it out!!! 25

• HID (Human Interface Device) with STM32L053 in 10minutes

STM32CubeMX

User code

STM32Cube
Middleware
USB – HID
HAL
STM32Cube & USB – Let’s try it out!!! 26

• Conditions

• Installed latest version of STM32CubeMX

• Installed latest version of STM32L0 Cube package

• Installed IAR EWARM 7.20 and higher

• STM32L0 Discovery kit

• USB mini B cable


STM32Cube & USB – Let’s try it out!!! 27

• Check the time 

• Launch STM32CubeMx tool

• Start New Project

• Select device STM32L053C8T6

• Enable USB Device (FS)


STM32Cube & USB – Let’s try it out!!! 28

• Include MiddleWare USB_DEVICE -> HID class

• Clock configuration
STM32Cube & USB – Let’s try it out!!! 29

• Menu: Project -> Settings …


• Give your project a name
• Select EWARM 7.xx as IDE

• Menu: Project -> Generate Code -> Click Open Project


STM32Cube & USB – Let’s try it out!!! 30

• In IAR EWARM, Menu: Project -> Options -> ST-LINK (select SWD)

• Compile the code: F7 or Menu: Project -> Make

• Connect the STM32L0 Discovery ST-LINK to PC over USB mini B cable

• 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

• Change the USB mini B cable connection on the STM32L0 Discovery


kit from ST-LINK to USB USER connector

• On PC: Device Manager -> Human Interface Device


STM32Cube & USB – Let’s try it out!!! 32

• As bonus you can change the Bus reported device description text to
any other one, e.g. ST is BEST

• It’s easy just go back to STM32CubeMX and find the way 

• Another option is directly in the code, Do you know where?


STM32 & USB out-of-box solutions 34

STM32Cube FW STM32F0 STM32F2 STM32F3 STM32F4 STM32L0


package (v1.0.0) (v1.1.0) (v1.0.0) (v1.3.0) (v1.0.0)

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

Custom HID Standalone X X X X X


USB Device

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

You might also like