Using USB on the LPC1300 As Simple as Using a UART COMPANY - - PowerPoint PPT Presentation

using usb on the lpc1300
SMART_READER_LITE
LIVE PREVIEW

Using USB on the LPC1300 As Simple as Using a UART COMPANY - - PowerPoint PPT Presentation

Using USB on the LPC1300 As Simple as Using a UART COMPANY CONFIDENTIAL Agenda USB Overview NXP LPC USB Products LPC13XX On-Chip Driver HID/MSD Bootloader Demo Write a Human Interface Device (HID) Flash with Mass Storage Device (MSD)


slide-1
SLIDE 1

COMPANY CONFIDENTIAL

Using USB on the LPC1300

As Simple as Using a UART

slide-2
SLIDE 2

COMPANY CONFIDENTIAL

Agenda

USB Overview NXP LPC USB Products LPC13XX On-Chip Driver HID/MSD Bootloader Demo

Write a Human Interface Device (HID) Flash with Mass Storage Device (MSD) Bootloader

5/16/10 Subject / Department / 22

slide-3
SLIDE 3

COMPANY CONFIDENTIAL 33

USB Review

slide-4
SLIDE 4

COMPANY CONFIDENTIAL 44

What is USB?

USB = Universal Serial Bus, V1.0 Released in 1996 Standard Managed by USB Implementers Forum, Inc. at USB.ORG Designed to Connect Peripherals to PCs Standard Includes: Cabling Characteristics (16 feet maximum) Standardized Connectors Bus Power Standardized Hardware Signaling Standardized Communications Protocol Standard Device Profiles Low Cost Interoperable Simultaneously Supports Many Peripherals Ubiquitous (~8 billion ports, sales about 2 billion/year)

slide-5
SLIDE 5

COMPANY CONFIDENTIAL 55

USB Variants

USB Versions 2.0 2.0 On-The-Go supports host-free connections 3.0 USB Speeds Low (1.5 Mb), Full (12 Mb), Hi (480 Mb) SuperSpeed (3.0), 4.8 Gbit/s Connectors Type A- on Hosts or Hubs, intended to connect devices Type B- on devices Type AB- USB On-The-Go

slide-6
SLIDE 6

COMPANY CONFIDENTIAL

USB Bus Topology

What is on the bus?

One Host. Usually a PC. Zero to 127 Devices. These can respond to In and Out requests from the Host. Zero or more Hubs. These can mux multiple USB devices onto one USB connection.

66

slide-7
SLIDE 7

COMPANY CONFIDENTIAL

USB Bus Terminology

Device Classs Mass Storage, HID, Audio, Printer, more Predefined Profiles Simplify Product Development Pipes, Endpoints, IN & OUT Pipes are Unidirectional Communications Channels between Host and Device Endpoints are Buffers at the Ends of the Pipes Endpoints Are Numbered 0-15 and are IN or OUT OUT: sent by the Host, received by the Device IN: received by the Host, sent by the Device Descriptors List Device capabilities Device, Configuration, Interface, Endpoint, and String Enumeration is the Process of discovering Devices on the bus and reading their Descriptors

77

slide-8
SLIDE 8

COMPANY CONFIDENTIAL 88

Descriptors

Data Structure with a defined format that enables a host to learn about a device and its capabilities. Device Descriptor Configuration Descriptor Interface Descriptor Interface Descriptor

Endpoint Descriptor Endpoint Descriptor Endpoint Descriptor Endpoint Descriptor

slide-9
SLIDE 9

COMPANY CONFIDENTIAL 9

9

Bus Enumeration

Bus enumeration

The process of identifying and configuring USB devices

During enumeration:

Assigning an address Reading “Descriptors” from device Assigning and loading a device driver

Host software responsibility

slide-10
SLIDE 10

COMPANY CONFIDENTIAL 10

10

Enumeration States

Attached:

Hub informs host of device attachment

Powered

Host will wait for 100ms and issues reset

Default

When the reset signal is released, the port has been enabled. The USB device is now in the Default state and can draw no more than 100 mA from VBUS Device responds on Address 0 & Endpoint 0 Device descriptor is fetched

Addressed

Host assigns a unique address to a USB device Hosts collects all other descriptors from a USB device

  • One device descriptor
  • One or more configuration descriptors
  • One or more interface descriptor
  • One or more endpoint descriptors

Configured

Host provides a configuration value to the device

Powered Default Addressed Configured

slide-11
SLIDE 11

COMPANY CONFIDENTIAL 11

11

NXP LPC USB Products

slide-12
SLIDE 12

COMPANY CONFIDENTIAL 12

