nxpusblib September 2012

nxpUSBlib September 2012 nxpUSBlib Progression BSP LPCRoot CDL LPC17xx PDL LPC177x_8x PDL LPC18xx PDL LPC43xx PDL + LPC11Uxx nxpUSBlib emWin ...
Author: Imogene Kennedy
9 downloads 2 Views 2MB Size
nxpUSBlib September 2012

nxpUSBlib Progression BSP

LPCRoot

CDL

LPC17xx PDL LPC177x_8x PDL LPC18xx PDL LPC43xx PDL

+ LPC11Uxx

nxpUSBlib

emWin

Board Chip IP

UDL

LWIP

nxpUSBlib

emWin

FreeRTOS

LPCOpen Platform

2

nxpUSBlib Compiler Switches

nxpUSBlib “Out of Box Experience”

4

Setting up nxpUSBlib with just 6 APIs!

Setup using just 6 APIs: • USB_Init() • *USB_Connect() • _DeviceTask() • _HostTask() • USB_USBTask() • Event_functions()

Events …….

ROM driversHID, MSC, CDC, custom * Device only

5

Overview Features Support demos, boards, chips Where to get started

Features USB 2.0 compliance

Host and device modes Low, full and high speed transfer rates Control, bulk, interrupt and isochronous transfer types

Keil4 and LPCXpresso4 compilers Open source USB library designed to run on all NXP LPC microcontrollers

The library has following limitations: - Can drive only one host or device at a time - Host mode support only one device

- No hub support 7

On-Chip USB ROM Drivers Customer benefits: – Savings of 4kB code space or more – API driven approach – Programming via USB using Mass Storage Class – Ease of use as a Virtual COM port – Custom class benefits

8

nxpUSBlib supports on-chip USB ROM Drivers LPC11U2x/3x LPC134x LPC18xx/43xx

Same API

LPC11U1x LPC17xx

USB Controller Support

Device

Host

Dual-Host Coming Soon!

10

Class Support

HID VCOM

Device Firmware Update (DFU*) MSC

Audio

Smart Card* *DFU, Smart Card Interface coming soon!

11

What is included in nxpUSBlib? Supported controllers – Full-speed, device mode controller – Full-speed, host and device mode controller – High-speed, host and device mode controller – Dual host and device controllers *

Supported transfer types – – – –

Control Bulk Interrupt Isochronous

Supported tool chains – Keil uVision 4 – LPCXpresso 4 – IAR EWARM 6 *

Supported boards (BSP) – LPCXpresso LPC11U1x/2x/3/, LPC1769, LPC1347* and Rev B base board – Hitex LPC1850/4350 Evaluation Board (rev A4) – NGX Xplorer (both LPC1830 and LPC4330) – Keil MCB1000, MCB1700, MCB1800, MCB4300 – Embedded Artists LPC177x/8x/407x/8x

Included examples – – – – – – –

Audio output host and device Audio input device * Keyboard host and device Mass storage host and device Mouse device VCOM device Dual role *

ROM drivers – HS: LPC1800, LPC4300 – FS: LPC11U2x, LPC134x *

*coming soon!

12

Where to get nxpUSBlib? nxpUSBlib website: http://www.lpcware.com/content/project/nxpusblib

Latest version of nxpUSBlib Links to development board vendors Links to compilers/debuggers and other tools Build and configuration documentation Forum

13

Configuring nxpUSBlib \libraries\nxpUSBLib\nxpUSBlibConfig.h /* This option effects only on high speed parts that need to perform fullspeed activities */

#define USB_FORCED_FULLSPEED

0

/* Define USE_USB_ROM_STACK = 1 to use MCU's internal ROM stack, 0 if otherwise */ #define USE_USB_ROM_STACK

0

14

What is available in the download? One zip file: – Full source to a complete USB stack – 10 example applications – Android Accessory project from Embedded Artists – Project files for uVision4 and LPCXpresso 4 – Documentation

15

KeyboardHost

MassStorageDevice

MassStorageHost

MouseDevice

VirtualSerialDevice

