Você está na página 1de 133

1646 USB7 USB Embedded Host and On-The-Go (OTG)

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

Agenda

Whats Available?

OTG vs Embedded Host vs Dual Role

Host and OTG stack architecture overview Mass Storage Host

Lab 1 Lab 2 Lab 3

Human Interface Device

Communication Device Class

OTG in more detail


1646 USB7 Slide 3

2012 Microchip Technology Incorporated. All Rights Reserved.

WHATS AVAILABLE

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

Embedded Host

Always a host, never a USB device Standard A connector Must always supply power Example: Data Logger

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

Dual Role (multi-connector devices)

2 connectors must only have one


accessible at any point of time Wants to be either embedded host or USB device, but doesnt need to dynamically switch Some electrical considerations Example: Data Logger with field update via PC

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

HOST AND OTG STACK OVERVIEW

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

High Level Software Architecture


User Code

Class Drivers

Host

Hardware
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7 Slide 9

High Level Software Architecture


User Code
USB_HOST_APP_DATA_EVENT_HANDLER()
Slide

Host

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

USB_HOST_APP_EVENT_HANDLER()

USBHostInitialize()

USBHostTasks()

10

USBHostTasks()

Keeps the USB host state machine going Needs to be called periodically

Needed for transfers to complete

Affects throughput

Needed for notifications of events

Attach, detach, etc.

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

11

USB_HOST_APP_EVENT_HANDLER()

Notification of most events occurring on the bus


Device attach Device detach Transfer complete Errors

Is called from USBHostTasks()


1646 USB7 Slide 12

2012 Microchip Technology Incorporated. All Rights Reserved.

USB_HOST_APP_DATA_EVENT_HANDLER()

Notification of time critical events on the bus

Timer interrupts

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

13

Host/Client Driver Interface


Class Drivers
Transmit Functions: USBHostWrite() USBHostRead() USBHostIsReadComplete() Etc. <Driver>DataEvent()

<Driver>Event()

usb_config.c usb_config.h

Host

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

14

usb_config.c/usb_config.h

Used for stack configuration

Used for host, device, and OTG configuration

Contains build options and data tables required for USB stack operation

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

15

Targeted Peripheral List (TPL)

List of supported devices for that embedded host and OTG

Devices not on that list will not be able to enumerate Specified by


Vendor ID(VID) and Product ID(PID) pair Or Class, Subclass, and Protocol set

2012 Microchip Technology Incorporated. All Rights Reserved.

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 } };

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

17

MASS STORAGE DEVICE CLASS (MSD) HOST

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

18

What is MSD?

Used to talk to memory devices

Thumb drives USB hard drives

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

19

USBHostMSDSCSIMediaDetect()

MSD Host Driver Architecture


FSfclose() FSfopen() FSfread() FSfwrite() FSInit()

USBHostMSDTasks()

File System Layer (FAT/FAT32)

MSD SCSI Transport

MSD

USB Host

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

20

MSD Host Driver Architecture


File System Layer (FAT/FAT32)
MediaInitialize() MediaDetect() SectorRead()

USBHostMSDSCSI

MSD SCSI Transport

SectorWrite()

MSD

USB Host

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

21

MSD Host Driver Architecture


File System Layer (FAT/FAT32)

MSD SCSI Transport


TransferIsComplete()

Transfer()

USBHostMSD

MSD

USB Host

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Initialize()

Slide

22

MSD Host Driver Architecture


File System Layer (FAT/FAT32)

MSD SCSI Transport

MSD
TransferIsComplete()

Read()

USBHost

USB Host

2012 Microchip Technology Incorporated. All Rights Reserved.

Write()
1646 USB7

Slide

23

Microchip Disk Drive (MDD) Overview


File System Layer (FAT/FAT32)

MSD
MSD SCSI Transport USB Host

MDD/FAT library used to talk to drives

Supports FAT12/FAT16/FAT32 Supports long file names and several character encodings Currently only supports a single drive

only one type only one at a time

Uses POSIX style interface

FSfopen() FSfclose() FSfread(), FSfwrite()


1646 USB7 Slide 24

2012 Microchip Technology Incorporated. All Rights Reserved.

The FSInit Function


Initializes data structures Loads device information from the MBR and Boot Sector Initializes Media Prototype: int FSInit (void); Returns:

TRUE if initialization is successful FALSE otherwise


