Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

16
Using the PSoC USB Using the PSoC USB March 17, 2012 March 17, 2012 Lloyd Moore, Lloyd Moore, President/Owner President/Owner

Transcript of Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Page 1: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Using the PSoC USBUsing the PSoC USB

March 17, 2012March 17, 2012Lloyd Moore, President/OwnerLloyd Moore, President/Owner

Page 2: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

OverviewOverview

USB BackgroundUSB Background USB Standard ClassesUSB Standard Classes Endpoints and Transfer TypesEndpoints and Transfer Types Enumeration Enumeration USB DescriptorsUSB Descriptors Example ProjectExample Project

Page 3: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

USB BackgroundUSB Background

Star topology, master / slave architectureStar topology, master / slave architecture• Host is the master, initiates all communicationsHost is the master, initiates all communications

Multiple speeds: Low=1.5Mbps, Full=12 Multiple speeds: Low=1.5Mbps, Full=12 Mbps, High=480Mbps, Super=5GbpsMbps, High=480Mbps, Super=5Gbps

Self powered vs. Bus poweredSelf powered vs. Bus powered• Low power: 100mA or 150mA Max (USB 2,3)Low power: 100mA or 150mA Max (USB 2,3)• High power: 500mA or 900mA Max (USB 2,3)High power: 500mA or 900mA Max (USB 2,3)

Vendor Id, Product Id, serial number Vendor Id, Product Id, serial number uniquely identify each deviceuniquely identify each device

Page 4: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Standard USB ClassesStandard USB Classes Used to define the Used to define the

USB device.USB device. Standardizes Standardizes

protocols and protocols and drivers for drivers for common devices.common devices.

Allows operating Allows operating systems to provide systems to provide default drivers.default drivers.

Can also create Can also create vendor specific vendor specific classes for custom classes for custom applications. applications.

AudioAudio Speakers, microphone, MIDISpeakers, microphone, MIDI

Communication (CDC)Communication (CDC) Virtual Serial Port, modem, Virtual Serial Port, modem, EthernetEthernet

Content SecurityContent Security File and resource accessFile and resource access

Firmware Upgrade (DFU)Firmware Upgrade (DFU) Device software upgradesDevice software upgrades

Human Interface (HID)Human Interface (HID) Keyboards, mice, joysticks, Keyboards, mice, joysticks, barcode scanners, UPSbarcode scanners, UPS

IrDA BridgeIrDA Bridge IR communicationsIR communications

Mass StorageMass Storage Hard drives, DVD, flash Hard drives, DVD, flash memorymemory

Personal HealthcarePersonal Healthcare Heart rate, blood pressure, Heart rate, blood pressure, glucose meters, ect.glucose meters, ect.

PrinterPrinter Printers – ya that simple!Printers – ya that simple!

Smart CardSmart Card Phone cards, keyless entryPhone cards, keyless entry

Still Image CaptureStill Image Capture Cameras, scannersCameras, scanners

Test & MeasurementTest & Measurement ADC, DAC, sensors, etc.ADC, DAC, sensors, etc.

VideoVideo Video cameras, web camsVideo cameras, web cams

Page 5: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

EndpointsEndpoints

Uniquely addressable portion of a USB device. Uniquely addressable portion of a USB device. 4 end points max for a low speed device, 16 for 4 end points max for a low speed device, 16 for

other speedsother speeds End point 0 is special, must be present and is End point 0 is special, must be present and is

used for enumeration and controlused for enumeration and control Data transfer happens at end points. Data transfer happens at end points. Simplest way to think about an end point is that it Simplest way to think about an end point is that it

provides an addressable buffer to send and provides an addressable buffer to send and receive data.receive data.

IN refers to dataflow TO the HostIN refers to dataflow TO the Host OUT refers to dataflow FROM the HostOUT refers to dataflow FROM the Host

Page 6: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Transfer TypesTransfer Types

Type Guarantees Typical Use

ControlControl Presence,Presence,

Error FreeError FreeDevice id and Device id and configurationconfiguration

BulkBulk Error FreeError Free Printer, hard Printer, hard drivedrive

InterruptInterrupt LatencyLatency

Error FreeError FreeKeyboard, Keyboard, mousemouse

IsochronousIsochronous Delivery rateDelivery rate Streaming Streaming audio & videoaudio & video

Page 7: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

EnumerationEnumeration

Process by which the host discovers what devices Process by which the host discovers what devices are connected and the properties of those are connected and the properties of those devices. devices.

Utilizes a series of resets and Control transfers to Utilizes a series of resets and Control transfers to end point 0. end point 0.

Each device given a unique address between 1 Each device given a unique address between 1 and 127. and 127.

