【stm32f407】SD协议(二)-SD卡

一.SD卡简介

1)  简介:

SD卡是基于flash的存储卡。

SD卡和MMC卡的区别在于初始化过程不同。

SD卡的通信协议包括SD和SPI两类。

SD卡使用卡内智能控制模块进行FLASH操作控制,包括协议、安全算法、数据存取、ECC算法、缺陷处理和分析、电源管理、时钟管理。

2)  类型:

MMC: MultiMedia card,有 7个触点(引脚),分为两种操作模式,分别为MMC模式与SPI模式,两种模式对引脚的定义是不同的。SPI模式只有 Host 具有SPI接口时才能使用。MMC只具有存储功能,不像SD卡还具有加密功能。
SD: Security Digtial card,共有9个触点(引脚),多余的 2 个引脚为数据线,但使用与MMC卡兼容的模式时,这两个多余的引脚没有起到作用。SD卡除了存储功能外,还有一种加密功能,但加密功能是收费的(所以开源的linux中只包含mmc的驱动目录),因为当初SD卡联盟中(索尼)就是发明这种卡就是用来存储音乐(淘汰卡带),并使用加密特性,防止拷贝。
TF卡:软件上SD卡一致,只是在硬件的体积上比SD卡西小,所以市场上很多的TF卡的SD外形卡套

3) 协议:

1.x:小于2GB的卡(但通过相关的软件,可以模拟实现大于2GB

2.0: 2<SD<32 GB

3.0: >32GB

二.SD卡引脚介绍

SD卡结构

1)  SD卡模式下引脚介绍

2)  SPI模式引脚介绍

三.SD卡寄存器介绍

1)  CIDThe Card IDentification (CID) register is 128 bits wide. It containsthe card identification information used during the card identification phase.Every individual Read/Write (RW) card shall have a unique identificationnumber. The structure of the CID register is defined in the followingparagraphs:

其中就不一一介绍,主要包含一些SD卡的信息

2)  RCAThe writable 16-bit relative card address register carries the cardaddress that is published by the card during the card identification. Thisaddress is usedfor the addressed host-card communication after the cardidentification procedure. The default value of the RCA register is 0x0000. Thevalue 0x0000 is

reserved to set all cards into the Stand-by Statewith CMD7.

3)  DSR:The 16-bit driver stage register is described in detail inChapter 6.5. It can be optionally used to improve the bus performance forextended operating conditions (depending on parameters like bus length,transfer rate or number of cards). The CSD register carries the informationabout the DSR register usage. The default value of the DSR register is 0x404.

4)  CSD:Table hows Definition of the CSD for the High Capacity SD MemoryCard (CSD Version 2.0). The following sections describe the CSD fields and therelevant data types for the High Capacity SD Memory Card.

CSD Version 2.0 is applied to only the High Capacity SDMemory Card. The field name in parenthesis is set to fixed value and indicatesthat the host is not necessary to refer these fields. The fixed values enableshost, which refers to these fields, to keep compatibility to CSD Version 1.0.The Cell Type field is coded as follows: R = readable, W(1) = writable once, W= multiple writable.

5)  SCR:In addition to the CSD register, there is another configurationregister named SD CARD Configuration Register (SCR). SCR provides informationon the SD Memory Card's special features that were configured into the givencard. The size of SCR register is 64 bits. This register shall be set in thefactory by the SD Memory Card manufacturer.

The following table describes the SCR register content.

6)  OCR

The 32-bit operation conditions register stores theVDDvoltage profile of the card. Additionally, this register includes statusinformation bits. One status bit is set if the card power up procedure has beenfinished. This register includes another status bit indicating the cardcapacity status after set power up status bit. The OCR register shall beimplemented by the cards.

The 32-bit operation conditions register stores theVDDvoltage profile of the card. Bit 7 of OCR is newly defined for Dual VoltageCard and set to 0 in default. If a Dual Voltage Card does not receive CMD8, OCRbit 7 in the response indicates 0, and the Dual Voltage Card which receivedCMD8, sets this bit to 1.

Additionally, this register includes 2 more status information bits.

Bit 31 - Card power up status bit, this status bit is setif the card power up procedure has been finished.

Bit 30 - Card capacity status bit, this status bit is setto 1 if card is High Capacity SD Memory Card. 0

indicates that the card is Standard Capacity SD MemoryCard. The Card Capacity status bit is valid after the card power up procedureis completed and the card power up status bit is set to 1. The Host shall readthis status bit to identify a Standard or High Capacity SD Memory Card. The OCRregister shall be implemented by the cards.

