30.07.2015 Views

Ways to Use USB in Embedded Systems - Embedded Tools GmbH

Ways to Use USB in Embedded Systems - Embedded Tools GmbH

Ways to Use USB in Embedded Systems - Embedded Tools GmbH

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example ConfigurationsFollow<strong>in</strong>g are examples of how <strong>USB</strong> can be utilized <strong>in</strong> the embedded system, for both hostand device. Where performance <strong>in</strong>formation is given, a “medium performance processor” isassumed <strong>to</strong> be a 50-80 MHz ARM7 or ColdFire.PC<strong>Embedded</strong> DevicePC Application<strong>Embedded</strong>ApplicationSerial Port API<strong>USB</strong> Serial/CDC<strong>USB</strong> CDC ClassFunction Driver<strong>USB</strong> Host Stack<strong>USB</strong> Device<strong>USB</strong> HostController Driver<strong>USB</strong> DeviceController DriverSoftware<strong>USB</strong> HostController<strong>USB</strong> DeviceControllerHardware<strong>USB</strong> CableFigure 1: PC <strong>to</strong> Device via <strong>USB</strong> SerialMost new PC’s and lap<strong>to</strong>ps do not provide serial or parallel ports; they have been replacedwith <strong>USB</strong> ports. Hence, connect<strong>in</strong>g a PC <strong>to</strong> embedded device via its RS232 port is no longerpossible. As part of their <strong>USB</strong> host stacks, popular PC operat<strong>in</strong>g systems (W<strong>in</strong>dows, Mac OS,and L<strong>in</strong>ux) <strong>in</strong>clude Communication Class Drivers (CDC). As shown <strong>in</strong> Figure 1, if theembedded device has a Serial/CDC Function Driver then it will look like a serial device <strong>to</strong>the PC. When it is plugged <strong>in</strong>, it will be recognized by the PC OS as a serial device, and itwill be au<strong>to</strong>matically assigned a COM port number. Then, term<strong>in</strong>al emula<strong>to</strong>rs and other serialapplications can communicate with the embedded device without any modification! Hence,we are back <strong>to</strong> where we started, which, <strong>in</strong> this case, is a good th<strong>in</strong>g. This use of <strong>USB</strong> isparticularly good for control and transferr<strong>in</strong>g serial data. Transfer rates of 800 KB/sec arefeasible at full speed and 2500 KB/sec at high speed for medium speed embedded processors.2


PC<strong>Embedded</strong> Device<strong>Embedded</strong>PC ApplicationApplicationFile SystemFile System<strong>USB</strong> MassMass S<strong>to</strong>rageS<strong>to</strong>rage FunctionClass DriverDriverPC <strong>USB</strong> Host<strong>Embedded</strong> <strong>USB</strong>Flash DriverStackDevice Stack<strong>USB</strong> Host<strong>USB</strong> DeviceFlash I/OSoftwareController DriverController DriverDriver<strong>USB</strong> Host<strong>USB</strong> DeviceFlash MemoryHardwareControllerController<strong>USB</strong> CableFigure 2: PC <strong>to</strong> Device via <strong>USB</strong> DiskAnother method <strong>to</strong> connect a PC or lap<strong>to</strong>p <strong>to</strong> an embedded device is for the embedded device<strong>to</strong> emulate a <strong>USB</strong> disk drive. Popular PC operat<strong>in</strong>g systems have built-<strong>in</strong> <strong>USB</strong> mass s<strong>to</strong>rageclass drivers that <strong>in</strong>terface their file systems <strong>to</strong> the <strong>USB</strong> host stack, as shown on the left sideof Figure 2. Add<strong>in</strong>g a mass s<strong>to</strong>rage function driver <strong>to</strong> the embedded device enables it <strong>to</strong> looklike a <strong>USB</strong> disk drive <strong>to</strong> the PC. Also shown, as an example, is how a resident flash memorycan be accessed as a flash disk via the <strong>USB</strong> function driver connected <strong>to</strong> its flash driver. Anyother type of s<strong>to</strong>rage media could be connected, <strong>in</strong>stead, via its own driver.When the embedded device is plugged <strong>in</strong><strong>to</strong> a PC, it is recognized as a disk drive andau<strong>to</strong>matically assigned a drive letter. Thereafter, files can be dragged and dropped <strong>to</strong> andfrom the embedded device as though it were a disk drive. In this example, a PC applicationcould read and write the files on the flash disk. Note that the embedded application uses alocal file system, as shown <strong>in</strong> Figure 2, <strong>to</strong> access the flash disk, itself. This file system must,of course, be W<strong>in</strong>dows-compatible. An important concept <strong>to</strong> understand is that with<strong>in</strong> the PC,the PC’s file system is used and the embedded device merely looks like another disk drive <strong>to</strong>it. This use of <strong>USB</strong> would be particularly good for upload<strong>in</strong>g acquired data files ordownload<strong>in</strong>g new versions of code files.3


