PSoC 5LP Vendor-Specific USBFS Tutorial

Similar documents
USB Interrupt Transfer Example PSoC 3 / PSoC 5

PSoC Filter Block Tutorial

Universal Serial Bus - USB 2.0

ECE 381 Lab 1a PSoC5 Blinking LED 1. Launch PSoC Creator 3.3 from the star menu

An Introduction to Universal Serial Bus

Bulk endpoints transport data whenever required and reliably; bulk data is acknowledged and therefore fault tolerant.

PSoC Academy: How to Create a PSoC BLE Android App Lesson 3: Configure the BLE Component 1

Read section 8 of this document for detailed instructions on how to use this interface spec with LibUSB For OSX

LibUSB - Create a Solution Without the Class Struggle

BOOTSTRAP YOURSELF WITH LINUX-USB STACK: DESIGN, DEVELOP, DEBUG, AND VALIDATE EMBEDDED USB

Serial Communications

Introducing Android Open Accessories and ADK. Jeff Brown, Erik Gilling, Mike Lockwood May 10, 2011

5.5" HDMI OLED-Display with Capacitive Touchscreen V1.0 SKU:DFR0524

Serial Communications

Trinket Fake USB Serial

ECE 471 Embedded Systems Lecture 30

Firmware Description:

LibUSB: Create a Solution Without the Class Struggle!

Bootloader project Project with a Bootloader Component and communication Component.

Setting Up U P D AT E D 1 / 3 / 1 6

High speed USB interface for digital processor system

USB3DevIP Data Recorder by FAT32 Design Rev Mar-15

CE PSoC 4: Time-Stamped ADC Data Transfer Using DMA

RedBoard Hookup Guide

Bootloader project Project with a Bootloader component and communication component.

Data acquisition from educational plants over USB in GNU/Linux

Wireless USB Periodic Transfer Models. Dan Froelich Intel

//////////////////////////////////////////////////////////////////////////////////

Note that FLIP is an Atmel program supplied by Crossware with Atmel s permission.

ADVANCED OPERATING SYSTEMS USB in a microkernel based operating system

SIMCom_3G_Linux_Driver_Applica tion Note_V1.00

Designing a USB Keyboard with the Cypress Semiconductor CY7C63413 USB Microcontroller

Designing a Low-Cost USB Interface for an Uninterruptable Power Supply with the Cypress Semiconductor CY7C63001 USB Controller

Pico ChipScope Documentation

USB Framework, IP Core and related software Tropea S.E., Melo R.A.

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

crane Documentation Release Globo.com

Use the Status Register when the firmware needs to query the state of internal digital signals.

Raspberry Pi Compute Module

ModusToolbox USB Configurator Guide

How to use Linux driver

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Introduction to USB/LPC23xx

Hacking the Kinect. Created by lady ada. Last updated on :21:33 AM UTC

PDIUSBD11 USB Peripheral with I 2 C Serial Interface

QUIZ Ch.6. The EAT for a two-level memory is given by:

An Universal USB 3.0 FIFO Interface For Data Acquisition

Human Interface Devices: Using Control and Interrupt Transfers

Getting Arduino / XLR8 Setup On Linux

PLX USB Development Kit

Installing the Software

Required software. Mac OS X In this section, you ll find instructions for downloading and configuring the Arduino IDE in Mac OS X.

8051 Intermidiate Development Board. Product Manual. Contents. 1) Overview 2) Features 3) Using the board 4) Troubleshooting and getting help

Hello, and welcome to this presentation of the STM32L4 USB 2.0 Full Speed interface. It covers the features of this interface, which is widely used

USB to Serial Adapter Driver Installation Manual

How to use the PSoC based 16C450 Replacement

PSoC Creator Quick Start Guide

AN0885: EFM8UB Low Energy USB Overview

Application Note: AN00136 USB Vendor Specific Device