12

LPC ARM Family Overview

ARM 7

Appl ication Processors

Conne ctivity Industria l Sm a rt Control White goods Se nsors e

  • Me

te ring 16-bit Applica tions Ba tte ry Applica tions

ARM 9 Cor t ex

(Up to 1 MHz) (Up to 8 4 MHz) (Up to 2 7 MHz)

M id- Range

Conne ctivity Industria l Consum e r Me dica l

LPC1000 LPC2000 LPC3000

Focu s Ap p lica tio n s

80C51

C900/LPC700

(Up to 1 8 MHz) ARM7TDMI-S ARM720T (LH7) ARM926EJ -S ARM922T (LH7A) ARM968 (LPC2900) Cortex-M0 Cortex-M3

Low Pow er / M ixed Signal

Industria l Consum e r Me dica l Autom

  • tive
  • bit Fam

il ies

(Up to 120 MHz) Focus Applications

slide-13
SLIDE 13

COMPANY CONFIDENTIAL

LPC ARM USB Product Families

NXP Part USB ARM Flash (kB) RAM (kB) Pins LPC134x Device Cortex M3 16-32 4-8 48 LPC175x,6x OTG Cortex M3 128 to 512 32 to 64 80 LPC214x,5x Device ARM7TDMI 32 to 512 10 to 42 64/100 LPC236x OTG ARM7TDMI 64-512 56 144 LPC247x OTG ARM7TDMI 0-512 48 208 LPC2921,3,5 Device ARM968E 128-512 24-40 100 LPC2927,29,3x OTG ARM968E 512-768 120 144/208 LPC313x,4x,5x HS OTG ARM968EJ 96-192 180/208 LPC318x OTG ARM926EJ 320 LPC32xx OTG ARM926EJ 0-256 296 LH79xxx Device ARM720T 16 176/208 LH7Axxx Host/Device ARM9TDMI 80 256/324

13 13

slide-14
SLIDE 14

COMPANY CONFIDENTIAL 14

14

LPC1000 Family (Cortex-M3/M0)

Functionality

(40-100 MHz) Cortex-M0 Cortex-M3 V2 Cortex-M3 V2

Hi gh Per for mance Low Power Mi xed Si gnal

Powe r Ma na ge m e nt Hum a n Inte rfa ce Ba tte ry Ope ra te d Se nsors Industria l Control Com m unica tion

(40-120 MHz)

slide-15
SLIDE 15

COMPANY CONFIDENTIAL 15

15

LPC134X USB Key Features

Fully compliant with the USB 2.0 specification (full speed) Supports 10 physical (5 logical) endpoints Supports Control, Bulk, Interrupt and Isochronous endpoints Supports SoftConnect feature to allow software to connect and disconnect from USB without re-plugging Double buffer implementation for one Bulk and Isochronous endpoint

slide-16
SLIDE 16

COMPANY CONFIDENTIAL

Click to edit Master text styles

Second level

  • Third level
  • Fourth level
  • Fifth level

LPC134x Block Diagram

Cortex M3 @ 72 MHz (17 mA- 230uA/MHz) 8 kB SRAM, 32 kB Flash 8 ch 10-bit ADC USB 2.0, SSP, I2C, UART Sleep, Deep-Sleep, Deep Power-Down (220 nA) 7x7 mm Package 33 HVQFN & 48 TQFP Simple to Use & Buy

5/16/10 Subject / Department / 16 16

AHB-LITE BUS MATRIX

slide-17
SLIDE 17

COMPANY CONFIDENTIAL 17

17

Low Cost USB Products

Cortex-M3 LPC1300 ARM926 LPC3100 $2.80 @ 10Ku $1.49 @ 10Ku

slide-18
SLIDE 18

COMPANY CONFIDENTIAL 18

18

LPC13XX On-Chip Driver

slide-19
SLIDE 19

COMPANY CONFIDENTIAL 19

19

USB Product Challenges

Implementing USB Device Functions USB Hardware Initialization USB Enumeration Handshake Data Translation/Formatting Responding to USB Overhead

  • Descriptor Requests
  • Configuration Commands
  • Status Reporting

Firmware Updates

  • Bootloader w/ Flash Programming
  • Bootloader Host Software

Getting USB VID/PID Possible Tool Vendor Porting Issues with Silicon Vendor’s Code C Programming Issues with Non-Standard 8-bit Architectures with RAM Banking, Stack Depth Limits, and Incompatible Pointer Types

slide-20
SLIDE 20

COMPANY CONFIDENTIAL 20

20

LPC13XX On-Chip Driver Benefits