PC<strong>Embedded</strong> DeviceWeb BrowserWeb ServerTCP/IP StackTCP/IP StackRNDIS over<strong>USB</strong><strong>USB</strong> RNDISFunction DriverPC <strong>USB</strong> Hoststack<strong>Embedded</strong> <strong>USB</strong>Device StackPC <strong>USB</strong> HostController Driver<strong>USB</strong> DeviceController DriverSoftware<strong>USB</strong> HostController<strong>USB</strong> DeviceControllerHardware<strong>USB</strong> CableFigure 3: Web Server Access via <strong>USB</strong> RNDISRNDIS (Remote Network Driver Interface Specification) permits emulat<strong>in</strong>g Ethernet over<strong>USB</strong>. It is not part of the <strong>USB</strong> specification, but a lot of popular PC operat<strong>in</strong>g systemssupport it. As shown <strong>in</strong> Figure 3, add<strong>in</strong>g an RNDIS function driver <strong>to</strong> an embedded deviceallows <strong>in</strong>terfac<strong>in</strong>g its <strong>USB</strong> device stack <strong>to</strong> its TCP/IP stack that, <strong>in</strong> turn, connects <strong>to</strong> its webserver. When the embedded device is plugged <strong>in</strong><strong>to</strong> a PC, its browser will au<strong>to</strong>maticallyconnect <strong>to</strong> the web server <strong>in</strong> the embedded device. Hence, it is possible <strong>to</strong> use a browser <strong>to</strong>access an embedded device’s web server, even when there is no Ethernet connection or it isdifficult <strong>to</strong> access. This can be convenient for field troubleshoot<strong>in</strong>g or configuration us<strong>in</strong>g alap<strong>to</strong>p. The same <strong>in</strong>formation accessed via the network <strong>to</strong> which the embedded device isconnected, can be accessed via <strong>USB</strong>.4


PC<strong>Embedded</strong> DevicePC ApplicationSound ManagerSound SystemAudioInterfaceMIDIInterface<strong>USB</strong> Audio<strong>USB</strong> AudioClass DriverFunction DriverPC <strong>USB</strong><strong>Embedded</strong> <strong>USB</strong>Host StackDevice StackPC <strong>USB</strong> HostController Driver<strong>USB</strong> DeviceController DriverSoundDriverSoftware<strong>USB</strong> HostController<strong>USB</strong> DeviceControllerAudioCodecHardware<strong>USB</strong> CableMicrophoneSpeakerFigure 4: <strong>USB</strong> Audio Device with MIDIThe <strong>USB</strong> Audio Class is def<strong>in</strong>ed such that if a <strong>USB</strong> device follows the specification, a PChost will treat it as a sound card. As shown <strong>in</strong> Figure 4, this is accomplished by add<strong>in</strong>g anaudio function driver <strong>to</strong> the embedded device. This function driver provides both an audio<strong>in</strong>terface and a MIDI (Musical Instrument Digital Interface) <strong>in</strong>terface <strong>to</strong> a sound manager,which <strong>in</strong> turn can connect <strong>to</strong> a microphone, speaker, or other audio gear, such as a musical<strong>in</strong>strument. Thus audio and MIDI streams can be transferred over a <strong>USB</strong> l<strong>in</strong>k rather thanus<strong>in</strong>g audio or MIDI cables. This uses the <strong>USB</strong> isochronous mode of data transfer.5


