Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Adam Syu
Microchip CAE
Class Objectives
When you finish this class you will be able to:
Describe the basics of USB, and how to apply them in an embedded application Identify Microchips USB MCUs, development boards, and USB software frameworks relevant to your project Analyze the capabilities and limitations of the CDC device class, and implement basic communications using the CDC device framework on PIC18/24/32 MCUs
COM 3101
Slide 3
Agenda Part 1:
Introduction to Full-Speed USB
Part 2:
Introduction to Microchips USB Device Frameworks
Part 3:
Using the Microchip CDC Class Device Framework (RS-232 Replacement)
COM 3101
Slide 4
Class Folders
COM3101T \Exercise\ Lab1a, Lab1b, .., Lab5 Microchip (Framework) \USB Precompiled Demos (*.hex) \USB Tools Presentation Files
2010 Microchip Technology Incorporated. All Rights Reserved. COM 3101
Slide 5
Part 1.
Introduction to Full-Speed USB
Agenda Part 1
USB Fundamentals The serious & important stuff
Basics/Speeds Topology/Physical Connection Architecture/Programmers Model USB Transactions USB Transfers Device Classes Enumeration Descriptors Power Planning VID/PID & USB Compliance
A little history...
USB was co-developed by a group of companies.
Compaq, Intel, Microsoft, NEC who wanted to make it much easier to add/remove peripheral devices from PCs
Jan., 1996 USB 1.0 Sep., 1998 USB 1.1 Apr., 2000 USB 2.0 2003 On-the-Go supplement to USB 2.0 (v1.0a)
COM 3101
Slide 8
USB Basics
USB is a Single Master + Multiple Slaves Polled Bus USB Host Controller (Master) and Root Hub
Mouse
Start Of Frame Mouse Packets
Printer
Speakers Packets
Speakers
Printer Packets
Frame
2010 Microchip Technology Incorporated. All Rights Reserved.
Frame
COM 3101
Frame
Slide 9
Hub
Repeats traffic (both directions), manages power
Compound Device
Contains a hub and 1 or more peripheral Host treats hub and peripheral function separately (each has its own address)
i.e. USB keyboard with 1-port hub
Composite Device
Has multiple interfaces active at the same time Host loads a driver for each interface
i.e. video camera (both audio & video interfaces active)
2010 Microchip Technology Incorporated. All Rights Reserved. COM 3101 Slide 10
USB 2.0
LS-USB 1.5 Mb/s CAN Serial Port 500 Kb/s 1 Mb/s FS-USB 12 Mb/s HS-USB 480 Mb/s
USB 1.1
Parallel Port 1.5 Mb/s 12 Mb/s
COM 3101
TIP
Connect Full-Speed Peripherals to an High-Speed HUB
USB 2.0 HS Host
480 Mb/s
12 Mb/s
12 Mb/s
12 Mb/s
<12 Mb/s
<12 Mb/s
LS/FS device
LS/FS device
COM 3101
LS/FS device
LS/FS device
Slide 12
Agenda Part 1
USB Fundamentals The serious & important stuff
Basics/Speeds Topology/Physical Connection Architecture/Programmers Model USB Transactions USB Transfers Device Classes Enumeration Descriptors Power Planning VID/PID & USB Compliance
PIC18 USB devices are designed to be peripherals. PIC24/PIC32 can function as either embedded host or peripheral.
Data Logger
Up to 126 peripherals...
Hub
COM 3101
Slide 14
Physical Interface
VBUS D+ DGND
VBUS D+ DGND
~ 5.0 V ~ 3.3 V
Half Duplex with NRZI (No Return to Zero Invert) Data Encoding Bus Power to each device:
4.40-5.25V Guaranteed 100 mA 500 mA maximum through negotiation Must use external power if more is required
COM 3101
Slide 15
Standard Connectors
- USB 2.0 Specification A USB Host
B FS, HS Device
COM 3101
Slide 16
Agenda Part 1
USB Fundamentals The serious & important stuff
Basics/Speeds Topology/Physical Connection Architecture/Programmers Model USB Transactions USB Transfers Device Classes Enumeration Descriptors Power Planning VID/PID & USB Compliance
Configuration Interface
Analog/Digital I/O
COM 3101
PIC
MCU
LED
RAM Endpoint 1 IN
Caps-Lock
Peripheral Device
Pipe Bundle
Interface Function Layer
Function
Interface-specific
SIE
Sending/Receiving on the PC Only High Level Access Four Basic Function Types Example:
Microchip General Purpose USB Device Driver
MPUSBOpen(); MPUSBRead(); MPUSBWrite(); MPUSBClose(); Microsoft WinUSB WinUSB_Initialize(); WinUsb_ReadPipe(); WinUsb_WritePipe(); WinUSB_Free();
2010 Microchip Technology Incorporated. All Rights Reserved.
driver
COM 3101
Slide 22
COM 3101
Slide 23
Agenda Part 1
USB Fundamentals The serious & important stuff
Basics/Speeds Topology/Physical Connection Architecture/Programmers Model USB Transactions USB Transfers Device Classes Enumeration Descriptors Power Planning VID/PID & USB Compliance
USB Transaction
USB Transaction Token Packet
SETUP and OUT token types inform the target device that the host wants to send data. IN token type informs the target device that the host wants to fetch data.
2010 Microchip Technology Incorporated. All Rights Reserved. COM 3101
Specifies: Target device address Endpoint number Direction of the data transfer
Slide 25
USB Transaction IN
USB Transaction IN Token Packet
Data Packet
Handshake Packet
Acknowledge - ACK
COM 3101
Slide 26
IN Transaction ACK
USB Traffic USB Transaction IN Token Packet (to EP1 IN) USB PIC MCU
Serial Interface
SIE Sends Data
If (
Data Packet
Engine
Handshake Packet
r Clea
N UOW
Keystrokes
=0
putsUSBUSART( )
Update BD
COM 3101
Slide 27
IN Transaction NAK
USB Traffic USB Transaction IN Token Packet (to EP1 IN) USB PIC MCU
If (
Handshake Packet
COM 3101
Slide 28
Serial
SIE Deposits Data
If (
UO WN =
Interface Engine
=1
ar e l C
COM 3101
Slide 29
Serial Interface
SI E isc ar ds Da SIE Sends NAK ta
If (
UO WN =
=0
Engine D
SFR EP1 OUT BD RAM (UOWN, Length, Endpoint 1 OUT Pointer) RAM Endpoint 1 IN SFR EP1 IN BD (UOWN, Length, Pointer)
COM 3101
Slide 30
Agenda Part 1
USB Fundamentals The serious & important stuff
Basics/Speeds Topology/Physical Connection Architecture/Programmers Model USB Transactions USB Transfers Device Classes Enumeration Descriptors Power Planning VID/PID & USB Compliance
Transfer
Transaction 1
64 Byte Payload
Key:
OUT Token Packet Data Packet ACK Handshake Packet
Transaction 2
64 Byte Payload
Transaction 3
1 Byte Payload
COM 3101
Slide 32
Data Integrity
Interrupt
Fixed, Periodic
Yes
Isochronous
Fixed, Periodic
90
No
Bulk
Yes
Control
Variable
10
Yes
Transactions
64
64
Frame
COM 3101
Slide 35
Int.
Isoc.
Int.
64
64
Int.
Frame
COM 3101
Slide 36
Control Interrupt
Transfer Type
COM 3101
Slide 37
Mouse
Printer
Speaker
Control + Interrupt
Control + Bulk
Control + Isochronous
COM 3101
Slide 38
Agenda Part 1
USB Fundamentals The serious & important stuff
Basics/Speeds Topology/Physical Connection Architecture/Programmers Model USB Transactions USB Transfers Device Classes Enumeration Descriptors Power Planning VID/PID & USB Compliance
Keyboard
Custom Class (Vendor Class) Human Interface Device Class (HID) Many more classes.
COM 3101 Slide 40
Host WinUSB Need .inf Yes Yes Yes LibUSB No Yes Yes 32 bit
Transfer Types for users data Control Interrupt Isochronous Bulk Max Speed No Yes No No 64 KB/s No No No Yes ~80 kB/s
COM 3101
Agenda Part 1
USB Fundamentals The serious & important stuff
Basics/Speeds Topology/Physical Connection Architecture/Programmers Model USB Transactions USB Transfers Device Classes Enumeration Descriptors Power Planning VID/PID & USB Compliance
Cable Connected
ADDRESS
COM 3101
Slide 43
Auto-Detection: Full-Speed
Peripheral Device
VUSB 3.3 V
1.5 k5%
+5V D+ DGND Transceiver
USB Connector
COM 3101
Slide 44
Auto-Detection: Low-Speed
Peripheral Device
VUSB 3.3 V
1.5 k5%
+5V D+ DGND Transceiver
USB Connector
COM 3101
Slide 45
DGND
USB Connector
COM 3101
Slide 46
Control Transfers
Endpoint 0 IN
(Control Data)
Descriptors
Other Endpoints
COM 3101
Slide 47
Agenda Part 1
USB Fundamentals The serious & important stuff
Basics/Speeds Topology/Physical Connection Architecture/Programmers Model USB Transactions USB Transfers Device Classes Enumeration Descriptors Power Planning VID/PID & USB Compliance
Descriptors
String 0 String 1 String N Configuration 1 Device
Endpoint