1646 USB7 Slide 25

2012 Microchip Technology Incorporated. All Rights Reserved.

The FSfopen Function


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:

Can also be used to open directories

Example

FSFILE * pointer; pointer = FSfopen (FILE.TXT, w+); if (pointer == NULL) // Error

// Or use WRITEPLUS macro

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

26

The FSfwrite Function

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

Returns: The number of objects written

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

27

The FSfclose Function


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:

0 if the file was closed successfully EOF (-1) otherwise

Example

FSFILE * pointer; pointer = FSfopen (FILE.TXT, w); if ( FSfclose (pointer) != 0) // Error

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

28

Mass Storage Host (MSD)

LAB 1

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

29

Lab 1 Objectives

Write file to drive Lab manual can be found at

C:\Masters\1646 USB7\manual.pdf

Open MPLAB X IDE,

Select File->Open Project Select the c:\Masters\1646 USB7\lab1_msd\MPLAB.X file.

Solutions are both in the lab manual and in the C:\Masters\1646 USB7 folder
1646 USB7 Slide 30

2012 Microchip Technology Incorporated. All Rights Reserved.

Lab 1 Summary

How to write a file on a USB thumb drive

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

31

HUMAN INTERFACE DEVICE CLASS (HID) HOST

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

32

What is the Human Interface Device Class (HID)?

Typically used for input devices

Keyboards, mice, barcode scanners, touch digitizers, game controllers, etc.

Sometimes used for other custom devices that dont need large amounts of throughput
1646 USB7 Slide 33

2012 Microchip Technology Incorporated. All Rights Reserved.

Reports

HID Devices transfer what are known as reports


Standardizes the data values for each type of input event Allows designer to select which features are implemented or not

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

35

HID Host Driver Architecture


USB_HOST_APP_EVENT_HANDLER ( EVENT_HOST_HID_KEYBOARD_ATTACHED, EVENT_HOST_HID_KEYBOARD_DETACHED, EVENT_HOST_HID_KEYBOARD_KEY_PRESSED, EVENT_HOST_HID_KEYBOARD_KEY_RELEASED )

HID Keyboard Driver HID Host USB Host


2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7

HID Mouse Driver Report Parser

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

37

EVENT_HOST_HID_KEYBOARD_DETACHED

Signals when a keyboard is detached *data is the handle of the detached keyboard

2012 Microchip Technology Incorporated. All Rights Reserved.

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.

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

39

Human Interface Device Class (HID)

LAB 2

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

42

Lab 2 Objectives

Create code to talk to a HID class device

Get the information from a USB keyboard when a key is pressed

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

43

Lab 2 Summary

Read information from a USB keyboard

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

44

COMMUNICATION DEVICE CLASS (CDC) HOST

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

45

What is the Communication Device Class (CDC)

Used for communication devices

USB modems
Some cell phones Cable modems USB Wi-Fi dongles

USB to Serial cables

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

46

2012 Microchip Technology Incorporated. All Rights Reserved.

USBHost_CDC_ACM_PortDetect() USBHost_CDC_ACM_PortStatusGet() USBHost_CDC_ACM_Write() USBHost_CDC_ACM_Read() USBHost_CDC_ACM_WriteStatus() USBHost_CDC_ACM_ReadStatus()

CDC Host API

CDC Host

USB Host

1646 USB7 Slide 47

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; }

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

48

USBHost_CDC_ACM_PortStatusGet()

Determines the status of a specified CDC device Prototype:


USB_CDC_ACM_DEVICE_STATUS USBHost_CDC_ACM_PortStatusGet(void* handle);

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:

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

50

USBHost_CDC_ACM_Write()

Writes data to a CDC device Prototype:


USB_CDC_ACM_RETURN_CODE USBHost_CDC_ACM_Write( void* handle, BYTE* data, DWORD size);

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:

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

51

USBHost_CDC_ACM_WriteStatus()

Writes data to a CDC device Prototype:


USB_CDC_ACM_RETURN_CODE USBHost_CDC_ACM_WriteStatus( void* handle, DWORD *size);

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:

2012 Microchip Technology Incorporated. All Rights Reserved.

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); }

2012 Microchip Technology Incorporated. All Rights Reserved.

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)

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

54

CDC Events

USB_EVENT_CDC_ACM_DEVICE_ATTACH

data = handle of the device attached