PC<strong>Embedded</strong> DevicePC ApplicationApplication TaskChannel 3SerialSerialSerialChannel 2Port 3Port 2Port 1Channel 1<strong>USB</strong> CDCPC CDC-ACM DriverFunction DriverPC <strong>USB</strong><strong>Embedded</strong> <strong>USB</strong>Host StackDevice StackPC <strong>USB</strong> HostController Driver<strong>USB</strong> DeviceController DriverUART 1DriverUART 2DriverSoftware<strong>USB</strong> HostController<strong>USB</strong> DeviceControllerExternalDevice 1ExternalDevice 2Hardware<strong>USB</strong> CableFigure 5: <strong>USB</strong> Multi-Port Serial Device with UART and Other ConnectionsIn Figure 1 we exam<strong>in</strong>ed the case of one serial channel over a <strong>USB</strong> connection. However it isactually possible <strong>to</strong> run multiple, <strong>in</strong>dependent serial channels over one <strong>USB</strong> connection. Thisis practical because of the higher speed of <strong>USB</strong>, as noted <strong>in</strong> the Figure 1 discussion. Figure 5shows the block diagram. The CDC ACM class driver <strong>in</strong> the PC is not the native driver thatcomes with the PC OS. It is a special driver that may need <strong>to</strong> be <strong>in</strong>stalled. This driver presentsmultiple virtual COM ports <strong>to</strong> the PC application and it multiplexes the correspond<strong>in</strong>g serialchannels over the <strong>USB</strong> connection.In the embedded device, the <strong>USB</strong> CDC function driver de-multiplexes the serial channels.Note that, <strong>in</strong> this example, one channel goes <strong>to</strong> an application task, which might return certa<strong>in</strong><strong>in</strong>ternal <strong>in</strong>formation, and the other two serial channels connect <strong>to</strong> actual UARTs. Theapplication <strong>in</strong> the PC can communicate with physical devices, (such as modem, bar codereader, pr<strong>in</strong>ter, etc.) connected <strong>to</strong> the UARTs as though they were connected directly <strong>to</strong> serialports on the PC (which we know does not actually have serial ports, anymore). The highthroughput of <strong>USB</strong> makes multiple channels feasible. For example, with a mediumperformance processor and full speed <strong>USB</strong>, a <strong>to</strong>tal bandwidth of 200 KB/sec is achievable.This would support 15 115.2 Kbaud channels, with capacity left over!6


PCPC App 1PC App 2<strong>Embedded</strong> Device<strong>Embedded</strong> ApplicationFile SystemRS232 APIAPIFile SystemCommunicationMass S<strong>to</strong>rageCDC-ACM<strong>USB</strong> Mass S<strong>to</strong>rage<strong>USB</strong> Serial PortDriverDriverFunction DriverFunction Driver<strong>USB</strong> Device Framework<strong>USB</strong> Composite Device FrameworkPC <strong>USB</strong> Host stack<strong>Embedded</strong> <strong>USB</strong> Device StackPC <strong>USB</strong> Host Controller Driver<strong>USB</strong> Device Controller DriverSoftware<strong>USB</strong> Host Controller<strong>USB</strong> Device ControllerHardware<strong>USB</strong> CableFigure 6: <strong>USB</strong> Composite DevicesIt is actually possible for one <strong>USB</strong> device <strong>to</strong> look like multiple <strong>USB</strong> devices <strong>to</strong> a <strong>USB</strong> host,simultaneously. This is made possible by the <strong>USB</strong> Composite Device Framework, as shown<strong>in</strong> Figure 6. The <strong>USB</strong> host (PC <strong>in</strong> this example) will recognize each <strong>USB</strong> device with<strong>in</strong> theembedded device and load its correspond<strong>in</strong>g class driver. In Figure 6 the device looks like a<strong>USB</strong> disk and a serial port. Note that both function drivers are present. This example is afairly common case that is supported by PC OSs. Many possible comb<strong>in</strong>ations are notsupported by PC OSs. This particular one would support an application <strong>in</strong> the PC transferr<strong>in</strong>gfiles and another application allow<strong>in</strong>g an opera<strong>to</strong>r <strong>to</strong> control or configure the embeddeddevice.7


<strong>Embedded</strong> Device<strong>Embedded</strong> ApplicationFile System(FAT or Other)<strong>USB</strong> Mass S<strong>to</strong>rageClass Driver<strong>Embedded</strong> <strong>USB</strong>Host Stack<strong>USB</strong> Host ControllerDriverSoftware<strong>USB</strong> Host Controller<strong>USB</strong> Thumb DriveHardwareFigure 7: <strong>USB</strong> Thumb Drive SupportFigure 7 shows how an embedded device can access a <strong>USB</strong> thumb drive (also called a “<strong>USB</strong>memory stick”). A mass s<strong>to</strong>rage class driver fits between the <strong>USB</strong> host stack and the local filesystem <strong>in</strong> the embedded device. It creates the usual read/write logical address API expectedof media drivers. Naturally the file system must be OS-compatible <strong>in</strong> order <strong>to</strong> exchangethumb drives with a PC. Thumb drives are commonly used <strong>to</strong> transfer data from embeddeddevices <strong>to</strong> PCs or <strong>to</strong> update firmware or configuration sett<strong>in</strong>gs and tables <strong>in</strong> embeddeddevices.8


