当前位置:网站首页>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 .
边栏推荐
- Matplotlib 绘制圆环图的两种方法!
- 西电AI专业排名超清北,南大蝉联全国第一 | 2022软科中国大学专业排名
- Add solid state to the computer
- 聊聊大火的多模态项目
- Definition of annotations and annotation compiler
- Simple Android weather app (III) -- city management and database operation
- ArCore支持的设备
- Coordinate system transformation, application in inertial navigation antenna
- Esp8266/esp32 +1.3 "or 0.96" IIC OLED pointer clock
- Audio and video format introduction, encoding and decoding, audio and video synchronization
猜你喜欢

Will the thunderstorm of Celsius be the "Lehman moment" in the field of encryption?

中部“第一城”,网安长沙以何安网?

字符串

DSP online upgrade (3) -- how to burn two projects in the on-chip flash of a DSP chip

Celsius 的暴雷,会是加密领域的“雷曼时刻”吗?

Xidian AI ranked higher than Qingbei in terms of AI major, and Nantah ranked first in China in terms of Software Science in 2022

Matplotlib 绘制圆环图的两种方法!

中国国际电子商务中心与易观分析联合发布:2021年4季度全国网络零售发展指数同比增长0.6%

Float floating layout clear floating

123. deep and shallow copy of JS implementation -- code text explanation
随机推荐
optional类,便利函数,创建Optional,Optional对象操作以及Optional流
leetcode:715. Range module [brainless segmenttree]
如何将MindSpore模型转ONNX格式并使用OnnxRuntime推理---开发测试篇
Odd number of characters exception
How to select embedded hands-on projects and embedded open source projects
poi实现操作生成word表格和操作word中的图表数据
Audio and video format introduction, encoding and decoding, audio and video synchronization
Performance optimization - image compression, loading and format selection
ArCore支持的設備
Start from scratch 10- background management system development
嵌入式软件项目流程、项目启动说明书(示例)
DSP online upgrade (1) -- understand the startup process of DSP chip
Matplotlib 绘制圆环图的两种方法!
[cloud based co creation] enterprise digitalization accelerates "new intelligent manufacturing"
ArCore支持的设备
Signal power spectrum estimation
Equals and hashcode
NLog自定义Target之MQTT
AI越进化越跟人类大脑像!Meta找到了机器的“前额叶皮层”,AI学者和神经科学家都惊了...
js正则-梳理