You are on page 1of 38

USB

Universal Serial Bus

Kuliah #10
TCK210 Teknik Interface dan Peripheral

Original logo (wikipedia.org) USB 2.0 (2000) USB 3.0 (2008)


Max 12 Mbps Max 480 Mbps Max 5 Gbps
Aplikasi USB

Serial, komunikasi berkecepatan tinggi


Pokok Bahasan: USB
● Mengapa digunakan?
● Dasar-dasar: kecepatan, topologi, endpoint,
tipe transfer, protokol
● Antarmuka Host dan Driver (Software)
● Aplikasi di sistem embedded
Setelah mempelajari bab ini, mahasiswa akan mampu
● [C2] menjelaskan perkembangan antarmuka USB
● [C2] menjelaskan topologi sistem USB
● [C2] menjelaskan kelas USB terutama HID dan storage
● [C5] mendesain sistem mikrokomputer dengan antarmuka USB sebagai
device
Lane Hauck, “Embedding USB”, 2002
Mengapa digunakan? Menawarkan
keunggulan
● Many standardized, low cost devices are
available
● Connectors and cables are standard
● USB devices are compliance-tested to insure
compatibility and uniform performance
● Using hubs, multiple USB devices can share
one connector
● USB devices can tell you about their
capabilities
Mengapa digunakan? Menawarkan
keunggulan

USB provides device power

USB devices can:
– Be put to sleep
– Be awakened
– Provide a system wakeup call

USB protocol takes care of low-level details
– Flow control
– Error checking

You decide how complex to make the
firmware
Dasar-dasar USB
● Kecepatan
● Antarmuka
● Topologi
● Endpoint
● Tipe transfer
● Hub
● Host dan driver
● Protokol OWI-535 Robotic Arm Edge
Kecepatan Transfer

USB 1.0 (1996) and 1.1 (1998)
– Low speed is 1.5 Mbits/sec

Packet size is limited to 8 bytes
– Full speed is 12 Mbits/sec
– 12 Mb/s is great for embedded
systems

USB 2.0 (2000)
– “Hi-speed” is 480 Mbits/sec

USB 3.0 (2008)
– Theoretical max speed is 5 Gbit/s
Antarmuka USB
● Standar USB 1.x/2.0

● USB Mini/Micro 1.x/2.0

Panjang kabel: 5m
Perlu hub agar lebih jauh
Pin USB (Standar)

● Pin 1 : VCC (5V)


● Pin 2 : Data -
● Pin 3 : Data +
● Pin 4 : Ground
Pin USB micro-B 3.0

No.1: power (VBUS) No.6: USB 3.0 signal transmission


line (−)
No.2: USB 2.0 differential pair
(D−) No.7: USB 3.0 signal transmission
line (+)
No.3: USB 2.0 differential pair
(D+) No.8: GND
No.4: USB OTG ID for identifying No.9: USB 3.0 signal receiving line
lines (−)
No.5: GND No.10: USB 3.0 signal receiving
line (+)
Antarmuka Host

Wikipedia.org
Kabel USB
Sinyal USB
● Jarak maksimal kabel 5 meter
● Skema enkoding: NRZI (non return to zero invert)

Receiver
Driver

Kabel 1 kaki Kabel 5 meter


Sinyal USB: Kode NRZI

● a 0 bit is transmitted by toggling the data lines from J to K or


vice-versa
● a 1 bit is transmitted by leaving the data lines as-is
Topologi: Star

● 1 host dapat melayani PC


sampai 127 peripheral USB Host
Root Hub

Hub
P P
P
Hub
P P
P
Endpoints

Up to 32
endpoints


Endpoints are logical channels inside a
peripheral device
– Diidentifikasi dengan tuple (device_address,
endpoint_number)

In hardware they’re addressable buffers (FIFOS)
– Every host transfer includes a 4-bit endpoint number
and a direction bit

CONTROL endpoint 0 is mandatory

All others are up to the design

Endpoints are handy for separating data types
Kelas Device
Kelas Peripheral / Device
4 Tipe Transfer

Control
– Mission-critical, highest error protection
– Used to interrogate, configure and control devices

Bulk (easiest to use and the most flexible)
– Large, sporadic, use all remaining available bandwidth
– Ex: file transfer