<strong>Embedded</strong> Device<strong>Embedded</strong> ApplicationTCP/IP Stack<strong>USB</strong> <strong>to</strong> Ethernet ClassDriver<strong>Embedded</strong> <strong>USB</strong>Host Stack<strong>USB</strong> Host ControllerDriverSoftware<strong>USB</strong> Host Controller<strong>USB</strong> <strong>to</strong> Ethernet Adap<strong>to</strong>rHardwareLANFigure 8: <strong>USB</strong> <strong>to</strong> EthernetIf an embedded device already has <strong>USB</strong> host capability, it is possible <strong>to</strong> connect it <strong>to</strong> a localEthernet network us<strong>in</strong>g a <strong>USB</strong> <strong>to</strong> Ethernet adapter. This can be done without add<strong>in</strong>g hardware<strong>to</strong> the embedded device. Figure 8 shows the software required <strong>to</strong> do the job. The <strong>USB</strong> <strong>to</strong>Ethernet class driver <strong>in</strong>terfaces the <strong>USB</strong> host stack <strong>to</strong> a TCP/IP stack <strong>in</strong> the embedded device.This allows some units <strong>to</strong> connect <strong>to</strong> a LAN without the expense of add<strong>in</strong>g Ethernetconnectivity <strong>to</strong> all units. It thus allows greater flexibility <strong>in</strong> meet<strong>in</strong>g cus<strong>to</strong>mer requirementsand saves redesign.9


<strong>Embedded</strong> Device<strong>Embedded</strong> ApplicationTCP/IP Stack802.11 MACWiFi Chipset Driver<strong>Embedded</strong> <strong>USB</strong>Host Stack<strong>USB</strong> Host ControllerDriverSoftware<strong>USB</strong> Host Controller<strong>USB</strong> WiFiWiFi AccessLap<strong>to</strong>pDonglePo<strong>in</strong>tPeer <strong>to</strong> PeerHardwareFigure 9: <strong>USB</strong> <strong>to</strong> WiFiWireless communication is becom<strong>in</strong>g more and more popular. Several vendors are provid<strong>in</strong>g<strong>USB</strong> <strong>to</strong> WiFi (802.11) chipsets which enable systems hav<strong>in</strong>g <strong>USB</strong> host ports <strong>to</strong> add wirelessconnectivity. These chipsets are commercially available <strong>in</strong> what are called “WiFi dongles” or“WiFi keys” and are generally <strong>in</strong>expensive. Figure 9 shows the software needed <strong>in</strong> theembedded device. The 802.11 Media Access Controller provides an Ethernet-like <strong>in</strong>terface <strong>to</strong>the local TCP/IP stack and controls the 802.11 controller <strong>in</strong> the WiFi chipset. The WiFichipset driver controls the <strong>USB</strong> <strong>in</strong>terface <strong>in</strong> the chipset. For security, 802.11 MAC alsoprovides WEP (Wired Equivalency Privacy) or WPA (WiFi Protected Access).Like the <strong>USB</strong> <strong>to</strong> Ethernet capability shown <strong>in</strong> Figure 8, this feature can be added <strong>to</strong> onlysome embedded units, as required. It is very useful <strong>in</strong> the field when a wired connection isnot available or <strong>to</strong>o expensive. Transfer rates of 200 KB/sec are typical for mediumperformance processors.10


