依JEDEC eMMC 5.1及经验辛苦整理,付费内容,禁止转载。
所在专栏 《元带你学: eMMC协议详解》
全文 8100字, 主要内容
对eMMC的command进行详细介绍,主要包含如下内容:
(1) emmc命令有哪些
(2) 使用不同命令时要注意的点
(3) command class 分类
(4) command 命令参数和响应格式
1.前言
eMMC 命令很多, 可以分成很多类。比较重要的是class 0/2/4/11。
2.command类型
command类型 | 说明 |
bc | 不带response的广播命令 |
bcr | 带有response的广播命令 |
ac | 点对点无数据传输 |
adtc | 点对点数据传输 |
表 command类型
3. command格式
如上图所示,eMMC Command 由 48 Bits 组成,各个 Bits 的解析如下所示:
表 command格式
- 总长度48bits;
- 固定以起始bit 值0开始,以End Bit 值1结束;
- transmiter bit表示数据的传输方向,1代表从host to device,即写操作, 0 表示 device to host, 即读操作;
- command index 用6个bits指示了command的索引,取值范围0~63;
- argument:有些command需要发送参数,是否需要发送参数依赖于具体的命令;
- CRC7是包含 Start Bit、Transmission Bit、 Command Index 和 Argument 内容的 CRC 校验值。通过CRC7保护,device 端在接收到CMD时同样会计算一个CRC值,如果与host发送的CRC不一致,则被认为是传输错误;
注1:eMMC可能不会支持0~63的所有命令,有些命令可能会不支持
注2: CRC 校验简单来说,是发送方将需要传输的数据“除于”(模2除)一个约定的数,并将得到的余数附在数据上一并发送出去。接收方收到数据后,再做同样的“除法”,然后校验得到余数是否与接收的余数相同。
如果不相同,那么意味着数据在传输过程中发生了改变。扩展阅读 CRC wiki 中的介绍。
Command 线是一跟线,所以在波形上看到这 48 bit 是依次传输的,看波形时, 要找到 Start bit(从高拉低),然后再数对应的bit 数目偏移, 一般偏移 2 个bit, 看对应的Command 是什么,来分析这一段波形的行为。
4. command class 分类
eMMC将command index(0~56)分成12个class,每个class代表一类功能,包含所有commands的一个子集。具体某一个设备支持哪些class的命令,可以通过CSD寄存器的CCC[95:84] feilds来查询,如bit84为1则表示支持class0。
其实一般命令(除了废弃classs)设备都会支持,也不复杂。要关注的是 class 11 Command Queue 命令,有的平台是不支持Command Queue, 这样无法做CMDQ Read 和 CMDQ Write, 智能用普通的Read(CMD16 or CMD17) 和 普通Write(CMD24 or CMD25) 命令,极速性能也会差一些。
对于 Pack Read 和 Pack Write, 虽然协议有这种, 但实际很少遇到。 这个功能不够灵活, 算是鸡肋功能, 但设备一般支持这个特性,只是主机几乎不会用到。所以大家也不要花太多resource 在 Pack Read/Write 上。
device command class | class description | note |
class 0 | basic | 基本命令 |
class 1 | obsolete | 废弃 |
class 2 | block read | 块数据读相关命令,包括设置块长度、读取单块、读取多块 |
class 3 | obsolete | 废弃 |
class 4 | block write | 块数据写相关命令,包括设置块个数、写入单块、写入多块、修改设备id寄存器、修改CSD、设置RTC |
class 5 | erase | 设置擦除组开始地址、设置擦除组结束地址、擦除操作 |
class 6 | write protection | 设置写保护、清除写保护、获取device的写保护状态、获取写保护类型 |
class 7 | lock device | lock/unlock device |
class 8 | application-specific | 指示下一个命令是一个特定应用命令而非标准命令 |
class 9 | I/O mode | 写寄存器、设置系统进入中断模式 |
class 10 | security protocols | 连续传输数据块从device to host或从host to device |
class 11 | command queuing | 执行队列里的任务 |
class 12 | reserved | \ |
表 command分类
以上转载自
https://www.cnblogs.com/smartjourneys/p/6657397.html
5. Command 命令和Response 格式
Basic commands (class 0 and class 1)
CMD0
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
GO_IDLE_STATE | bc | [31:0] 00000000 | None | Resets the Device to idle state |
GO_PRE_IDLE_STATE | bc | [31:0] F0F0F0F0 | None | Resets the Device to pre-idle state |
BOOT_INITIATION | - | [31:0]FFFFFFFA | None | Initiate alternative boot operation |
CMD1
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SEND_OP_COND | bcr | [31:0] OCR without busy | R3 | Asks Device, in idle state, to send its Operating Conditions Register contents in the response on the CMD line. |
CMD2
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
ALL_SEND_CID | bcr | [31:0] stuff bits | R2 | Asks Device to send its CID number on the CMD line |
CMD3
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SET_RELATIVE_ADDR | ac | [31:16] RCA, [15:0] stuff bits | R1 | Assigns relative address to the Device |
CMD4
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SET_DSR | bc | [31:16] DSR, [15:0] stuff bits | - | Programs the DSR of the Device |
CMD5
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SLEEP_AWAKE | ac | [31:16] RCA, [15]Sleep/Awake, [14:0] stuff bits | R1b | Toggles the Device between Sleep state and Standby state. |
CMD6
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SWITCH | ac | [31:26] Set to 0, [25:24] Access, [23:16] Index, [15:8] Value, [7:3] Set to 0, [2:0] Cmd Set | R1b | Switches the mode of operation of the selected Device or modifies the EXT_CSD registers. |
CMD7
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SELECT/DESELECT_CARD | ac | [31:16] RCA, [15:0] stuff bits | R1/R1b | Command toggles a device between the standby and transfer states or between the programming and disconnect states. |
CMD8
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SEND_EXT_CSD | adtc | [31:0] stuff bits | R1 | Device sends its EXT_CSD register as a block of data. |
CMD9
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SEND_CSD | ac | [31:16] RCA, [15:0] stuff bits | R2 | Addressed Device sends its Device-pecific data (CSD) on the CMD line. |
CMD10
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SEND_CID | ac | [31:16] RCA, [15:0] stuff bits | R2 | Addressed Device sends its Device identification (CID) on CMD the line. |
CMD12
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
STOP_TRANSMISSION | ac | [31:16] RCA, [15:1] stuff bits, [0] HPI | R1/R1b | Forces the Device to stop transmission. If HPI flag is set the device shall interrupt its internal operations in a well-defined timing. |
CMD13
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SEND_STATUS | ac | [31:16] RCA, [15] SQS, [14:1] stuff bits, [0] HPI | R1 | In case SQS bit = 0: Addressed Device sends its status register. If HPI flag is set the device shall interrupt its internal operations in a well-defined timing. In case SQS bit = 1: indicate that this is a QSR query. In response device shall send the QSR (Queue Status Register). In this case HPI must be set to ‘0’ |
CMD14
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
BUSTEST_R | adtc | [31:0] stuff bits | R1 | A host reads the reversed bus testing data pattern from a Device. |
CMD15
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
GO_INACTIVE_STATE | ac | [31:16] RCA, [15:0] stuff bits | - | Sets the Device to inactive state |
CMD19
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
BUSTEST_W | adtc | [31:0] stuff bits | R1 | A host sends the bus test data pattern to a Device |
NOTE 1 - CMD7, R1 while selecting from Stand-By State to Transfer State; R1b while selecting from Disconnected State to Programming State.
NOTE 2 - CMD12, RCA in CMD12 is used only if HPI bit is set. The argument does not imply any RCA check on the device side.
NOTE 3 - CMD12, R1 for read cases and R1b for write cases.
Block-oriented read commands (class 2)
CMD16
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SET_BLOCKLEN | ac | [31:0] block length | R1 | Sets the block length (in bytes) for all following block commands (read and write). Default block length is specified in the CSD |
CMD17
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
READ_SINGLE_BLOCK | adtc | [31:0] data address | R1 | Reads a block of the size selected by the SET_BLOCKLEN command |
CMD18
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
READ_MULTIPLE_BLOCK | adtc | [31:0] data address | R1 | Continuously transfers data blocks from Device to host until interrupted by a stop command, or the requested number of data blocks is transmitted If sent as part of a packed read command, the argument shall contain the first read data address in the pack (address of first individual read command inside the pack). |
CMD21
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SEND_TUNING_BLOCK | adtc | [31:0] stuff bits | R1 | 128 clocks of tuning pattern (64 byte in 4bit mode or 128 byte in 8 bit mode) is sent for HS200 optimal sampling point detection. |
NOTE 1 - CMD17 & CMD18, Data address for media =<2 32="" gb="" is="" a="" bit="" byte="" address="" and="" data="" for="" media=""> 2GB is a 32 bit sector (512 B) address.
NOTE 2 - CMD17, The transferred data must not cross a physical block boundary, unless READ_BLK_MISALIGN is set in the CSD register.
Block-oriented write commands (class 4)
CMD23 (default)
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SET_BLOCK_COUNT | ac | [31] Reliable Write Request, [30] ‘0’ non- packed, [29] tag request,[28:25] context ID, [24]: forced programming, [23:16] set to 0, [15:0] number of blocks | R1 | Defines the number of blocks (read/write) and the reliable writer parameter (write) for a block read or write command. |
CMD23 (packed)
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SET_BLOCK_COUNT | ac | [31] set to 0, [30] ‘1’ packed, [29:16] set to 0, [15:0] number of blocks | R1 | Defines the number of blocks (read/write) for the following packed write command or for the header of the following packed read command. |
CMD24
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
WRITE_BLOCK | adtc | [31:0] data address | R1 | Writes a block of the size selected by the |
SET_BLOCKLEN command. |
CMD25
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
WRITE_MULTIPLE_BLOCK | adtc | [31:0] data address | R1 | Continuously writes blocks of data until a STOP_TRANSMISSION follows or the requested number of block received. If sent as a packed command (either packed write, or the header of packed read) the argument shall contain |
the first read/write data address in the pack (address of first individual command inside the pack). |
CMD26
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
PROGRAM_CID | adtc | [31:0] stuff bits | R1 | Programming of the Device identification register. This command shall be issued only once. The Device contains hardware to prevent this operation after the first programming. Normally this command is reserved for the manufacturer. |
CMD27
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
PROGRAM_CSD | adtc | [31:0] stuff bits | R1 | Programming of the programmable bits of the CSD. |
CMD49
Abbr. | Type | Argument | Resp | Description |
---|---|---|---|---|
SET_TIME | adtc | [31:0] stuff bits | R1 | Sets the real time clock according to the RTC information in the 512 B data block. |
NOTE 1 - CMD24 & CMD25, Data address for media =<2 32="" gb="" is="" a="" bit="" byte="" address="" and="" data="" for="" media=""> 2GB is a 32 bit sector (512 B) address.
NOTE 2 - CMD24, The transferred data must not cross a physical block boundary, unless READ_BLK_MISALIGN is set in the CSD register.
Block-oriented write protection commands (class 6)
Erase commands (class 5)
I/O mode commands (class 9)
Lock Device commands (class 7)
Application-specific commands (class 8)
Security Protocols (class 10)
Command Queue (Class 11)
本部分你转载自
eMMC Commands_子曰小玖的博客-CSDN博客
参考
[1] https://www.cnblogs.com/smartjourneys/p/6657397.html
免责声明:
本文根据公开信息整理,旨在介绍更多的存储知识,所载文章仅为作者观点,不构成投资或商用建议。本文仅用于学习交流, 不允许商用。若有疑问或有侵权行为请联系作者处理。