Professional Documents
Culture Documents
1544 USB5
Slide
Class Objective
When you finish this class you will be able to:
1544 USB5
Slide
Class Objective
When you finish this class you will be able to:
Add a professional look and feel to the USB
system
Understand some of the ways to improve data
rates
1544 USB5
Slide
Agenda
Function explanations
Single and multiple point acquisitions
Continuous data acquisition
USB descriptor acquisition
1544 USB5
Slide
Class Agenda
1544 USB5
Slide
Principles of
Bidirectional USB
Communication
1544 USB5
Slide
USB Transaction
USB Transaction
Token Packet
Specifies:
Target device address
Endpoint number
Direction of the data transfer
1544 USB5
Slide
USB Transaction - IN
USB Transaction
IN Token Packet
Data Packet
1544 USB5
Slide
USB Transaction - IN
USB Transaction
IN Token Packet
Data Packet
Handshake Packet
Acknowledge - ACK
1544 USB5
Slide
Data Packet
Handshake Packet
1544 USB5
Slide
10
Data Packet
Isochronous transfer
does not guarantee data
integrity. Therefore,
there is no handshake
packet.
Handshake Packet
1544 USB5
Slide
11
1544 USB5
Slide
12
Windows Side
Host PC
Peripheral Device
Default
Pipe
USB Adapter/Controller
Physical Device
Logical Device
Hardware
Hardware
Driver
Specific
Pipes
Embedded System
System Software
User Code
Cable
Bus Interface
Physical Connection
Logical Connection
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
13
Windows USB
Send/Receive Data Packet
Start
Find Device
Open Pipe
Write/Read Data
Close Pipe
SetupDiGetClassDevs
SetupDiEnumDeviceInterfaces
SetupDiGetDeviceInterfaceDetail
Retrieve Device
Information Set for all
devices of specified Class
(if device is present)
MPUSBIsVidPidEqual
SetupDiGetDeviceInterfaceDetail
SetupDiDestroyDeviceInfoList
Clean up
Slide
14
Windows USB
Send/Receive Data Packet
Start
Find Device
Open Pipe
Write/Read Data
Close Pipe
1544 USB5
Slide
15
Windows USB
Send/Receive Data Packet
Start
Find Device
Open Pipe
Write/Read Data
Close Pipe
1544 USB5
Slide
16
Windows USB
Send/Receive Data Packet
Start
Find Device
Open Pipe
Write/Read Data
Close Pipe
1544 USB5
Slide
17
HID vs Custom
Device?
1544 USB5
Slide
18
Custom Device
Yes
Yes
Yes
Yes
HID
No
Yes
No
No
Yes
Yes
Yes
Yes
1.5 MB/s
Yes
Yes
No
No
64 kB/s
Transfer Types
Control
Interrupt
Bulk
Isochronous
Max Speed
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
19
Disadvantages of CDC
CDC Overview
No customization
1544 USB5
Slide
20
Building a Custom
USB System with
VB.Net
1544 USB5
Slide
21
Windows Programming
USB
Communicator
Overview
Written in VB.Net
Class-Based APP
Multithreaded
1544 USB5
Slide
22
Windows Side
Host PC
Peripheral Device
Device-Specific Comm
Default
Pipe
USB Adapter/Controller
Physical Device
Logical Device
Hardware
Hardware
Driver
Specific
Pipes
Embedded System
System Software
User Code
Cable
Bus Interface
Physical Connection
Logical Connection
Ref: http://www.microsoft.com/technet/prodtechnol/wce/support/usbce.mspx
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
23
Windows Side
User Code
1544 USB5
Slide
24
Windows Side
User Code
1544 USB5
Slide
25
Windows Side
MPUSBClass
User Code
1544 USB5
Slide
26
Windows Side
MPUSBClass
User Code
Data
Data
MPUSBAPI.DLL
1544 USB5
Slide
27
Windows Side
Graphical User Interface
Data Processing
Callback Processing
Responses to Windows Events
WM_DEVICECHANGE
All Decision Making
MPUSBClass
User Code
Data
Data
MPUSBAPI.DLL
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
28
Windows Side
Bridge between User APP and
MPUSBAPI.DLL
Easy to use Properties/Methods/Functions
Friendly interface to USB
Functions, such as USB Message Pump,
SendMessage, DeviceIndex, TargetVID_PID
and others.
USB Communicator App
Data
MPUSBClass
User Code
Data
Data
MPUSBAPI.DLL
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
29
Windows Side
Bridge between User APP and Microchip USB
Driver
Low Level Functions:
USB Open/Close Pipe
Low Level Reads/Writes
GetUSBDescriptors
MPUSBClass
User Code
Data
Data
MPUSBAPI.DLL
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
30
Question
Yes
What is the advantage of the APP/Class/DLL interface?
Portability
Flexibility
Code Simplicity:
1. Dim USBDevice As MPUSBClass
2. USBDevice = New MPUSBClass(TxtData, dispDelegate)
3. USBDevice.TargetVID_PID="vid_04d8&pid_000c
4. USBDevice.TargetEP=" \MCHP_EP1
5. USBDevice. DeviceSerialNumber=1033
6. USBDevice.USBListen=True
7. USBDevice.SendCommand(READ_DATA)
Device with SN 1033 will automatically be tracked on the USB bus (even
if other devices with the same VID/PID are plugged into the system.
The communication is only between the Host and this device.
Sub ProcessData is automatically called by the class when USB data
arrives.
1544 USB5
Slide
31
Windows Side
MPUSBClass
User Code
Data
Data
MPUSBAPI.DLL
1544 USB5
Slide
32
User
Code
MPUSBClass
Shared Members
Properties
Events/Delegates
DeviceCount
TargetVID_PID
DevicesAddedRemoved
EnumDevices
TargetEP
DataArrivedCallBack
GetProductString
DeviceSerialNumber
GetMfgString
DeviceInstance
USBListen
Methods
New
Dispose
SendCommand
ReceivePacket
1544 USB5
Slide
33
User
Code
MPUSBClass
Shared Members
Properties
Events/Delegates
DeviceCount
TargetVID_PID
DevicesAddedRemoved
EnumDevices
TargetEP
DataArrivedCallBack
GetProductString
DeviceSerialNumber
GetMfgString
DeviceInstance
USBListen
Methods
New
Dispose
SendCommand
ReceivePacket
1544 USB5
Slide
34
Shared Functions
1544 USB5
Slide
35
Shared Functions
Shared Members
DeviceCount
Vid_Pid - String
Returns a count of devices on USB bus that have
matching VID/PID
EnumDevices
GetProductString
GetMfgString
GetSerialNumber
1544 USB5
Slide
36
Shared Functions
Shared Members
DeviceCount
EnumDevices
GetProductString
GetMfgString
Vid_Pid - String
EndPoint - String
Array of strings, each including: Product String +
SW Ver + Module Instance + SN
Returns True if success
GetSerialNumber
1544 USB5
Slide
37
Shared Functions
Shared Members
DeviceCount
EnumDevices
GetProductString
GetMfgString
GetSerialNumber
Vid_Pid - String
Device Instance - Integer
Returns Device Product String
1544 USB5
Slide
38
Shared Functions
Shared Members
DeviceCount
EnumDevices
GetProductString
Inputs:
GetMfgString
Return:
GetSerialNumber
Vid_Pid - String
Device Instance - Integer
Returns Manufacture String
1544 USB5
Slide
39
Shared Functions
Shared Members
DeviceCount
EnumDevices
GetProductString
GetMfgString
GetSerialNumber
Vid_Pid - String
Device Instance - Integer
Returns Device Serial Number
1544 USB5
Slide
40
Shared Functions
Shared Members
DeviceCount
EnumDevices
GetProductString
GetMfgString
GetSerialNumber
Additional Functions:
QueryDevice Opens In/Out pipe, sends a packet and receives
one back.
SendReceivePacket Sends/Receives a packet through open
In/Out pipes.
GetUSBDescriptor Gets USB Descriptors.
IndexFromSN Finds device with matching SN and returns its
Index.
QueryDevice
SendReceivePacket
GetUSBDescriptor
IndexFromSN
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
41
User
Code
MPUSBClass
Shared Members
Properties
Events/Delegates
DeviceCount
TargetVID_PID
DevicesAddedRemoved
EnumDevices
TargetEP
DataArrivedCallBack
GetProductString
DeviceSerialNumber
GetMfgString
DeviceInstance
USBListen
Methods
New
Dispose
SendCommand
ReceivePacket
1544 USB5
Slide
42
Properties
TargetVID_PID Property (String)
Sets/Returns the VID_PID for the target device.
Properties
Default: vid_04d8&pid_000c
TargetVID_PID
TargetEP
DeviceSerialNumber
DeviceInstance
USBListen
1544 USB5
Slide
43
Properties
Properties
TargetVID_PID
Default: \MCHP_EP1
TargetEP
DeviceSerialNumber
DeviceInstance
USBListen
1544 USB5
Slide
44
Properties
Properties
TargetVID_PID
TargetEP
DeviceSerialNumber
DeviceInstance
USBListen
1544 USB5
Slide
45
Properties
Properties
TargetVID_PID
TargetEP
DeviceSerialNumber
DeviceInstance
USBListen
1544 USB5
Slide
46
Properties
Properties
TargetVID_PID
TargetEP
DeviceSerialNumber
DeviceInstance
USBListen
1544 USB5
Slide
47
User
Code
MPUSBClass
Shared Members
Properties
Events/Delegates
DeviceCount
TargetVID_PID
DevicesAddedRemoved
EnumDevices
TargetEP
DataArrivedCallBack
GetProductString
DeviceSerialNumber
GetMfgString
DeviceInstance
USBListen
Methods
New
Dispose
SendCommand
ReceivePacket
1544 USB5
Slide
48
Events
DeviceAddedRemoved Event
Inputs:
Outputs:
Events/Delegates
None
None
DevicesAddedRemoved
DataArrivedCallBack
None
ArrayData() - Array of Bytes containing the
Arrived Data
1544 USB5
Slide
49
User
Code
MPUSBClass
Shared Members
Properties
Events/Delegates
DeviceCount
TargetVID_PID
DevicesAddedRemoved
EnumDevices
TargetEP
DataArrivedCallBack
GetProductString
DeviceSerialNumber
GetMfgString
DeviceInstance
USBListen
Methods
New
Dispose
SendCommand
ReceivePacket
1544 USB5
Slide
50
Methods
Methods
New Method
Inputs:
UpdateControl - Control used to invoke the
DataArrivedCallBack function.
New
Dispose
DisplayDelegate - DataArrivedCallBack
Delegate. Invoked when new data has
arrived on USB bus.
SendCommand
ReceivePacket
1544 USB5
Slide
51
Methods
Methods
New
Dispose
SendCommand
ReceivePacket
Dispose Method
Inputs:
Outputs:
None
None
1544 USB5
Slide
52
Methods
Methods
New
Dispose
SendCommand
SendCommand
ReceivePacket
Inputs:
Outputs:
1544 USB5
Slide
53
Methods
Methods
New
Dispose
SendCommand
ReceivePacket
ReceivePacket
Inputs:
Outputs:
None
cmdToReceive () - Data Byte Array
1544 USB5
Slide
54
Methods
Methods
New
Dispose
SendCommand
ReceivePacket
USBListenServer
MsgArrived
Private Methods
(Accessible from within the MPUSBClass only)
USBListenServer - The USB Message Pump
MsgArrived - Used to Track WM_DEVICECHANGE
InitializeClass - Called by New Method
DisposeClass - Called by Dispose Method
InitializeClass
DisposeClass
1544 USB5
Slide
55
MPUSBAPI.DLL
MPUSBClass
User Code
Data
Data
MPUSBAPI.DLL
1544 USB5
Slide
56
MPUSBAPI.DLL
MPUSBAPI.DLL
MPUSBGetDLLVersion
MPUSBGetDLLVersion
Input:
None
1544 USB5
Slide
57
MPUSBAPI.DLL
MPUSBAPI.DLL
MPUSBGetDeviceCount
MPUSBGetDLLVersion
Input:
MPUSBGetDeviceCount
1544 USB5
VIDPID - String
Slide
58
MPUSBAPI.DLL
MPUSBAPI.DLL
MPUSBGetDLLVersion
MPUSBGetDeviceCount
MPUSBOpen
MPUSBOpen
Input:
Instance - Device Instance
pVID_PID - String
pEP - String
dwDir - Direction (Read/Write)
dwReserved - Future Use
Returns the handle to the Endpoint Pipe with
matching VID & PID.
1544 USB5
Slide
59
MPUSBAPI.DLL
MPUSBAPI.DLL
MPUSBGetDLLVersion
MPUSBGetDeviceCount
MPUSBOpen
MPUSBRead
MPUSBRead
Input:
handle - Handle to Open Pipe
dwLen - Bytes to Read
dwMilliseconds - Time-out
Output: pData - Data Buffer
pLength - Data Read Length
Returns 0 if failed, 1 if success.
1544 USB5
Slide
60
MPUSBAPI.DLL
MPUSBAPI.DLL
MPUSBGetDLLVersion
MPUSBGetDeviceCount
MPUSBOpen
MPUSBRead
MPUSBWrite
Input:
handle - Handle to Open Pipe
pData - Data Buffer
dwLen - Bytes to Write
dwMilliseconds - Time-out
MPUSBWrite
1544 USB5
Slide
61
MPUSBAPI.DLL
MPUSBAPI.DLL
MPUSBGetDLLVersion
MPUSBGetDeviceCount
MPUSBOpen
MPUSBRead
MPUSBClose
Input:
handle - Handle to Open Pipe
MPUSBWrite
Closes a given handle.
MPUSBClose
1544 USB5
Slide
62
MPUSBAPI.DLL
MPUSBAPI.DLL
MPUSBGetDLLVersion
MPUSBGetDeviceCount
MPUSBOpen
MPUSBRead
MPUSBWrite
MPUSBClose
MPUSBGetDeviceDescriptor
MPUSBGetDeviceDescriptor
Input:
handle - Handle to Open Pipe
pDscParam - Pointer to
GET_DESCRIPTOR_PARAMETER
1544 USB5
Slide
63
MPUSBAPI.DLL
MPUSBAPI.DLL
MPUSBReadInt
Input:
handle - Handle to Open Pipe
dwLen - Bytes to Read
dwMilliseconds - Time-out
MPUSBGetDLLVersion
MPUSBGetDeviceCount
MPUSBOpen
MPUSBRead
MPUSBWrite
MPUSBClose
MPUSBGetDeviceDescriptor
MPUSBReadInt
Slide
64
1544 USB5
Slide
65
Program Requirements
1544 USB5
Slide
66
Windows USB
Single Point Acquisition
Start
Declare USBDevice as
MPUSBClass;
Initialize USBDevice (set
equal to New
MPUSBClass)
Display Data
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Send/Receive
Packet
Slide
67
User
Code
MPUSBClass
Shared Members
Properties
Events/Delegates
DeviceCount
TargetVID_PID
DevicesAddedRemoved
EnumDevices
TargetEP
DataArrivedCallBack
GetProductString
DeviceSerialNumber
GetMfgString
DeviceInstance
USBListen
Methods
New
Dispose
SendCommand
ReceivePacket
1544 USB5
Slide
68
Variable Declarations
Array Declaration
Class Declaration/Usage
MyDev.CustomProperty = Value
MyDev.SendInformation (DataArray)
1544 USB5
Slide
69
Pot Value:
10-bit
LowByte is in Data(1)
HiByte is in Data(2)
Data Returned
1544 USB5
Slide
70
Lab 1
Sequential Single
Point Acquisition
30 Minutes
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
71
Advantages/Disadvantages of Sequential
Send/Receive Packet?
Advantages
Easy to use
Easy to debug
Easy to understand
Disadvantages
1544 USB5
Slide
72
Multithreaded Data
Acquisition
Program Requirements
1544 USB5
Slide
73
Windows USB
Multithreaded Data Acquisition
Start
Initialize Class;
Setup VID/PID,
Instance, EP
Send
Packet
Display
Data
Process Data
1544 USB5
Start USB
Listener
USB Listener Thread
Slide
74
Multithreaded Data
Acquisition
USB Communicator App
Data
User
Code
MPUSBClass
Shared Members
Properties
Events/Delegates
DevicesAddedRemoved
DeviceCount
TargetVID_PID
EnumDevices
TargetEP
GetProductString
GetMfgString
DeviceSerialNumber
4
5
DeviceInstance
USBListen
DataArrivedCallBack
Methods
1
New
Dispose
SendCommand
ReceivePacket
1544 USB5
Slide
75
Multithreaded Data
Acquisition
Helpful Hints
Class Declaration/Initialization
Array Declaration
Use Form1_FormClosing
Subs
Use Form1_Load
Finalization
Initialization
Data Returned
1544 USB5
Slide
76
Lab 2
Multithreaded Data
Acquisition
30 Minutes
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
77
Multiple Devices
Communication
What if:
Solutions
Device Enumeration
Device Serial Number
1544 USB5
Slide
78
Multiple Devices
Communication
MPUSBClass.DeviceCount Number of
devices with matching VID/PID on USB bus
MPUSBClass.EnumDevices Enumerates
devices, Outputs Product String + SW Ver (if
avail) + Module Instance + SN
Example:
1544 USB5
Slide
79
Multiple Devices
Communication
Label
TextBox1:
TextBox
Button:
Resistance
1544 USB5
Slide
80
Multiple Devices
Communication
Check DeviceCount
EnumDevices
Populate ComboBox
Start
Setup VID/PID,
Instance, EP
Send
Packet
Start USB
Listener
Process Data
Display Data
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
81
Multiple Devices
Communication
Helpful Hints
Class Declaration/Initialization
Array Declaration
Data Returned
Use Form1_FormClosing
Subs
Use Form1_Load
Finalization
Initialization
ComboBox
1544 USB5
Slide
82
Lab 3
Multiple Devices
Communication
40 Minutes
Save all your work after you are finished.
Lab 3 code will be reused in Lab 4.
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
83
Multiple Devices
Communication
2.
Sub DevicesChangedMessage()
1544 USB5
Slide
84
Multiple Devices
Communication
Start
Setup VID/PID,
Index
Send
Packet
Check DeviceCount
EnumDevices
Populate ComboBox
Start USB
Listener
Update Device
Instance/SN
Re Enum
Devices
Display Data
2011 Microchip Technology Incorporated. All Rights Reserved.
DevicesAddedRemoved
Event
(WM_DEVICECHANGE )
Process Data
1544 USB5
85
Lab 4
Automatic Device
Enumeration
(Multiple Devices
Communication)
10 Minutes
2011 Microchip Technology Incorporated. All Rights Reserved.
1544 USB5
Slide
86
Adding Commands to
USB Communicator
1544 USB5
Slide
87
Adding Commands
User.H
User.C
Step 3
Test command
1544 USB5
Slide
88
Lab 5
1544 USB5
Slide
89
Customizing Device
usb_descriptors.c
CFG01 structure
VID/PID
USB_DEV_DSC
Serial Number
sd000 structure
Manufacture String
sd001 structure
Product String
sd002 structure
1544 USB5
Slide
90
Data Rate
1544 USB5
Slide
91
1544 USB5
Slide
92
1544 USB5
Slide
93
Summary
1544 USB5
Slide
94
Summary
Function Explanations
Single and Multiple Point Acquisitions
Continuous Data Acquisition
USB Descriptor acquisition
1544 USB5
Slide
95
Summary
1544 USB5
Slide
96
PN: DM163025
1544 USB5
Slide
97
References
http://www.microchip.com/C18
http://www.microchip.com/mplabide
http://www.microsoft.com
1544 USB5
Slide
98
Questions?
1544 USB5
Slide
99
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.
2011, Microchip Technology Incorporated, All Rights Reserved.
1544 USB5
Slide
100