IAR Embedded Workbench Keil MCB1000 development board — N/A — LPCXpresso LPC11Uxx on the LPCXpresso Rev B base N/A board N/A N/A Keil MCB1700 development board — — — Keil MCB1800/4300 development board — — — LPC177x_8x on the Embedded Artist OEM RevA basse — board — — LPCXpresso LPC17xx on the LPCXpresso Rev B base N/Aboard N/A N/A Hitex Rev A4 Evaluation Board with LPC1850 — — — NGX Xplorer Evaulation Board (M3 or M4) — — — Element 14 gaming board with LPC4350 — — — Keil uVision Keil MCB1000 development board — N/A  LPCXpresso LPC11Uxx on the LPCXpresso Rev B base N/A board N/A N/A Keil MCB1700 development board    Keil MCB1800/4300 development board    LPC177x_8x on the Embedded Artist OEM RevA basse  board   LPCXpresso LPC17xx on the LPCXpresso Rev B base N/Aboard N/A N/A Hitex Rev A4 Evaluation Board with LPC1850    NGX Xplorer Evaulation Board (M3 or M4)    Element 14 gaming board with LPC4350 LPCXpresso Keil MCB1000 development board — N/A  LPCXpresso LPC11Uxx on the LPCXpresso Rev B base — board N/A  Keil MCB1700 development board    Keil MCB1800/4300 development board    LPC177x_8x on the Embedded Artist OEM RevA basse  board   LPCXpresso LPC17xx on the LPCXpresso Rev B base board   Hitex Rev A4 Evaluation Board with LPC1850    NGX Xplorer Evaulation Board (M3 or M4)    Element 14 gaming board with LPC4350   

KeyboardDevice

GenericHIDDevice

AudioOutputHost

AudioOutputDevice

nxpUSBlib Support demos, boards, chips

Board Coverage

— N/A — — — N/A — — —

N/A N/A — — — N/A — — —

 N/A  — — N/A   —

N/A N/A — — — N/A — — —

— N/A — — — N/A — — —

— N/A — — — N/A — — —

 N/A    N/A  

N/A N/A    N/A  

 N/A    N/A  

N/A N/A    N/A  

 N/A    N/A  

 N/A    N/A  

 N/A  N/A   N/A  N/A                                    

        

16

nxpUSBlib Support demos, boards, chips PART coverage

USB Class coverage USB Class Mass Storage HID (generic) HID (Keyboard) HID (Mouse) CDC/ACM (virtual com) Audio (output) Audio (input) DFU Still Image Capture Printer CCID (smart card) PHDC (medical) UVC (video) *

Host HS + FS — HS + FS — HS + FS FS * — — — — — —

Device HS + FS HS + FS HS + FS HS + FS HS + FS FS HS + FS — — — — — —

Completed on the LPOP branch

Part LPC18xx LPC43xx LPC11U1x LPC175x_6x LPC177x_8x LPC407x_8x LPC1347 LPC11U2x_3x

Host   N/A    N/A N/A

Device        

ROM driver support Part LPC18xx LPC43xx LPC11U2x_3x LPC1347

MSC    

HID   — —

CDC   — —

DFU — — — —

Custom (audio)   — —

17

Directory structure Download file BSP and CDL nxpUSBlib

Download file Each library, ex: emWin, nxpUSBlib,.., has its own folder Ready to go applications

Board Support Package: everything related to board: GPIOs, power… Common Driver Library: supported MCU drivers

Keil multiple project workspace, one-click open all supported nxpUSBlib Keil projects

19

BSP and CDL

-Only selected board is built #define BOARD BOARD_XPLORER4330 - Output is BSP.a or BSP.lib - Include directory: BSP\

- CMSIS and Lib are copied from CMSIS released packages - Only selected MCU is built - Output is CDL.a or CDL.lib - Include directory: CDL\CMSISv2p00_LPCxxxx\inc CDL\LPCxxxxLib\inc

20

nxpUSBlib - Architecture: ARCH_LPC - Attribute: align, weak..

#elif (defined (__LPC18XX__)||defined(__LPC43XX__)) #define USB_CAN_BE_HOST #define __LPC_EHCI__ nxpUSBlib\Drivers\USB\C #define USB_CAN_BE_DEVICE

ore\USBMode.h

#if (USE_USB_ROM_STACK) #define USB_DEVICE_ROM_DRIVER #endif