data = handle of the device that detached data = handle of the device that completed read. Use ReadStatus() to get the amount of data

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

55

Communication Device Class (CDC)

LAB 3

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

56

Lab 3 Objectives

Establish communication with a serial device using a USB to Serial converter cable

Test sending and receiving data

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

57

Lab 3 Summary

Created a connection to a USB to UART conversion cable

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

58

Embedded Host Example Circuit Full size A


PIC24, dsPIC DSC, or PIC32MX with the USB OTG module
5v PPTC

Receptacle

VBUS
3.3v 150F

VUSB .1F A/D

D2K 2K D+ GND

DD+

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

59

Certification Considerations Embedded Host


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

2012 Microchip Technology Incorporated. All Rights Reserved.

OTG IN DETAIL

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

61

High Level Software Architecture


User Code

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

Device plugged into the B side of a cable. Starts out as a peripheral


1646 USB7 Slide 63

2012 Microchip Technology Incorporated. All Rights Reserved.

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

Built into PIC24F and PIC32MX devices with USB OTG


1646 USB7 Slide 64

2012 Microchip Technology Incorporated. All Rights Reserved.

Mechanical

Pin 1

Micro A/B Receptacle


Pin 1: VBus Pin 2: DPin 3: D+ Pin 4: ID Pin 5: GND


1646 USB7 Slide 65

2012 Microchip Technology Incorporated. All Rights Reserved.

Mechanical

Pin 1

Micro B Receptacle

Pin 1: VBus Pin 2: DPin 3: D+ Pin 4: ID Pin 5: GND


1646 USB7 Slide 66

2012 Microchip Technology Incorporated. All Rights Reserved.

Mechanical

Micro A Plug

Pin 1

Pin 1: VBus Pin 2: DPin 3: D+ Pin 4: GND (ID) Pin 5: GND


1646 USB7 Slide 67

2012 Microchip Technology Incorporated. All Rights Reserved.

Mechanical

Micro B Plug

Pin 1

Pin 1: VBus Pin 2: DPin 3: D+ Pin 4: Floating (ID) Pin 5: GND


1646 USB7 Slide 68

2012 Microchip Technology Incorporated. All Rights Reserved.

OTG Cable Example


Micro A Plug

Micro A/B

Micro B Plug

Micro A/B

Host

Peripheral

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

69

OTG Cable Example


Micro B Plug Micro A Plug

Micro A/B

Micro A/B

Peripheral

Host

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

70

OTG Cable Example


Micro A Plug

Micro A/B

Micro B Plug

Micro B

Host

Peripheral

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

71

OTG Cable Example


Micro B Plug Micro A Plug

Micro A/B

Micro B

Peripheral

DOESNT FIT!!

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

OTG Descriptor

Returned in the GetDescriptor(Configuration) request


Required only if B-Device supports any OTG specific features Tells the host (A-Device) what the B-Device is capable of

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

75

Host Negotiation Protocol (HNP)

Allows two connected OTG devices to exchange roles


A-device still provides the power Roles stay swapped until bus goes idle

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

76

Session Request Protocol (SRP)

OTG allows host to power down bus when not in use

SRP provides a way for a device to signal to a power down host that it wants to talk

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

77

Attach Detection Protocol (ADP)

OTG allows host to power down bus when not in use

Determine if a device has detached while the bus is powered down

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

78

OTG Acceptance

OTG acceptance is currently very low


Nearly impossible to find cables Certified connectors are easier, but not a wide range of selection Nearly impossible to find real products

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

79

Certification Considerations OTG

Checklists

OTG Peripheral Systems

SRP HNP TPL Power restrictions

Unconfigured power
1646 USB7 Slide 80

2012 Microchip Technology Incorporated. All Rights Reserved.

OTG Example Circuit


PIC24F or PIC32MX USB device
GPIO GPIO 3.3v

MCP1253
nSHDN PGOOD SELECT VIN C+ C-

10 F

1 F

Micro A/B Receptacle


VBUS DD+

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

OTG vs. Embedded Host


OTG
OTG Protocols Some are required (SRP, HNP, ADP)
Mechanical Electrical Micro A/B receptacle 2m max cable 1.0F < CDRD_VBUS < 6.5F 8mA min to connected peripheral device (if Adevice)

Embedded Host
Optional (or not possible)
A receptacle 5m max cable CHST_VBUS > 120F

