eMMC(四)——基本命令

1. 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

      cmd0带参数0xF0F0F0F0,GO_PRE_IDLE_STATE是软件reset命令,使得设备进入pre_idle状态

      cmd0带参数0xFFFFFFFA,该命令使得device进入boot operation mode,device将主动发送数据到总线上,数据区域和大小由ECSD寄存器控制。

      cmd0带参数0x00000000, GO_IDLE_STATE,reset 设备,使得设备进入Idle状态。

      为了兼容,如果设备收到CMD0,并且参数不是0xFFFFFFFA或者0xF0F0F0F0,那么该命令会被看做reset命令。

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.

      CMD1 如果设备不支持boot mode,或者BOOT_PARTITION_ENABLE位被清除,power up后设备会立刻进入idle状态。在idle状态,除非收到CMD1,设备会忽略所有传输。对于EMMC4.2之前的版本,device在上电后会立刻进入idle状态。

      CMD1是一个特定的同步命令,用来协商操作电压范围以及查看设备是否仍处在power-up序列。CMD1的响应除了包含操作电压profile,还包含一个busy标记,用来指明设备是否仍然处在power-up序列,没有准备号identification

      设备应该在收到CMD1 1s内完成初始化,CMD1 带参数0x00FF8000或者0x00000800,表示host要使用的电压值。

      对于传统的MMC卡来说,host可以通过CMD1来来判断卡的电压是否匹配。host通过CMD1的参数来指定VDD的电压范围,如果MMC卡不回,则认为不支持,这个时候MMC卡需要进入Inactive State, host将不会在访问这张卡。
      如果MMC卡支持该VDD电压,则在response中返回其电压范围。
      需要注意的是如果CMD1的参数设置为0,则表示host在询问MMC卡的电压范围。询问之后host 需要重发CMD1 选择一个电压范围。
      note: 对于支持2.7-3.6V 和1.75-1.9V 两段电压范围的MMC卡, host 想要选择1.75-1.9V 电压,开始上电时也是建议先将VDD电压升到2.7-3.6V ,在发完CMD1之后,先关闭VDD,在开启1.75-1.9V的电压。

      对于EMMC卡来说是不支持 CMD1 去check 电压范围的。其实这比较好理解,EMMC是固定在PCB上的,一开始就知道电压参数了,没必要做这些选择。

在这里插入图片描述

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

      CMD2 ALL_SEND_CID 用来从device获取CID,R2用来用来返回device’s CID。

CMD3

Abbr. Type Argument Resp Description
SET_RELATIVE_ADDR ac [31:16] RCA, [15:0] stuff bits R1 Assigns relative address to the Device

      CMD3 SET_RELATIVE_ADDR 用来给设置设备的relative device address(RCA),设备收到CMD3后,会立刻从identification mode进入Stand-by State,并且不会再响应任何identification。

EMMC 正常初始化流程:
(和SD不同,EMMC不需要切电压)
CMD0 -> CMD1 ->CMD2…

在这里插入图片描述

CMD4

Abbr. Type Argument Resp Description
SET_DSR bc [31:16] DSR, [15:0] stuff bits - Programs the DSR of the Device

      CMD4 用来设置device的DSR(device stage register)寄存器。

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.

      用来切换设备到Sleep state或者Standby state。设备在Sleep state的电源消耗是最小的,在这个状态下设备仅响应RESET命令(CMD0 参数为0x00000000或者0xF0F0F0F0)和SLEEP/AWAKE命令(CMD5),其他命令都会被忽略。

     Sleep command: CMD5 参数bit15为1; Awake command: CMD参数bit15为0

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.

      切换设备的操作模式或者修改EXT_CSD寄存器,SWITCH命令可以用来写EXT_CSD或者改变命令集。如果SWITCH命令用来改变命令集,那么Index和Value被忽略不会修改EXT_CSD; 如果SWITCH用来写EXT_CSD寄存器,Cmd Set被忽略。

CMD6参数

