Escolar Documentos
Profissional Documentos
Cultura Documentos
1646 USB7
Slide
Objectives
To know what host enabled options are available To understand how they are different and when they should be selected over another Get hands-on experience on several of the available USB host class drivers To know where to go next to get more information, tools, training, etc., to get a design going
1646 USB7 Slide 2
Agenda
Whats Available?
WHATS AVAILABLE
1646 USB7
Slide
Embedded Host
Always a host, never a USB device Standard A connector Must always supply power Example: Data Logger
1646 USB7
Slide
On-The-Go (OTG)
Mobile, simple hosts Want to be host sometimes but device sometimes Power consumption Micro A/B connector Example: Smart Phones or Tablets
1646 USB7
Slide
1646 USB7
Slide
1646 USB7
Slide
Class Drivers
Host
Hardware
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7 Slide 9
Host
1646 USB7
USB_HOST_APP_EVENT_HANDLER()
USBHostInitialize()
USBHostTasks()
10
USBHostTasks()
Keeps the USB host state machine going Needs to be called periodically
Affects throughput
1646 USB7
Slide
11
USB_HOST_APP_EVENT_HANDLER()
USB_HOST_APP_DATA_EVENT_HANDLER()
Timer interrupts
1646 USB7
Slide
13
<Driver>Event()
usb_config.c usb_config.h
Host
1646 USB7
Slide
14
usb_config.c/usb_config.h
Contains build options and data tables required for USB stack operation
1646 USB7
Slide
15
1646 USB7
Slide
16
TPL Implementation
Located in usb_config.c
USB_TPL usbTPL[NUM_TPL_ENTRIES] = { /*[1] Device identification information [2] Initial USB configuration to use [3] Client driver table entry [4] Flags (HNP supported, client driver entry, SetConfiguration() commands allowed) --------------------------------------------------------------------[1] [2][3] [4] ---------------------------------------------------------------------*/ { INIT_CL_SC_P( 8ul, 6ul, 0x50ul ), 0, 0, {TPL_CLASS_DRV} } // SCSI - most MSD drives { INIT_VID_PID( 0x18D1ul, 0x2D00ul ), 0, 1, {0} }, // This specific device (Android) } CLIENT_DRIVER_TABLE usbClientDrvTable[NUM_CLIENT_DRIVER_ENTRIES] = { { USBHostMSDEventHandler, NULL, 0 }, { AndroidAppEventHandler, AndroidAppDataEventHandler, ANDROID_INIT_FLAG_BYPASS_PROTOCOL } };
1646 USB7
Slide
17
1646 USB7
Slide
18
What is MSD?
1646 USB7
Slide
19
USBHostMSDSCSIMediaDetect()
USBHostMSDTasks()
MSD
USB Host
1646 USB7
Slide
20
USBHostMSDSCSI
SectorWrite()
MSD
USB Host
1646 USB7
Slide
21
Transfer()
USBHostMSD
MSD
USB Host
1646 USB7
Initialize()
Slide
22
MSD
TransferIsComplete()
Read()
USBHost
USB Host
Write()
1646 USB7
Slide
23
MSD
MSD SCSI Transport USB Host
Supports FAT12/FAT16/FAT32 Supports long file names and several character encodings Currently only supports a single drive
Initializes data structures Loads device information from the MBR and Boot Sector Initializes Media Prototype: int FSInit (void); Returns:
Loads file information or creates a new file Prototype: FSFILE * FSfopen (const char * fileName, const char * mode); Arguments
fileName: The name of the file to open Mode: FS_READ, FS_WRITE, FS_APPEND, or PLUS modes A pointer to the initialized file object on success NULL on failure
Returns:
Example
1646 USB7
Slide
26
This function will write n items of size bytes from the structure pointed to by ptr to the file pointed to by stream Prototype: size_t FSfwrite (const void * ptr, size_t size, size_t n, FSFILE * stream); Arguments:
ptr: A pointer to the data to be written size: The size of the objects to write n: The number of objects to write stream: The file the data will be written to
1646 USB7
Slide
27
Updates information in the root and FAT Frees the memory used by the FSFILE object Prototype: int FSfclose (FSFILE * fo); Argument: A pointer to the file to close Returns:
Example
1646 USB7
Slide
28
LAB 1
1646 USB7
Slide
29
Lab 1 Objectives
C:\Masters\1646 USB7\manual.pdf
Solutions are both in the lab manual and in the C:\Masters\1646 USB7 folder
1646 USB7 Slide 30
Lab 1 Summary
1646 USB7
Slide
31
1646 USB7
Slide
32
Sometimes used for other custom devices that dont need large amounts of throughput
1646 USB7 Slide 33
Reports
Standardizes the data values for each type of input event Allows designer to select which features are implemented or not
1646 USB7
Slide
34
Reports
Report ID LR X shift Y shift RL Y shift Report ID
X shift
Report ID X shift Y shift Right Click Occurred
HGF EDCBA
PONML K J I T SRQ
1646 USB7
Slide
35
Slide
36
EVENT_HOST_HID_KEYBOARD_ATTACHED
Signals when a new keyboard is attached *data is the handle of the attached keyboard
Useful for getting information about the attached keyboard Used to identify which keyboard is sending a given message
1646 USB7
Slide
37
EVENT_HOST_HID_KEYBOARD_DETACHED
Signals when a keyboard is detached *data is the handle of the detached keyboard
1646 USB7
Slide
38
EVENT_HOST_HID_KEYBOARD_KEY_PRESSED EVENT_HOST_HID_KEYBOARD_KEY_RELEASED
*data is a EVENT_HOST_HID_KEYBOARD_KEY_EVENT_DATA*
typedef struct
{ USB_HID_KEYBOARD_KEYS key; void* keyboard; } EVENT_HOST_HID_KEYBOARD_KEY_EVENT_DATA;
Provides the HID key pressed and the handle for the associated keyboard.
1646 USB7
Slide
39
LAB 2
1646 USB7
Slide
42
Lab 2 Objectives
1646 USB7
Slide
43
Lab 2 Summary
1646 USB7
Slide
44
1646 USB7
Slide
45
USB modems
Some cell phones Cable modems USB Wi-Fi dongles
1646 USB7
Slide
46
CDC Host
USB Host
USBHost_CDC_ACM_PortDetect()
Detects new CDC ports available and returns handles to those ports for access by the application Prototype:
void* USBHost_CDC_ACM_PortDetect(void);
Arguments
None void* - handle to the detected CDC port. NULL if no port detected
Returns:
Example
void* device = NULL; while(1) { USBTasks(); if(device == NULL) { device = USBHost_CDC_ACM_PortDetect(); continue; }
1646 USB7
Slide
48
USBHost_CDC_ACM_PortStatusGet()
Arguments
void* handle the handle of the device that you are checking the status of. USB_HOST_CDC_ACM_STATUS__UNKNOWN_DEVICE USB_HOST_CDC_ASCM_STATUS__DEVICE_READY
Returns:
1646 USB7
Slide
49
USBHost_CDC_ACM_PortStatusGet()
Example
void* device = NULL; while(1) { USBTasks(); if(device == NULL) { device = USBHost_CDC_ACM_PortDetect(); continue; } switch(USBHost_CDC_ACM_PortStatusGet(device)) { case USB_HOST_CDC_ACM_STATUS__DEVICE_READY: break; case USB_HOST_CDC_ACM_STATUS__UNKNOWN_DEVICE: device = NULL; continue; default: continue; } // do something meaningful with the CDC device here
1646 USB7
Slide
50
USBHost_CDC_ACM_Write()
Arguments
void* handle handle of the device to write to BYTE* data the data that needs to be written DWORD size the amount of data to send USB_CDC_ACM_RETURN_CODE USB_SUCCESS USB_BUSY USB_UNKNOWN_DEVICE USB_<various error codes>
Returns:
1646 USB7
Slide
51
USBHost_CDC_ACM_WriteStatus()
Arguments
void* handle handle of the device to check DWORD *size pointer to a DWORD where the actual amount of data written will be stored USB_CDC_ACM_RETURN_CODE USB_SUCCESS USB_BUSY USB_UNKNOWN_DEVICE USB_<various error codes>
Returns:
1646 USB7
Slide
52
USBHost_CDC_ACM_WriteStatus()
Example
BYTE TxData[2]; DWORD size; //... Do all of the device detection... if(USBHost_CDC_ACM_WriteStatus(device, &size) != USB_BUSY) { TxData[0] = 'H'; TxData[1] = 'i'; USBHost_CDC_ACM_Write(device, TxData, 2); }
1646 USB7
Slide
53
USBHost_CDC_ACM_Read() USBHost_CDC_ACM_ReadStatus()
Identical to Write() and WriteStatus() expect that they read instead Note: The ReadStatus() function return USB_SUCCESS when either:
The request amount of data is received A transfer is completed (i.e. - you requested 100 bytes but the transfer was only 2 bytes)
1646 USB7
Slide
54
CDC Events
USB_EVENT_CDC_ACM_DEVICE_ATTACH
USB_EVENT_CDC_ACM_DEVICE_DETACH
USB_EVENT_CDC_ACM_READ_COMPLETE
USB_EVENT_CDC_ACM_WRITE_COMPLETE
data = handle of the device that completed write. Use WriteStatus() to get the amount of data
1646 USB7
Slide
55
LAB 3
1646 USB7
Slide
56
Lab 3 Objectives
Establish communication with a serial device using a USB to Serial converter cable
1646 USB7
Slide
57
Lab 3 Summary
1646 USB7
Slide
58
Receptacle
VBUS
3.3v 150F
D2K 2K D+ GND
DD+
1646 USB7
Slide
59
Checklists
Systems
Hub error message Device not supported message Over-current notification Resettable overcurrent protection Drop voltage
No Silent Failures
Power
TPL
1646 USB7 Slide 60
OTG IN DETAIL
1646 USB7
Slide
61
Function Drivers
Class Drivers
Device
OTG Controls
Host
Hardware
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7 Slide 62
Device Types
A Device
Device plugged into the A side of a cable. Starts out as the host
B Device
New
th 5
Pin
Old connectors had 4 pins on the receptacle that were used: VBUS, GND, D+, and DOTG connectors have 5 pins on the receptacle that are used: VBUS, GND, D+, D-, and ID
ID pin is used to determine which side of the cable is the A (host) side ID should be pulled high through a resistor
Mechanical
Pin 1
Mechanical
Pin 1
Micro B Receptacle
Mechanical
Micro A Plug
Pin 1
Mechanical
Micro B Plug
Pin 1
Micro A/B
Micro B Plug
Micro A/B
Host
Peripheral
1646 USB7
Slide
69
Micro A/B
Micro A/B
Peripheral
Host
1646 USB7
Slide
70
Micro A/B
Micro B Plug
Micro B
Host
Peripheral
1646 USB7
Slide
71
Micro A/B
Micro B
Peripheral
DOESNT FIT!!
1646 USB7
Slide
72
Mechanical
Cables
Allowable Types
Micro-A plug to Micro-B plug Micro-A plug to Standard-A receptacle Micro-B plug to Standard-A plug Captive cable with Micro-A plug 2 meters or less (different from USB-v2.0 limit of 5 meters)
1646 USB7 Slide 73
Length
OTG Descriptor
Required only if B-Device supports any OTG specific features Tells the host (A-Device) what the B-Device is capable of
1646 USB7
Slide
74
OTG Descriptor
Offset 0 Field bLength Size 1 Value Number Description Size of Descriptor (3 for v1.3 or earlier, 5 for v2.0) OTG type = 9 Attribute Fields D7-D3: reserved D2: ADP supported D1: HNP supported D0: SRP supported Binary coded decimal revision number that the device is compliant to (0200H for example)
1
2
bDescriptorType
bmAttributes
1
1
Constant
Bitmap
bcdOTG
OTG
1646 USB7
Slide
75
A-device still provides the power Roles stay swapped until bus goes idle
1646 USB7
Slide
76
SRP provides a way for a device to signal to a power down host that it wants to talk
1646 USB7
Slide
77
1646 USB7
Slide
78
OTG Acceptance
Nearly impossible to find cables Certified connectors are easier, but not a wide range of selection Nearly impossible to find real products
1646 USB7
Slide
79
Checklists
Unconfigured power
1646 USB7 Slide 80
MCP1253
nSHDN PGOOD SELECT VIN C+ C-
10 F
1 F
GND
VBUS VUSB 3.3v .1 F DD+ USBID
2012 Microchip Technology Incorporated. All Rights Reserved.
VOUT
ID
4.7 F
GND
Vdd
1646 USB7
Slide
81
Embedded Host
Optional (or not possible)
A receptacle 5m max cable CHST_VBUS > 120F
1646 USB7
Slide
82
GETTING STARTED
1646 USB7
Slide
83
Embedded Host
Data logging to a thumb drive MCHPUSB host temperature, pot reader HID Host talking to a keyboard HID Host talking to a mouse Printer Host (PCL5 and PostScript) CDC Host hosting a serial to USB converter Simple USB Charger Simple demo writing to a thumb drive Bootloading from a thumb drive
1646 USB7
Slide
84
OTG
MCHPUSB OTG (We currently support only v1.3 of the OTG specification)
1646 USB7
Slide
85
Development Kit
Explorer 16 (DV164033)
PIC24FJ64GB004 USB PIM (MA240019) PIC24FJ256GB110 USB PIM (MA240014) PIC32MX USB PIM (MA320002)
1646 USB7
Slide
86
Starter Kits
1646 USB7
Slide
87
Worldwide network of training facilities Product, Tools and Applications-orientated classes (Ethernet, USB, Motor Control, etc..) Flexible
Most classes are half or one day duration Easily modified to fit a specific customer need Most classes are $49 or $99 (US) Significant discounts on development tools used in the class Many centers reduce travel expenses
1646 USB7 Slide 88
Cost Effective
New to Microchip
New to PIC18 New to PIC24
New to USB
1646 USB7
Slide
89
Summary
Today we covered:
What host options are available How they are different Got hands on experience
Writing to a thumb drive Getting information from a keyboard Using a CDC serial converter
The End
Questions?
Ask now Ask the experts later Find me in the hall, at lunch, at dinner,
Please fill out a survey Come play with all of the demos Enjoy the rest of your classes!
1646 USB7 Slide 91
Thanks!!
Trademarks
The Microchip name and logo, the Microchip logo, dsPIC, KeeLoq, KeeLoq logo, MPLAB, PIC, PICmicro, PICSTART, PIC32 logo, rfPIC and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. Analog-for-the-Digital Age, Application Maestro, chipKIT, chipKIT logo, CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense, HI-TIDE, In-Circuit Serial Programming, ICSP, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, mTouch, Omniscient Code Generation, PICC, PICC-18, PICDEM, PICDEM.net, PICkit, PICtail, REAL ICE, rfLAB, Select Mode, Total Endurance, TSHARC, UniWinDriver, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies. 2012, Microchip Technology Incorporated, All Rights Reserved.
1646 USB7
Slide
92
OTG Appendix
Below is additional material for those interested to know more about how OTG works.
1646 USB7
Slide
93
Device Types
A Device
Device plugged into the A side of a cable. Starts out as the host
B Device
New
th 5
Pin
Old connectors had 4 pins on the receptacle that were used: VBUS, GND, D+, and DOTG connectors have 5 pins on the receptacle that are used: VBUS, GND, D+, D-, and ID
ID pin is used to determine which side of the cable is the A (host) side ID should be pulled high through a resistor
Mechanical
Pin 1
Mechanical
Pin 1
Micro B Receptacle
Mechanical
Micro A Plug
Pin 1
Mechanical
Micro B Plug
Pin 1
Micro A/B
Micro B Plug
Micro A/B
Host
Peripheral
1646 USB7
Slide
100
Micro A/B
Micro A/B
Peripheral
Host
1646 USB7
Slide
101
Micro A/B
Micro B Plug
Micro B
Host
Peripheral
1646 USB7
Slide
102
Micro A/B
Micro B
Peripheral
DOESNT FIT!!
1646 USB7
Slide
103
Mechanical
Cables
Allowable Types
Micro-A plug to Micro-B plug Micro-A plug to Standard-A receptacle Micro-B plug to Standard-A plug Captive cable with Micro-A plug 2 meters or less (different from USB-v2.0 limit of 5 meters)
1646 USB7 Slide 104
Length
1646 USB7
Slide
105
OTG Descriptor
Required only if B-Device supports any OTG specific features Tells the host (A-Device) what the B-Device is capable of
1646 USB7
Slide
106
OTG Descriptor
Offset 0 Field bLength Size 1 Value Number Description Size of Descriptor (3 for v1.3 or earlier, 5 for v2.0) OTG type = 9 Attribute Fields D7-D3: reserved D2: ADP supported D1: HNP supported D0: SRP supported Binary coded decimal revision number that the device is compliant to (0200H for example)
1
2
bDescriptorType
bmAttributes
1
1
Constant
Bitmap
bcdOTG
OTG
1646 USB7
Slide
107
Session
1646 USB7
Slide
108
SRP support
OTG devices are required to be able to respond to and initiate SRP A-Devices allowed to respond to SRP B-Devices allowed to initiate SRP
1646 USB7
Slide
109
B-Device
Before attempting to start new session, must first determine the previous session has ended
Time the decay of the previous session end Pull VBUS down to speed up end of session
1646 USB7
Slide
110
VIH D+ VIL
VIH
Vbus VIL
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7 Slide 111
Cable determines which device is the host (A-Device) and the peripheral (BDevice)
Whichever device that has the Micro A plug plugged into its Micro A/B receptacle is the default host/A-Device
Micro A Plug Micro B Plug
Micro A/B
Micro A/B
Host
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7
Peripheral
Slide
112
The B-Device will become the host until the session ends A-Device continues to source the VBUS power
Micro A Plug
Micro A/B
Micro B Plug
Micro A/B
Can be set in the default, address, or configured states Only cleared at the end of a session or on a bus reset
If HNP is not supported on the B-Device, then it should STALL on any of these Set Feature requests
1646 USB7 Slide 114
4)
A-Device uses SetFeature(HNP) During suspend the B-Device turns off D+ pull-up A-Device turns D+ pull-up on B-Device detects D+ pull-up and asserts a bus reset
1 2 3 4
VIH D+ VIL
A-Device Driving
A-Device Pull-Downs A-Device Pull-ups
B-Device Driving
B-Device Pull-ups
1646 USB7
Slide
115
B is now the host and controls the bus When B-Device is done, stops all bus activity On the Idle condition, the B-Device enables its D+ pull-up and the A-device disables its pull-up A-Device either asserts reset or turns off VBUS 1 2 3 4 5 6 7 8
VIH D+ VIL
A-Device Driving
A-Device Pull-Downs A-Device Pull-ups
B-Device Driving
B-Device Pull-ups
1646 USB7
Slide
116
Used to determine if remote device is still attached after a session has ended Done using a constant current source to determine if the capacitance on VBUS has changed (called ADP probing)
1646 USB7 Slide 117
A B-device shouldnt try to start a new session until it determines that the A-Device isnt ADP probing anymore (called ADP sensing)
1646 USB7
Slide
118
T
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7 Slide 119
I = (C1 + C2) * dV/dT, thus it will take longer for the same current source to reach the same voltage
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7 Slide 120
IA_VBUS_OUT min = 8mA 4.4v <= VA_VBUS_OUT <= 5.25v Must error if VA_VBUS_OUT < VA_VBUS_VLD
4.75v <= VA_VBUS_OUT <= 5.25v
1646 USB7
Slide
121
Peripheral Only
1646 USB7
Slide
122
VBus
Pin 1
RA_BUS_IN
CDRD_VBUS
When A-Device is powered but not supplying VBus, RA_BUS_IN max <= 100K 1.0F < CDRD_VBUS < 6.5F
1646 USB7
Slide
123
Quiz!
1)
2)
True or False: If I plug in any 100mA normal USB device into an OTG device, everything should always be fine. True or False: There is no electrical difference between an OTG host and an Embedded host.
1646 USB7 Slide 124
Embedded Host
Optional
Not possible Not possible Allowed to support generic classes (i.e.- any HID mouse) A CHST_VBUS > 120F
Slide 125
Required
Required Optional Allowed to support generic classes (i.e.any HID mouse) Micro A/B 1.0F < CDRD_VBUS < 6.5F
1646 USB7
Agenda
Overview Mechanical Protocol Electrical Certification Considerations Resources (Examples, Classes, Software, etc.)
1646 USB7 Slide 126
Checklists
Systems
Hub error message Device not supported message Over-current notification Resettable overcurrent protection Drop voltage
No Silent Failures
Power
TPL
1646 USB7 Slide 127
Checklists
Unconfigured power
1646 USB7 Slide 128
Port accessibility
If more than one connector is accessible at any point of time, then they need to be able to work at the same time Peripheral Systems
1646 USB7 Slide 129
Checklists
Receptacle
VBUS
3.3v VUSB .1F A/D 150F
D2K 2K D+ GND
DD+
1646 USB7
Slide
130
MCP1253
nSHDN PGOOD SELECT VIN C+ C-
10 F
1 F
GND
VBUS VUSB 3.3v .1 F DD+ USBID
2012 Microchip Technology Incorporated. All Rights Reserved.
VOUT
ID
4.7 F
GND
Vdd
1646 USB7
Slide
131
3.3v
PPTC
.1F A/D
2K 2K
VBUS Input 1F
DD+
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7
Software Architecture
User Code
Function Drivers
Class Drivers
Device
OTG Controls
Host
Hardware
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7 Slide 133
OTG References
1)
2)
USB_OTG_and_EH_2-0.pdf On-The-Go Supplement to the USB 2.0 Specification Micro-USB_1_01.pdf Universal Serial Bus MicroUSB Cables and Connectors Specification
1646 USB7 Slide 134
Acronyms
SRP Session Request Protocol HNP Host Negotiation Protocol OTG On-The-Go USB Universal Serial Bus DRD Dual Role Device PPTC Polymeric Positive Temperature Coefficient SIE Serial Interface Engine BDT Buffer Descriptor Table
1646 USB7 Slide 135