Title: Firmware for USB 2.0
1(No Transcript)
2Firmware for USB 2.0
- Ryan AugustinNetchip Technology, Inc
- ryan_at_netchip.com
3Agenda
- USB 2.0 device-side programming
- New USB 2.0 features a programmers glossary
- Choosing a chip from a programmers perspective
- Performance fast transfers, race conditions
- Development aids
- Standard tools (USB analyzer)
- Manufacturers Tools and support
- Your Rev 1 board Tips, hints, steps to success
4USB 2.0 Glossary, Features For the Chip
Programmer
- Glossary
- CHIRP - Device/host Whos 2.0, whos 1.1?
- PING - Better way to NAK OUT packets
- Micro-frame - 8 micro-frames per frame
- ? -
- USB 2.0 features for chip programmers
- 480 Mbit/s - 40 times faster than USB 1.1
- Bulk/Int 512 - Bulk and Interrupt MaxPkt now 512
- ISO 1024 - ISO MaxPkt now 1024 (up to 3 per
micro frame)
5USB 2.0 Max Packet Size
6Choosing a Chip Programmers Perspective
- Get involved choosing the chip
- Understand the hardware designers restrictions
- Understand your task
- Can the chip help you and the HW designer?
- Pitfalls e.g. The endianism problem
- Can the chip maker help?
- Development kits
- Support policy
7Choosing a Chip Transfers and Hardware
- Programmed I/O (Firmware transfer loop)
- Transfer Rate One pass of a for loop
- End conditions
- Packet level How much overhead?
- Transfer level ZLPs and dribble bytes
- Write samples (Surprise!)
- DMA
- End conditions
- Deep FIFOs
- The buzz
- Double depth (2 x 512 byte) minimum
- FIFO allotment
8Transfer Firmware Programmed I/O
- IN and OUT transfer firmware
- Interrupt handlers
- Arbitrary length transfers (zero to a zillion1)
- Fast! (any type Iso, Bulk, Interrupt, Control)
- Critical considerations
- End of Transfer handling Short Packets and ZLPs
- Handling asynchronous nature of the USB
- Dribble bytes (on 16 and 32 bit CPUs)
9Transfer Firmware IN Transfer
- Usb_Interrupt() For arbitrary length IN transfer
- Read IntStat Which endpoint interrupted?
- Write EpStat Re-arm endpoint interrupt
- Read EpStat Check for Short Packet
- (Short packet? Finish and return)
- Read EpCount Get available FIFO space
- Copy for loop
- Return from Interrupt
- Deep FIFOs
10Transfer Firmware OUT Transfer
- Usb_Interrupt() For arbitrary length OUT
transfer - Read IntStat Which endpoint interrupted?
- Write EpStat Re-arm endpoint interrupt
- Read EpCount Get FIFO count (in bytes)
- Read EpStat Check for Short Packet
- (Short Packet? Re-read EpCount)
- Copy for loop (32-bit)
- Return from Interrupt
- Short Packet (ZLP) detection
- NAK OUTs after Short Packet
11Transfer Firmware Summary
- Write critical transfer code to find weak spots
- ZLPs
- Dribble bytes
- Race conditions
- See for yourself Get a development kit
12Development Kits
- Development Kit for a USB 2.0 device
- PCI card with NET2290
- Plugged into Windows PC
USB 2.0 Device
NET2290
USB 2.0 Host
USB Cable
13Development Kits Highlights
- Goals of the kit
- Show the chip in action
- Provide a good HW platform for learning firmware
- Provide Ready to port sample source code
- Allows development without hardware
- Develop your firmware without hardware
- Develop host drivers and apps without hardware
- Prove concepts without hardware
- Includes host-side and device-side tools
14Development Kits Device-Side Software Tools
- USB device-side monitor application
- Interactive and intuitive
- Comprehensive command set
- Full control of
- Chip register content
- Transfer content (fill, copy, compare, )
- Transfer size
- EP0 Standard, Vendor Specific Read and Write
- Multiple commands
- Can you repeat that?
15Development Kits Host-Side Software Tools
- USB Host-Side Monitor Application
- Interactive and intuitive
- Comprehensive command set
- Full control over transfers
- Transfer content (fill, copy, compare, )
- Transfer size
- EP0 Standard, Vendor Specific Read and Write
- Multiple commands
- Can you repeat that?
- Loopback tests
16Your New USB 2.0 Device Rev 1 Prototype Board
- Relaxed board dimensions
- Header pins
- Diagnostic serial port
- Room for emulator pod (if applicable)
- Board layout and USB signal quality
17Your New USB 2.0 Device Development Environment
- A good development environment is priceless
- Tools
- USB bus analyzer
- USB host-side program
- printf()
- History()
- Minimal run-time penalty
- Simple It stores a text key and few parameters
- Example History(TxPk, ExpectLen, GotLen, pBuf)
- Call History() anywhere in your code
- Make a HISTORY() macro (add or remove at compile
time) - Examine History memory after problem occurs
18Your New USB 2.0 Device History() Module
- typedef struct _HISTORY_BUF char Text Arg1
Arg2 Arg3 HISTORY_BUF - define HISTORY_ENTRIES 1000 // Number of
historical events - static HISTORY_BUF HistoBufHISTORY_ENTRIES //
History is recorded here - static HistoryCount 0 // Current
historical event - void History(char Text, Arg1, Arg2, Arg3)
- memcpy(HistoBufHistoryCount.Text, Text,
4) // Text key (E.g. TxCo - HistoBufHistoryCount.Arg1 Arg1
- HistoBufHistoryCount.Arg2 Arg2
- HistoBufHistoryCount.Arg3 Arg3
- HistoryCount // Prepare for next event
- if (HistoryCount gt HISTORY_ENTRIES)
- HistoryCount 0 // History rewrites itself
-
- memset(HistoBufHistoryCount, 0,
sizeof(HISTORY_BUF)) // Easy to spot
terminator
19Your New USB 2.0 Device Bringing up the Board
- Take small steps!
- Prove register access
- Prove interrupt subsystem
- Vendor Specific enumeration
- Basic IN and OUT transfers
- Loopback transfers
- Special transfers
- Special enumeration
20Your New USB 2.0 Device Enumeration
- Everything has to work at the same time
- You cant single step (except PDK)
- Things that can cause enumeration failures
- Set Address request (gotcha!)
- Signal quality
- Descriptor content
- and plenty more!
- Use Vendor Specific enumeration first
21Your New USB 2.0 Device - Bringing up the
Board
- Take small steps!
- Prove register access
- Prove interrupt subsystem
- Vendor Specific enumeration
- Basic IN and OUT transfers
- Loopback transfers
- Special transfers (Control, ISO, Interrupt)
- Special enumeration (for class devices)
- Debugger Gotcha
22NET2290 A Few Special Features
- Built-in Standard Request handlers
- Automatic Enumeration
- Class devices must handle Get Configuration
- Self configuring FIFOs
- Ready signal on FIFO access
- and more!
23Question and Answers
?
?
?
?
www.netchip.com
?
?
?
?
24Thank You! From Ryan Augustin and
- NetChip Technology, Inc.
- www.netchip.com