100mA min to connected peripheral

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

82

Where to go for more information

GETTING STARTED

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

83

Software Examples Available

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

84

Software Examples Available

OTG

MCHPUSB OTG (We currently support only v1.3 of the OTG specification)

All software available, free download from:


www.microchip.com/usb

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

85

Demo Tools Available

Development Kit

Explorer 16 (DV164033)

USB PICtail Plus Daughter Card (AC164131)

PIC24FJ64GB004 USB PIM (MA240019) PIC24FJ256GB110 USB PIM (MA240014) PIC32MX USB PIM (MA320002)

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

86

Demo Tools Available

Starter Kits

PIC24F Starter Kit (DM240011) PIC32MX USB Starter Board (DM320003)

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

87

Microchip Regional Training Centers (RTCs)


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

2012 Microchip Technology Incorporated. All Rights Reserved.

RTC Training Curriculum


MPLAB Tool Basics TLS0103 PIC18 Arch. MCU2101 16-bit Arch. MCU3101 Intro USB COM3101 USB Device COM3201 USB Host COM3202 PIC18 Peri. MCU2121 16-bit Peri. MCU3121

New to Microchip
New to PIC18 New to PIC24

New to USB

USB Device Ap. USB Emb. Host

2012 Microchip Technology Incorporated. All Rights Reserved.

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

Available development resources


1646 USB7 Slide 90

2012 Microchip Technology Incorporated. All Rights Reserved.

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!!

2012 Microchip Technology Incorporated. All Rights Reserved.

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.

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.

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

93

Device Types

A Device

Device plugged into the A side of a cable. Starts out as the host

B Device

Device plugged into the B side of a cable. Starts out as a peripheral


1646 USB7 Slide 94

2012 Microchip Technology Incorporated. All Rights Reserved.

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

Built into PIC24F and PIC32MX devices with USB OTG


1646 USB7 Slide 95

2012 Microchip Technology Incorporated. All Rights Reserved.

Mechanical

Pin 1

Micro A/B Receptacle


Pin 1: VBus Pin 2: DPin 3: D+ Pin 4: ID Pin 5: GND


1646 USB7 Slide 96

2012 Microchip Technology Incorporated. All Rights Reserved.

Mechanical

Pin 1

Micro B Receptacle

Pin 1: VBus Pin 2: DPin 3: D+ Pin 4: ID Pin 5: GND


1646 USB7 Slide 97

2012 Microchip Technology Incorporated. All Rights Reserved.

Mechanical

Micro A Plug

Pin 1

Pin 1: VBus Pin 2: DPin 3: D+ Pin 4: GND (ID) Pin 5: GND


1646 USB7 Slide 98

2012 Microchip Technology Incorporated. All Rights Reserved.

Mechanical

Micro B Plug

Pin 1

Pin 1: VBus Pin 2: DPin 3: D+ Pin 4: Floating (ID) Pin 5: GND


1646 USB7 Slide 99

2012 Microchip Technology Incorporated. All Rights Reserved.

OTG Cable Example


Micro A Plug

Micro A/B

Micro B Plug

Micro A/B

Host

Peripheral

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

100

OTG Cable Example


Micro B Plug Micro A Plug

Micro A/B

Micro A/B

Peripheral

Host

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

101

OTG Cable Example


Micro A Plug

Micro A/B

Micro B Plug

Micro B

Host

Peripheral

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

102

OTG Cable Example


Micro B Plug Micro A Plug

Micro A/B

Micro B

Peripheral

DOESNT FIT!!

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

Targeted Peripheral List (TPL)

List of supported devices for that embedded host and OTG

Devices not on that list will not be able to enumerate

Manufacturer, Model, and Description are minimally required

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

105

OTG Descriptor

Returned in the GetDescriptor(Configuration) request


Required only if B-Device supports any OTG specific features Tells the host (A-Device) what the B-Device is capable of

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

107

Session Request Protocol (SRP)

Saves power on A-Device

B-Device needs way to request VBUS from A-Device


The time between the VBUS rising above the valid threshold until it drops below the valid threshold again

Session

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

108

Session Request Protocol (SRP)

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

109

Session Request Protocol (SRP)

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

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

110

Session Request Protocol (SRP) D+ Pulsing


A-Device Driving A-Device Pull-Downs
1 2 3 4

B-Device Driving B-Device Pull-ups