Interrupt
– Guaranteed quick responses (bounded latency)
– Ex: pointing devices, keyboards

Isochronous
– Guaranteed data rate, but w/ possible data lost
– Ex: realtime audio or video
Frame Data USB (Cypress)

1 msec frame

...
SOF

SOF
Video Audio Mouse Control Printer Printer

Isochronous Interrupt Control Bulk

• 12MHz = 1.5MB/s or 1500 bytes/ms (full speed)


• Isochronous/Interrupt traffic have guaranteed bandwidth
• Control traffic is “best-effort”
• Bulk uses what is left
Hub USB

PC PC
USB USB USB USB

Hub
Device Device Device
USB USB USB USB

Device Device
Hub: Memberikan Arus ke Device

PC PC Wall Wart
USB USB
USB USB

500 500
500 500

Hub Hub
Device Device
USB USB USB USB
USB USB USB USB
500 500
100 100

Device Device Device Device


Hub: Device Lebih Banyak

PC Wall Wart
USB USB

500 500

Hub
Device
USB USB USB USB USB USB USB
500 500 500

Device Device Device

 Easy way to expand and power devices


Kontroler Host dan Driver
Application Application

Class Driver

IRP

USB Driver

Host Controller Driver

Transaction List

Host Controller Host Controller

PC Simple Embedded
Implementasi PC
 Apps or class drivers create IO
Application Request Packets (IRP)
 USB Driver
Class Driver
• Processes IRP’s
IRP
• Manages CONTROL pipe
• Division of duties between USBD and HCD
USB Driver is not defined
 Host Controller Driver (HCD)
Host Controller Driver • Provides abstraction
– Of host controller registers
Transaction List – Of data transfer specifics
• HCD creates a transaction list
– Schedule of transfers
Host Controller
 Host Controller turns transaction list
into packets
Implementasi PC: Kompleks
 App needs no knowledge of
Application
• Which host controller is installed
• USB signaling details
Class Driver
• Bus utilization details
IRP • Transaction lists
USB Driver
 App talks to buffers in your device
using “pipes”
Host Controller Driver
 Most of the HCD/HC complexity is due
to the flexible nature of USB
Transaction List
• 127 devices
• Devices appear and disappear at random
Host Controller
• Bandwidth must be fairly shared between
devices
Implementasi Embedded
 Looks simple Application
 The hardware is simple
 But software is “low-level”
• Detect USB device attachment
• Detect speed
• Enumerate devices
• Suspend and resume devices
• Manage error recovery
• Generate USB resets
Host Controller
• Conduct transfers
Simple Embedded
RTOS Menjembatasi Host - Driver

• Examples Application • Host Controller


– WinCE vendor may
– Linux provide a small
– VxWorks
Class Driver driver to make
the chip look like
something the
RTOS with a RTOS supports
USB
"Stack"

Host Controller
Implementasi USB
USB Host/Device
USB On The Go (OTG), 2006

Connect two peripherals together
– PC is not required (but still
supported)

Allow peripherals to awaken each
other
– Session Request Protocol
(SRP)
● Allow devices to exchange the host role
– Host Negotiation Protocol (HNP)
● New OTG devices can tap into the existing 900 million
USB devices
USB On The Go (OTG)

Defines a new connector and cable
– “Mini-AB” receptacle
– Mini-A to Mini-B cable
– Cable establishes the default host

A-Device is the default host

Host turns on VBUS

Dual-role USB devices:
– Sometimes a peripheral, sometimes a host
– Must use the new AB connector
– Provide limited host capability
– Supply 8 mA (min) on VBUS
– Operate at full speed (high speed optional)
APLIKASI USB
USB Physical Hit Counter (AVRTiny)

http://www.bobhobby.com/2008/04/22/usb-physical-hit-counter-based-on-avr-attiny25/
Skematik
Kelas Peripheral / Device
USB Peripheral Dev Tools
Serial

Develop--Debug PC USB

Test USB

Full-speed USB
Development Board
Embedded Host
Serial

Develop--Debug PC USB

Test Host
Transfers

Add-on board
contains USB host
plus 4-port hub

Full-speed USB
Development Board

You might also like