Implements USB Device Functions Host Driverless USB Bootloader also On-Chip Up to 6KB Extra Flash Memory for your Product’s Firmware Binary ROM Driver Circumvents Potential Tool Vendor Porting Issues Tested and Validated USB Certified Code Reduces Product Development Risk No Banking, Stack Depth, or Pointer Type Issues

slide-21
SLIDE 21

COMPANY CONFIDENTIAL 21

21

LPC13XX On-Chip Driver Features

Robustness- Bootloader and Driver Stored In ROM Up to 6KB Extra Flash Memory for your Product’s Firmware Bootloader ROM Features: UART In-System Programming Driverless USB In System Programming (MSD) In Application Programming (Flash Programming Library) On Chip USB Driver Features: Clock and Pin Initialization USB Initialization USB Connect USB Interrupt Handler Supported Device Classes: Mass Storage Human Interface Device

slide-22
SLIDE 22

COMPANY CONFIDENTIAL 22

22

LPC13XX USB VID/PID

USB Devices Uniquely Identified by a Vendor ID (VID) and Product ID (PID) Which Are 16-bit Numbers The USB Implementers Forum Assigns VIDs, Which are Required for a USB Logo Vendor ID: $2000 one-time cost USB Logo Licensee: $2000 for a 2-year term USB-IF Membership: $4000/year With your own VID, you may produce 65,536 distinct products For internal or low volume use: Piggyback your Product ID on NXP’s Vendor ID See www.standardics.nxp.com for policy

slide-23
SLIDE 23

COMPANY CONFIDENTIAL 23

23

LPC13XX USB Driver Functions

  • Hardware Initialization
  • Enumeration
  • Endpoint management
  • Status reporting
  • Feature reporting
  • Transmission of

descriptors

  • Configuration

commands

  • Development Time

Savings

  • Quick Time-To-Market
  • Successful Product

Init Connect GetInReport SetOutReport

USB Driver Code Your MCU Firmware Simplified USB API

slide-24
SLIDE 24

COMPANY CONFIDENTIAL 24

24

USB Project Code Size

Flash Code Size in KB Using Keil uVision4 in “default” Optimization

0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 Flash Only Flash + R OM Driver HID MS D

slide-25
SLIDE 25

COMPANY CONFIDENTIAL 25

25

LPC13XX On-Chip USB Bootloader

On-Chip USB Bootloader Implements a Mass Storage Device Can Eliminate a Product Manufacturing Step Works Without Driver Install Creates a Standard Disk Volume Drag-and-Drop Flashing, or Write Your Own App Reads Are Simple, Too

slide-26
SLIDE 26

COMPANY CONFIDENTIAL

How To Enter the USB Bootloader

Apply USB VBUS and…

  • Have Unprogrammed Flash
  • Pull P0.1 Low
  • OR: Call Bootloader from your App (Requires Prior Programming)

Security- Code Read Protection (CRP)

Prevents Copying of Flash Contents JTAG is blocked in all CRP modes CRP1 Allows partial programming CRP2 Allows programming only if whole chip is erased CRP3 ISP (Bootloader) access disabled

  • Caution: If CRP3 is selected, no future factory testing can be performed on the device.

Even NXP can not access the CRP protected flash!

26 26

LPC13XX On-Chip USB Bootloader

slide-27
SLIDE 27

COMPANY CONFIDENTIAL 27

27

HID/MSD Bootloader Demo

Write a Human Interface Device (HID) Flash with Mass Storage Device (MSD) Bootloader

slide-28
SLIDE 28

COMPANY CONFIDENTIAL

LPC13XX HID Device Pseudocode

main() {

  • 1. Initialize LPC13XX chip
  • 2. Set up USB driver
  • 3. Set up Interrupt and In/Out

callbacks

  • 4. Call USB driver connect

}

28 28

slide-29
SLIDE 29

COMPANY CONFIDENTIAL

LPC13XX HID Device Code

29 29

/*

/* Enable Timer32_1 and IOCON clocks */ LPC_SYSCON->SYSAHBCLKCTRL |= (EN_TIMER32_1 | EN_IOCON); /* Use USB PLL and pin init function in ROM */ (*rom)->pUSBD->init_clk_pins();

  • 1. Initialize the LPC13XX chip
slide-30
SLIDE 30

COMPANY CONFIDENTIAL

LPC13XX HID Device Code

30 30

