How to implement USB Host step by step-my practical experience

Source: Internet
Author: User

Some time ago, I made a project to implement the USB function, including USB flash drive reading and writing and using USB mouse and keyboard. After some time, the debugging is finally completed. Now, let's take a look at some key debugging points. On the one hand, we can sort out our own ideas, on the other hand, we hope to give some reference to our fellow colleagues who are doing similar work, and hope to help everyone.

My system is Linux 2.6, and the USB master controller uses Epson's s1r72v17, USB driverCodeProvided by Epson. Before getting started, I first downloaded relevant materials from Epson's website, including Datasheet and hardware design documents and Software Porting documents for this chip. (Data download URL: http://www.epson.jp/device/semicon_e/product/inteRFace/index.htm)

In this project, my main task is to design and debug the hardware and port the Linux 2.6 driver provided by Epson to my system.

The design of the USB hardware system is relatively simple (reference). It is connected to the CPU through the address data bus. In addition, the USB controller has an interrupt signal to connect to the CPU system. S1r72v17 requires three different voltages: 3.3 V, 1.8v, and 5 V. Another part of the circuit is about the USB interface circuit, includingDifferential signal line pairAndOver-Current Protection Circuit. In addition, the 72v17 also requires a clock, which can be provided by a 12 m crystal or a 24 m or 48 m active crystal oscillator.

 

In the process of hardware circuit design, the key is the bus connection method and the cabling of the differential signal line. 72v17 has three bus access modes: 8bits mode, 16 bits be mode, and 16 bits Strobe mode. The be mode requires the CPU to provide the wbel and wbeh signals to access the high and low bytes respectively, in Strobe mode, the CPU needs to provide wrh and WRL signals to access high and low bytes respectively. Pay attention to the following points when wiring the differential signal line pair:

1> differential impedance 90 Euro

2> DM/dp should be as short as possible, so that the signal transmission delay is kept below 1ns

3> the two wires must be parallel and have an equal length.

4> the two PCB layers must be full blocks and cannot be separated.

5> avoid wiring the attachment on these two lines. In particular, high-speed signals and clock signals should be kept away from this line.

6> if you cannot keep straight lines, you can leave the arc at the inflection point to reduce signal reflection.

7> vbus lines must be kept away from DP/DM

8> If the signal line has forks or other devices are connected online, ensure the matching impedance.

9> do not pass through the signal line

10> recommendedAnti-static and Surge Protection Devices

EPSON's website provides 72 v17 driver code under linux2.6.14 and the relevant porting manual. Because my system happens to be 2.6.17, and the driver instruction manual is detailed, it does not take too much effort to transplant the software. Among them, the key isRegister AccessFor others, you only need to follow the porting manual settings.

Is the structure diagram of the USB System in Linux. the USB core and class layers do not need to be modified, and the driver code provided by Epson is the USB host controller driver layer.

The following describes the driver file:

The migration workload of the software is not large. First, you need to change the makefile and kconfig of USB.

Add the following configuration to driver/USB/host/kconfig:

Config usb_v17_hcd

Tristate "s1r72v17 HCD support"

Depends on USB

Default y

Add the following content to driver/USB/makefile:

OBJ-$ (config_usb_v17_hcd) + = Host/

OBJ-$ (config_usb_v17_hcd) + = s1r72v17-hcd.o

 

Then you need to change the system configuration, add in arch/ARM/mach-s3c2410/mach-star.c

 

 // For Epson start  Static   Struct Resource s1r72xxx_ohci_resources [] = {[  0 ] = {. Start = Zero X 28000000  ,. End = 0x2c000000  ,. Flags = Ioresource_mem ,},[  1 ] = {. Start = Irq_eint5,. End = Irq_eint5,. flags = Ioresource_irq ,},};  Static U64 v17_dma_mask = 0 xfffffffful  ;  Static   Struct Platform_device epson_ohci_device = {. Name = "  S1r72v17  "  ,. ID =- 1  ,. Dev = {. Dma_mask = & V17_dma_mask,. coherent_dma_mask = 0 xfffffffful  ,},. Num_resources = Array_size (s1r72xxx_ohci_resources),. Resource = S1r72xxx_ohci_resources ,};  //  For Epson end 

Finally, you must configure the Linux System by Using make menuconfig.

HCd driver Device Drivers->USB support-> <*>V17_hcd support.<*>USB Mass Storage support<>USB Human Interface Device (full hid) Support USB hid Boot Protocol Driver-> <*>USB hidbp keyboard (simple boot) Support<*>USB hidbp mouse (simple boot) Support Device Driver->Block devices<*>Low performance USB Block driver

If there is no problem with register access, you can compile it.

OK! After the compiled image file is down to the Board, the USB function of the system is implemented. Try the USB flash drive. The following information will appear on the Super Terminal.

Bash- 2 . 05a # hub. C: USB New Device connect on bus1/ 1 , Assigned device number 2 Usb_get_device_descriptor !!! Scsi0: SCSI emulation  For  USB mass storage devices vendor: Generic Model: USB flash drive Rev: % Z! Y type: direct -Access ansi scsi Revision: 02 Attached SCSI removable disk SDA at scsi0, Channel  0 , ID 0 , Lun 0 SCSI device SDA: 254720   512 - Byte Hdwr sectors ( 130  MB) SDA: write protect  Is  Offpartition check: SDA: < 7 > USB- Storage: queuecommand () called sda1 sda2 sda3 sda4 

You can use mount to read and write the USB flash disk. In addition, the USB mouse and USB keyboard can also work.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.