Serial Ports are so 1990! | Cypress Semiconductor
Serial Ports are so 1990!
Summary: 0 Replies, Latest post by Gautam Das on 10 Nov 2011 02:51 AM PST
Verified Answers: 0
10 Nov 2011 02:51 AM PST#1
Let’s face it, serial ports on designs are fading away which is causing many embedded developers headaches when they want to add a reliable method to transfer data from the PSoC to the PC. Many people shy away from USB because it appears intimidating. In reality, once some basics of USB are understood, it really isn’t that difficult to understand and use.
In a nutshell, a USB system consists of a host, which is typically a personal computer (PC) and multiple peripheral devices connected through a tiered-star topology. This topology may also include hubs that allow additional connection points to the USB system. The host itself contains two components, the host controller and the root hub. The host controller is a hardware chipset with a software driver layer that is responsible for the following tasks:
- Detect attachment and removal of USB devices
- Manage data flow between host and devices
- Provide and manage power to attached devices
- Monitor activity on the bus
At least one host controller is present in a host and it is possible to have more than one host controller. Each controller allows the connection of up to 127 devices with the use of external USB hubs. The root hub is an internal hub that connects to the host controller(s) and acts as the first interface layer to the USB in a system. Currently on your PC, there are multiple USB ports. These ports are part of the root hub in your PC. For simplicity, look at the root hub and host controller from the abstract view of a “black box” that we call the host.
USB devices consist of one or more device functions, such as a mouse, keyboard, or audio device for example. Each device is given an address by the host, which is used in the data communication between that device and the host. USB device communication is done though pipes. These pipes are a connection pathway from the host controller to an addressable buffer called an endpoint. An endpoint stores received data from the host and holds data that is waiting to transmit to the host. A USB device can have multiple endpoints and each endpoint has a pipe associated with it.
There are two types of pipes in a USB system, control pipes and data pipes. The USB specification defines four different data transfer types. Which pipe is used depends on the data transfer type.
- Control Transfers Used for sending commands to the device, make inquiries, and configure the device. This transfer uses the control pipe.
- Interrupt Transfers Used for sending small amounts of bursty data that requires a guaranteed minimum latency. This transfer uses a data pipe.
- Bulk Transfers Used for large data transfers that use all available USB bandwidth with no guarantee on transfer speed or latency. This transfer uses a data pipe.
- Isochronous Transfers Used for data that requires a guaranteed data delivery rate. Isochronous transfers are capable of this guaranteed delivery time due to their guaranteed latency, guaranteed bus bandwidth, and lack of error correction. Without the error correction, there is no halt in transmission while packets containing errors are resent. This transfer uses a data pipe.
Every device has a control pipe and it is through this pipe that control transfers to send and receive messages from the device are performed. Optionally, a device may have data pipes for transferring data through interrupt, bulk, or isochronous transfers. The control pipe is the only bidirectional pipe in the USB system. All the data pipes are unidirectional. Each endpoint is accessed with a device address (assigned by the host) and an endpoint number (assigned by the device). When information is sent to the device the device address and endpoint number are identified with a token packet. The host initiates this token packet before a data transaction.
When a USB device is first connected to a host, the USB enumeration process is initiated. Enumeration is the process of exchanging information between the device and the host that includes learning about the device. Additionally, enumeration includes assigning an address to the device, reading descriptors (which are data structures that provide information about the device), and assigning and loading a device driver. This entire process can occur in seconds. Once this process is complete, the device is ready to transfer data to the host. Two files are affiliated with enumeration and the loading of a driver. These files are the INF and SYS file, and they exist on the host side.
After a device has been enumerated, the host directs all traffic flow to the devices on the bus. When implementing USB in a PSoC, all you need to do is configure the USB Full Speed component as described in the component data sheet, and then use the Cypress provided API’s to load data into an IN endpoint and take data out of an OUT endpoint.
Since the host manages the traffic, it will handle everything else in conjunction with the dedicated USB hardware in the PSoC. Most of the intimidating factors regarding USB are on the host side, and in most USB applications users will not need to worry about the host side of things. That aspect is reserved for the most advanced of USB applications.
All the user needs to do is determine what data they want to transfer between the PSoC and the PC, and what type of transfer they want to initiate (Control/Interrupt/Bulk/Isochronous).
Once you get a USB project working, you will wonder why you ever used serial ports in the first place.
For more information about USB pertaining to the following topics, along with links to other Cypress PSoC USB application notes refer to AN57294- USB 101: An Introduction to Universal Serial Bus 2.0.
- USB History
- USB Architecture
- USB Physical Interface
- USB Speeds
- USB Power
- USB Endpoints
- USB Communication Protocol
- USB Descriptors
- USB Class Devices
- USB Enumeration and Configuration Process
- USB Compliance and Windows Logo Testing