<strong>Embedded</strong> Device<strong>Embedded</strong> ApplicationAT Command<strong>USB</strong> CDC-ACMClass Driver<strong>Embedded</strong> <strong>USB</strong>Host Stack<strong>USB</strong> Host ControllerDriverSoftware<strong>USB</strong> Host Controller<strong>USB</strong> ModemHardwarePSTNFigure 10: <strong>USB</strong> Modem Access,If an embedded device already has <strong>USB</strong> host capability, add<strong>in</strong>g a <strong>USB</strong> CDC-ACM classdriver can be used <strong>to</strong> add dialup modem capability <strong>to</strong> the system. This is shown <strong>in</strong> Figure 10.No hardware change is necessary. <strong>USB</strong> modems are available that connect <strong>to</strong> phone l<strong>in</strong>es orconnect wirelessly <strong>to</strong> the PSTN system. Even some cell phones offer <strong>USB</strong> modems thatconnect wirelessly. Hence, this can be a flexible option for connect<strong>in</strong>g <strong>to</strong> an embedded device.It is especially useful when the dialup communication is only needed occasionally. Also, one<strong>USB</strong> modem can be shared between multiple devices <strong>to</strong> save the cost of add<strong>in</strong>g modemhardware. Dialup connections are very useful for long distance communication.11


<strong>Embedded</strong> Device<strong>Embedded</strong> ApplicationSerial ClassDriverCus<strong>to</strong>m ClassDriver 3Cus<strong>to</strong>m ClassDriver 4<strong>Embedded</strong> <strong>USB</strong> Host Stack<strong>USB</strong> Host Controller DriverSoftware<strong>USB</strong> Host ControllerHardwareExternal <strong>USB</strong> HubSerialSerialActua<strong>to</strong>rActua<strong>to</strong>rSensor 1Sensor 234Figure 11: Connection <strong>to</strong> Multiple Sensors and Actua<strong>to</strong>rsFigure 11 shows how an external hub can be used <strong>to</strong> connect an embedded control unit <strong>to</strong>multiple sensors and actua<strong>to</strong>rs. In this diagram, it is assumed that the sensors are serialdevices. They are handled by a serial class driver. The actua<strong>to</strong>rs are assumed <strong>to</strong> be cus<strong>to</strong>mdevices requir<strong>in</strong>g cus<strong>to</strong>m class drivers. A well-structured <strong>USB</strong> host stack permits easilyadd<strong>in</strong>g cus<strong>to</strong>m class drivers. Standard <strong>USB</strong> peripherals, such as pr<strong>in</strong>ters and bar-code readerscould also be added. They would be supported by standard class drivers. For example akeyboard or joystick would be supported by an HID class driver. A gam<strong>in</strong>g mach<strong>in</strong>e is a goodexample of a unit <strong>in</strong>corporat<strong>in</strong>g cus<strong>to</strong>m sensors and actua<strong>to</strong>rs and standard <strong>USB</strong> peripherals.12


Conclusion<strong>USB</strong> usage <strong>in</strong> embedded systems so far has been largely centered on deal<strong>in</strong>g with the loss ofserial and parallel ports on PC’s and lap<strong>to</strong>ps, the loss of parallel <strong>in</strong>terface pr<strong>in</strong>ters, and withcapitaliz<strong>in</strong>g on the low cost and convenience of <strong>USB</strong> thumb drives for transport<strong>in</strong>g<strong>in</strong>formation. However, as we hope this article has shown, <strong>USB</strong> offers many other capabilitiesthat are available <strong>to</strong> solve other problems <strong>in</strong> the embedded space. We expect <strong>to</strong> see these usesgrow <strong>in</strong> the future.Micro Digital’s software supports all of the configurations described <strong>in</strong> this article.Y<strong>in</strong>gbo Hu is the lead developer of smx<strong>USB</strong>D, smx<strong>USB</strong>H, and smxWiFi, as well as smxFSand smxFFS products of Micro Digital Inc. He specializes <strong>in</strong> writ<strong>in</strong>g device drivers forembedded peripherals, such as <strong>USB</strong> and flash, and he has 11 years experience develop<strong>in</strong>greal-time embedded software. He graduated with a Masters Degree from Beij<strong>in</strong>g Universityof Aeronautics and Astronautics.Ralph Moore is the current President and founder of Micro Digital, Inc. He graduated fromCaltech with a Bachelors degree <strong>in</strong> physics long before the first “embedded system” or eventhe first <strong>in</strong>tegrated circuit. He has watched our <strong>in</strong>dustry develop with amazement. Mr. Mooreis also the architect of the smx ® real time multitask<strong>in</strong>g kernel.Copyright © 2008 Micro Digital Inc. All rights reserved. www.smxr<strong>to</strong>s.comsmx is a registered trademark of Micro Digital Inc. smx product names are trademarks of Micro Digital Inc.s:\market<strong>in</strong>g\articles\ways <strong>to</strong> use usb <strong>in</strong> embedded systems.doc 9/17/0813

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!