7)  SSR:The SD Status contains status bits that are related to the SDMemory Card proprietary features and may be used for futureapplication-specific usage

8)  CSR:The response format R1 contains a 32-bit field named cardstatus. This field is intended to transmit the card’s status information (whichmay be stored in a local status register) to the host. If not specifiedotherwise, the status entries are always related to the previous issuedcommand.

四.SD协议命令

五.命令响应

All responses are sent via the command line CMD. Theresponse transmission always starts with the left bit of the bit stringcorresponding to the response codeword. The code length depends on the responsetype.

A response always starts with a start bit (always 0),followed by the bit indicating the direction of transmission (card = 0). Avalue denoted by ‘x’ in the tables below indicates a variable entry. Allresponses except for the type R3 (see below) are protected by a CRC (seeChapter 4.5 for the definition of CRC7). Every command codeword is terminatedby the end bit (always 1). There are five types of responses for the SD MemoryCard. The SDIO Card supports additional response types named R4 and R5. Referto SDIO Card Spec for detailed information on the SDIO commands and responses.Their formats are defined as follows:

六.SD卡使用过程

SD卡初始化过程

从图中,我们看到,不管什么卡(这里我们将卡分为4类:SD2.0高容量卡(SDHC,最大32G),SD2.0标准容量卡(SDSC,最大2G),SD1.x卡和MMC卡),首先我们要执行的是卡上电(需要设置SDIO_POWER[1:0]=11),上电后发送CMD0,对卡进行软复位,之后发送CMD8命令,用于区分SD2.0,只有2.0及以后的卡才支持CMD8命令,MMC卡和V1.x的卡,是不支持该命令的。CMD8的格式如表所示:

这里,我们需要在发送CMD8的时候,通过其带的参数我们可以设置VHS位,以告诉SD卡,主机的供电情况,VHS位定义如表所示

这里我们使用参数0X1AA,即告诉SD卡,主机供电为2.7~3.6V之间,如果SD卡支持CMD8,且支持

该电压范围,则会通过CMD8的响应(R7)将参数部分原本返回给主机,如果不支持CMD8,或者不支持这个电压范围,则不响应。在发送CMD8后,发送ACMD41(注意发送ACMD41之前要先发送CMD55),来进一步确认卡的操作电压范围,并通过HCS位来告诉SD卡,主机是不是支持高容量卡(SDHC)。

ACMD41的命令格式如表所示

ACMD41得到的响应(R3)包SDOCR寄存器内容,OCR寄存器内容定义如表所示:

对于支持CMD8指令的卡,主机通过ACMD41的参数设置HCS位为1,来告诉SD卡主机支SDHC卡,如果设置为0,则表示主机不支持SDHC卡,SDHC卡如果接收到HCS0,则永远不会反回卡就绪状态。对于不支持CMD8的卡,HCS位设置为0即可。

SD卡在接收到ACMD41后,返回OCR寄存器内容,如果是2.0的卡,主机可以通过判断OCRCCS位来判断是SDHC还是SDSC;如果是1.x的卡,则忽略该位。OCR寄存器的最

后一个位用于告诉主机SD卡是否上电完成,如果上电完成,该位将会被置1

对于MMC卡,则不支持ACMD41,不CMD55,对MMC卡,我们只需要在发送CMD0后,在发送CMD1(作用同ACMD41),MMC卡的OCR寄存器,实现MMC卡的初始化。

至此,我们便实现了对SD卡的类型区分,图中,最后发送了CMD2CMD3命令,用于获得卡CID寄存器数据和卡相对地址(RCA)。

CMD2,用于获得CID寄存器的数据,CID寄存器数据各位定义如表所示:

SD卡在收到CMD2后,将返回R2长响应(136位),其中包含128位有效数据(CID

存器内容),存放在SDIO_RESP1~44个寄存器里面。通过读取这四个寄存器,就可以获得

SD卡的CID信息。

CMD3,用于设置卡相对地址(RCA,必须为非0),对于SD卡(非MMC卡),在收到

CMD3后,将返回一个新的RCA给主机,方便主机寻址。RCA的存在允许一个SDIO接口挂

多个SD卡,通过RCA来区分主机要操作的是哪个卡。而对于MMC卡,则不是由SD卡自动

返回RCA,而是主机主动设置MMC卡的RCA,即通过CMD3带参数(高16位用于RCA

置),实现RCA设置。同样MMC卡也支持一个SDIO接口挂多个MMC卡,不同于SD卡的

是所有的RCA都是由主机主动设置的,而SD卡的RCA则是SD卡发给主机的。

