By: Ailson Jack
Date: 2023.11.12
个人博客:http://www.only2fire.com/
本文在我博客的地址是:http://www.only2fire.com/archives/163.html,排版更好,便于学习,也可以去我博客逛逛,兴许有你想要的内容呢。
微信公众号:
嵌入式那些事
面向块的读命令(class 2)
CMD16
CMD16的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
ac | [31:0] block length | R1 | SET_BLOCKLEN | Sets the block length (in bytes) for all following block commands (read and write). Default block length is specified in the CSD. |
CMD16的参数[31:0]位域填写块长度,命令的类型为ac,CMD16的命令缩写为SET_BLOCKLEN,命令响应为R1,命令功能为设置接下来所有块操作命令(读和写)的块长度(以字节为单位),默认的块长度在CSD寄存器中被指定。
CMD17
CMD17的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:0] data address | R1 | READ_SINGLE_BLOCK | Reads a block of the size selected by the SET_BLOCKLEN command. |
CMD17的参数[31:0]位域填写数据地址,命令的类型为adtc,CMD17的命令缩写为READ_SINGLE_BLOCK,命令响应为R1,命令功能为从eMMC设备指定地址读取一块数据,数据块的长度由SET_BLOCKLEN命令(CMD16)设置或者使用默认的块长度。
Data address for media =<2 GB is a 32 bit byte address and data address for media > 2 GB is a 32 bit sector (512 B)
address.
The transferred data must not cross a physical block boundary, unless READ_BLK_MISALIGN is set in the CSD
register.
CMD18
CMD18的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:0] data address | R1 | READ_MULTIPLE_BLOCK | 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). |
CMD18的参数[31:0]位域填写数据地址,命令的类型为adtc,CMD18的命令缩写为READ_MULTIPLE_BLOCK,命令响应为R1,命令功能为从eMMC设备指定地址开始连续传输数据块到Host,直到被STOP_TRANSMISSION命令(CMD12)中断,或者已经读完请求的数据块数量。
Data address for media =<2 GB is a 32 bit byte address and data address for media > 2 GB is a 32 bit sector (512 B)
address.
CMD21
CMD21的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:0] stuff bits | R1 | SEND_TUNING_BLOCK | 128 clocks of tuning pattern (64 byte in 4 bit mode or 128 byte in 8 bit mode) is sent for HS200 optimal sampling point detection. |
CMD21的参数[31:0]位域可以是任意值(默认填写0),命令的类型为adtc,CMD21的命令缩写为SEND_TUNING_BLOCK,命令响应为R1,命令功能为eMMC设备发送128个时钟的tuning模式数据(4位模式下64字节,8位模式下128字节)用于HS200模式下Host优化采样点。
面向块的写命令(class 4)
CMD23(default)
CMD23(default)的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
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 | SET_BLOCK_COUNT | non-packed command version Defines the number of blocks (read/write) and the reliable writer parameter (write) for a block read or write command. |
CMD23(default)的参数[31]位填写Reliable Write Request,[30]填写0,[29]位填写tag request,[28:25]位域填写context ID,[24]位填写forced programming,[23:16]位域填写0,[15:0]位域填写数据块数量,命令的类型为ac,CMD23(default)的命令缩写为SET_BLOCK_COUNT,命令响应为R1,命令功能为定义数据块的数量(用于读写)。
CMD23(packed)
CMD23(packed)的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
ac | [31] set to 0 [30] ‘1’ packed [29:16] set to 0 [15:0] number of blocks | R1 | SET_BLOCK_COUNT | packed command version Defines the number of blocks (read/write) for the following packed write command or for the header of the following packed read command. |
CMD23(packed)的参数[31]位填写0,[30]填写1,[29:16]位域填写0,[15:0]位域填写数据块数量,命令的类型为ac,CMD23(packed)的命令缩写为SET_BLOCK_COUNT,命令响应为R1,命令功能为定义数据块的数量(用于读写)。
CMD24
CMD24的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:0] data address | R1 | WRITE_BLOCK | Writes a block of the size selected by the SET_BLOCKLEN command. |
CMD24的参数[31:0]位域填写数据地址,命令的类型为adtc,CMD24的命令缩写为WRITE_BLOCK,命令响应为R1,命令功能为写一块数据到eMMC设备指定地址,数据块的长度由SET_BLOCKLEN命令(CMD16)设置或者使用默认的块长度。
Data address for media =<2 GB is a 32 bit byte address and data address for media > 2 GB is a 32 bit sector (512 B) address.
The transferred data must not cross a physical block boundary unless WRITE_BLK_MISALIGN is set in the CSD.
CMD25
CMD25的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:0] data address | R1 | WRITE_MULTIPLE_BLOCK | 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). |
CMD25的参数[31:0]位域填写数据地址,命令的类型为adtc,CMD25的命令缩写为WRITE_MULTIPLE_BLOCK,命令响应为R1,命令功能为连续写入数据块到eMMC设备指定地址,直到被STOP_TRANSMISSION命令(CMD12)中断,或者已经写完了请求的数据块数量。
Data address for media =<2 GB is a 32 bit byte address and data address for media > 2 GB is a 32 bit sector (512 B) address.
CMD26
CMD26的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:0] stuff bits | R1 | PROGRAM_CID | 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. |
CMD26的参数[31:0]位域可以是任意值(默认填写0),命令的类型为adtc,CMD26的命令缩写为PROGRAM_CID,命令响应为R1,命令功能为写eMMC设备的CID寄存器。
CMD26命令只能烧写一次CID寄存器,正常情况下是制造商使用这个命令。
CMD27
CMD27的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:0] stuff bits | R1 | PROGRAM_CSD | Programming of the programmable bits of the CSD. |
CMD27的参数[31:0]位域可以是任意值(默认填写0),命令的类型为adtc,CMD27的命令缩写为PROGRAM_CSD,命令响应为R1,命令功能为修改eMMC设备CSD寄存器的可编程位。
CMD49
CMD49的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:0] stuff bits | R1 | SET_TIME | Sets the real time clock according to the RTC information in the 512 B data block. |
CMD49的参数[31:0]位域可以是任意值(默认填写0),命令的类型为adtc,CMD49的命令缩写为SET_TIME,命令响应为R1,命令功能为根据RTC信息数据块,设置eMMC设备的real time clock。
擦除命令(class 5)
CMD35
CMD35的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
ac | [31:0] data address | R1 | ERASE_GROUP_START | Sets the address of the first erase group within a range to be selected for erase |
CMD35的参数[31:0]位域填写数据地址,命令的类型为ac,CMD35的命令缩写为ERASE_GROUP_START,命令响应为R1,命令功能为设置擦除操作的first erase group地址。
Data address for media =<2 GB is a 32 bit byte address and data address for media > 2 GB is a 32 bit sector (512B)
address.
The Device will ignore all LSB’s below the Erase Group size, effectively rounding the address down to the Erase
Group boundary.
CMD36
CMD36的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
ac | [31:0] data address | R1 | ERASE_GROUP_END | Sets the address of the last erase group within a continuous range to be selected for erase |
CMD36的参数[31:0]位域填写数据地址,命令的类型为ac,CMD36的命令缩写为ERASE_GROUP_END,命令响应为R1,命令功能为设置擦除操作的last erase group地址。
Data address for media =<2 GB is a 32 bit byte address and data address for media > 2 GB is a 32 bit sector (512B)
address.
The Device will ignore all LSB’s below the Erase Group size, effectively rounding the address down to the Erase
Group boundary.
CMD38
CMD38的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
ac | [31] Secure request [30:16] set to 0 [15] Force Garbage Collect request [14:2] set to 0 [1] Discard Enable [0] Identify Write Blocks for Erase (or TRIM Enable) | R1b | ERASE | Erases all previously selected write blocks according to argument bits. When all argument bits are zero CMD38 will perform an erase on erase group(s). When Bit 0 = 1 and Bit 1=0 then CMD38 will perform a TRIM on the sector(s). When Bit 0 =1 and Bit 1=1 then CMD38 will perform a DISCARD on the sector(s). To maintain backward compatibility the device must not report an error if bits 31 and 15 are set. The device behavior when these are set is undefined. All other argument settings should trigger an ERROR. |
CMD38的参数[31]位填写Secure request,[30:16]位域填写0,[15]位填写Force Garbage Collect request,[14:2]位域填写0,[1]位填写Discard Enable,[0]位填写Identify Write Blocks for Erase,命令的类型为ac,CMD38的命令缩写为ERASE,命令响应为R1b,命令功能为根据参数位的配置擦除之前选择的数据块。
Argument bit 15 is an optional feature that is only supported if SEC_GB_CL_EN (EXT_CSD[231] bit 4) is set.
Argument bit 31 is an optional feature that is only supported if SEC_ER_EN (EXT_CSD[231] bit 0) is set.
擦除命令的参数如下表所示:
eMMC 5.1总线协议标准主要提供了4种擦除数据的方法,以满足不同场景的擦除需求:
擦除方式 | 擦除单位 | 描述 |
---|---|---|
Erase | Erase Group | 以Erase Group为擦除单位擦除数据,擦除完成后重新读取擦除地址 的数据会返回全0或者1的数据,但在物理存储介质上,可能还保留着原始数据。 |
TRIM | Write Block | 以Write Block为擦除单位擦除数据,擦除完成后重新读取擦除地址 的数据会返回全0或者1的数据,但在物理存储介质上,可能还保留着原始数据。 |
Discard | Write Block | 以Write Block为擦除单位擦除数据,擦除完成后重新读取擦除地址 的数据可能会返回擦除前的数据。 |
Sanitize | — | 将标记擦除的数据块的数据在物理介质上清除。 |
这里主要讲讲Erase操作,其他的擦除操作,根据需要可以阅读下eMMC 5.1 spec。
Erase操作的数据擦除单位为Erase Group。一个Erase Group由一个或者多个Write Block组成。eMMC设备的最基本的数据写单元为Write Block。Erase操作可以进行一个或者多个Erase Group的数据擦除。
当EXT_CSD寄存器的[175]字节的ERASE_GROUP_DEF为0时,Erase Group的大小通过CSD寄存器的[46:42]位域的ERASE_GRP_SIZE和[41:37]位域的ERASE_GRP_MULT共同确定,计算公式如下:
Erase Group Size = (ERASE_GRP_SIZE + 1) * (ERASE_GRP_MULT + 1)
当EXT_CSD寄存器的[175]字节的ERASE_GROUP_DEF为1时,Erase Group的大小通过EXT_CSD寄存器的[224]字节的HC_ERASE_GRP_SIZE来设置,计算公式如下:
Erase Group Size = HC_ERASE_GRP_SIZE * 512KB
eMMC设备在执行Erase操作时,通常并不会进行实际物理数据的擦除,只是将待擦除的Erase Group中的Block从地址空间中unmap,然后从后台的空闲Block中选择已经完成物理擦除的Block,重新map到该地址空间中,然后告知Host端已完成Erase操作。实际物理擦除操作则在后台选择合适的时机进行。
这样的逻辑可以减少Host执行Erase操作的等待时间,提高eMMC设备的响应速度。
Host可以擦除eMMC设备连续范围内的Erase Group。擦除步骤主要分为以下3步:
- Host使用ERASE_GROUP_START(CMD35)命令定义Erase Group范围的起始地址;
- Host使用ERASE_GROUP_END(CMD36)命令定义Erase Group范围的最后地址;
- Host发送命令参数为0的ERASE(CMD38)命令给eMMC设备,用于开始擦除过程;
设备锁定命令(class 7)
CMD42
CMD42的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:0] stuff bits. | R1 | LOCK_UNLOCK | Used to set/reset the password or lock/unlock the Device. The size of the data block is set by the SET_BLOCK_LEN command. |
CMD42的参数[31:0]位域可以是任意值(默认填写0),命令的类型为adtc,CMD42的命令缩写为LOCK_UNLOCK,命令响应为R1,命令功能为设置/复位password或者锁定/解锁eMMC设备。
CMD42只能在SDR模式(single data rate)下使用。在DDR模式(dual data rate),CMD42不会被执行并且会被视为非法命令。
CMD42的命令数据块结构如下图所示:
- SET_PWD:该位为1,表示设置一个新的password;
- CLR_PWD:该位为1,表示清除PWD;
- LOCK_UNLOCK:该位为1,表示锁定eMMC设备;该位为0,表示解锁eMMC设备;
- ERASE:该位为1,表示强制擦除操作(所有其他位应该为0),并且只发送命令字节;
- PWD_LEN:定义接下来的password的长度(以字节为单位)。有效的password的长度范围为:1-16字节;
- PWD:password数据;
特定应用命令(class 8)
CMD55
CMD55的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
ac | [31:16] RCA [15:0] stuff bits | R1 | APP_CMD | Indicates to the Device that the next command is an application specific command rather than a standard command |
CMD55的参数[31:16]位域填写RCA,[15:0]位域可以是任意值(默认填写0),命令的类型为ac,CMD55的命令缩写为APP_CMD,命令响应为R1,命令功能为告诉eMMC设备下个命令是特定应用命令,不是标准命令。
CMD56
CMD56的命令类型,参数,响应类型,命令缩写和描述如下表所示:
Type | Argument | Resp | Abbreviation | Command Description |
---|---|---|---|---|
adtc | [31:1] stuff bits. [0]: RD/WR1 | R1 | GEN_CMD | Used either to transfer a data block to the Device or to get a data block from the Device for general purpose / application specific commands. The size of the data block shall be set by the SET_BLOCK_LEN command. |
CMD56的参数[31:1]位域可以是任意值(默认填写0),[0]位填写数据传输方向,命令的类型为adtc,CMD56的命令缩写为GEN_CMD,命令响应为R1,命令功能为在通用命令或者特定应用命令中,用于传输一个数据块到eMMC设备或者从eMMC设备获取一个数据块。
欢迎关注博主的公众号(微信搜索公众号:嵌入式那些事
),可以扫描下面的公众号二维码:
如果文中有什么问题欢迎指正,毕竟博主的水平有限。
如果这篇文章对你有帮助,记得点赞和关注博主就行了^_^。
排版更好的内容见我博客的地址:http://www.only2fire.com/archives/163.html
注:转载请注明出处,谢谢!^_^