微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32 USB Mass Storage 例程调试笔记

STM32 USB Mass Storage 例程调试笔记

时间:11-20 来源:互联网 点击:

状态阶段。命令阶段是由主机通过批量端点发送一个CBW(命令封装包)的结构,在CBW中定义了要操作的命令以及传输数据的方向和数量,数据阶段的传输方向由命令阶段决定,而状态阶段则总是由设备返回该命令完成的状态。

CBW的结构如下图

官方文档对这些字段的介绍:

dCBWSignature:
Signature that helps identify this data packet as a CBW. The signature field shall contain the value
43425355h (little endian), indicating a CBW.
dCBWTag:
A Command Block Tag sent by the host. The device shall echo the contents of this field back to the
host in the dCSWTag field of the associated CSW. The dCSWTag positively associates a CSW with thecorresponding CBW.
dCBWDataTransferLength:
The number of bytes of data that the host expects to transfer on the Bulk-In or Bulk-Out endpoint (asindicated by the Direction bit) during the execution of this command. If this field is zero, the device andthe host shall transfer no data between the CBW and the associated CSW, and the device shall ignore
bmCBWFlags:
The bits of this field are defined as follows:
Bit 7 Direction - the device shall ignore this bit if the dCBWDataTransferLength field is
zero, otherwise:
0 = Data-Out from host to the device,
1 = Data-In from the device to the host.
Bit 6 Obsolete. The host shall set this bit to zero.
Bits 5..0 Reserved - the host shall set these bits to zero.
bCBWLUN:
The device Logical Unit Number (LUN) to which the command block is being sent. For devices that
support multiple LUNs, the host shall place into this field the LUN to which this command block is
addressed. Otherwise, the host shall set this field to zero.
bCBWCBLength:
The valid length of the CBWCB in bytes. This defines the valid length of the command block. The
only legal values are 1 through 16 (01h through 10h). All other values are reserved.
CBWCB:
The command block to be executed by the device. The device shall interpret the first bCBWCBLength
bytes in this field as a command block as defined by the command set identified by bInterfaceSubClass .
If the command set supported by the device uses command blocks of fewer than 16 (10h) bytes in
length, the significant bytes shall be transferred first, beginning with the byte at offset 15 (Fh). The
device shall ignore the content of the CBWCB field past the byte at offset (15 + bCBWCBLength - 1).

命令封装包CSW

dCSWSignature:
Signature that helps identify this data packet as a CSW. The signature field shall contain the value
53425355h (little endian), indicating CSW.
dCSWTag:
The device shall set this field to the value received in the dCBWTag of the associated CBW.
bCSWStatus:
bCSWStatus indicates the success or failure of the command. The device shall set this byte to zero if
the command completed successfully. A non-zero value shall indicate a failure during command
execution according to the following table:
Value Description
00h Command Passed ("good status")
01h Command Failed
02h Phase Error
03h and 04h Reserved (Obsolete)
05h to FFh Reserved

定义一个缓冲区用来接收命令块封装包CBW,然后进入到数据处理阶段,在数据处理中,对CBW进行解码,返回或者接收响应的数据。数据发送或者接收完毕后,进入到状态阶段,返回命令执行的情况,然后再次进入命令阶段,等待主机发送CBW包。

3.SCSI命令集

小型计算机系统接口(英语:Small Computer System Interface; 简写:SCSI),一种用于计算机和智能设备之间(硬盘、软驱、光驱、打印机、扫描仪等)系统级接口的独立处理器标准。 SCSI是一种智能的通用接口标准。它是各种计算机与外部设备之间的接口标准。

在U盘中经常用到的命令有:INQUIRY、READ CAPACITY 、READ(10)、WRITE(10)命令等。

INQUIRY命令请求查询目标设备的一些基本信息,操作码为0x12,。

READ FORMAT CAPACITIES命令可以让主机读取设备各种可能的格式化容量的列表,如果设备中没有存储设

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top