Coming soon |
1. What is the Universal Serial Bus (USB)
The large diversity of ports (parallel, serial, midi, joystick, etc) with their specific requirements and the lack of plug-and-play feature were almost the main reasons that pushed the most known companies in the technology domain to seek for a substitution. These companies developed the USB standard and formed the USB Implementers Forum.
The USB provided the most successful serial interface having the following characteristics:
- simplicity and flexibility (plug-and-play)
- bi-directionality
- increasing speeds
- low cost
Since developed, the USB has been continuously ameliorated always keeping compatibility with the new technologies evolution and requirements.
The STM32 USB hardware and software are compliant with USB1.1 and USB2.0 specifications and all the following sections will speak about these standard devices.
1.1. USB 2.0 Standard overview
This section focuses on the USB2.0 standard and provides a general overview about the rich characteristics of this standard.
1.1.1. Speed
The USB2.0 supports three speeds:
- Low speed (LS): the data bandwidth varies from 10 to 100 Kb/s. This speed is mainly
dedicated to interactive devices (mouse, keyboard, etc) - Full speed (FS): the data bandwidth varies from 500 Kb/s to 10 Mb/s. This speed is mainly
dedicated to phone and audio devices (microphone, speaker, etc) - High speed (HS): the data bandwidth varies from 500 Kb/s to 10 Mb/s. This speed is mainly
dedicated to video and storage devices (printer, camera, etc)
At protocol level, the USB grants a very high compatibility, so users can not see big differences
between dealing with different speeds
1.1.2. USB interconnect components
The USB interconnect has three main components:
- Host or Root Hub: it is unique for every USB system. It is responsible of initiating
all transactions. - Function or Device: the final point in the interconnect ensuring the user's required
roles (keyboard, mouse, microphone, etc) - Hub: a bridge ensuring the communication between the host and many devices. It has
one upstream port to be connected directly (point to point connection through USB cable)
or indirectly (connection through another hub) to the host and many downstream ports to be
connected directly or indirectly to the USB Functions.
The previous components can be connected to each other through USB cables with a maximum length of 5 meters.
1.1.3. USB interconnect topology
The USB physical interconnect is characterized by a tired star topology. Each star has a hub at the center with one upstream
connection directly or indirectly with the host and one or more downstream connection(s) with function or other hub.
A maximum of 127 devices (functions or hubs) can be connected to one host (root hub) with a maximum of 5 hubs
connected in series.
1.1.4. Power
Generally, the host (root hub) provides power for functions direct connection. Some hubs may supply power for directly connected downstream functions. For the functions, there are two types:
- Bus powered functions: these devices rely totally on the bus power coming from the upstream hub.
- Self powered functions: these devices are capable of providing their own power independently from the bus.
1.1.5. System configuration
The USB system has an intelligent mechanism to detect the device attachment and detachment at any time.
- Device attachment: the host can detect at any time the detachment of a device by continuously
querying a bit for all the connected hub ports. Once a device is attached, the host enables
the port and gives the device a unique address then establish a communication with this newly
connected device to conclude if it is a function or a hub. - Device detachment: once a device is detached, the corresponding port will be disabled. If a
hub is detached, all the downstream devices' ports that were attached
to the removed hub will be disabled and the detached hub's upstream port will be disabled. - Bus enumeration: it is a set of hardware and software events allowing the host to continuously detect and address and recognize the newly connected device. It includes also the set of events ensuring the removal of a device.
1.1.6. USB Data transfers
USB communication is based on four main transfer types:
- Control transfer: mainly used for the configuration data of the newly attached device.
- Bulk transfer: used for large amounts of data transmission or reception.
- Interrupt transfer: used for limited data transmission with minimal latency.
- Isochronous transfer: used for data transfer with real-time requirements.
More detailed explanations of the USB characteristics and data flow will be explained with code examples in the following pages.
2. Getting started with STM32 and USB
This section provides answers that can be asked when starting the use of the STM32 MCU's USB.
2.1. What does the STM32 support?
All the STM32 families (not all products) include the USB IP. Depending on the hardware, each STM32 MCU including the USB can support:
- Device in FS speed only.
- Device and Host in FS speed.
- Device and Host in HS speed.
- Device and Host in HS speed.
Some STM32 MCUs include two USB peripherals and support both Device and Host in FS and HS speed. An overview of the USB hardware over the STM32 MCUs will be provided in the next pages.
2.2. How can I select one STM32 MCU for my USB application?
For every USB application, it is important to select the correct STM32 with required USB role (Host or Device) and speed (LS or FS or HS). But there are many STM32 MCUs having the same USB hardware implementation, how to choose?
Besides the USB features, the STM32 MCUs offer a large set of peripherals with large features portfolio. The diversity of peripherals and features guarantees the flexibility and ease of the required application's implementation. In fact, the convenient MCU selection is one of the most secrets of a successful USB application.
To select the convenient MCU, the following features must be taken into consideration depending on the application requirements:
- The MCU performance have a direct impact on data transfer and processing in the STM32 system.
- The memories (RAM and ROM) availability and sizes are very important for applications processing large amounts of data.
- the required peripherals availability and features must be checked when selecting the STM32 MCU because peripherals versions and combinations can largely differ from one MCU to another.
- The power consumption is a very important requirement for some applications
The STM32 compliant with USB section provides an overview of all the STM32 MCUs including USB, it also includes some of the most important features for USB applications requirements.
2.3. Where can I find more detailed information about the USB for the selected STM32 MCU?
For every STM32 MCU, there is a set of documents providing information about all the integrated peripherals and among others the USB. All the STM32 MCUs have a page providing a generic overview with a direct link to the MCU's datasheet.
In fact, all the STM32 MCU's USB peripheral information are integrated mainly in the datasheet (specially the electrical characterization) and the reference manual (includes all the MCU's peripherals information thus it provides a detailed information about the integrated USB peripheral(s)).
2.4. Is there any provided STM32 USB code examples?
Every STM32 Family has a package includes the MCU's drivers and peripherals examples called the STM32Cube Firmware package. This package includes the USB Device and Host (if supported by the MCU) drivers and code examples for all the supported speeds.
To access the USB code, the STM32Cube Firmware package must be installed. When opening the installed folder, the following steps must be followed:
- Open "Projects" sub-folder.
- Open the folder having the name of the convenient board including the selected MCU.
- Open "Applications" sub-folder
- Select the USB convenient sub-folder ("USB_Device" for device applications and USB_Host for host applications if supported by the MCU)
- Select the convenient application
- Select the convenient IDE (IAR, STM32CubeIDE, KEIL)
At this level, the application's code can be debugged and can be loaded into the STM32 t check the results as mentioned in the readme.txt file which is provided within the application sub-folder. A detailed explanation of all the STM32 USB code parts will be explained in the following pages.
Special STM32 USB trainings videos were published to help you to understand easier the USB concepts and the STM32 supported features
The following videos focuse on explaining the USB 2.0 main concepts.
Learn how to use USB Device and USB Host within STM32 based application ...
STM32 USB training - USB Introduction
STM32 USB training - USB transfers
STM32 USB training - USB descriptors
STM32 USB training - USB standard class overview
STM32 USB training - USB over STM32 family
STM32 USB training - STM32 USB hardware design
STM32 USB training - STM32 USB Device library
STM32 USB training - USB CDC device basic labs
STM32 USB training - USB VCP Zero Packet Length lab
STM32 USB training - USB CDC libusb device lab
STM32 USB training - USB MSC DFU host labs
STM32 USB training - USB HID host labs
STM32 USB training -USB driver signature
USB training - USB CDC throughput
STM32 USB training - USB DFU device labs
STM32 USB training - STM32 USB Host library
STM32 USB training - USB VCP host labs
STM32 USB training - USB MSC host labs
In the following pages, some parts of the videos will be explained in more details with some code examples extracted from the STM32Cube firmware.
4. STM32 compliant with USB
The place to put a table with all STM32 compliant with the feature
5. Specific tools
Links and explanations for the tech domain dedicated tools
6. STMicroelectronics Resources
The place for AN, UM... direct links
7. Examples
The area where FAE's, collab... can put examples (linked to Github)
[[Category:]]