在获得卡RCA之后,我们便可以发送CMD9(带RCA参数),获得SD卡的CSD寄存器

内容,从CSD寄存器,我们可以得到SD卡的容量和扇区大小等十分重要的信息

 

### 回答1: 现代嵌入式系统大量使用SD卡存储数据,但在大量数据存储在SD卡上时,需要保证SD卡的文件系统稳定压缩。通常,我们使用Bootloader程序实现SD卡Firmware升级功能,该程序支持从SD卡获得启动信息,进而读取Firmware文件更新系统。在本文中,我们将详细介绍STM32F407 SD卡升级Bootloader程序下载。 1. 准备材料:  STM32F407核心板;  USB转串口模块;  SD卡 FAT32文件系统; 2. 确定SD卡Firmware文件格式: Firmware文件应该是整个程序代码和堆栈的BIN文件格式,用于升级整个系统软件。 3. 配置系统引导文件: 使用STMCubeMx或其他软件将Bootloader程序配置为系统引导文件,启动时首先加载它。 4. Bootloader程序下载准备工作: 在F407SDIO1端口运行Bootloader程序,将Flash扇区1准备成一个Firmware更新的接收数据块。 5. SD卡下载: 从SD卡中打开Firmware文件夹查找Firmware更新程序(含APP压缩包在内),启动STM32F407 Bootloader程序从SD卡中读取整个文件,将文件传输至Flash扇区1。升级过程通常需要等待一段时间。 6. 启动更新程序: 在更新完成后重新启动针对新Firmware更新程序,观察系统是否正常运行,APP程序更新后的状态是否与预期一致。 7. 完整性检查: 确定存储在SD卡上的Firmware文件的大小以进行检查,确认每次更新时文件的大小以及完整性。此外,应检查当前正在运行的Firmware版本,以确认其是Firmware更新后的最新版本。 以上是关于STM32F407 SD卡升级Bootloader程序下载的详细步骤,需要工程师们按照步骤进行升级,以确保整个系统在Firmware更新后的可靠性,有效提升嵌入式系统的稳定性和确保可靠性,同时避免因硬件损坏或数据丢失而造成的混乱和损失。 ### 回答2: STM32F407是一款易于使用的高性能微控制器,可以进行SD卡升级和Bootloader程序下载。在进行升级和下载之前,需要先下载相应的编译器和ST-Link工具。接下来,按照以下步骤进行操作: 1. 在SD卡中添加升级文件,如固件文件。 2. 在ST-Link工具中选择"Firmware Upgrade"选项,点击"Connect"按钮连接STM32F407芯片。 3. 确认芯片型号和FLASH大小并进行擦除。 4. 选择"Program and Verify"选项,并选择升级文件进行下载。 5. 点击"Start"按钮开始下载。 下载完成后,可以进行Bootloader程序的下载。首先需要建立一个新项目,将Bootloader程序添加进去,并进行编译。接下来,将STM32F407芯片连接到ST-Link工具中,选择"Connect"选项,然后点击"Program and Verify"选项进行下载。完成后,可以重启设备并测试Bootloader程序是否正常运行。 总的来说,STM32F407SD卡升级和Bootloader程序下载过程相对较为简单,只需要按照以上步骤进行操作即可。其中需要注意的是,在下载过程中不能中断电力供应,否则可能会导致芯片损坏。 ### 回答3: 在使用STM32F407微控制器的开发板进行SD卡升级时,需要先将Bootloader程序下载到板子中。Bootloader程序允许在初次启动时进行SD卡升级,这可以利用SD卡来更新控制器的固件,使得系统更稳定、更可靠。 下载Bootloader程序的方法有很多种,可以通过ST-Link V2下载器,也可以通过串口下载程序。使用ST-Link V2下载器可以通过JTAG/SWD接口将Bootloader程序下载到系统中,需要注意的是,在下载时需要选择正确的程序烧录地址。 如果使用串口下载程序,则需要在Bootloader程序中添加一个串口下载器的协议,并将该程序编译到系统中。此时,我们需要将升级文件打包成一个.bin等进制格式的文件,并通过串口将其发送给Bootloader程序进行升级,具体操作步骤可以参考相应的程序开发文档。 总结来说,SD卡升级Bootloader程序的下载主要有两种方式,一是通过ST-Link V2下载器进行下载,是通过串口将程序编译到系统中并进行升级。在具体实现过程中,需要注意选择正确的烧录地址,并严格按照开发文档操作,确保升级过程顺利完成。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wireless_Link

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值