5 6

VIH D+ VIL

VIH
Vbus VIL
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7 Slide 111

Host Negotiation Protocol (HNP)

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

Host Negotiation Protocol (HNP)

HNP allows devices to switch roles without having to switch cable


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

Host Peripheral Host


2012 Microchip Technology Incorporated. All Rights Reserved.

HNP Session End


1646 USB7

Peripheral Host Peripheral


Slide 113

Set Feature Requests

Lets the B-device know that the A-Device supports HNP


Can be set in the default, address, or configured states Only cleared at the end of a session or on a bus reset

Clear feature does not work on these features

If HNP is not supported on the B-Device, then it should STALL on any of these Set Feature requests
1646 USB7 Slide 114

2012 Microchip Technology Incorporated. All Rights Reserved.

Host Negotiation Protocol (HNP)


1) 2) 3)

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 Host Bus Traffic


B Host Bus Traffic

A-Device Driving
A-Device Pull-Downs A-Device Pull-ups

B-Device Driving
B-Device Pull-ups

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

115

Host Negotiation Protocol (HNP)


5) 6) 7) 8)

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 Host Bus Traffic


B Host Bus Traffic

A-Device Driving
A-Device Pull-Downs A-Device Pull-ups

B-Device Driving
B-Device Pull-ups

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

116

Attach Detection Protocol (ADP)

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

2012 Microchip Technology Incorporated. All Rights Reserved.

Attach Detection Protocol (ADP)

A B-device shouldnt try to start a new session until it determines that the A-Device isnt ADP probing anymore (called ADP sensing)

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

118

Attach Detection Protocol (ADP)


Micro A/B Receptacle VBUS C1 DD+ ID GND V

I = C1 * dV/dT I is constant C1 is constant Thus dV/dT is constant

T
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7 Slide 119

Attach Detection Protocol (ADP)


Micro A/B Receptacle VBUS C1 DD+ ID GND Micro A/B Receptacle VBUS DD+ ID GND C2

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

Current Sourcing Requirements

A-Devices supporting loads <= 100mA


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

A-Devices supporting loads > 100mA

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

121

Current Draw Limits

Dual Role Device

Unconfigured: 150uA average over 1ms


Unconfigured: 8mA average over 1ms

Peripheral Only

2012 Microchip Technology Incorporated. All Rights Reserved.

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

As compared to CHST_VBUS > 120F

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

OTG vs. Embedded Host


OTG
SRP
HNP ADP Targeted Peripheral list Mechanical Electrical

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

2012 Microchip Technology Incorporated. All Rights Reserved.

Agenda

Overview Mechanical Protocol Electrical Certification Considerations Resources (Examples, Classes, Software, etc.)
1646 USB7 Slide 126

2012 Microchip Technology Incorporated. All Rights Reserved.

Certification Considerations Embedded Host


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

2012 Microchip Technology Incorporated. All Rights Reserved.

Certification Considerations OTG

Checklists

OTG Peripheral Systems

SRP HNP TPL Power restrictions

Unconfigured power
1646 USB7 Slide 128

2012 Microchip Technology Incorporated. All Rights Reserved.

Certification Considerations DRD

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

2012 Microchip Technology Incorporated. All Rights Reserved.

Embedded Host Example Circuit Full size A


PIC24F or PIC32MX USB device
5v PPTC

Receptacle

VBUS
3.3v VUSB .1F A/D 150F

D2K 2K D+ GND

DD+

2012 Microchip Technology Incorporated. All Rights Reserved.

1646 USB7

Slide

130

OTG Example Circuit


PIC24F or PIC32MX USB device
GPIO GPIO 3.3v

MCP1253
nSHDN PGOOD SELECT VIN C+ C-

10 F

1 F

Micro A/B Receptacle


VBUS DD+

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

DRD Example Circuit


5v

PIC24F or PIC32MX USB device


VUSB

3.3v

PPTC

Full size A Receptacle


150F

.1F A/D

2K 2K

VBUS DD+ GND

VBUS Input 1F

DD+
2012 Microchip Technology Incorporated. All Rights Reserved. 1646 USB7

B, Micro B, or Mini B Receptacle VBUS DD+ GND


Slide 132

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

2012 Microchip Technology Incorporated. All Rights Reserved.

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

2012 Microchip Technology Incorporated. All Rights Reserved.

Você também pode gostar