/*

HidDevInfo.idVendor = USB_VENDOR_ID; HidDevInfo.idProduct = USB_PROD_ID; HidDevInfo.bcdDevice = USB_DEVICE; HidDevInfo.StrDescPtr = (uint32_t)&USB_StrDesc[0]; HidDevInfo.InReportCount = 1; // Bytes received HidDevInfo.OutReportCount = 1; // Bytes sent HidDevInfo.InReport = GetInReport; // In callback HidDevInfo.OutReport = SetOutReport; // Out callback HidDevInfo.SampleInterval = 0x20; DeviceInfo.DevType = USB_DEVICE_CLASS_HUMAN_INTERFACE; DeviceInfo.DevDetailPtr = (uint32_t)&HidDevInfo;

(*rom)->pUSBD->init(&DeviceInfo); // Call USB Init

  • 2. Set Up USB Driver

USB String Descriptor

slide-31
SLIDE 31

COMPANY CONFIDENTIAL

LPC13XX HID- String Descriptor

The USB String Descriptor Supplies Extended Device Information to the PC Manufacturer = “NXP SEMICOND” Product = “NXP LPC13XX HID” Serial = “DEMO00000000” Interface[0] = “HID” Actual Descriptor Format (See USB Specification) Uses Unicode Strings C Declaration Style is More Complex than a T ypical String… Modify the Example

31 31

Unicode String

slide-32
SLIDE 32

COMPANY CONFIDENTIAL

LPC13XX HID Device Code

32 32

/*

/* Delegate USB hardware interrupt to on-chip driver */ USB_IRQHandler(void) { (*rom)->pUSBD->isr(); } /* On-chip driver callback: Host request for data */ void GetInReport (uint8_t src[], uint32_t length) { src[0] = LPC_GPIO0->DATA; // Send switch state } /* On-chip driver callback: Data sent by host */ void SetOutReport (uint8_t dst[], uint32_t length) { LPC_GPIO2->DATA = dst[0]; // Set LED state }

  • 3. Write Interrupt and In/Out callbacks
slide-33
SLIDE 33

COMPANY CONFIDENTIAL

LPC13XX HID Device Code

33 33

/*

/* Register In/Out callbacks */ HidDevInfo.InReport = GetInReport; HidDevInfo.OutReport = SetOutReport;

  • 3b. Set Up Interrupt and In/Out callbacks
slide-34
SLIDE 34

COMPANY CONFIDENTIAL

LPC13XX HID Device Code

34 34

/*

(*rom)->pUSBD->connect(TRUE); /* USB Connect */

  • 4. Call USB Driver Connect
slide-35
SLIDE 35

COMPANY CONFIDENTIAL

LPC1300 HID Demo (Keil tools)

35 35

  • Install Keil uVision IDE. Evaluation

available from

www.keil.com/demo/eval/arm.htm

  • Start Keil uVision4 IDE and choose

“Open Project…” from the “Project” menu

  • Open

C:\Keil\ARM\Boards\Keil\MCB1000\ USBHID_rom\USBHID.uvproj

slide-36
SLIDE 36

COMPANY CONFIDENTIAL

LPC1300 HID Demo (Keil tools)

36 36

  • Click “Build”
slide-37
SLIDE 37

COMPANY CONFIDENTIAL

LPC1300 HID Demo (Keil tools)

37 37

  • Plug the MCB1000 into the PC’s USB port
  • Reset the MCB1000 while holding the Boot button.
  • Find the new disk drive labeled CRP DISABLD. This is

the LPC1343 in USB bootloader mode.

  • Delete the old file firmware.bin from this disk drive.
  • Drag C:\Keil\ARM\Boards\Keil\MCB1000\

USBHID_rom\Obj\USBHID.bin onto your CRP DISABLD disk.

  • Reset the MC1000 board.

You should see an LED blinking. This means the application has flashed properly.

Flash the Board!

slide-38
SLIDE 38

COMPANY CONFIDENTIAL

LPC1300 HID Demo (Keil tools)

38 38

  • In Windows, start

C:\Keil\ARM\Utilities\HID_Client\Release\HIDClient.exe

  • Control the LEDs and monitor the pushbutton state
slide-39
SLIDE 39

COMPANY CONFIDENTIAL 39

39

Conclusion

NXP LPC13XX MCUs Ship with Drivers In On-Chip ROM Drivers Implement USB Device Functions USB Bootloader also On-Chip Up to 6KB Extra Flash Memory for your Product’s Firmware Binary ROM Driver Circumvents Potential Tool Vendor Porting Issues Tested and Validated USB Code Reduces Product Development Risk and Firmware Development Time 32-bit Architecture Eases Software Development Headaches

slide-40
SLIDE 40

COMPANY CONFIDENTIAL

5/16/10 Subject / Department / 40 40

Thank you!