October 11, 20001. 2 Firmware for USB 2.0 Ryan Augustin Netchip Technology, Inc [email protected].

24
October 11, 2000 1

Transcript of October 11, 20001. 2 Firmware for USB 2.0 Ryan Augustin Netchip Technology, Inc [email protected].

October 11, 2000 1

October 11, 2000 2

Firmware for USB 2.0Firmware for USB 2.0

Ryan AugustinRyan AugustinNetchip Technology, IncNetchip Technology, Inc

[email protected]@netchip.com

October 11, 2000 3

AgendaAgenda

USB 2.0 device-side programmingUSB 2.0 device-side programming New USB 2.0 features: a programmer’s glossaryNew USB 2.0 features: a programmer’s glossary Choosing a chip Choosing a chip from a programmer’s perspectivefrom a programmer’s perspective Performance: fast transfers, race conditionsPerformance: fast transfers, race conditions Development aids:Development aids:

– Standard tools (USB analyzer)Standard tools (USB analyzer)– Manufacturer’s Tools and supportManufacturer’s Tools and support

Your “Rev 1” board: Tips, hints, steps to successYour “Rev 1” board: Tips, hints, steps to success

October 11, 2000 4

USB 2.0 Glossary, Features – For the Chip ProgrammerUSB 2.0 Glossary, Features – For the Chip Programmer

GlossaryGlossary CHIRPCHIRP - Device/host: Who’s 2.0, who’s 1.1?- Device/host: Who’s 2.0, who’s 1.1? PINGPING - Better way to NAK OUT packets- Better way to NAK OUT packets Micro-frameMicro-frame - 8 micro-frames per frame- 8 micro-frames per frame ?? - - USB 2.0 features for chip programmersUSB 2.0 features for chip programmers 480 Mbit/s480 Mbit/s - 40 times faster than USB 1.1- 40 times faster than USB 1.1 Bulk/Int: 512Bulk/Int: 512 - Bulk and Interrupt MaxPkt now 512- Bulk and Interrupt MaxPkt now 512 ISO: 1024ISO: 1024 - ISO MaxPkt now 1024 (up to 3 per- ISO MaxPkt now 1024 (up to 3 per

micro frame) micro frame)

October 11, 2000 5

USB 2.0 Max Packet SizeUSB 2.0 Max Packet Size

10241024(1,2 or 3 per µ(1,2 or 3 per µframe)frame)

10231023(one per frame)(one per frame)

ISOISO

64648, 16, 32, 648, 16, 32, 64CONTROL CONTROL (bMaxPacketSize0)(bMaxPacketSize0)

512 / 1024512 / 10248, 16, 32, 648, 16, 32, 64BULK / BULK / INTERRUPTINTERRUPT

USB USB 2.02.0USB USB 1.11.1wMaxPacketSizewMaxPacketSize

October 11, 2000 6

Choosing a Chip –Programmers PerspectiveChoosing a Chip –Programmers Perspective

Get involved choosing the chipGet involved choosing the chip Understand the hardware designer’s restrictionsUnderstand the hardware designer’s restrictions Understand your taskUnderstand your task Can the chip help you and the HW designer?Can the chip help you and the HW designer?

– Pitfalls: e.g. The “endianism” problemPitfalls: e.g. The “endianism” problem Can the chip maker help?Can the chip maker help?

– Development kitsDevelopment kits– Support policySupport policy

October 11, 2000 7

Choosing a Chip –Transfers and HardwareChoosing a Chip –Transfers and Hardware

Programmed I/O (Firmware transfer loop):Programmed I/O (Firmware transfer loop):– Transfer Rate: One pass of a “for” loopTransfer Rate: One pass of a “for” loop– End conditions:End conditions:

Packet level: How much overhead?Packet level: How much overhead? Transfer level: ZLPs and dribble bytesTransfer level: ZLPs and dribble bytes

– Write samples Write samples (Surprise!)(Surprise!) DMADMA

– End conditionsEnd conditions Deep FIFOsDeep FIFOs

– The “buzz”The “buzz”– Double depth (2 x 512 byte) minimumDouble depth (2 x 512 byte) minimum– FIFO allotmentFIFO allotment

October 11, 2000 8

Transfer Firmware –Programmed I/OTransfer Firmware –Programmed I/O

IN and OUT transfer firmware:IN and OUT transfer firmware:– Interrupt handlersInterrupt handlers– Arbitrary length transfers (zero to a zillion+1)Arbitrary length transfers (zero to a zillion+1)– Fast! (any type: Iso, Bulk, Interrupt, Control)Fast! (any type: Iso, Bulk, Interrupt, Control)

Critical considerations:Critical considerations:– End of Transfer handling: Short Packets and ZLPsEnd of Transfer handling: Short Packets and ZLPs– Handling asynchronous nature of the USBHandling asynchronous nature of the USB– ““Dribble” bytes (on 16 and 32 bit CPUs)Dribble” bytes (on 16 and 32 bit CPUs)