Process class specific requests - Device: response to standard request. There is a call back rout to specific class control request - Host: state machine to enumerate a connected device, finish when set device configuration

nxpUSBlib configuration

#define MAX_USB_CORE 2 #define USB_PORT_SELECTED(((USB_PORT)>=(MAX_USB_CORE))?1:USB_PORT)

Process device data under register level - Setup USB core - Interrupt service Process host data under register level

- nxpUSBlib references to CDL\CMSISv2p00_LPCxxxx\LPCxxxx.h - Same APIs but different content for specific chips/cores in HCD, HAL, DCD - Output is nxpUSBlib.a or nxpUSBlib.lib - Include: nxpUSBlib\Drivers\USB\

21

Configuring nxpUSBlib \libraries\nxpUSBLib\nxpUSBlibConfig.h /** ARCH is fixed to ARCH_LPC as this library built for NXP MCUs */ #define ARCH

ARCH_LPC

/** Available configuration number in a device */ #define FIXED_NUM_CONFIGURATIONS

1

/** Control endpoint max packet size */ #define FIXED_CONTROL_ENDPOINT_SIZE

64

/** This option only affects high speed parts that need to test full speed activities */ #define USB_FORCED_FULLSPEED

0

/** Define USE_USB_ROM_STACK = 1 to use MCU's internal ROM stack, 0 if otherwise */ #define USE_USB_ROM_STACK

0

/** Define the running USB port* */ #define USB_PORT

0

22

Getting Started with nxpUSBlib

nxpUSBlib Board Support Package (BSP)

LPC1788/4088

24

Build and debug an example application in 4 easy steps Step 1. Import projects Step 2. Configure projects Step 3. Build application Step 4. Debug application

Step 1. Import projects Start LPCXpresso and direct it to the location where you placed the “LPC4330_HID_Workspace” … it would be a good idea to move it from the Flash drive to the desktop Once you browse to the workspace, press the “OK” button

Step 1. Import projects It’s always a good idea to check the project indexer to ensure the settings are correct You can find the index in the following menu: Windows>Preferences>C/C++>Indexer The Build configuration for the indexer should be set to “Use active build configuration” Press the “OK” button

Step 1. Import projects In the Quickstart Panel, there is an Import and Export tab

Within the Import and Export tab, select “Import existing projects” The entire contents of nxpUSBlib is displayed You can select only the ones you want to use, or you can choose everything Here, we select the items we want to use: BSP, CDL, Example, and nxpUSBlib

Select “Finish”

Step 1. Import projects Your Project Explorer should look like this, if you chose only the four key items, however, it may contain more if you imported everything

Step 2. Configure projects Right-click on BSP (Board Support Package) and select: – – – –

Build Configurations-> Manage Select “LPC4330_Xplorer” Press the “Set Active” button Press OK

Step 2. Configure projects Right-click on CDL (Common Driver Library) and select: – – – –

Build Configurations-> Manage Select “LPC43xx_M4” Press the “Set Active” button Press OK

Step 2. Configure projects Right-click on Example_GenericHIDDevice and select: – – – –

Build Configurations-> Manage Select “LPC43xx_M4” Press the “Set Active” button Press OK

Step 2. Configure projects Right-click on nxpUSBlib and select: – – – –

Build Configurations-> Manage Select “LPC43xx_Device” Press the “Set Active” button Press OK

Step 2. Configure projects Right-click on the “Example_GenericHIDDevice” in the Project Explorer, and select “Properties” from the context menu In Properties, under the C/C++ Build->MCU Settings, select LPC4330 Press “OK”

