USB: Universal Serial Bus
USB: Universal Serial Bus
Hyde,
J.
(2001).
USB
Design
by
Example:
A
Prac6cal
Guide
to
Building
I/O
Devices.
Second
Edi6on.
Enhanced
host
controller
specica6on
h8p://www.intel.com/technology/usb/ehcispec.htm
Microchip
(h8p://www.microchip.com)
pic18f4550
microcontroller,
pickit2
programmer,
C
compiler
and
MPLAB
IDE
PICDEM
development
board
(no
hardware
programmer
needed;
bootloader
enables
ashing
microcontroller
rmware
through
USB)
My
notes
h8p://www.cprince.com/PubRes/Hardware/LinuxUSB/
Outline
RS-232
serial
communica6on
Wiring,
power
&
hardware
congura6on
USB
organiza6on
Congura6ons
&
endpoints
Transac6on
types
Bus
data
communica6on
Control
transfers
Interrupt
transfers
Hardware
development
Some
Linux
host
sobware
Devices
classes
Interrupts
&
Interrupts
RS-232
Serial
Bytes
are
shibed
out
onto
wire,
for
serial
transmission
of
bits
Transmission
is
point
to
point.
A
serial
port
connects
to
one
single
other
serial
port
via
wires
Bits
are
received
serially
at
receiving
end,
and
shibed
back
into
byte
form
Communica6on
is
bidirec6onal
and
full-duplex
RS-232
communica6on
protocol
is
just
about
sending
byte
data
serially
4
Devices
start
using
100mA
power
During
congura6on,
can
request
use
of
up
to
500mA
(Dierent
wiring
for
USB
3)
6
These
include
HID:
Human
Interface
Device
E.g.,
Mouse,
joys6ck
Such devices can oben be controlled by generic class device drivers If a device ts neatly into one or more of these predened classes, then [with appropriate exis6ng support from the opera6ng system], you dont need [an addi6onal] device driver (p. 10, Hyde, 2001)
HID
on
Linux
sta6c
char
*hid_types[]
=
{"Device",
"Pointer",
"Mouse",
"Device",
"Joys6ck,
"Gamepad",
"Keyboard",
"Keypad",
"Mul6-Axis
Controller"};
From:
/usr/src/linux-source-2.6.22/drivers/hid/usbhid/hid-core.c
Ubuntu Linux
However,
host
controllers
use
hardware
interrupts
(presumably,
to
interact
with
host)
E.g.,
see
h8p://www.gelato.unsw.edu.au/lxr/source/ drivers/usb/host/uhci-hcd.c
10
11
12
Interrupt
These
endpoints
transfer
small
amounts
of
data
at
a
xed
rate
every
6me
the
USB
host
asks
the
device
for
data;
primary
transport
method
for
USB
keyboards
and
mice
Also,
guaranteed
to
make
it
through
14
Endpoint
types
-
2
Bulk
Transfer
large
amounts
of
data
Used
for
devices
that
need
to
transfer
data
with
no
data
loss
Transfers
not
guaranteed
to
make
it
through
the
bus
in
a
specic
amount
of
6me
Isochronous
Also
transfer
large
amounts
of
data,
but
data
not
guaranteed
to
make
it
through
Used
with
devices
that
can
handle
data
loss
E.g.,
audio
and
video
devices
15
Interrupt transfer type does not mean hardware interrupts Interrupt and control transfers: Always guaranteed to make it through on 6me
16
17
18
Packet
types
Token
indicates
the
endpoint
number
to
be
used
for
sending/receiving
data
Data
Size
limit
is
1024
bytes
Handshake
ACK,
NAK,
STALL
(requires
host
interven6on)
Start
of
frame
h8p://www.beyondlogic.org/usbnutshell/usb3.shtml
19
20
Data
Rates
Low-speed
&
full-speed
Frame
rate:
1000
Hz
Low-speed:
1.5
Mbps
1,200
bits
per
frame
(prac6cally)
Control
Transfers
Used
to
control
the
gadget
Endpoint
0
on
gadget
Packets
sent
in
2
or
3
phases
Setup;
op6onal
data
phase;
status
phase
22
23
24
25
26
27
End!
28
29
30
Interrupt
Transfers
Not
really
interrupts
Just
another
USB
transac6on
type
This
transac6on
type
emphasizes
quality
&
6me
(same
as
control),
but
intended
for
more
general
data
transfer
to
and
from
gadget
31
32
Hardware
Development
Whats
involved?
Microcontroller
Circuit
in
which
the
microcontroller
will
run
Firmware
for
the
microcontroller
Assembler
or
C
compiler
to
program
rmware
Programmer
for
microcontroller
Sobware
to
download
rmware
to
microcontroller
Sobware
for
the
host
33
Example Circuit
h8p://www.create.ucsb.edu/%7Edano/CUI/MediaInterfaceCircuit.jpg
34
Linux
tail
f
/var/log/messages
Host
sobware
for
HID
libusb
h8p://libusb.wiki.sourceforge.net/
libhid
h8p://libhid.alioth.debian.org/
test_libhid.c
Commands
lsusb
E.g.,
lsusb
-d
04d8:0000
vvv
lshid
37
38