Unit 3 and Unit 4: Chapter 4 INPUT/OUTPUT ORGANIZATION

Homework 9: Software Design Considerations

USB INTERFACE AND DRIVER Mentor: Dr. Yann Hang Lee Team Members: Jubin Mehta, Koshik Samota (jmehta3,

Device I/O Programming

manifold Documentation

Full Speed USB (USBFS) Features. General Description. When to Use a USBFS USB Full Speed device interface driver

Fuzzing the USB in your devices

One 32-bit counter that can be free running or generate periodic interrupts

How to decrypt 3ds ROM s: This Guide is STRICTLY for 3DS s that are on firmware s I will go back and make this

ECE Microcontrollers. Serial Peripheral Interface (SPI) & NRF24 Radio

Saleae Device SDK Starting a Device SDK Project on Windows Starting a Device SDK Project on Linux... 7

Getting Started with Apache NiFi Registry

Downloading, Installing, and Configuring Audacity Under OS X

AN PSoC 3 and PSoC 5 SFF-8485 Serial GPIO (SGPIO) Initiator Interface. Application Note Abstract. Introduction

Pico Computing. M 501 / M 503 Getting Started Guide. March 7, Overview 1. 2 System Requirements 1. 3 Ubuntu Linux Configuration 2

USB Complete. The Developer's Guide Fifth Edition. Jan Axelson. Lakeview Research LLC Madison, WI 53704

Atmel 328-Processor for RaspberryPi

Introduction to USB. Alan Ott SCaLE 15x March 2-5, 2017

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Design Of Linux USB Device Driver For LPC2148 Based Data Acquisition System Including GSM.

Base Timer Channel (BT) Features. General Description. When to Use a PDL_BT Component 1.0

Arduino Uno R3 INTRODUCTION

Embedded USB Host/Slave Controller

Pypeline Documentation

PCAN-PCI PCI to CAN Interface. User Manual V2.1.0

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

Renesas 78K/78K0R/RL78 Family In-Circuit Emulation

USB 3.0 Software Architecture and Implementation Issues. Terry Moore, CEO MCCI Corporation

Arduino 01: Installing the Arduino Application and Firmware. Jeffrey A. Meunier University of Connecticut

How to Dual-Boot OS X and Ubuntu

PCAN-cPCI CompactPCI to CAN Interface. User Manual V2.0.0

Understand USB (in Linux)

RETROPIE INSTALLATION GUIDE

EZ-Link (AN2720SC) Single-Chip USB-to-USB Networking Solution FEATURES OVERVIEW

System Reference Guide. PSoC Creator. cy_boot Component v3.40 Document Number: , Rev. *A

PHYS 623 Field Programmable Gate Arrays Laboratory 1

Certified Wireless USB Wire Adapter Model

Device: MOD This document Version: 1.0. Matches module version: v3 [29 June 2016] Date: 23 October 2017

Embedded Driving Me Nuts: Writing a Real Driver In User Space

Making USB Device Drivers Easier Using the HID Class

Module Introduction. Purpose This training module covers 68K/ColdFire Ethernet and USB

Transcription:

PSoC 5LP Vendor-Specific USBFS Tutorial Eric Ponce May 9, 2016 Introduction This tutorial sets up a simple USBFS (USB Full Speed) implementation to echo back sent data on the PSoC 5LP. This example uses Python to interface with the PSoC. PSoC Setup Firstly, create a new project in PSoC Creator for the PSoC 5LP. The supplied example code is called usb_echo. In the TopDesign.cysch file, drag in a USBFS block under Communications-USB. Open the configuration screen by double clicking the component. Change its name to USB. Under Descriptor Root, highlight the Device Descriptor label and set the values as follows: Vendor ID: 0x4B4 o This ID describes the vendor for the USB device. In this case, we ll borrow Cypress s. Vendor ID s are assigned by the USB-IF and cost several thousand dollars a year! Product ID: 0x80 o This describes individual vendor products. 0x80 was arbitrarily chosen. Device Release: 0x00 o Version number. Useful for determining product version when designing USB application and potentially distributing firmware updates

Device Class: 0xFF (Vendor Specific) o Our device does not describe to any of the USB standard device classes so we choose the generic Vendor Specific class. Device Subclass: 0x00 (No subclass) o We aren t taking advantage of subclasses in this application Device Protocol: 0x0 o Since we re vendor specific, this is also arbitrary. Manufacturer String: Cypress o The manufacturer of the PSoC! Product String: usb_echo o Our product s name Now, click Configuration Descriptor and set the values as follows: Configuration String: main o The description of our only configuration. In this case, we called it main Max Power (ma): 50mA

o This value tells the host how much power the device expects to draw. This allows the host to cut off the device in the case of hardware failures resulting in large current draw. Device Power: Bus Powered o Tell the host to give us power Remote Wakeup: Disabled o This application won t use remote wakeup capabilities Onto Alternate Setting 0. Set the values as shown below: Interface String: main o Our only interface, so we ll call it main Class: 0xFF (Vendor-Specific) o Once again, this application doesn t conform to any standard classes, so we ll go with vendor-specific Subclass: 0x00 (No subclass) o No need for subclasses here Protocol: 0x0

o Arbitrarily decided since we re vendor specific Here comes the point where we actually decide how we are going to communicate. Endpoints are unidirectional (except for control transfers) communication channels that can be designated to specific tasks by the driver. In this case we need two endpoints, one for in (into the Host or out from the PSoC), and one for out (out from the Host or into the PSoC), so press the Add Endpoint button. Select the first endpoint and set the settings as follows: Endpoint Number: EP1 o Each interface can have up to 9 endpoints, but endpoint 0 is reserved for control type transfers. Our first endpoint will be endpoint 1. Direction: In o This endpoint will be our means of sending data to the Host PC. Transfer Type: Bulk o There are four transfer types available to endpoints in the USB protocol: Control, Interrupt, Bulk, and Isochronous. Control transfers allow us to perform a variety of command and status operations, such as retrieving all those settings we just set up!

Interrupt transfers are useful for applications with non-periodic data transfers requiring quick attention, much like the microcontroller interrupts you should be familiar with Bulk transfers allow for large bursts of data and has guaranteed delivery and error detection Isochronous transfers involve bounded latency data transfers with no delivery guarantees. Useful with real time data when you don t mind losing a few packets. Max Packet Size: 64 o The maximum size of a packet allowable on this endpoint For endpoint 2, set the following values: Endpoint Number: EP2 Direction: Out Transfer Type: Bulk Max Packet Size: 64 Press okay to save the values and open the design-wide resources file. Navigate to the Clocks tab. Here we will set the clocks to the values required for the tight timing tolerances of USB. Double click the USB_CLK line to open the clock configuration window and set the values described below:

Set the IMO (internal main oscillator) frequency to 24 Mhz +-0.25% Activate 100KHz in the ILO (internal low-frequency oscillator) and select 100KHz to be routed Enable the USB clock Back in the Pins tab, we can leave the USB:Dm and the USB:Dp pins empty so that Creator can select the correct pins for us. Compile the program so that Creator generates the necessary APIs for you and then open main.c. The following code initializes the USB device (and particularly the OUT endpoint) and echoes out and received data. Remember that the OUT endpoint is OUT from the HOST and into the PSoC

#include <project.h> uint8 buffer[512], length; int main() { CyGlobalIntEnable; // Enable interrupts USB_Start(0, USB_3V_OPERATION); // Start the USB peripheral while(!usb_getconfiguration()); // Wait until USB is configured USB_EnableOutEP(2); // Enable our output endpoint (EP2) for(;;){ while(usb_getepstate(2) == USB_OUT_BUFFER_EMPTY); // Wait until we have data length = USB_GetEPCount(2); // Get the length of received data USB_ReadOutEP(2, buffer, length); // Get the data while(usb_getepstate(1)!= USB_IN_BUFFER_EMPTY); // Wait until our IN EP is empty USB_LoadInEP(1, buffer, length); // Echo the data back into the buffer } } Upload the program to the PSoC and move onto the next step. Software Requirements and Setup (Windows 7/10) Ensure that you have Python 3 installed and available in your PATH (i.e. you can run python from the command line) Besides Python, we are also going to need libusb (a C library for interfacing with USB) and PyUSB. We will use libusb to generate a generic driver for our device and then PyUSB and Python to communicate with it. To generate the proper libusb driver, we will use a program called Zadig (http://zadig.akeo.ie/). Download it and run it to be presented the interface below: Then, plug in your device though the USB port (generally not the same port used to program the device) and it should show up in Zadig. Set the driver type to libusb-win32 and press install.

Once the driver is installed, in the windows Device Manager (can be search for in the Start Menu), your device should show up under libusb-win32 device if it installed correctly Now that this device has been successfully installed, we need to install PyUSB. Fortunately, Python comes with a package manager called pip. To install pyusb simply enter the command `pip install pyusb` into your command line.

Software Requirements and Setup (Mac OS X) For Mac OS X it is recommended to use a package manager such as homebrew (http://brew.sh). It will greatly simplify installation of the necessary requirements. This tutorial assumes you have installed homebrew Install python and libusb using the command brew install python3 libusb in your command line. Now that python is installed, you can use pip to install PyUSB. To install PyUSB, run the command pip install pyusb. Software Requirements and Setup (Linux) This tutorial is assuming Ubuntu Linux, but Ubuntu s package manager can be substituted by your Linux distribution s package manager and associated command flags. Ubuntu uses aptget and the install command line flag to signal installation of requested packages. Install python3, pip, and libusb: sudo apt-get install python3 python3-pip libusb-dev Install pyusb using pip: sudo pip3 install pyusb Using Python to talk to the device The following python code should run on all three platforms. The program activates the USB device assigned to our vendor and product ID and finds the IN and OUT endpoints. Then it waits for user input, sends the entered endpoint, and prints out the received input, assuming the received input is of the same size as the sent output. Certain Linux distributions and setups may require a sudo before running the code to give python the necessary privileges to access USB devices.

Here is the python script: import usb.core import usb.util import array # search for our device by product and vendor ID dev = usb.core.find(idvendor=0x4b4, idproduct=0x80) #raise error if device is not found if dev is None: raise ValueError('Device not found') # set the active configuration (basically, start the device) dev.set_configuration() # get interface 0, alternate setting 0 intf = dev.get_active_configuration()[(0, 0)] # find the first (and in this case only) OUT endpoint in our interface epout = usb.util.find_descriptor( intf, custom_match= \ lambda e: \ usb.util.endpoint_direction(e.bendpointaddress) == \ usb.util.endpoint_out) # find the first (and in this case only) IN endpoint in our interface epin = usb.util.find_descriptor( intf, custom_match= \ lambda e: \ usb.util.endpoint_direction(e.bendpointaddress) == \ usb.util.endpoint_in) # make sure our endpoints were found assert epout is not None assert epin is not None print("message: ") t = input() # get the user input i = len(t) epout.write(t) # send it print("received: " + str(epin.read(i))) # receive the echo

Remarks This tutorial borrows heavily from Craig Cheney s 2013 USB tutorial written for 6.115 A more in-depth tutorial for using the PyUSB library (which uses the libusb backend) can be found at https://github.com/walac/pyusb/blob/master/docs/tutorial.rst There are various transfer types to explore that may be more suitable for your application. A good introduction to USB can be found at http://www.beyondlogic.org/usbnutshell/usb1.shtml DMA should also be explored as a more efficient way of moving large amounts of data into and out of the USB communication buffers.