Step 3. Build application Select “Build all projects [Build all projects[LPC43xx]”

Step 4. Debug application

Connect LPC-Link to board with 10-pin cable Pin 1 is marked with red band. Connect the LPC-Link to the PC with the mini USB cable. Plug the micro USB cable into USB0

Step 4. Debug application Select “Debug „Example_GenericHIDDevice‟ [LPC43xx]

Step 4. Debug application The first time you run the project, you may be asked to select which JTAG device (core) to use. You should select Device 1.

Step 4. Debug application There is a utility you can use to send/receive data from the HID device “HID Client” http://www.nxp-lpc.com/updated_materials/USBlib/HIDClient.zip In the drop-down list, you should see “nxpUSBlib Generic HID Demo” Pressing button SW2 on the Xplorer board will send the button press to bit 5 of the input (checked/unchecked) Checking/unchecking outputs 0 and 1 will turn on and off the LEDs on the Xplorer board.

Step 4. Debug application The LPC43xx family of microcontrollers contain USB drivers in ROM. This can save a significant amount of code space, so we are going to use the ROM stack by setting the appropriate bit in the nxpUSBlibConfig.h file, as shown below. You can also decide if you want to use port USB0 or USB1 What is the difference in size when using the USB_ROM_STACK and not using the ROM stack (no optimization)? Without: 26172 With ROM Drivers: 17700 Q. What is the difference between USB0 and USB1? A. USB0 has high-speed USB phy. USB1 requires a ULPI transceiver for highspeed operation.

Another Hands-on Lab

Configure and run the LPC4330 as a mass storage device using nxpUSBlib. Use Keil if you’re adventurous (hint use lpcware for method)!

Why use nxpUSBlib?

Why use nxpUSBlib? Full-featured Open source Runs on all USB capable LPC microcontrollers Offered free of charge when using LPC micros

Support on-chip ROM drivers Easy to use Host and device High-speed and full-speed Why not? 44

Comparison with USB stacks

Significant savings (~50%) using nxpUSBlib + on-chip ROM drivers Limitations with USBHostLite: Supports one class only (Mass storage)

45

Best-in-Class Support from NXP team!

We want to hear from you!

LPCForums

USB http://www.lpcware.com/forums/peripherals-forums/usb

46

Summary

Summary

48

One Stop Shop for USB! Widest range of USB controllers – Full-speed and high-speed USB interfaces available – Device, host and dual host controllers – Certified at USB.org!

FREE USB stacks – nxpUSBlib + other stacks

On-chip ROM drivers – HID, MSC, CDC, Custom class

FREE PID program

49

Where to get started? www.nxp.com/microcontrollers – MCU homepage

www.nxp.com/lpczone – Product updates and training www.nxp.com/lpcxpresso – Low-cost development

www.lpcware.com – Download nxpUSBlib!

50

Appendix

Host operation Main route Enumeration EHCI Control on LPC18xx Non control on LPC18xx

Main Route

53

Enumeration

54

EHCI

55

Control on LPC18xx

56

Non control on LPC18xx

57

Device operation Main route Standard and class request LPC18xx Control on LPC18xx Non control on LPC18xx Configuring nxpUSBlib nxpUSBlib with device ROM stack

nxpUSBlib with device ROM stack

59

Main route

60

Standard and Class Request

61

LPC18xx

typedef struct { /*---------- Word 1: ----------*/ uint32_t : 15; __IO uint32_t IntOnSetup : 1; uint32_t MaxPacketSize : 11; uint32_t : 2; __IO uint32_t ZeroLengthTermination : 1; uint32_t Mult : 2; uint32_t : 0; /*---------- Word 2 ----------*/ uint32_t currentTD; /*---------- Word 3 - 10 ---------*/ __IO DeviceTransferDescriptor overlay; /*---------- Word 11-12 ----------*/ __IO uint8_t SetupPackage[8]; uint16_t TransferCount; uint16_t IsOutReceived; uint16_t reserved[6]; } DeviceQueueHead, *PDeviceQueueHead;

typedef struct { /*---------- Word 1 ----------*/ uint32_t NextTD; /*---------- Word 2 ----------*/ uint32_t : 3; __IO uint32_t TransactionErr : 1; uint32_t : 1; __IO uint32_t BufferErr : 1; __IO uint32_t Halted : 1; __IO uint32_t Active : 1; uint32_t : 2; uint32_t MultiplierOverride : 2; uint32_t : 3; __IO uint32_t IntOnComplete : 1; __IO uint32_t TotalBytes : 15; uint32_t : 0 ; /*---------- Word 3 - 7 ----------*/ uint32_t BufferPage[5]; uint32_t reserved; } DeviceTransferDescriptor, *PDeviceTransferDescriptor

62

Control on LPC18xx

63

Non control on LPC18xx

64