Power and bandwidth requirements are collected Power and bandwidth requirements are collected and allocated.and allocated.• Device will not be “connected” if resources are not Device will not be “connected” if resources are not

available.available. Communication details collected by way of Communication details collected by way of

“descriptors”“descriptors”

Page 8: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

DescriptorsDescriptors

Data structures which allow the host to Data structures which allow the host to learn about a device and how to learn about a device and how to communicate with it. communicate with it.

Essentially a language which defines the Essentially a language which defines the protocol between the host and each protocol between the host and each device.device.

Can be quite complex but standard Can be quite complex but standard descriptors are well defined. descriptors are well defined.

Standard device drivers can interpret Standard device drivers can interpret these for a wide range of devices. these for a wide range of devices.

Page 9: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Example ProjectExample Project Configure a PSoC 5 to send data from the Configure a PSoC 5 to send data from the

CapSense buttons and slider to a PC in the form CapSense buttons and slider to a PC in the form of a joystick.of a joystick.

Will be using the CY8CKIT-001, and PSoC Will be using the CY8CKIT-001, and PSoC Creator 1.0 for this demo.Creator 1.0 for this demo.• Upgraded LCD display Lumex LCM-S02004DSRUpgraded LCD display Lumex LCM-S02004DSR• If using PSoC Creator 2.0 will also need to add 24Mhz If using PSoC Creator 2.0 will also need to add 24Mhz

crystal to bottom of processor module due to a crystal to bottom of processor module due to a tighter clock requirement.tighter clock requirement.

Data will be shown on LCD as well as sent to PC. Data will be shown on LCD as well as sent to PC. Will be using a “canned” set of code as the Will be using a “canned” set of code as the

configuration is pretty time consuming.configuration is pretty time consuming.

Page 10: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Hardware ConfigurationHardware Configuration

DebugLcd used to control the LCD displayDebugLcd used to control the LCD display CapSense will run the CapSense buttons CapSense will run the CapSense buttons

and slider control for inputand slider control for input• Heavy filtering here as the demo board USB Heavy filtering here as the demo board USB

spews lots of noise to CapSense when running.spews lots of noise to CapSense when running. USBFS – USB 2.0 Full Speed driver, will USBFS – USB 2.0 Full Speed driver, will

configure this to be a Joystick HID device configure this to be a Joystick HID device to send information to the PC.to send information to the PC.

Page 11: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Device DescriptorDevice Descriptor

Walkthrough live configuration of Walkthrough live configuration of descriptor.descriptor.

Page 12: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Clock ConfigurationClock Configuration

IMO = 24.000 MHz

USB = IMOx2

ILO = 100KHz

Page 13: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

USB Initialization CodeUSB Initialization Code

USBFS_Start() configures the USBFS_Start() configures the hardwarehardware

Next we wait while the USB device Next we wait while the USB device goes through enumerationgoes through enumeration

Finally prepare the first set of data to Finally prepare the first set of data to be dropped to the host when be dropped to the host when requestedrequested

Page 14: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Main LoopMain Loop

General operational pattern is to wait for General operational pattern is to wait for Host to grab data currently at the end Host to grab data currently at the end point, then replace it.point, then replace it.

USBFS_bGetEPAckState() waits for grabUSBFS_bGetEPAckState() waits for grab USBFS_LoadInEP() loads next batch of data USBFS_LoadInEP() loads next batch of data

to be grabbed by the hostto be grabbed by the host

Page 15: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

ResourcesResources Book: USB Complete, Fourth EditionBook: USB Complete, Fourth Edition

• Jan AxelsonJan Axelson• ISBN: 978-1-931448-08-6ISBN: 978-1-931448-08-6

PSoC Application notes: AN57294, AN57473, AN58726PSoC Application notes: AN57294, AN57473, AN58726 PSoC Product Web Site:PSoC Product Web Site:

• http://www.cypress.com/?id=1353http://www.cypress.com/?id=1353 PSoC Developer Community:PSoC Developer Community:

• http://www.psocdeveloper.com/forums/http://www.psocdeveloper.com/forums/ PSoC Training On Demand:PSoC Training On Demand:

• http://www.cypress.com/traininghttp://www.cypress.com/training PSoC Full Development Kit (1, 3, 5): $249PSoC Full Development Kit (1, 3, 5): $249

• http://www.cypress.com/?rID=37464http://www.cypress.com/?rID=37464 My Contact Info: My Contact Info:

[email protected]@CyberData-Robotics.com• http://www.CyberData-Robotics.comhttp://www.CyberData-Robotics.com

Page 16: Using the PSoC USB March 17, 2012 Lloyd Moore, President/Owner.

Questions????Questions????

Will be around a bit after the meeting Will be around a bit after the meeting for individual questionsfor individual questions

Feel free to e-mail meFeel free to e-mail me