当前位置:网站首页>What USB driver needs to know

What USB driver needs to know

2022-06-21 10:34:00 Longcheng deficit

For personal understanding only , The error of , Welcome to correct .

Hardware aspect :

USB Interface , Four lines , Power Supply 、 Ground plus difference D+ D-

Using differential lines can improve data reliability and speed

Actually , For driver development , Just know so much about the hardware .

however , Contact USB People who , Most people still think USB It's more complicated . This complexity comes from the logical level . To further expand , Add some hardware content :

firstly ,USB It's a serial bus , But the data processed by the computer is based on bytes , Although not necessarily strict parallelism , But at the physical level , That is, close to the bottom of the hardware , The data is converted through serial parallel conversion , And then transmit on the differential line mentioned above . Sending is parallel to serial , Receiving is a serial to parallel recovery .

In general , It is understandable that the underlying physical connection is a reliable channel . As for what is transmitted on this channel , That's it USB The agreement . Just like memory just stores instructions and data , These instructions and data can express more logical meanings through combination .

second , The chip itself is based on USB Purpose of the equipment ( Mass storage 、 keyboard 、 mouse 、 Show 、 The Internet 、 Printing, etc ) Some functions have been realized . Chip based commands 、 state 、 The data register can complete USB Adaptation of the protocol , And finally complete the data transmission . The realization of some functions mentioned here , Including the above-mentioned physical signal level .

The rest can revolve around software .

Software aspect :

The hardware layer lays the foundation for the software , Provide a channel for data transmission , Software should consider how to organize data , Consider further how to comply with USB agreement .

in the light of USB, You need to understand the following concepts :

(1)USB The equipment is divided into host controller and equipment , Undertake the master-slave functions respectively . Generally, the host controller controls the use of the bus .

(2)USB Connection expansion of equipment , Through the hub . The host controller leads out the root HUB, root HUB It can be connected to USB Equipment or USB HUB, however USB Devices cannot be directly connected .

(3) The device information can be obtained through the device descriptor .

(4) The device information can be configured through the configuration descriptor .

(5) The interface can be specified in the configuration descriptor , Each interface corresponds to a logic function , Interfaces are described by interface descriptors .

(6) An interface consists of one or more endpoints . Usually, by default, it has 0 End point No .0 The No. endpoint is often the control endpoint ,USB The host controller passes 0 End point No , Obtain device interface information and configure interfaces .

(7)USB Host controllers generally use other endpoints to complete data transmission , Like input and output .

At the software level , It can be understood in this way :

(1) A physics USB The device consists of multiple logical devices , A logical device provides a specific function .

(2) Logical devices are described through interfaces , Consisting of endpoints .

(3) From a software point of view , Each endpoint forms a logical pipeline with the host controller and its software , The data in the pipeline is continuous and meaningful .

(4) The physical hardware connection may be transmitting data from multiple pipelines at the same time , But through a special format , Both hardware and software can distinguish which pipeline the currently transmitted data belongs to .

(5) There are many types of data transmitted in the channel , For example, control transmission 、 Synchronous transmission 、 Interrupt transmission 、 Batch transmission, etc .

(6) The data transmitted in the channel is organized as IRP(IO The request packet ),IRP Consists of transactions , Different transaction composition frames are transmitted through hardware .

for instance , For example, for U Disk speaking , Hardware includes USB Device controller and storage FLASH.USB The equipment controller is responsible for handling USB Agreement related content , Provide commands to the driver 、 state 、 Data register .

(1) When U Insert the disk into the computer , After power on ,USB Firmware pairs in the device USB Configure the device controller , Wait for the query and configuration of the host controller .

(2) When U After the disk is inserted into the computer , The computer host controller will detect USB Device access . according to USB standard , The host controller follows U Discoid 0 Port no. ( Assume U The disk has only one interface ) communicate .

(3) because 0 Data format of port No 、 The functional requirements are defined in the specification , So pass 0 Port no. , The host controller can know what device is currently inserted , What features are supported .

(4) next , The host controller communicates with 0 The channel established by port , Complete the further configuration of the equipment and the establishment of other logic pipelines , For example, data input and data output are two pipelines .

(5)USB The driver at the equipment end is responsible for cooperating with the host controller to complete 0 Interaction of channel No , And establish other channels .

(6) After the interactive work , The computer side should set the USB The device ID is a U disc , And provide the way for the upper software to access the file system . before this ,U The drive at the disk end needs to be set in advance FLASH Format to a file system .

(7) Direction U When writing data on disk , Write the data and address according to USB After the organization is normalized, it is sent by the host controller to through the write channel U Disk controller ,U After the disk driver reads the data and address , Write data through FLASH command ( Generally, it is to erase first and then write ) Write specific blocks and sectors .

(8) When reading U Disk data , The host controller sends the read address through the read channel ,U After the disk driver obtains the command and address , Read FLASH Specific block data , Send it to the host .

In the above process , Yes USB In terms of equipment , Commands that drive access 、 state 、 The data registers are all for USB Bus communication service , Data press USB Packaging required by the specification 、 Unpack 、 Business 、 grouping 、 Frames and so on are completed by hardware , The driver just gets the result through the register .

The host controller side is similar . That is to say, some processes are completed by hardware , Some processes are driven , And it's universal ( such as PC distinguish U disc ), Some processes are device specific , It needs to be written separately .

Based on the above information , Learn more about USB Bare metal drive ( adopt USB Chip manual ), Better understanding of specifications and chips . Based on bare metal drive , And then Linux And other operating system frameworks USB Driver writing , It is relatively easy .

原网站

版权声明
本文为[Longcheng deficit]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221440143563.html