October 11, 2000 9

Transfer Firmware –IN TransferTransfer Firmware –IN Transfer

Usb_Interrupt(): For arbitrary length IN transferUsb_Interrupt(): For arbitrary length IN transfer Read IntStat Read IntStat – Which endpoint interrupted? – Which endpoint interrupted? Write EpStat Write EpStat – Re-arm endpoint interrupt – Re-arm endpoint interrupt Read EpStatRead EpStat – Check for Short Packet – Check for Short Packet

(Short packet? Finish and return)(Short packet? Finish and return) Read EpCount – Get available FIFO spaceRead EpCount – Get available FIFO space Copy Copy – “for” loop – “for” loop Return from InterruptReturn from Interrupt

Deep FIFOsDeep FIFOs

October 11, 2000 10

Transfer Firmware –OUT TransferTransfer Firmware –OUT Transfer

Usb_Interrupt(): For arbitrary length OUT transferUsb_Interrupt(): For arbitrary length OUT transfer Read IntStat Read IntStat – Which endpoint interrupted?– Which endpoint interrupted? Write EpStat Write EpStat – Re-arm endpoint interrupt– Re-arm endpoint interrupt Read EpCountRead EpCount – Get FIFO count (in bytes)– Get FIFO count (in bytes) Read EpStatRead EpStat – Check for Short Packet – Check for Short Packet

(Short Packet? Re-read EpCount)(Short Packet? Re-read EpCount)

Copy Copy – “for” loop (32-bit) – “for” loop (32-bit) Return from InterruptReturn from Interrupt

Short Packet (ZLP) detectionShort Packet (ZLP) detection NAK OUTs after Short PacketNAK OUTs after Short Packet

October 11, 2000 11

Transfer Firmware –SummaryTransfer Firmware –Summary

Write critical transfer code to find weak spotsWrite critical transfer code to find weak spots– ZLPsZLPs– Dribble bytesDribble bytes– Race conditionsRace conditions

See for yourself: Get a development kitSee for yourself: Get a development kit

October 11, 2000 12

Development KitsDevelopment Kits

USB 2.0 Host

USB 2.0 “Device”

USB Cable

NET2290

Development Kit for a Development Kit for a USB 2.0 deviceUSB 2.0 device

PCI card with NET2290PCI card with NET2290

Plugged into Windows PCPlugged into Windows PC

October 11, 2000 13

Development Kits –HighlightsDevelopment Kits –Highlights

Goals of the kit:Goals of the kit:– Show the chip in actionShow the chip in action– Provide a good HW platform for learning firmwareProvide a good HW platform for learning firmware– Provide “Ready to port” sample source codeProvide “Ready to port” sample source code

Allows development without hardware:Allows development without hardware:– Develop your firmware without hardwareDevelop your firmware without hardware– Develop host drivers and apps without hardwareDevelop host drivers and apps without hardware– Prove concepts without hardwareProve concepts without hardware

Includes host-side and device-side toolsIncludes host-side and device-side tools

October 11, 2000 14

Development Kits –Device-Side Software ToolsDevelopment Kits –Device-Side Software Tools

USB device-side monitor applicationUSB device-side monitor application Interactive and intuitiveInteractive and intuitive Comprehensive command setComprehensive command set Full control of:Full control of:

– Chip register contentChip register content– Transfer content (fill, copy, compare, …)Transfer content (fill, copy, compare, …)– Transfer sizeTransfer size– EP0: Standard, Vendor Specific; Read and WriteEP0: Standard, Vendor Specific; Read and Write

Multiple commandsMultiple commands Can you repeat that?Can you repeat that?

October 11, 2000 15

Development Kits –Host-Side Software ToolsDevelopment Kits –Host-Side Software Tools

USB Host-Side Monitor ApplicationUSB Host-Side Monitor Application Interactive and intuitiveInteractive and intuitive Comprehensive command setComprehensive command set Full control over transfers:Full control over transfers:

– Transfer content (fill, copy, compare, …)Transfer content (fill, copy, compare, …)– Transfer sizeTransfer size– EP0: Standard, Vendor Specific; Read and WriteEP0: Standard, Vendor Specific; Read and Write

Multiple commandsMultiple commands Can you repeat that?Can you repeat that? Loopback testsLoopback tests

October 11, 2000 16

Your New USB 2.0 Device –Rev 1: Prototype BoardYour New USB 2.0 Device –Rev 1: Prototype Board

Relaxed board dimensionsRelaxed board dimensions Header pinsHeader pins Diagnostic serial portDiagnostic serial port Room for emulator pod (if applicable)Room for emulator pod (if applicable) Board layout and USB signal qualityBoard layout and USB signal quality

October 11, 2000 17

Your New USB 2.0 Device Development EnvironmentYour New USB 2.0 Device Development Environment

A good development environment is A good development environment is pricelesspriceless Tools:Tools:

– USB bus analyzerUSB bus analyzer– USB host-side programUSB host-side program

printf()printf() History()History()