[31:26] Set to 0
[25:24] Access, 00 切换command set; 01 设置Value中指定的位; 10 清除Value中指定的位; 11 写入Value指定的值。
[23:16] Index, EXT_CSD的索引值,index值为0255,但是仅仅0191为有效索引值。
[15:8] Value,
[7:3] Set to 0
[2:0] Cmd Set ,要切换的command set

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.

      当设备处在Stand-by状态,CMD7把设备从Stand-by State切换到Transfer State;也可以把设备从Transfer State切换回Stand-by State.

      当设备处在Disconnect状态,CMD7把设备从Disconnect State切换到Programming State

      在以上两种情况下,使用当前的RCA会选择设备,任何其他RCA 地址都会取消选择。使用RCA 0x0000表示取消选择。

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.

      请求设备发送它的EXT_CSD寄存器,通过数据块的方式发送。

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.

      参数指定设备的RCA [31:16] RCA。请求设备发送它的Device-specific data(CSD)到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.

      参数指定设备的RCA [31:16] RCA,请求设备发送它的Device identification(CID)到CMD 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.

      所有的read commands: CMD17 CMD18 CMD21 CMD30,都可以在任意时刻被CMD12打断。设备会返回到Transfer State

      所有的write commands: CMD24 CMD25 CMD26 CMD27,都可以被CMD12中止,但是要求在发送CMD7之前发送。

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’

      请求设备发送它的状态寄存器,如果设置了HPI flag,那么设备会在一个定义良好的时间内中断。

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

      设置设备状态为inactive。

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.


2. 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

       设置接下来所有block命令(读和写)的block尺寸。缺省的块长度在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

      读取参数指定地址的数据块,块长度是CMD16设置的(或者使用缺省block size)。

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).

      连续从设备读取数据块到host,直到被stop命令中断,或者已经达到请求的数据块数量。

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.

      HS200模式专用,用来优化HOST采样点,HOST发送CMD21命令,device发送tuning模式数据块。Host会在不同采样点采集数据,找到最佳采样点。

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.


3. 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.

[30] ‘0’ non-packed ‘1’ packed

[24] forced programming, 设置为1,强迫数据直接写入存储介质,而不是仅写入cache

[15:0] number of blocks,

定义读写块数目。

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.

      协议个数据块到设备中,尺寸由之前的CMD16 SET_BLOCKLEN定义。

CMD24

Abbr. Type Argument Resp Description
WRITE_BLOCK adtc [31:0] data address R1 Writes a block of the size selected by the

      协议个数据块到设备中,尺寸由之前的CMD16 SET_BLOCKLEN定义。

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

      连续数据块,直到STOP_TRANSMISSION或者已经写完了请求的数据块。

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.

      写设备CID寄存器。这个命令只能烧写一次,正常情况下是制造商使用这个命令。

CMD27

Abbr. Type Argument Resp Description
PROGRAM_CSD adtc [31:0] stuff bits R1 Programming of the programmable bits of the CSD.

      更改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.

     设置device的real time clock,device使用这个时钟做一些内部维护工作。

     这个命令类似CMD24 WRITE_BLOCK,会发送一个RTC information 数据块。

     面向块的写保护命令。

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.

4. Erase commands

CMD35

CMD35 ERASE_GROUP_START

参数[31:0] 对于=<2G的介质,表示32bits byte地址,对于>2GB介质,是32bits sector地址,会按照Erase group对齐。

该命令设置erase操作的首earse group地址。

CMD36

CMD36 ERASE_GROUP_END

参数[31:0]对于=<2G的介质,表示32bits byte地址,对于>2GB介质,是32bits sector地址,会按照Erase group对齐。
该命令设置erase操作的最后一个erase group地址。

CMD38

CMD38 ERASE

删除前面选择的所有earse block。


数据擦除

      eMMC 标准提供了几种主动擦除数据的方法,以满足不同的场景需求。

擦除方式 擦除单位 描述
Erase Erase Group 按 Erase Group 擦除数据,完成后重新读取会返回全为 0 或者 1 的数据,但在物理存储介质上,可能还保留着原始数据
TRIM Write Block 按 Write Block 擦除数据,完成后重新读取会返回全为 0 或者 1 的数据,但在物理存储介质上,可能还保留着原始数据
Discard Write Block 按 Write Block 擦除数据,完成后重新读取可能会返回擦除前的数据
Sanitize - 将标记擦除的 Block 的数据在物理介质上清除

Erase

      Erase 操作以 Erase Group 为单位进行一个或者多个 Group 的数据擦除,一个 Erase Group 由一个或者多个 Write Block 组成。
      eMMC Device 在执行 Erase 操作时,通常并不会进行实际物理数据的擦除,只是将待擦除的 Erase Group 中的 Block 从地址空间中 unmap,然后从后台的空闲 Block 中选择已经完成物理擦除的 Block,重新 map 到该地址空间中,然后告知 Host 端已完成 Erase 操作。实际物理擦除操作则在后台选择合适的时机进行。
      这样的逻辑可以减少 Host 执行 Erase 操作的等待时间,提高 eMMC Devcie 的响应速度。

Guess you like

Origin blog.csdn.net/yangguoyu8023/article/details/110856312