– Minimal run-time penalty Minimal run-time penalty – Simple: It stores a text key and few parameters Simple: It stores a text key and few parameters

Example History(“TxPk”, ExpectLen, GotLen, pBuf);Example History(“TxPk”, ExpectLen, GotLen, pBuf);– Call History() anywhere in your codeCall History() anywhere in your code– Make a HISTORY() macro (add or remove at compile time)Make a HISTORY() macro (add or remove at compile time)– Examine History memory after problem occursExamine History memory after problem occurs

October 11, 2000 18

Your New USB 2.0 Device –History() ModuleYour New USB 2.0 Device –History() Module

typedef struct _HISTORY_BUF { char* Text; Arg1; Arg2; Arg3; } HISTORY_BUFtypedef struct _HISTORY_BUF { char* Text; Arg1; Arg2; Arg3; } HISTORY_BUF#define HISTORY_ENTRIES 1000#define HISTORY_ENTRIES 1000 // Number of historical events// Number of historical eventsstatic HISTORY_BUF HistoBuf[HISTORY_ENTRIES];static HISTORY_BUF HistoBuf[HISTORY_ENTRIES]; // History is recorded here// History is recorded herestatic HistoryCount = 0;static HistoryCount = 0; // Current historical event// Current historical event

void History(char * Text, Arg1, Arg2, Arg3) {void History(char * Text, Arg1, Arg2, Arg3) {memcpy(&HistoBuf[HistoryCount].Text, Text, 4);memcpy(&HistoBuf[HistoryCount].Text, Text, 4); // Text key (E.g. “TxCo”// Text key (E.g. “TxCo”HistoBuf[HistoryCount].Arg1 = Arg1;HistoBuf[HistoryCount].Arg1 = Arg1;HistoBuf[HistoryCount].Arg2 = Arg2;HistoBuf[HistoryCount].Arg2 = Arg2;HistoBuf[HistoryCount].Arg3 = Arg3;HistoBuf[HistoryCount].Arg3 = Arg3;HistoryCount++;HistoryCount++; // Prepare for next event// Prepare for next event

if (HistoryCount >= HISTORY_ENTRIES) {if (HistoryCount >= HISTORY_ENTRIES) {HistoryCount = 0;HistoryCount = 0; // History rewrites itself// History rewrites itself

}}memset(&HistoBuf[HistoryCount], 0, sizeof(HISTORY_BUF));memset(&HistoBuf[HistoryCount], 0, sizeof(HISTORY_BUF)); // “Easy to spot” // “Easy to spot” terminatorterminator

}}

October 11, 2000 19

Your New USB 2.0 Device –Bringing up the BoardYour New USB 2.0 Device –Bringing up the Board

Take small steps!Take small steps! Prove register accessProve register access Prove interrupt subsystemProve interrupt subsystem Vendor Specific enumerationVendor Specific enumeration Basic IN and OUT transfersBasic IN and OUT transfers Loopback transfersLoopback transfers Special transfersSpecial transfers Special enumerationSpecial enumeration

October 11, 2000 20

Your New USB 2.0 Device –EnumerationYour New USB 2.0 Device –Enumeration

Everything has to work at the same timeEverything has to work at the same time You can’t single step (except PDK)You can’t single step (except PDK) Things that can cause enumeration failures:Things that can cause enumeration failures:

– Set Address request (gotcha!)Set Address request (gotcha!)– Signal qualitySignal quality– Descriptor contentDescriptor content

… … and plenty more!and plenty more! Use Vendor Specific enumeration firstUse Vendor Specific enumeration first

October 11, 2000 21

Your New USB 2.0 Device: - Bringing up the BoardYour New USB 2.0 Device: - Bringing up the Board

Take small steps!Take small steps! Prove register accessProve register access Prove interrupt subsystemProve interrupt subsystem Vendor Specific enumerationVendor Specific enumeration Basic IN and OUT transfersBasic IN and OUT transfers Loopback transfersLoopback transfers Special transfers (Control, ISO, Interrupt)Special transfers (Control, ISO, Interrupt) Special enumeration (for class devices)Special enumeration (for class devices)Debugger “Gotcha”Debugger “Gotcha”

October 11, 2000 22

NET2290 –A Few Special FeaturesNET2290 –A Few Special Features

Built-in Standard Request handlers Built-in Standard Request handlers

““Automatic Enumeration”Automatic Enumeration”

Class devices must handle Get Class devices must handle Get ConfigurationConfiguration

Self configuring FIFOsSelf configuring FIFOs Ready signal on FIFO accessReady signal on FIFO access

… … and more!and more!

October 11, 2000 23

??

Question and AnswersQuestion and Answers

www.netchip.comwww.netchip.com?? ?? ?? ??

?? ????

October 11, 2000 24

Thank You! From Ryan Augustin

and…

Thank You! From Ryan Augustin

and…NetChip Technology, Inc.NetChip Technology, Inc.

www.netchip.comwww.netchip.com