SD 主机
支持的芯片[ RTL8730E ][ RTL8721F ][RTL8735C]
概述
SD Host 提供了访问 SD 卡、MMC 卡和 SDIO 卡的硬件通信接口,实现数据存储和设备扩展功能。其主要特性包括:
协议支持: SD Host 支持 SD 协议、MMC 协议和 SDIO 协议,具有高度兼容性。
数据宽度: 支持 1-bit 和 4-bit 数据总线宽度,能够适应不同的传输速率需求。
高速操作: 支持标准模式和高速模式,数据传输最高可达 50MHz。
块传输:支持单块传输和多块传输,最大化利用总线带宽。
支持 DMA: 通过模块内部的 DMA 控制器,自动搬移数据以降低 CPU 占用。
SDIO 扩展:支持无线通信模块、蓝牙模块等 SDIO 设备的连接,增强系统功能。
备注
暂不支持与 SDIO 卡通信。
备注
如需使用此芯片与 SDIO 卡进行通信,请联系 Realtek。
备注
不支持与 SDIO 卡通信。
上层应用
SD Host 为虚拟文件系统(VFS)应用和 USB 大容量存储设备(MSC)应用提供底层支持。
VFS
VFS 提供与多种底层文件系统交互的便捷接口,用于多平台开发。
基于 SD Host 的 VFS 应用的层级架构和主要相关驱动如图所示:
基于 SD Host 的 VFS 架构
用户可以参考 SD 卡中的 VFS ,了解 VFS 如何基于 SD Host 在 SD 卡或 MMC 卡上实现文件级操作。
备注
VFS 当前最高支持 32GByte 的 SD 卡或 MMC 卡。
USB MSC
USB MSC 应用将连接到 SD Host 接口的设备作为 USB 存储设备连接至计算机,提高数据管理的灵活性。
更多详细信息请参考 存储设备方案 。
Raw API
SDHOST Exported Types
-
struct SDIOHCFG_TypeDef
SDHOST CFG Structure Definition.
Public Members
-
u8 sdioh_bus_speed
Specifies SD Host bus speed, which should be SD_SPEED_DS or SD_SPEED_HS.
-
u8 sdioh_bus_width
Specifies SD Host bus width, which should be a value of SDHOST Bus Width.
-
u32 sdioh_cd_pin
Specifies the card detect pin, which should be _PNC if not used, or an available GPIO pad.
-
u32 sdioh_wp_pin
Specifies the write protection pin, which should be _PNC if not used, or an available GPIO pad.
-
u8 sdioh_bus_speed
-
enum SD_RESULT
SD operation result type.
Values:
/* Operation completed successfully. */ SD_OK = 0 /* No SD card detected. */ SD_NODISK /* SD card has been inserted. */ SD_INSERT /* SD card initialization failed. */ SD_INITERR /* SD card is write-protected. */ SD_PROTECTED /* General SD operation error. */ SD_ERROR
-
struct SDIOH_CmdTypeDef
SDHOST Command Parameters Structure Definition.
Public Members
-
u32 arg
Specify the argument to be transfered with command.
-
u8 idx
Specify the command to be transfered.
-
u8 rsp_type
Specify the response type. Should be a value of SDHOST Card Response Classification.
-
u8 rsp_crc_chk
Specify CRC7 check enable or not. Should be ENABLE or DISABLE.
-
u8 data_present
Specify whether there is data transfer on the data line after getting response from the card. Should be a value of SDHOST Data Present
-
u32 arg
-
struct SDIOH_DmaCtl
SDHOST DMA Control Structure Definition.
Public Members
-
u32 start_addr
Specify the DMA start address. Unit: 8 Bytes.
-
u16 blk_cnt
Specify the DMA transfer length. Unit: 512 Bytes).
-
u8 op
Specify the data move direction. Should be a value of SDHOST DMA Operation.
-
u8 type
Specify the transfer type. Shold be a value of SDHOST DMA Transfer Type.
-
u32 start_addr
-
struct SDIOH_InitTypeDef
SDHOST Init Structure Definition.
Public Members
-
u8 SDIOH_idle_level
Indicate the idle pin level mask. When operate in 1-Bit bus width, this value is 0x03. When operate in 4-Bit bus width, this value is 0x1F.
-
u8 SDIOH_idle_level
-
enum SD_COMMAND
SD command index enumeration.
Values:
/* CMD0: Go Idle State. */ SD_CMD_GoIdleSte = 0 /* CMD1: Send operating condition (eMMC only). */ EMMC_CMD_SendOpCond = 1 /* CMD2: Send all CID numbers. */ SD_CMD_AllSendCid = 2 /* CMD3: Ask card to publish new RCA. */ SD_CMD_SendRelAddr = 3 /* CMD4: Set DSR register. */ SD_CMD_SetDsr = 4 /* CMD6: Check/switch card function. */ SD_CMD_SwitchFunc = 6 /* ACMD6: Set bus width. */ SD_CMD_SetBusWidth = 6 /* CMD7: Select/deselect card. */ SD_CMD_SelDeselCard = 7 /* CMD8: Send interface condition (SD only). */ SD_CMD_SendIfCond = 8 /* CMD8: Send extended CSD register (eMMC only). */ EMMC_CMD_SendExtCsd = 8 /* CMD9: Send card-specific data. */ SD_CMD_SendCsd = 9 /* CMD10: Send card identification. */ SD_CMD_SendCid = 10 /* CMD11: Switch signaling voltage to 1.8V (SD only). */ SD_CMD_VolSwitch = 11 /* CMD12: Stop transmission. */ SD_CMD_StopXsmission = 12 /* CMD13: Send card status. */ SD_CMD_SendSts = 13 /* CMD16: Set block length in bytes. */ SD_CMD_SetBlklen = 16 /* CMD17: Read single block. */ SD_CMD_RdSingleBlk = 17 /* CMD18: Read multiple blocks. */ SD_CMD_RdMulBlk = 18 /* CMD19: Send tuning block for sampling clock tuning (SD only). */ SD_CMD_SendTuningBlk = 19 /* ACMD22: Get the number of successfully written blocks. */ SD_CMD_SendNumWrBlks = 22 /* CMD23: Set block count for transfer. */ SD_CMD_SetBlkCnt = 23 /* ACMD23: Set number of write blocks to pre-erase before writing. */ SD_CMD_SetWrBlkEraseCnt = 23 /* CMD24: Write single block. */ SD_CMD_WrBlk = 24 /* CMD25: Write multiple blocks. */ SD_CMD_WrMulBlk = 25 /* CMD27: Program CSD register. */ SD_CMD_ProgCsd = 27 /* CMD32: Set first write block address to be erased (SD only). */ SD_CMD_EraseBlkSt = 32 /* CMD33: Set last write block address to be erased (SD only). */ SD_CMD_EraseBlkEd = 33 /* CMD35: Set first erase group start address (eMMC only). */ EMMC_CMD_EraseAddrSt = 35 /* CMD36: Set last erase group end address (eMMC only). */ EMMC_CMD_EraseAddrEd = 36 /* CMD38: Erase selected blocks. */ SD_CMD_Erase = 38 /* ACMD41: Send host capacity support and request card operating condition (SD only). */ SD_CMD_SdSendOpCond = 41 /* ACMD51: Read SD configuration register (SCR) (SD only). */ SD_CMD_SendScr = 51 /* CMD55: Indicate that the next command is an application-specific command (SD only). */ SD_CMD_AppCmd = 55
-
struct SD_CardInfo
SD CardInfo Structure Definition.
Public Members
-
u8 csd[SDIOH_CSD_LEN]
Store the card-specific data (CSD) of the current SD card.
-
u16 rca
Store the relative address (RCA) of the current SD card.
-
u8 is_sdhc_sdxc
Indicate whether the current card is SDSC (0) or SDHC/SDXC (1).
-
u8 sd_spec_ver
Specify the physical layer specification version of the current card, which would be a value of SD Specification Version
-
u32 capaticy
Specify the capacity of the current card. Unit: KB.
-
u32 read_bl_len
Specify max. read data block length of current card. Unit: byte.
-
u32 write_bl_len
Specify max. write data block length. Unit: byte.
-
u8 sig_level
Indicate the current signaling voltage level: 0 for 3.3V, 1 for 1.8V.
-
u8 bus_spd
Specify current bus speed, which would be a value of SD Access Mode.
-
u8 dma_buf[SDIOH_C6R2_BUF_LEN]
DMA buffer, 32 byte-alignment.
-
u8 csd[SDIOH_CSD_LEN]
-
enum HAL_LockTypeDef
HAL Lock structure definition.
Values:
/* Resource is not locked. */ HAL_UNLOCKED = 0x00U /* Resource is locked. */ HAL_LOCKED = 0x01U
-
struct SDIO_CardInfoTypeDef
SDIO Card Information Structure definition.
Public Members
-
u32 CardType
Specifies the card type.
-
u32 CardVersion
Specifies the card version.
-
u32 CardSpecVer
Specifies the card physical layer spec version.
-
u16 Class
Specifies the class of the card command.
-
u32 RelCardAdd
Specifies the Relative Card Address.
-
u32 BlockNbr
Specifies the Card Capacity in blocks.
-
u32 BlockSize
Specifies one block size in bytes.
-
u32 LogBlockNbr
Specifies the Card logical Capacity in blocks.
-
u32 LogBlockSize
Specifies logical block size in bytes.
-
u32 CardType
-
struct SDIO_CmdInitTypeDef
SDMMC Command Control structure.
Public Members
-
u32 Argument
Specifies the SDMMC command argument which is sent to a card as part of a command message. If a command contains an argument, it must be loaded into this register before writing the command to the command register.
-
u8 CmdIndex
Specifies the SDMMC command index. Valid range: 0 to 63.
-
u8 CmdType
Specifies command type.
-
u8 RespType
Specifies the SDMMC response type. This parameter can be a value of SDHOST Response Type
-
u8 DataPresent
Specifies whether data is present.
-
u32 Argument
-
struct SDIO_DataInitTypeDef
SDMMC Data Control structure.
Public Members
-
u8 TransType
Data transfer type; refer to SDHOST_Transfer_Type values.
-
u8 TransDir
Data transfer direction; use SDHOST Transfer Direction values.
-
u8 AutoCmdEn
Auto command enable; use SDHOST Transfer Control values.
-
u8 DmaEn
DMA mode selection; use SDHOST DMA Mode values.
-
u16 BlockSize
Data block size in bytes per transfer unit.
-
u16 BlockCnt
Number of data blocks to transfer.
-
u8 TransType
-
struct SD_HdlTypeDef
SD Handle Structure Definition.
Public Members
-
SDIOHOST_TypeDef *Instance
SD registers base address.
-
SDIO_CardInfoTypeDef Card
Card information.
-
HAL_LockTypeDef Lock
SD locking object.
-
u32 CSD[4]
SD card specific data table.
-
u32 CID[4]
SD card identification number table.
-
u32 SCR[2]
SD configuration register.
-
SD_StateTypeDef State
SD card State.
-
u32 Context
SD transfer context.
-
u32 ErrorCode
SD Card Error codes.
-
u8 *pTxBuffPtr
Pointer to SD Tx transfer Buffer.
-
u8 *pRxBuffPtr
Pointer to SD Rx transfer Buffer.
-
u32 TxXferSize
SD Tx Transfer size.
-
u32 RxXferSize
SD Rx Transfer size.
-
SDIOHOST_TypeDef *Instance
SD Card State Type Definition
-
enum SD_CardStateTypeDef
SD card state machine states reported by the SD card.
Values:
/* SD card is in ready state. */ SD_CARD_READY = 0x00000001U /* SD card is in identification state. */ SD_CARD_IDENTIFICATION = 0x00000002U /* SD card is in standby state. */ SD_CARD_STANDBY = 0x00000003U /* SD card is in data transfer state. */ SD_CARD_TRANSFER = 0x00000004U /* SD card is in sending data state. */ SD_CARD_SENDING = 0x00000005U /* SD card is in receiving data state. */ SD_CARD_RECEIVING = 0x00000006U /* SD card is in programming state. */ SD_CARD_PROGRAMMING = 0x00000007U /* SD card is in disconnected state. */ SD_CARD_DISCONNECTED = 0x00000008U /* SD card error state indicator. */ SD_CARD_ERROR = 0x000000FFU
SD CID Register Structure Definition
Not supported.
-
struct SD_CardCIDTypeDef
SD Card Identification (CID) register decoded structure.
Public Members
-
u8 ManufacturerID
Manufacturer ID.
-
u16 OEM_AppliID
OEM/Application ID.
-
u32 ProdName1
Product Name part1.
-
u8 ProdName2
Product Name part2.
-
u8 ProdRev
Product Revision.
-
u32 ProdSN
Product Serial Number.
-
u8 Reserved1
Reserved1.
-
u16 ManufactDate
Manufacturing Date.
-
u8 ManufacturerID
SD CSD Register Structure Definition
Not supported.
-
struct SD_CardCSDTypeDef
SD Card-Specific Data (CSD) register decoded structure.
Public Members
-
u8 CSDStruct
CSD structure.
-
u8 SysSpecVersion
System specification version.
-
u8 Reserved1
Reserved.
-
u8 TAAC
Data read access time 1.
-
u8 NSAC
Data read access time 2 in CLK cycles.
-
u8 MaxBusClkFrec
Max. bus clock frequency.
-
u16 CardComdClasses
Card command classes.
-
u8 RdBlockLen
Max. read data block length.
-
u8 PartBlockRead
Partial blocks for read allowed.
-
u8 WrBlockMisalign
Write block misalignment.
-
u8 RdBlockMisalign
Read block misalignment.
-
u8 DSRImpl
DSR implemented.
-
u8 Reserved2
Reserved.
-
u32 DeviceSize
Device Size.
-
u8 MaxRdCurrentVDDMin
Max. read current @ VDD min.
-
u8 MaxRdCurrentVDDMax
Max. read current @ VDD max.
-
u8 MaxWrCurrentVDDMin
Max. write current @ VDD min.
-
u8 MaxWrCurrentVDDMax
Max. write current @ VDD max.
-
u8 DeviceSizeMul
Device size multiplier.
-
u8 EraseGrSize
Erase group size.
-
u8 EraseGrMul
Erase group size multiplier.
-
u8 WrProtectGrSize
Write protect group size.
-
u8 WrProtectGrEnable
Write protect group enable.
-
u8 ManDeflECC
Manufacturer default ECC.
-
u8 WrSpeedFact
Write speed factor.
-
u8 MaxWrBlockLen
Max. write data block length.
-
u8 WriteBlockPaPartial
Partial blocks for write allowed.
-
u8 Reserved3
Reserved.
-
u8 ContentProtectAppli
Content protection application.
-
u8 FileFormatGroup
File format group.
-
u8 CopyFlag
Copy flag (OTP).
-
u8 PermWrProtect
Permanent write protection.
-
u8 TempWrProtect
Temporary write protection.
-
u8 FileFormat
File format.
-
u8 ECC
ECC code.
-
u8 CSDStruct
SD State enumeration structure
Not supported.
-
enum SD_StateTypeDef
SD driver state machine states.
Values:
/* SD not yet initialized or deinitialized. */ SD_STATE_RESET = 0x00000000U /* SD initialized and ready for use. */ SD_STATE_READY = 0x00000001U /* SD timeout state. */ SD_STATE_TIMEOUT = 0x00000002U /* SD process ongoing. */ SD_STATE_BUSY = 0x00000003U /* SD programming state. */ SD_STATE_PROGRAMMING = 0x00000004U /* SD receiving state. */ SD_STATE_RECEIVING = 0x00000005U /* SD data transfer state. */ SD_STATE_TRANSFER = 0x00000006U /* SD is in error state. */ SD_STATE_ERROR = 0x0000000FU
SD Status Types
Not supported.
-
struct SD_StatusTypeDef
SD card status decoded structure reported via ACMD13 (SD_STATUS).
Public Members
-
u8 DataBusWidth
Shows the currently defined data bus width.
-
u8 SecuredMode
Card is in secured mode of operation.
-
u16 CardType
Carries information about card type.
-
u32 ProtectedAreaSize
Carries information about the capacity of protected area.
-
u8 SpeedClass
Carries information about the speed class of the card.
-
u8 PerformanceMove
Carries information about the card's performance move.
-
u8 AllocationUnitSize
Carries information about the card's allocation unit size.
-
u16 EraseSize
Determines the number of AUs to be erased in one operation.
-
u8 EraseTimeout
Determines the timeout for a single AU erase operation.
-
u8 EraseOffset
Carries information about the erase offset.
-
u8 DataBusWidth
SDHOST Exported Constants
SDHOST Bus Width
/* 1-bit bus width. */
#define SDIOH_BUS_WIDTH_1BIT ((u8)0x00U)
/* 4-bit bus width. */
#define SDIOH_BUS_WIDTH_4BIT ((u8)0x01U)
Not supported.
/* SD host 8-bit bus width. */
#define SDIOH_BUS_WIDTH_8BIT ((u8)0x02U)
/* Check if SD bus width is valid. */
#define IS_SD_BUS_WIDTH (((WIDTH) == SDIOH_BUS_WIDTH_1BIT) || \
((WIDTH) == SDIOH_BUS_WIDTH_4BIT) || \
((WIDTH) == SDIOH_BUS_WIDTH_8BIT))
SDHOST Card Response
/* Response register 0. */
#define SDIO_RESP0 ((u8)0x00U)
/* Response register 1. */
#define SDIO_RESP1 ((u8)0x01U)
/* Response register 2. */
#define SDIO_RESP2 ((u8)0x02U)
/* Response register 3. */
#define SDIO_RESP3 ((u8)0x03U)
/* Response register 4. */
#define SDIO_RESP4 ((u8)0x04U)
/* Response register 5. */
#define SDIO_RESP5 ((u8)0x05U)
/* Response register 1. */
#define SDIO_RESP1 ((u8)0x04U)
/* Response register 2. */
#define SDIO_RESP2 ((u8)0x08U)
/* Response register 3. */
#define SDIO_RESP3 ((u8)0x0CU)
/* Check if SD response register is valid. */
#define IS_SD_RESP (((RESP) == SDIO_RESP0) || \
((RESP) == SDIO_RESP1) || \
((RESP) == SDIO_RESP2) || \
((RESP) == SDIO_RESP3))
SDHOST DMA ALIGN ADDR
/* DMA buffer alignment size in bytes (8-byte alignment required by hardware). */
#define SDIOH_DMA_ALIGN_SZ (8)
SD Access Mode
/* Default speed mode, 3.3V signaling, up to 25 MHz (function 0). */
#define SD_SPEED_DS ((u8)0x00U)
/* High speed mode, 3.3V signaling, up to 50 MHz (function 1). */
#define SD_SPEED_HS ((u8)0x01U)
/* Keep current bus speed without switching. */
#define SD_KEEP_CUR_SPEED ((u8)0x0FU)
/* SDR12 mode, 1.8V signaling, up to 25 MHz (function 0). */
#define SD_SPEED_SDR12 ((u8)0x02U)
/* SDR25 mode, 1.8V signaling, up to 50 MHz (function 1). */
#define SD_SPEED_SDR25 ((u8)0x03U)
/* SDR50 mode, 1.8V signaling, up to 100 MHz (function 2). */
#define SD_SPEED_SDR50 ((u8)0x04U)
/* SDR104 mode, 1.8V signaling, up to 208 MHz (function 3). */
#define SD_SPEED_SDR104 ((u8)0x05U)
/* DDR50 mode, 1.8V signaling, up to 50 MHz DDR (function 4). */
#define SD_SPEED_DDR50 ((u8)0x06U)
/* SDR12 mode, 1.8V signaling, up to 25 MHz (function 0). */
#define SD_SPEED_SDR12 ((u8)0x00U)
/* SDR25 mode, 1.8V signaling, up to 50 MHz (function 1). */
#define SD_SPEED_SDR25 ((u8)0x01U)
/* SDR50 mode, 1.8V signaling, up to 100 MHz (function 2). */
#define SD_SPEED_SDR50 ((u8)0x02U)
/* SDR104 mode, 1.8V signaling, up to 208 MHz (function 3). */
#define SD_SPEED_SDR104 ((u8)0x03U)
/* DDR50 mode, 1.8V signaling, up to 50 MHz DDR (function 4). */
#define SD_SPEED_DDR50 ((u8)0x04U)
/* Check if SD bus speed mode is valid. */
#define IS_SD_BUS_SPEED (((SPEED) == SD_SPEED_DS) || \
((SPEED) == SD_SPEED_HS) || \
((SPEED) == SD_SPEED_SDR12) || \
((SPEED) == SD_SPEED_SDR25) || \
((SPEED) == SD_SPEED_SDR50) || \
((SPEED) == SD_SPEED_SDR104) || \
((SPEED) == SD_SPEED_DDR50))
SD Block Size
/* Block size is 512 bytes by default. */
#define SD_BLOCK_SIZE (512)
/* Malloc size: 8 blocks. */
#define SD_MALLOC_BLK_CNT (8)
SD CMD6 Operation Mode
/* CMD6 check mode: query function support without switching. */
#define SD_CMD6_CHECK_MODE ((u8)0x00U)
/* CMD6 switch mode: switch to the selected function. */
#define SD_CMD6_SWITCH_MODE ((u8)0x01U)
SD Specification Version
/* SD physical layer specification version 1.01. */
#define SD_SPEC_V101 ((u8)0x0)
/* SD physical layer specification version 1.10. */
#define SD_SPEC_V110 ((u8)0x1)
/* SD physical layer specification version 2.00. */
#define SD_SPEC_V200 ((u8)0x2)
/* SD physical layer specification version 3.00. */
#define SD_SPEC_V300 ((u8)0x3)
SD RESP ACMD
/* Status bit indicating an application command follows. */
#define SD_APP_CMD BIT(5)
Not supported.
SDIO RESP0 CMD
/* Status bit indicating an address error. */
#define SD_ADDRESS_ERROR BIT(6)
/* Status bit indicating a block length error. */
#define SD_BLOCK_LEN_ERROR BIT(5)
/* Status bit indicating a write protection violation. */
#define SD_WP_VIOLATION BIT(2)
Not supported.
SDXC Power Control ACMD41
/* Select power saving mode for SDXC ACMD41. */
#define SD_POWER_SAVING 0
/* Select maximum performance mode for SDXC ACMD41. */
#define SD_MAX_PERFORM 1
Not supported.
SD Switch 18 Request ACMD41
/* Keep current voltage without switching. */
#define SD_USE_CUR_VOL 0
/* Request switch to 1.8V signaling via ACMD41. */
#define SD_SWITCH_18V 1
Not supported.
SD Capacity Support ACMD41
/* Host supports SDSC cards only. */
#define SD_SUPPORT_SDSC_ONLY 0
/* Host supports SDHC and SDXC cards. */
#define SD_SUPPORT_SDHC_SDXC 1
Not supported.
SDHOST Work Mode
/* Normal write transfer mode */
#define SDIOH_NORMAL_WRITE 0
/* Auto write mode 3 */
#define SDIOH_AUTO_WRITE3 1
/* Auto write mode 4 */
#define SDIOH_AUTO_WRITE4 2
/* Auto read mode 3 */
#define SDIOH_AUTO_READ3 5
/* Auto read mode 4 */
#define SDIOH_AUTO_READ4 6
/* Send command and get response mode */
#define SDIOH_SEND_CMD_GET_RSP 8
/* Auto write mode 1 */
#define SDIOH_AUTO_WRITE1 9
/* Auto write mode 2 */
#define SDIOH_AUTO_WRITE2 10
/* Normal read transfer mode */
#define SDIOH_NORMAL_READ 12
/* Auto read mode 1 */
#define SDIOH_AUTO_READ1 13
/* Auto read mode 2 */
#define SDIOH_AUTO_READ2 14
/* Tuning mode */
#define SDIOH_TUNING 15
Not supported.
SDHOST Card Response Type
/* No response expected */
#define SDIOH_RESP_NONE 0
/* Response type R1 */
#define SDIOH_RESP_R1 1
/* Response type R2 */
#define SDIOH_RESP_R2 2
/* Response type R3 */
#define SDIOH_RESP_R3 3
/* Response type R6 */
#define SDIOH_RESP_R6 4
/* Response type R7 */
#define SDIOH_RESP_R7 5
Not supported.
SDHOST Card Response Classification
/* No response classification */
#define SDIOH_NO_RESP 0
/* 6-byte response classification */
#define SDIOH_RSP_6B 1
/* 17-byte response classification */
#define SDIOH_RSP_17B 2
Not supported.
SDHOST Data Present
/* No data present after command response */
#define SDIOH_NO_DATA 0
/* Data present after command response */
#define SDIOH_DATA_EXIST 1
Not supported.
SDHOST DMA Transfer Type
/* Normal DMA transfer type */
#define SDIOH_DMA_NORMAL 0
/* 64-byte DMA transfer type */
#define SDIOH_DMA_64B 1
/* R2 response DMA transfer type */
#define SDIOH_DMA_R2 2
Not supported.
SDHOST Mode
/* SD 2.0 compatible mode (Default Speed / High Speed, 3.3V signaling). */
#define SDIOH_SD20_MODE 0
/* DDR (double data rate) mode. */
#define SDIOH_DDR_MODE 1
/* UHS-I mode (SD 3.0 specification). */
#define SDIOH_SD30_MODE 2
Not supported.
SDHOST DMA Operation
/* DMA write operation (host to card) */
#define SDIOH_DMA_WRITE 0
/* DMA read operation (card to host) */
#define SDIOH_DMA_READ 1
Not supported.
SDHOST Timeout Value
/* Maximum timeout value when checking the command complete flag, unit: us. */
#define SDIOH_CMD_CPLT_TIMEOUT 5000
/* Maximum timeout value when checking the transfer complete flag, unit: us. */
#define SDIOH_XFER_CPLT_TIMEOUT 1000000
/* Read operation timeout value, unit: us. */
#define SDIOH_READ_TIMEOUT 100000
/* Write operation timeout value, unit: us. */
#define SDIOH_WRITE_TIMEOUT 250000
/* Erase operation timeout value, unit: us. */
#define SDIOH_ERASE_TIMEOUT 2000000
Not supported.
SDHOST CMD Value
/* Transmission bit of SD_CMD0 register; set to 1 when the host is the transmitter. */
#define HOST_COMMAND BIT(6)
/* Command index mask of SD_CMD0 register. */
#define SDIOH_CMD_IDX_MASK 0x3F
/* VHS field value in CMD8 for the 2.7-3.6V voltage range. */
#define SDIOH_CMD8_VHS 0x1
/* Check pattern field value in CMD8. */
#define SDIOH_CMD8_CHK_PATN 0xAA
/* OCR field value in ACMD41 representing VDD voltage window bits [23:15]. */
#define SDIOH_OCR_VDD_WIN 0xFF8000
Not supported.
SDHOST Specific Data Length
/* Buffer length for CMD6 status data and R2 responses, in bytes. */
#define SDIOH_C6R2_BUF_LEN 64
/* CSD register response length, in bytes */
#define SDIOH_CSD_LEN 16
Not supported.
SDHOST Signal Level
/* Signal voltage level 3.3V */
#define SDIOH_SIG_VOL_33 0
/* Signal voltage level 1.8V */
#define SDIOH_SIG_VOL_18 1
Not supported.
SD Context Enumeration
Not supported.
/* No SD transfer context active. */
#define SD_CONTEXT_NONE 0x00000000U
/* Context flag: single-block read operation. */
#define SD_CONTEXT_READ_SINGLE_BLOCK 0x00000001U
/* Context flag: multiple-block read operation. */
#define SD_CONTEXT_READ_MULTIPLE_BLOCK 0x00000002U
/* Context flag: single-block write operation. */
#define SD_CONTEXT_WRITE_SINGLE_BLOCK 0x00000010U
/* Context flag: multiple-block write operation. */
#define SD_CONTEXT_WRITE_MULTIPLE_BLOCK 0x00000020U
/* Context flag: transfer processed in interrupt mode. */
#define SD_CONTEXT_IT 0x00000008U
/* Context flag: transfer processed in DMA mode. */
#define SD_CONTEXT_DMA 0x00000080U
SD Supported Card Type
Not supported.
/* SD Standard Capacity card type (up to 2 GB). */
#define CARD_SDSC 0x00000001U
/* SD High/Extended Capacity card type (SDHC/SDXC). */
#define CARD_SDHC_SDXC 0x00000002U
/* SDIO-only card type (no memory function). */
#define CARD_SDIO_ONLY 0x00000004U
/* Combo card type (memory + SDIO functions). */
#define CARD_COMBO 0x00000008U
/* Unsupported card type identifier. */
#define CARD_UNSUPPORTED 0x00000010U
SD Supported Version
Not supported.
/* SD card version 1.x identifier. */
#define CARD_V1_X 0x00000001U
/* SD card version 2.x identifier. */
#define CARD_V2_X 0x00000002U
SDIO CMD Argument
Not supported.
/* Extract number of I/O functions from R4 OCR response. */
#define SD_RESP_R4_NUM_FUNCTIONS (((ocr) >> 28) & 0x7)
/* R4 response bit: memory present or not. */
#define SD_RESP_R4_MEM_PRESENT (1<<27)
/* Shift position of OCR field in R4 response. */
#define SD_RESP_R4_0CR_SHIFT 0
/* Bitmask of OCR voltage window in R4 response. */
#define SD_RESP_R4_0CR_MASK 0x00fffff0
/* CMD52/CMD53 direction flag: read operation. */
#define BUS_READ 0
/* CMD52/CMD53 direction flag: write operation. */
#define BUS_WRITE 1
/* CMD52 argument flag: read direction (bit 31 = 0). */
#define SD_ARG_CMD52_R_FLAG (0 << 31)
/* CMD52 argument flag: write direction (bit 31 = 1). */
#define SD_ARG_CMD52_W_FLAG (1 << 31)
/* Shift position of function number field in CMD52 argument. */
#define SD_ARG_CMD52_FUNC_SHIFT 28
/* Bitmask of function number field in CMD52 argument. */
#define SD_ARG_CMD52_FUNC_MASK 0x7
/* CMD52 argument flag: read-after-write (RAW) operation. */
#define SD_ARG_CMD52_RAW_FLAG (1 << 27)
/* Shift position of register address field in CMD52 argument. */
#define SD_ARG_CMD52_ADDR_SHIFT 9
/* Bitmask of register address field in CMD52 argument. */
#define SD_ARG_CMD52_ADDR_MASK 0x1ffff
/* Shift position of data byte field in CMD52 argument. */
#define SD_ARG_CMD52_DATA_SHIFT 0
/* Bitmask of data byte field in CMD52 argument. */
#define SD_ARG_CMD52_DATA_MASK 0xff
/* CMD53 argument flag: read direction (bit 31 = 0). */
#define SD_ARG_CMD53_R_FLAG (0 << 31)
/* CMD53 argument flag: write direction (bit 31 = 1). */
#define SD_ARG_CMD53_W_FLAG (1 << 31)
/* Shift position of function number field in CMD53 argument. */
#define SD_ARG_CMD53_FUNC_SHIFT 28
/* Bitmask of function number field in CMD53 argument. */
#define SD_ARG_CMD53_FUNC_MASK 0x7
/* CMD53 argument flag: block transfer mode. */
#define SD_ARG_CMD53_BLOCK_MODE (1 << 27)
/* CMD53 argument flag: byte transfer mode. */
#define SD_ARG_CMD53_BYTE_MODE (0 << 27)
/* CMD53 argument flag: incrementing address operation. */
#define SD_ARG_CMD53_OP_CODE (1 << 26)
/* Shift position of register address field in CMD53 argument. */
#define SD_ARG_CMD53_ADDR_SHIFT 9
/* Bitmask of register address field in CMD53 argument. */
#define SD_ARG_CMD53_ADDR_MASK 0x1ffff
/* Shift position of byte/block count field in CMD53 argument. */
#define SD_ARG_CMD53_COUNT_SHIFT 0
/* Bitmask of byte/block count field in CMD53 argument. */
#define SD_ARG_CMD53_COUNT_MASK 0x1ff
/* Maximum byte/block count value for CMD53. */
#define SD_ARG_CMD53_COUNT_MAX 512
SDIO Device CCCR Register Offsets
Not supported.
/* CCCR offset: CCCR/SDIO revision register. */
#define SDIOD_CCCR_REV ((u32)0x00)
/* CCCR offset: SD specification revision register. */
#define SDIOD_CCCR_SDREV ((u32)0x01)
/* CCCR offset: I/O function enable register. */
#define SDIOD_CCCR_IOEN ((u32)0x02)
/* CCCR offset: I/O function ready register. */
#define SDIOD_CCCR_IORDY ((u32)0x03)
/* CCCR offset: interrupt enable register. */
#define SDIOD_CCCR_INTEN ((u32)0x04)
/* CCCR offset: interrupt pending register. */
#define SDIOD_CCCR_INTPEND ((u32)0x05)
/* CCCR offset: I/O abort register. */
#define SDIOD_CCCR_IOABORT ((u32)0x06)
/* CCCR offset: bus interface control register. */
#define SDIOD_CCCR_BICTRL ((u32)0x07)
/* CCCR offset: card capabilities register. */
#define SDIOD_CCCR_CAPABILITIES ((u32)0x08)
/* CCCR offset: common CIS base address pointer byte 0 (LSB). */
#define SDIOD_CCCR_CISPTR_0 ((u32)0x09)
/* CCCR offset: common CIS base address pointer byte 1. */
#define SDIOD_CCCR_CISPTR_1 ((u32)0x0A)
/* CCCR offset: common CIS base address pointer byte 2 (MSB). */
#define SDIOD_CCCR_CISPTR_2 ((u32)0x0B)
/* CCCR offset: bus suspend register. */
#define SDIOD_CCCR_BUSSUSP ((u32)0x0C)
/* CCCR offset: function select register. */
#define SDIOD_CCCR_FUNCSEL ((u32)0x0D)
/* CCCR offset: execution flags register. */
#define SDIOD_CCCR_EXECFLAGS ((u32)0x0E)
/* CCCR offset: ready flags register. */
#define SDIOD_CCCR_RDYFLAGS ((u32)0x0F)
/* CCCR offset: function 0 block size register byte 0 (LSB). */
#define SDIOD_CCCR_BLKSIZE_0 ((u32)0x10)
/* CCCR offset: function 0 block size register byte 1 (MSB). */
#define SDIOD_CCCR_BLKSIZE_1 ((u32)0x11)
/* CCCR offset: power control register. */
#define SDIOD_CCCR_POWER_CONTROL ((u32)0x12)
/* CCCR offset: bus speed select register. */
#define SDIOD_CCCR_SPEED_CONTROL ((u32)0x13)
/* CCCR offset: UHS-I support register. */
#define SDIOD_CCCR_UHS_I ((u32)0x14)
/* CCCR offset: drive strength register. */
#define SDIOD_CCCR_DRIVE ((u32)0x15)
/* CCCR offset: interrupt extension register. */
#define SDIOD_CCCR_INTEXT ((u32)0x16)
/* CCCR offset: separate interrupt control register. */
#define SDIOD_SEP_INT_CTL ((u32)0xF2)
/* Compute FBR base address offset for function x. */
#define SDIOD_FBR_BASE ((x) * 0x100)
/* FBR offset: function 1 block size register byte 0 (LSB). */
#define SDIOD_CCCR_F1BLKSIZE_0 (SDIOD_FBR_BASE(0x1) + 0x10)
/* FBR offset: function 1 block size register byte 1 (MSB). */
#define SDIOD_CCCR_F1BLKSIZE_1 (SDIOD_FBR_BASE(0x1) + 0x11)
SDIO Device CCCR Register Bit Definitions
Not supported.
/* Bitmask of SDIO specification revision in CCCR_REV. */
#define SDIO_REV_SDIOID_MASK ((u8)0xF0)
/* Bitmask of CCCR format version in CCCR_REV. */
#define SDIO_REV_CCCRID_MASK ((u8)0x0F)
/* Bitmask of SD physical layer spec version in CCCR_SDREV. */
#define SD_REV_PHY_MASK ((u8)0x0F)
/* CCCR_IOEN bit: enable I/O for function 1. */
#define SDIO_FUNC_ENABLE_1 ((u8)0x02)
/* CCCR_IOEN bit: enable I/O for function 2. */
#define SDIO_FUNC_ENABLE_2 ((u8)0x04)
/* CCCR_IOEN bit: enable I/O for function 3. */
#define SDIO_FUNC_ENABLE_3 ((u8)0x08)
/* CCCR_IORDY bit: I/O ready status for function 1. */
#define SDIO_FUNC_READY_1 ((u8)0x02)
/* CCCR_IORDY bit: I/O ready status for function 2. */
#define SDIO_FUNC_READY_2 ((u8)0x04)
/* CCCR_IORDY bit: I/O ready status for function 3. */
#define SDIO_FUNC_READY_3 ((u8)0x08)
/* CCCR_INTEN bit: master interrupt enable. */
#define INTR_CTL_MASTER_EN ((u8)0x01)
/* CCCR_INTEN bit: interrupt enable for function 1. */
#define INTR_CTL_FUNC1_EN ((u8)0x02)
/* CCCR_INTEN bit: interrupt enable for function 2. */
#define INTR_CTL_FUNC2_EN ((u8)0x04)
/* SEP_INT_CTL bit: out-of-band interrupt mask. */
#define SEP_INTR_CTL_MASK ((u8)0x01)
/* SEP_INT_CTL bit: out-of-band interrupt output enable. */
#define SEP_INTR_CTL_EN ((u8)0x02)
/* SEP_INT_CTL bit: out-of-band interrupt polarity. */
#define SEP_INTR_CTL_POL ((u8)0x04)
/* CCCR_INTPEND bit: interrupt pending for function 1. */
#define INTR_STATUS_FUNC1 ((u8)0x02)
/* CCCR_INTPEND bit: interrupt pending for function 2. */
#define INTR_STATUS_FUNC2 ((u8)0x04)
/* CCCR_INTPEND bit: interrupt pending for function 3. */
#define INTR_STATUS_FUNC3 ((u8)0x08)
/* CCCR_IOABORT bit: reset all I/O functions. */
#define IO_ABORT_RESET_ALL ((u8)0x08)
/* CCCR_IOABORT bitmask: select function to abort. */
#define IO_ABORT_FUNC_MASK ((u8)0x07)
/* CCCR_BICTRL bit: disable card detect pull-up. */
#define BUS_CARD_DETECT_DIS ((u8)0x80)
/* CCCR_BICTRL bit: card supports continuous SPI interrupt. */
#define BUS_SPI_CONT_INTR_CAP ((u8)0x40)
/* CCCR_BICTRL bit: enable continuous SPI interrupt. */
#define BUS_SPI_CONT_INTR_EN ((u8)0x20)
/* CCCR_BICTRL bitmask: SD bus width selection field. */
#define BUS_SD_DATA_WIDTH_MASK ((u8)0x03)
/* CCCR_BICTRL value: set bus width to 4-bit mode. */
#define BUS_SD_DATA_WIDTH_4BIT ((u8)0x02)
/* CCCR_BICTRL value: set bus width to 1-bit mode. */
#define BUS_SD_DATA_WIDTH_1BIT ((u8)0x00)
/* CCCR_CAP bit: supports 4-bit mode for low-speed card. */
#define SDIO_CAP_4BLS ((u8)0x80)
/* CCCR_CAP bit: card is a low-speed card. */
#define SDIO_CAP_LSC ((u8)0x40)
/* CCCR_CAP bit: enable interrupt between data blocks in 4-bit mode. */
#define SDIO_CAP_E4MI ((u8)0x20)
/* CCCR_CAP bit: supports interrupt between data blocks in 4-bit mode. */
#define SDIO_CAP_S4MI ((u8)0x10)
/* CCCR_CAP bit: supports suspend/resume. */
#define SDIO_CAP_SBS ((u8)0x08)
/* CCCR_CAP bit: supports read wait. */
#define SDIO_CAP_SRW ((u8)0x04)
/* CCCR_CAP bit: supports multi-block transfer. */
#define SDIO_CAP_SMB ((u8)0x02)
/* CCCR_CAP bit: supports direct commands during multi-byte transfer. */
#define SDIO_CAP_SDC ((u8)0x01)
/* CCCR_POWER bit: card supports master power control (RO). */
#define SDIO_POWER_SMPC ((u8)0x01)
/* CCCR_POWER bit: enable master power control above 200 mA (RW). */
#define SDIO_POWER_EMPC ((u8)0x02)
/* CCCR_SPEED bit: card supports high-speed clocking mode (RO). */
#define SDIO_SPEED_SHS ((u8)0x01)
/* CCCR_SPEED bit: enable high-speed clocking mode (RW). */
#define SDIO_SPEED_EHS ((u8)0x02)
/* Function interrupt mask bit: enable mask for function 1. */
#define SDIO_FUNC_MASK_F1 ((u8)0x01)
/* Function interrupt mask bit: enable mask for function 2. */
#define SDIO_FUNC_MASK_F2 ((u8)0x02)
SDHOST Error Codes
Not supported.
/* No SD error. */
#define SD_ERROR_NONE 0x00000000U
/* Command CRC check failed. */
#define SD_ERROR_CMD_CRC_FAIL 0x00000001U
/* Data block CRC check failed. */
#define SD_ERROR_DATA_CRC_FAIL 0x00000002U
/* Command response timed out. */
#define SD_ERROR_CMD_RSP_TIMEOUT 0x00000004U
/* Data transfer timed out. */
#define SD_ERROR_DATA_TIMEOUT 0x00000008U
/* TX FIFO underrun during data write. */
#define SD_ERROR_TX_UNDERRUN 0x00000010U
/* RX FIFO overrun during data read. */
#define SD_ERROR_RX_OVERRUN 0x00000020U
/* Command address not aligned to block boundary. */
#define SD_ERROR_ADDR_MISALIGNED 0x00000040U
/* Block length is not allowed or mismatch. */
#define SD_ERROR_BLOCK_LEN_ERR 0x00000080U
/* Erase command sequence error. */
#define SD_ERROR_ERASE_SEQ_ERR 0x00000100U
/* Invalid erase parameter for this card. */
#define SD_ERROR_BAD_ERASE_PARAM 0x00000200U
/* Write attempted to write-protected region. */
#define SD_ERROR_WRITE_PROT_VIOLATION 0x00000400U
/* Card lock/unlock command failed. */
#define SD_ERROR_LOCK_UNLOCK_FAILED 0x00000800U
/* CRC check of previous command failed. */
#define SD_ERROR_COM_CRC_FAILED 0x00001000U
/* Command not legal for current card state. */
#define SD_ERROR_ILLEGAL_CMD 0x00002000U
/* Card internal ECC failed on last read. */
#define SD_ERROR_CARD_ECC_FAILED 0x00004000U
/* Internal card controller error. */
#define SD_ERROR_CC_ERR 0x00008000U
/* General or unknown card error. */
#define SD_ERROR_GENERAL_UNKNOWN_ERR 0x00010000U
/* Card could not sustain data transfer in stream read. */
#define SD_ERROR_STREAM_READ_UNDERRUN 0x00020000U
/* Card could not sustain data transfer in stream write. */
#define SD_ERROR_STREAM_WRITE_OVERRUN 0x00040000U
/* CID or CSD register overwrite attempted. */
#define SD_ERROR_CID_CSDMMC_OVERWRITE 0x00080000U
/* Erase skipped because some blocks are write-protected. */
#define SD_ERROR_WP_ERASE_SKIP 0x00100000U
/* Command executed without card ECC being enabled. */
#define SD_ERROR_CARD_ECC_DISABLED 0x00200000U
/* Erase sequence was reset before completion. */
#define SD_ERROR_ERASE_RESET 0x00400000U
/* Authentication key exchange sequence error. */
#define SD_ERROR_AKE_SEQ_ERR 0x00800000U
/* Voltage range not supported by the card. */
#define SD_ERROR_INVALID_VOLTRANGE 0x01000000U
/* Command address argument out of allowed range. */
#define SD_ERROR_ADDR_OUT_OF_RANGE 0x02000000U
/* Request not applicable in current card state. */
#define SD_ERROR_REQUEST_NOT_APPLICABLE 0x04000000U
/* Invalid function parameter passed. */
#define SD_ERROR_INVALID_PARAMETER 0x08000000U
/* Feature not supported by this card or host. */
#define SD_ERROR_UNSUPPORTED_FEATURE 0x10000000U
/* Card or host controller is busy. */
#define SD_ERROR_BUSY 0x20000000U
/* DMA transfer error. */
#define SD_ERROR_DMA 0x40000000U
/* Software-level operation timed out. */
#define SD_ERROR_TIMEOUT 0x80000000U
SDHOST Command Index
Not supported.
/* CMD0: Go to idle state. R0. */
#define SDMMC_GO_IDLE_STATE 0
/* CMD1: Send operating condition register (MMC only). R3. */
#define SDMMC_SEND_OP_COND 1
/* CMD2: Ask all cards to send their CID numbers. R2. */
#define SDMMC_ALL_SEND_CID 2
/* CMD3: Set relative address (MMC: assign RCA). R1. */
#define SDMMC_SET_RELATIVE_ADDR 3
/* CMD6: Switch function or bus speed mode (MMC SWITCH). R1B. */
#define SDMMC_SWITCH 6
/* CMD7: Select or deselect a card. R1. */
#define SDMMC_SELECT_CARD 7
/* CMD8: Send extended CSD register (MMC only). R1. */
#define SDMMC_SEND_EXT_CSD 8
/* CMD9: Send card-specific data (CSD) register. R2. */
#define SDMMC_SEND_CSD 9
/* CMD10: Send card identification (CID) register. R1. */
#define SDMMC_SEND_CID 10
/* CMD11: Read data until stop command (MMC stream read). R1. */
#define SDMMC_READ_DAT_UNTIL_STOP 11
/* CMD12: Stop data transmission. R1B. */
#define SDMMC_STOP_TRANSMISSION 12
/* CMD13: Send card status register. R1. */
#define SDMMC_SEND_STATUS 13
/* CMD16: Set block length in bytes. R1. */
#define SDMMC_SET_BLOCKLEN 16
/* CMD17: Read a single block. R1. */
#define SDMMC_READ_BLOCK_SINGLE 17
/* CMD18: Read multiple blocks until CMD12. R1. */
#define SDMMC_READ_BLOCK_MULTIPLE 18
/* CMD19: Send tuning block for sampling clock calibration. R1. */
#define SDMMC_SEND_TUNING_BLOCK 19
/* CMD20: Write data until stop command (MMC stream write). R1. */
#define SDMMC_WRITE_DAT_UNTIL_STOP 20
/* CMD23: Set block count for next multi-block read or write. R1. */
#define SDMMC_SET_BLOCK_COUNT 23
/* CMD24: Write a single block. R1. */
#define SDMMC_WRITE_BLOCK_SINGLE 24
/* CMD25: Write multiple blocks until CMD12. R1. */
#define SDMMC_WRITE_BLOCK_MULTIPLE 25
/* CMD35: Set first address of erase group (MMC only). R1. */
#define SDMMC_ERASE_GROUP_START 35
/* CMD36: Set last address of erase group (MMC only). R1. */
#define SDMMC_ERASE_GROUP_END 36
/* CMD38: Erase all previously selected write blocks. R1B. */
#define SDMMC_ERASE 38
/* CMD55: Indicate next command is an application-specific command. R1. */
#define SDMMC_APP_CMD 55
/* CMD3: Ask SD card to publish a new relative card address (RCA). R6. */
#define SDMMC_SEND_RELATIVE_ADDR 3
/* CMD6: Check or switch SD card function (access mode, etc.). R1. */
#define SDMMC_SEND_SWITCH_FUNC 6
/* CMD8: Send interface condition; verify card operating voltage (SD only). R7. */
#define SDMMC_SEND_IF_COND 8
/* CMD11: Switch bus signaling voltage from 3.3V to 1.8V (SD only). R1. */
#define SDMMC_SWITCH_VOLTAGE 11
/* CMD32: Set first write block address to be erased (SD only). R1. */
#define SDMMC_SD_ERASE_GROUP_START 32
/* CMD33: Set last write block address to be erased (SD only). R1. */
#define SDMMC_SD_ERASE_GROUP_END 33
/* CMD58: Read OCR register (SPI mode). R3. */
#define SDMMC_READ_OCR 58
/* CMD59: Turn CRC on or off (SPI mode). R1. */
#define SDMMC_CRC_ON_OFF 59
/* ACMD6: Set SD bus width to 1-bit or 4-bit. R1. */
#define SDMMC_APP_SET_BUS_WIDTH 6
/* ACMD13: Send SD card status (512-bit data block). R1. */
#define SDMMC_APP_SDMMC_STATUS 13
/* ACMD22: Get number of successfully written write blocks. R1. */
#define SDMMC_APP_SEND_NUM_WR_BLOCKS 22
/* ACMD23: Set number of write blocks to pre-erase before writing. R1. */
#define SDMMC_APP_SET_WR_BLK_ERASE_CNT 23
/* ACMD41: Send host capacity support and request card operating condition. R3. */
#define SDMMC_APP_OP_COND 41
/* ACMD51: Read SD configuration register (SCR). R1. */
#define SDMMC_APP_SEND_SCR 51
/* CMD5: Send I/O operating condition register (SDIO only). R4. */
#define SDMMC_IO_SEND_OP_COND 5
/* CMD52: Direct I/O read or write of a single byte (SDIO only). R5. */
#define SDMMC_IO_RW_DIRECT 52
/* CMD53: Extended I/O read or write of multiple bytes or blocks (SDIO only). R5. */
#define SDMMC_IO_RW_EXTENDED 53
/* Check if SD command index is valid (0 to 63). */
#define IS_SD_CMD_INDEX ((INDEX) < 0x40U)
SDHOST R1 Error Masks
Not supported.
/* R1 status: address argument out of allowed range. */
#define SDMMC_R1_ADDR_OUT_OF_RANGE 0x80000000U
/* R1 status: address not aligned to block length. */
#define SDMMC_R1_ADDR_MISALIGNED 0x40000000U
/* R1 status: block length invalid or mismatched. */
#define SDMMC_R1_BLOCK_LEN_ERR 0x20000000U
/* R1 status: erase command sequence error. */
#define SDMMC_R1_ERASE_SEQ_ERR 0x10000000U
/* R1 status: invalid erase parameter for this card. */
#define SDMMC_R1_BAD_ERASE_PARAM 0x08000000U
/* R1 status: write attempted to write-protected region. */
#define SDMMC_R1_WRITE_PROT_VIOLATION 0x04000000U
/* R1 status: card lock/unlock operation failed. */
#define SDMMC_R1_LOCK_UNLOCK_FAILED 0x01000000U
/* R1 status: card is currently locked. */
#define SDMMC_R1_CARD_IS_LOCKED 0x02000000U
/* R1 status: CRC check of previous command failed. */
#define SDMMC_R1_COM_CRC_FAILED 0x00800000U
/* R1 status: command not legal for current card state. */
#define SDMMC_R1_ILLEGAL_CMD 0x00400000U
/* R1 status: card internal ECC failed on last read. */
#define SDMMC_R1_CARD_ECC_FAILED 0x00200000U
/* R1 status: internal card controller error. */
#define SDMMC_R1_CC_ERROR 0x00100000U
/* R1 status: general or unknown error. */
#define SDMMC_R1_GENERAL_UNKNOWN_ERROR 0x00080000U
/* R1 status: card could not sustain data in stream read. */
#define SDMMC_R1_STREAM_READ_UNDERRUN 0x00040000U
/* R1 status: card could not sustain data in stream write. */
#define SDMMC_R1_STREAM_WRITE_OVERRUN 0x00020000U
/* R1 status: CID or CSD register overwrite attempted. */
#define SDMMC_R1_CID_CSDMMC_OVERWRITE 0x00010000U
/* R1 status: erase skipped for write-protected blocks. */
#define SDMMC_R1_WP_ERASE_SKIP 0x00008000U
/* R1 status: command executed without card ECC enabled. */
#define SDMMC_R1_CARD_ECC_DISABLED 0x00004000U
/* R1 status: erase sequence was reset before completion. */
#define SDMMC_R1_ERASE_RESET 0x00002000U
/* R1 status: authentication key exchange sequence error. */
#define SDMMC_R1_AKE_SEQ_ERROR 0x00000008U
/* Bitmask of all error bits in R1 card status response. */
#define SDMMC_R1_ERRORBITS 0xFDFFE008U
SDHOST R5 Error Masks
Not supported.
/* Bitmask of all error bits in R5 I/O response. */
#define SDMMC_R5_ERRORBITS 0x0000CB00U
/* R5 status: CRC check of previous command failed. */
#define SDMMC_R5_COM_CRC_ERROR 0x00008000U
/* R5 status: illegal command in current function state. */
#define SDMMC_R5_ILLEGAL_COMMAND 0x00004000U
/* R5 field: current I/O state of the card [12:11]. */
#define SDMMC_R5_IO_CURRENT_STATE 0x00003000U
/* R5 status: general or unknown I/O error. */
#define SDMMC_R5_GENERAL_ERROR 0x00000800U
/* R5 status: invalid SDIO function number. */
#define SDMMC_R5_INVALID_FUNC_NUM 0x00000200U
/* R5 status: argument is out of allowed range. */
#define SDMMC_R5_OUT_OF_RANGE 0x00000100U
SDHOST R6 Error Masks
Not supported.
/* R6 status: general or unknown error during SEND_RCA. */
#define SDMMC_R6_GENERAL_UNKNOWN_ERROR 0x00002000U
/* R6 status: illegal command in current card state. */
#define SDMMC_R6_ILLEGAL_CMD 0x00004000U
/* R6 status: CRC check of previous command failed. */
#define SDMMC_R6_COM_CRC_FAILED 0x00008000U
SDHOST ACMD41 Argument
Not supported.
/* OCR bit indicating high capacity (SDHC/SDXC) card. */
#define SDMMC_HIGH_CAPACITY 0x40000000U
/* OCR bit indicating 1.8V switching accepted. */
#define SDMMC_SWITCH_1_8V_ACCEPTED 0x10000000U
/* OCR voltage window mask for 3.2–3.3V range. */
#define SDMMC_VOLTAGE_WINDOW_SD 0x00100000U
SDHOST CMD8 Argument
Not supported.
/* CMD8 check pattern for interface condition verification. */
#define SDMMC_CHECK_PATTERN 0x000001AAU
SDHOST SCR Bitmasks
Not supported.
/* Bitmask for SD specification version field in SCR[59:56]. */
#define SDMMC_MASK_SCR_SPEC_VER 0x0F000000U
/* Shift position of SD specification version in SCR register. */
#define SDMMC_SHIFT_SCR_SPEC_VER 24U
/* Extract SD specification version from SCR register value. */
#define SDMMC_GET_SPEC_VER (((x) & SDMMC_MASK_SCR_SPEC_VER) >> SDMMC_SHIFT_SCR_SPEC_VER)
/* SCR bit indicating 4-bit wide bus support (SCR[50]). */
#define SDMMC_WIDE_BUS_SUPPORT 0x00040000U
/* SCR bit indicating 1-bit bus support (SCR[48]). */
#define SDMMC_SINGLE_BUS_SUPPORT 0x00010000U
SDHOST CCC Bits
Not supported.
/* Card command class 0: basic commands (CMD0, CMD1, etc.). */
#define SDMMC_CCC_BASIC (1 << 0)
/* Card command class 2: block read commands. */
#define SDMMC_CCC_BR (1 << 2)
/* Card command class 4: block write commands. */
#define SDMMC_CCC_BW (1 << 4)
/* Card command class 5: erase commands. */
#define SDMMC_CCC_ERASE (1 << 5)
/* Card command class 6: write protection commands. */
#define SDMMC_CCC_WP (1 << 6)
/* Card command class 7: lock card commands. */
#define SDMMC_CCC_LC (1 << 7)
/* Card command class 8: application-specific commands. */
#define SDMMC_CCC_AS (1 << 8)
/* Card command class 9: I/O mode commands. */
#define SDMMC_CCC_IOM (1 << 9)
/* Card command class 10: switch function commands. */
#define SDMMC_CCC_SWITCH (1 << 10)
SDHOST Timeout Values
Not supported.
/* Infinite wait timeout value (no timeout). */
#define SDMMC_WAIT_FOREVER (0xFFFFFFFFU)
/* Command send and response timeout in microseconds (5ms). */
#define SDMMC_CMD_TIMEOUT 5000U
/* Hardware data transfer timeout in microseconds (1s). */
#define SDMMC_DAT_TIMEOUT 1000000U
/* Read operation software timeout in microseconds (100ms). */
#define SDMMC_READ_TIMEOUT 100000U
/* Write operation software timeout in microseconds (500ms). */
#define SDMMC_WRITE_TIMEOUT 500000U
/* Stop transmission command timeout in microseconds (500ms). */
#define SDMMC_STOP_TRANS_TIMEOUT 500000U
/* Erase operation timeout in microseconds (250ms). */
#define SDMMC_ERASE_TIMEOUT 250000U
/* Maximum number of voltage negotiation retry attempts. */
#define SDMMC_MAX_VOLT_TRIAL 0x0000FFFFU
SDHOST Bitfield Masks
Not supported.
/* All-zero 32-bit constant for register clearing. */
#define SDMMC_ALLZERO 0x00000000U
/* Bitmask for bits 0–7 of a 32-bit value. */
#define SDMMC_0TO7BITS 0x000000FFU
/* Bitmask for bits 8–15 of a 32-bit value. */
#define SDMMC_8TO15BITS 0x0000FF00U
/* Bitmask for bits 16–23 of a 32-bit value. */
#define SDMMC_16TO23BITS 0x00FF0000U
/* Bitmask for bits 24–31 of a 32-bit value. */
#define SDMMC_24TO31BITS 0xFF000000U
SDHOST Clock Frequency
Not supported.
/* High-speed SD bus clock frequency in kHz (50 MHz). */
#define SD_TRANS_HS_50MHZ 50000
/* Default-speed SD bus clock frequency in kHz (25 MHz). */
#define SD_TRANS_DS_25MHZ 25000
/* SD card initialization clock frequency in kHz (400 kHz max per spec). */
#define SD_INIT_400K 400
SDHOST Command Type
Not supported.
/* Normal SD/MMC command type. */
#define SDMMC_CMD_NORMAL ((u8)0x0)
/* Suspend command type (SDIO bus suspend). */
#define SDMMC_CMD_SUSPEND ((u8)0x1)
/* Resume command type (SDIO function select). */
#define SDMMC_CMD_RESUME ((u8)0x2)
/* Abort command type (stop I/O data transfer). */
#define SDMMC_CMD_ABORT ((u8)0x3)
/* Check if SD command type is valid. */
#define IS_SD_CMD_TYPE (((CMD) == SDMMC_CMD_NORMAL) || \
((CMD) == SDMMC_CMD_SUSPEND) || \
((CMD) == SDMMC_CMD_RESUME) || \
((CMD) == SDMMC_CMD_ABORT))
SDHOST Response Type
Not supported.
/* No response expected from SD/MMC command. */
#define SDMMC_RSP_NONE ((u8)0x0)
/* Response R1: 32-bit card status. */
#define SDMMC_RSP_R1 ((u8)0x1)
/* Response R1b: R1 with optional busy signal on DAT0. */
#define SDMMC_RSP_R1B ((u8)0x2)
/* Response R2: 136-bit long response (CID or CSD). */
#define SDMMC_RSP_R2 ((u8)0x3)
/* Response R3: OCR register value. */
#define SDMMC_RSP_R3 ((u8)0x4)
/* Response R4: SDIO operating condition register. */
#define SDMMC_RSP_R4 ((u8)0x5)
/* Response R5: SDIO I/O direct R/W response. */
#define SDMMC_RSP_R5 ((u8)0x6)
/* Response R5b: R5 with optional busy signal on DAT0. */
#define SDMMC_RSP_R5B ((u8)0x7)
/* Response R6: published relative card address (RCA). */
#define SDMMC_RSP_R6 ((u8)0x8)
/* Response R7: card interface condition (CMD8). */
#define SDMMC_RSP_R7 ((u8)0x9)
/* Check if SD response type is valid. */
#define IS_SD_RESP_TYPE (((RESP) == SDMMC_RSP_NONE) || \
((RESP) == SDMMC_RSP_R1) || \
((RESP) == SDMMC_RSP_R1B) || \
((RESP) == SDMMC_RSP_R2) || \
((RESP) == SDMMC_RSP_R3) || \
((RESP) == SDMMC_RSP_R4) || \
((RESP) == SDMMC_RSP_R5) || \
((RESP) == SDMMC_RSP_R5B) || \
((RESP) == SDMMC_RSP_R6) || \
((RESP) == SDMMC_RSP_R7))
/* No response (R0). */
#define SD_RESP_NO ((u8)0x0)
/* 136-bit response length (R2: CID or CSD). */
#define SD_RESP_LEN136 ((u8)0x1)
/* 48-bit response length (R1/R3/R4/R5/R6/R7). */
#define SD_RESP_LEN48 ((u8)0x2)
/* 48-bit response with busy check on DAT0 (R1b/R5b). */
#define SD_RESP_LEN48_BUSY ((u8)0x3)
SDHOST DPSM State
Not supported.
/* Data path state machine: no data transfer. */
#define SDIO_TRANS_NO_DATA ((u8)0x00U)
/* Data path state machine: data transfer present. */
#define SDIO_TRANS_WITH_DATA ((u8)0x01U)
/* Check if SD data transfer type is valid. */
#define IS_SD_DATA_TYPE (((TYPE) == SDIO_TRANS_WITH_DATA) || \
((TYPE) == SDIO_TRANS_NO_DATA))
SDHOST Data Block Size
Not supported.
/* Check if SD data block size is valid; up to 2048 bytes for SDIO cards, 512 bytes for SD memory cards. */
#define IS_SD_BLOCK_SIZE ((SIZE) <= 0x800)
SDHOST Transfer Type
Not supported.
/* Single block data transfer type. */
#define SDIO_TRANS_SINGLE_BLK ((u8)0x00U)
/* Infinite block transfer; stopped only by CMD12. */
#define SDIO_TRANS_INFIN_BLK ((u8)0x01U)
/* Multiple block transfer; block count set by BlockCnt. */
#define SDIO_TRANS_MULTI_BLK ((u8)0x02U)
/* Multiple block transfer with automatic CMD12 stop. */
#define SDIO_TRANS_MULTI_STOP ((u8)0x03U)
/* Check if SD transfer block type is valid. */
#define IS_SD_TRANSFER_TYPE (((TYPE) == SDIO_TRANS_SINGLE_BLK) || \
((TYPE) == SDIO_TRANS_INFIN_BLK) || \
((TYPE) == SDIO_TRANS_MULTI_BLK) || \
((TYPE) == SDIO_TRANS_MULTI_STOP))
SDHOST Transfer Direction
Not supported.
/* Data transfer direction: host to card (write). */
#define SDIO_TRANS_HOST_TO_CARD ((u8)0x00U)
/* Data transfer direction: card to host (read). */
#define SDIO_TRANS_CARD_TO_HOST ((u8)0x01U)
/* Check if SD transfer direction is valid. */
#define IS_SD_TRANSFER_DIR (((DIR) == SDIO_TRANS_HOST_TO_CARD) || \
((DIR) == SDIO_TRANS_CARD_TO_HOST))
SDHOST Transfer Control
Not supported.
/* Auto command disabled for data transfer. */
#define SDIO_TRANS_AUTO_DIS ((u8)0x00U)
/* Auto CMD12 enabled; sent automatically after multi-block transfer completes. */
#define SDIO_TRANS_AUTO_CMD12_EN ((u8)0x01U)
/* Auto CMD23 enabled; block count pre-programmed before multi-block transfer. */
#define SDIO_TRANS_AUTO_CMD23_EN ((u8)0x02U)
SDHOST DMA Mode
Not supported.
/* DMA disabled for data transfer. */
#define SDIO_TRANS_DMA_DIS ((u8)0x00U)
/* DMA enabled for data transfer. */
#define SDIO_TRANS_DMA_EN ((u8)0x01U)
/* Simple DMA (SDMA) mode. */
#define SDIO_SDMA_MODE ((u8)0x00)
/* 32-bit address ADMA2 mode. */
#define SDIO_ADMA2_32B_MODE ((u8)0x02)
/* 64-bit address ADMA2 mode. */
#define SDIO_ADMA2_64B_MODE ((u8)0x03)
/* Check if SD DMA mode is valid. */
#define IS_SD_DMA_MODE (((MODE) == SDIO_SDMA_MODE) || \
((MODE) == SDIO_ADMA2_32B_MODE) || \
((MODE) == SDIO_ADMA2_64B_MODE))
SD CMD6 Func Group
Not supported.
/* Minimum CMD6 function group number. */
#define SD_FUNC_GROUP_MIN ((u8)0x01U)
/* Maximum CMD6 function group number. */
#define SD_FUNC_GROUP_MAX ((u8)0x06U)
/* CMD6 function group 1: access mode (bus speed selection). */
#define SD_ACCESS_MODE ((u8)0x01U)
/* CMD6 function group 2: command system. */
#define SD_COMMAND_SYSTEM ((u8)0x02U)
/* CMD6 function group 3: driver strength. */
#define SD_DRIVER_STRENGTH ((u8)0x03U)
/* CMD6 function group 4: current limit. */
#define SD_CURRENT_LIMIT ((u8)0x04U)
SDIO Function Number
Not supported.
/* SDIO function number 0 (common I/O area). */
#define SDIO_FUNC0 0x00U
/* SDIO function number 1. */
#define SDIO_FUNC1 0x01U
/* SDIO function number 2. */
#define SDIO_FUNC2 0x02U
/* SDIO function number 3. */
#define SDIO_FUNC3 0x03U
/* SDIO function number 4. */
#define SDIO_FUNC4 0x04U
/* SDIO function number 5. */
#define SDIO_FUNC5 0x05U
/* SDIO function number 6. */
#define SDIO_FUNC6 0x06U
/* SDIO function number 7. */
#define SDIO_FUNC7 0x07U
SDHOST Exported Functions
SD Initialization and De-initialization Functions
SDHOST Functions
-
u32 SDIOH_Init(u8 BusBitMode)
Initialize the SD host controller and enable the SD clock.
- 参数:
BusBitMode -- Bus width mode, which can be SDIOH_BUS_WIDTH_1BIT or SDIOH_BUS_WIDTH_4BIT.
- 返回:
HAL operation result:
HAL_OK: SD host initialized successfully.
Others: SD host failed to initialize.
-
u32 SDIOH_Busy(void)
Check whether SD host is busy.
- 返回:
HAL operation result:
HAL_OK: Not busy.
HAL_BUSY: Busy.
-
u32 SDIOH_CheckBusState(u8 status, u32 timeout_us)
Wait until the SD host bus transitions to the specified logic state within a given timeout.
- 参数:
status --
SD host bus state, which can be 0 or 1:
0: wait for bus to go low
1: wait for bus to go high
timeout_us -- Timeout value in microseconds.
- 返回:
HAL operation result:
HAL_OK: Bus switched to specified state within timeout.
HAL_TIMEOUT: Timeout waiting for bus state.
-
u32 SDIOH_CheckTxError(u16 *status)
Check whether an error occurred during an SD host transfer.
- 参数:
status -- Pointer to a 16-bit variable used to store the detailed error status.
- 返回:
HAL operation result:
HAL_OK: No error occurred during transfer.
HAL_ERR_UNKNOWN: An error occurred during transfer.
-
void SDIOH_DMAConfig(SDIOH_DmaCtl *dma_ctl)
Set SD host DMA configuration.
- 参数:
dma_ctl -- Pointer to an SDIOH_DmaCtl structure which contains the DMA configuration parameters.
-
void SDIOH_DMAReset(void)
Reset SD host DMA configuration.
-
void SDIOH_DeInit(void)
De-initialize SD host peripheral.
-
void SDIOH_DebounceCmd(u8 NewState)
Enable or disable the card-detect debounce function.
- 参数:
NewState -- ENABLE or DISABLE.
备注
Only insertion debounce is implemented.
-
u32 SDIOH_DebounceGet(void)
Get the card-detect debounce count value.
- 返回:
Debounce count value (unit: 1 ms).
-
void SDIOH_DebounceSet(u32 debouncevalue)
Set the card-detect debounce count.
- 参数:
debouncevalue -- Debounce count value (unit: 1 ms).
-
u8 SDIOH_GetBusWidth(void)
Get SD host bus width.
- 返回:
Bus width:
0: 1-bit bus.
1: 4-bit bus.
-
u32 SDIOH_GetISR(void)
Get SD host interrupt status.
- 返回:
SD host interrupt status.
-
u8 SDIOH_GetResponse(u8 byte_index)
Get a byte from the SD host command response register.
- 参数:
byte_index -- Index of the response byte to read.
- 返回:
The value of the specified response byte.
-
void SDIOH_INTClearPendingBit(u8 SDIO_IT)
Clear SD host pending interrupt status.
- 参数:
SDIO_IT --
SD host interrupt pending bit, which can be one or combination of the following values:
SDIOH_DMA_TRANSFER_DONE
SDIOH_CARD_ERROR
SDIOH_CARD_END
-
void SDIOH_INTConfig(u8 SDIO_IT, u32 newState)
Configure SD host interrupt enable/disable.
- 参数:
SDIO_IT --
SD host interrupt source, which can be one or combination of the following values:
SDIOH_DMA_CTL_INT_EN
SDIOH_CARD_ERR_INT_EN
SDIOH_CARD_END_INT_EN
newState -- New state of the interrupt, which can be ENABLE or DISABLE.
-
u32 SDIOH_InitialModeCmd(u8 NewState, u8 Level)
Enable or disable SD host initialization (card identification) mode.
- 参数:
NewState -- New state of the initialization mode, which can be ENABLE or DISABLE.
Level --
Signal level, which can be one of the following values:
SDIOH_SIG_VOL_33
SDIOH_SIG_VOL_18
- 返回:
HAL operation result:
HAL_OK: SD host configured successfully.
Others: SD host failed to configure.
-
void SDIOH_PreDMATrans(void)
Enable DMA completion interrupt and set semaphore wait flag before a DMA transfer.
-
u32 SDIOH_SendCommand(SDIOH_CmdTypeDef *cmd_attrib, u32 timeout_us)
Send a command to the SD card via SD host.
- 参数:
cmd_attrib -- Pointer to an SDIOH_CmdTypeDef structure containing the command attributes.
timeout_us -- Timeout value in microseconds.
- 返回:
HAL operation result:
HAL_OK: Command sent successfully.
Others: Error occurred.
-
void SDIOH_SetBusWidth(u8 width)
Set SD host bus width.
- 参数:
width -- Bus width to set, which can be SDIOH_BUS_WIDTH_1BIT or SDIOH_BUS_WIDTH_4BIT.
-
void SDIOH_SwitchSpeed(u8 clk_div, u8 mode)
Set the SD host clock divider and bus speed mode.
- 参数:
clk_div --
Clock divider, which can be one of the following values:
SDIOH_CLK_DIV1: divide by 1
SDIOH_CLK_DIV2: divide by 2
SDIOH_CLK_DIV4: divide by 4
SDIOH_CLK_DIV8: divide by 8
mode -- Bus speed mode, which can be SDIOH_SD20_MODE.
备注
Only SD 2.0 mode (SDIOH_SD20_MODE) is supported.
-
u32 SDIOH_WaitDMADone(u32 timeout_us)
Wait some time for SD host DMA done.
- 参数:
timeout_us -- Timeout value in microseconds.
- 返回:
HAL operation result:
HAL_OK: SD host DMA done within a specified time.
HAL_TIMEOUT: SD host DMA timeout.
-
u32 SDIOH_WaitTxDone(u32 timeout_us)
Wait for the SD host transfer to complete.
- 参数:
timeout_us -- Timeout value in microseconds.
- 返回:
HAL operation result:
HAL_OK: SD host TX completed within the specified timeout.
HAL_TIMEOUT: SD host TX timeout.
-
u32 SDIOH_Init(SDIOHOST_TypeDef *SDIOx)
Initialize the SD host controller and enable the SD clock.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
HAL status:
HAL_OK: Success.
Others: Failure.
-
u32 SDIO_CheckState(SDIOHOST_TypeDef *SDIOx)
Check that the SDIO bus and state machine are idle and the card is inserted.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
HAL status:
HAL_OK: Success.
Others: Failure.
-
void SDIO_ClearErrSts(SDIOHOST_TypeDef *SDIOx, u32 SDIO_IT)
Clear SDIOx error status.
- 参数:
SDIOx -- Pointer to SD host controller.
SDIO_IT -- Specified SDIOx error status to be cleared.
-
void SDIO_ClearNormSts(SDIOHOST_TypeDef *SDIOx, u32 SDIO_IT)
Clear SDIOx normal status.
- 参数:
SDIOx -- Pointer to SD host controller.
SDIO_IT -- Specified SDIOx normal status to be cleared.
-
u32 SDIO_ConfigBusWidth(SDIOHOST_TypeDef *SDIOx, u8 BusWidth)
Configure the SD host data bus width.
- 参数:
SDIOx -- Pointer to SD host controller.
BusWidth -- Bus width to configure: SDIOH_BUS_WIDTH_1BIT or SDIOH_BUS_WIDTH_4BIT.
- 返回:
HAL status:
HAL_OK: Success.
Others: Failure.
-
u32 SDIO_ConfigClock(SDIOHOST_TypeDef *SDIOx, u32 ClkKHz)
Configure the SD host clock frequency and enable the SD clock.
- 参数:
SDIOx -- Pointer to SD host controller.
ClkKHz -- Target clock frequency in kHz.
- 返回:
HAL status:
HAL_OK: Success.
Others: Failure.
-
u32 SDIO_ConfigDMA(SDIOHOST_TypeDef *SDIOx, u8 DmaMode, u32 DmaAddr)
Configure the DMA mode and set the DMA system address.
- 参数:
SDIOx -- Pointer to SD host controller.
DmaMode -- DMA mode: SDIO_SDMA_MODE (SDIO_ADMA2_32B_MODE and SDIO_ADMA2_64B_MODE are not supported).
DmaAddr -- System memory address for the DMA transfer.
- 返回:
HAL status:
HAL_OK: Success.
Others: Failure.
-
void SDIO_ConfigData(SDIOHOST_TypeDef *SDIOx, SDIO_DataInitTypeDef *Data)
Configure the SDMMC data path according to the specified parameters in the SDIO_DataInitTypeDef.
- 参数:
SDIOx -- Pointer to SD host controller.
Data -- Pointer to an SDIO_DataInitTypeDef structure that contains the configuration information for the SDMMC data.
-
void SDIO_ConfigErrIntSig(SDIOHOST_TypeDef *SDIOx, u32 SDIO_IT, u32 NewState)
Enable or disable specified SDIOx error interrupt signal.
- 参数:
SDIOx -- Pointer to SD host controller.
SDIO_IT -- Specified SDIOx error interrupt sources to be enabled or disabled.
NewState -- New state of the specified SDIOx error interrupt signal. This parameter can be ENABLE or DISABLE.
-
void SDIO_ConfigErrIntSts(SDIOHOST_TypeDef *SDIOx, u32 SDIO_IT, u32 NewState)
Enable or disable specified SDIOx error interrupt status.
- 参数:
SDIOx -- Pointer to SD host controller.
SDIO_IT -- Specified SDIOx error interrupt sources to be enabled or disabled.
NewState -- New state of the specified SDIOx error interrupt status. This parameter can be ENABLE or DISABLE.
-
void SDIO_ConfigNormIntSig(SDIOHOST_TypeDef *SDIOx, u32 SDIO_IT, u32 NewState)
Enable or disable specified SDIOx normal interrupt signal.
- 参数:
SDIOx -- Pointer to SD host controller.
SDIO_IT -- Specified SDIOx normal interrupt sources to be enabled or disabled.
NewState -- New state of the specified SDIOx normal interrupt signal. This parameter can be ENABLE or DISABLE.
-
void SDIO_ConfigNormIntSts(SDIOHOST_TypeDef *SDIOx, u32 SDIO_IT, u32 NewState)
Enable or disable specified SDIOx normal interrupt status.
- 参数:
SDIOx -- Pointer to SD host controller.
SDIO_IT -- Specified SDIOx normal interrupt sources to be enabled or disabled.
NewState -- New state of the specified SDIOx normal interrupt status. This parameter can be ENABLE or DISABLE.
-
u32 SDIO_GetErrSts(SDIOHOST_TypeDef *SDIOx)
Get SDIOx error status.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
SDIOx error status.
-
u32 SDIO_GetNormSts(SDIOHOST_TypeDef *SDIOx)
Get SDIOx normal status.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
SDIOx normal status.
-
u8 SDIO_GetPowerState(SDIOHOST_TypeDef *SDIOx)
Get the SD host power state.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
Power status of the controller:
0x00: Power OFF.
0x01: Power ON.
-
u32 SDIO_GetResponse(SDIOHOST_TypeDef *SDIOx, u8 Response)
Return the response received from the card for the last command.
- 参数:
SDIOx -- Pointer to SD host controller.
Response --
Specifies the SDMMC response register. This parameter can be one of the following values:
SDIO_RESP0: Response Register 0
SDIO_RESP1: Response Register 1
SDIO_RESP2: Response Register 2
SDIO_RESP3: Response Register 3
- 返回:
The corresponding response register value.
-
u32 SDIO_GetStatus(SDIOHOST_TypeDef *SDIOx)
Get SDIOx present status.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
SDIOx present status.
-
void SDIO_PowerState_OFF(SDIOHOST_TypeDef *SDIOx)
Set the SD host power state to OFF.
- 参数:
SDIOx -- Pointer to SD host controller.
-
void SDIO_PowerState_ON(SDIOHOST_TypeDef *SDIOx)
Set the SD host power state to ON.
- 参数:
SDIOx -- Pointer to SD host controller.
-
u32 SDIO_ReadFIFO(SDIOHOST_TypeDef *SDIOx)
Read one word (32 bits) from the Rx FIFO.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
The data read from the Rx FIFO.
-
u32 SDIO_ResetAll(SDIOHOST_TypeDef *SDIOx)
Perform a full software reset of the SD host controller.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
HAL status:
HAL_OK: Success.
Others: Failure.
-
void SDIO_SendCommand(SDIOHOST_TypeDef *SDIOx, SDIO_CmdInitTypeDef *Command)
Configure the SDMMC command path according to the specified parameters in SDIO_CmdInitTypeDef structure and send the command.
- 参数:
SDIOx -- Pointer to SD host controller.
Command -- Pointer to an SDIO_CmdInitTypeDef structure that contains the configuration information for the SDMMC command.
-
void SDIO_WriteFIFO(SDIOHOST_TypeDef *SDIOx, u32 *pWriteData)
Write one word (32 bits) to the Tx FIFO.
- 参数:
SDIOx -- Pointer to SD host controller.
pWriteData -- Pointer to the 32-bit word to write.
SDMMC Functions
Not supported.
-
u32 SDIO_CmdRWDirect(SDIOHOST_TypeDef *SDIOx, u32 Argument)
Send the SDIO direct read/write command (CMD52).
- 参数:
SDIOx -- Pointer to SD host controller.
Argument -- CMD52 argument encoding function number, address, direction, and data.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDIO_CmdRWExtended(SDIOHOST_TypeDef *SDIOx, u32 Argument)
Send the SDIO extended read/write command (CMD53).
- 参数:
SDIOx -- Pointer to SD host controller.
Argument -- CMD53 argument encoding function number, address, direction, block/byte mode, and count.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDIO_CmdSendOpCond(SDIOHOST_TypeDef *SDIOx, u32 Ocr)
Send the SDIO operation condition command (CMD5).
- 参数:
SDIOx -- Pointer to SD host controller.
Ocr -- Operation condition register value to send.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDIO_WaitResp(SDIOHOST_TypeDef *SDIOx, u8 RespType, u32 TimeOutUs)
Wait for command completion and check for error conditions.
- 参数:
SDIOx -- Pointer to SD host controller.
RespType -- Response type, which can be a value of SDHOST Response Type.
TimeOutUs -- Timeout value in microseconds.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CheckErrResp1(u32 resp)
Check for error conditions for R1 response.
- 参数:
resp -- R1 Response of CMD.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CheckErrResp5(u32 resp)
Check for error conditions for R5 response.
- 参数:
resp -- R5 Response of CMD.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CheckErrResp6(u32 resp)
Check for error conditions for R6 response.
- 参数:
resp -- R6 Response of CMD.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdAppCommand(SDIOHOST_TypeDef *SDIOx, u32 Argument)
Send the Application command to verify that the next command is an application-specific command rather than a standard command.
- 参数:
SDIOx -- Pointer to SD host controller.
Argument -- Card RCA shifted to bits [31:16], or 0 for a broadcast.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdAppOperCommand(SDIOHOST_TypeDef *SDIOx, u32 Argument)
Send the command asking the accessed card to send its operating condition register (OCR).
- 参数:
SDIOx -- Pointer to SD host controller.
Argument -- Command Argument.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdBlockLength(SDIOHOST_TypeDef *SDIOx, u32 BlockSize)
Send CMD16 (SET_BLOCKLEN) to set the data block length and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
BlockSize -- Block length to be set.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdBusWidth(SDIOHOST_TypeDef *SDIOx, u32 BusWidth)
Send the Bus Width command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
BusWidth -- Bus width argument: 0 for 1-bit mode, 2 for 4-bit mode.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdErase(SDIOHOST_TypeDef *SDIOx, u32 BlockCnt)
Send the Erase command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
BlockCnt -- Count of blocks to be erased.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdGoIdleState(SDIOHOST_TypeDef *SDIOx)
Send the Go Idle State command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdOperCond(SDIOHOST_TypeDef *SDIOx)
Send the Operating Condition command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdReadMultiBlock(SDIOHOST_TypeDef *SDIOx, u32 ReadAdd)
Send the Read Multi Block command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
ReadAdd -- Read start address.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdReadSingleBlock(SDIOHOST_TypeDef *SDIOx, u32 ReadAdd)
Send the Read Single Block command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
ReadAdd -- Read start address.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSDEraseEndAdd(SDIOHOST_TypeDef *SDIOx, u32 EndAdd)
Send the End Address Erase command for SD and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
EndAdd -- End address of erase range.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSDEraseStartAdd(SDIOHOST_TypeDef *SDIOx, u32 StartAdd)
Send the Start Address Erase command for SD and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
StartAdd -- Start address of erase range.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSelDesel(SDIOHOST_TypeDef *SDIOx, u32 Addr)
Send the Select Deselect command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
Addr -- Address of the card to be selected.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSendCID(SDIOHOST_TypeDef *SDIOx)
Send the Send CID command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSendCSD(SDIOHOST_TypeDef *SDIOx, u32 Argument)
Send the CSD command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
Argument -- Card RCA shifted to bits [31:16].
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSendSCR(SDIOHOST_TypeDef *SDIOx)
Send the Send SCR command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSendStatus(SDIOHOST_TypeDef *SDIOx, u32 Argument)
Send the Status command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
Argument -- Card RCA shifted to bits [31:16].
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSetRelAdd(SDIOHOST_TypeDef *SDIOx)
Send the Set Relative Address command (CMD3) and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSetWrBlkEraseCnt(SDIOHOST_TypeDef *SDIOx, u32 BlockCnt)
Send the set write block erase count command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
BlockCnt -- Number of write blocks to be pre-erased before writing.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdStatusRegister(SDIOHOST_TypeDef *SDIOx)
Send the Status register command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdStopTransfer(SDIOHOST_TypeDef *SDIOx)
Send the Stop Transfer command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdSwitch(SDIOHOST_TypeDef *SDIOx, u32 Argument)
Send the SD switch function command (CMD6) to check or switch card function.
- 参数:
SDIOx -- Pointer to SD host controller.
Argument -- CMD6 argument encoding mode, function group, and function value.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdWriteMultiBlock(SDIOHOST_TypeDef *SDIOx, u32 WriteAdd)
Send the Write Multi Block command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
WriteAdd -- Write start address.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
-
u32 SDMMC_CmdWriteSingleBlock(SDIOHOST_TypeDef *SDIOx, u32 WriteAdd)
Send the Write Single Block command and check the response.
- 参数:
SDIOx -- Pointer to SD host controller.
WriteAdd -- Write start address.
- 返回:
Error state:
SD_ERROR_NONE: No error.
Others: Error detected.
SD Peripheral Control Functions
-
u32 SD_SwitchBusSpeed(u8 speed)
Switch the SD bus speed.
- 参数:
speed -- Bus speed mode: SD_SPEED_DS or SD_SPEED_HS.
- 返回:
HAL operation result:
HAL_OK: Switch speed successfully.
Others: Fail to switch speed.
-
SD_RESULT SD_SwitchBusSpeed(SD_HdlTypeDef *hsd, u8 BusSpeed)
Switch the SD bus speed.
- 参数:
hsd -- Pointer to SD handle.
BusSpeed -- Bus speed mode: SD_SPEED_DS or SD_SPEED_HS.
- 返回:
SD operation result:
SD_OK: Success.
Others: Failure.
-
SD_RESULT SD_ConfigBusSpeed(SD_HdlTypeDef *hsd, u8 BusSpeed)
Configure the SD bus clock speed by switching the card mode and updating the host clock.
- 参数:
hsd -- Pointer to SD handle.
BusSpeed -- Target bus speed mode: SD_SPEED_DS or SD_SPEED_HS.
- 返回:
SD operation result:
SD_OK: Success.
SD_ERROR: Failure.
-
SD_RESULT SD_ConfigBusWidth(SD_HdlTypeDef *hsd, u8 WideMode)
Configure the SD bus width if the requested mode is supported by the card.
- 参数:
hsd -- Pointer to SD handle.
WideMode --
Specifies the SD card wide bus mode This parameter can be one of the following values:
SDIOH_BUS_WIDTH_8BIT: 8-bit data transfer
SDIOH_BUS_WIDTH_4BIT: 4-bit data transfer
SDIOH_BUS_WIDTH_1BIT: 1-bit data transfer
- 返回:
SD operation result:
SD_OK: Success.
Others: Failure.
-
SD_RESULT SD_SwitchFunction(SD_HdlTypeDef *hsd, u8 mode, u8 grp, u8 func, u8 *pData)
Check (Mode 0) or switch (Mode 1) a card function using CMD6.
- 参数:
hsd -- Pointer to an SD handle.
mode -- Operation mode, which can be a value of SD CMD6 Operation Mode.
grp -- Function group, which can be a value of SD CMD6 Func Group.
func -- Function, which can be a value of 0x0-0xF.
pData -- Pointer to a buffer to store the switch function status, which should be 32-byte aligned.
- 返回:
SD operation result:
SD_OK: success.
SD_ERROR: fail.
SD Input and Output Operation Functions
-
u32 SD_Erase(uint32_t StartBlock, uint32_t EndBlock)
Erase data in the SD card.
- 参数:
StartBlock -- The start block to erase.
EndBlock -- The end block to erase.
- 返回:
HAL operation result:
HAL_OK: Erase data successfully.
Others: Failed to erase data.
-
u32 SD_ReadBlock(uint8_t *readbuff, uint32_t BlockIdx)
Read one block from the SD card.
- 参数:
readbuff -- Buffer to store the read data (must be 32-byte aligned).
BlockIdx -- Index of the starting block to read.
- 返回:
HAL operation result:
HAL_OK: Read data successfully.
Others: Fail to read data.
-
u32 SD_ReadMultiBlocks(uint8_t *readbuff, uint32_t BlockIdx, uint32_t NumberOfBlocks)
Read multiple blocks from the SD card.
- 参数:
readbuff -- The buffer to read data blocks (must be 32-byte aligned).
BlockIdx -- The index of the starting block to read.
NumberOfBlocks -- The number of blocks to be read.
- 返回:
HAL operation result:
HAL_OK: Read data successfully.
Others: Fail to read data.
-
u32 SD_WriteBlock(uint8_t *writebuff, uint32_t BlockIdx)
Write one block to the SD card.
- 参数:
writebuff -- Buffer containing the data to write (must be 32-byte aligned).
BlockIdx -- The index of the starting block to write.
- 返回:
HAL operation result:
HAL_OK: Write data successfully.
Others: Fail to write data.
-
u32 SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t BlockIdx, uint32_t NumberOfBlocks)
Write multiple blocks to the SD card.
- 参数:
writebuff -- The buffer to write data blocks (must be 32-byte aligned).
BlockIdx -- The index of the starting block to write.
NumberOfBlocks -- The number of blocks to write.
- 返回:
HAL operation result:
HAL_OK: Write data successfully.
Others: Fail to write data.
-
SD_RESULT SD_Erase(SD_HdlTypeDef *hsd, u32 BlockStartAdd, u32 BlockEndAdd)
Erase data in the SD card.
- 参数:
hsd -- Pointer to SD handle.
BlockStartAdd -- The start block to erase.
BlockEndAdd -- The end block to erase.
- 返回:
SD operation result:
SD_OK: Erase data successfully.
Others: Failed to erase data.
备注
This API should be followed by a check on the card state through SD_GetCardState().
-
SD_RESULT SD_IO_RW_Direct(SD_HdlTypeDef *hsd, u8 RWFlag, u8 Func, u32 Addr, u8 In, u8 *Out)
Perform a CMD52 direct read or write on the SDIO card.
- 参数:
hsd -- Pointer to SD handle.
RWFlag -- Transfer direction: BUS_READ or BUS_WRITE.
Func -- SDIO function number.
Addr -- Register address to access.
In -- Data byte to write (used when RWFlag is BUS_WRITE).
Out -- Pointer to store the read-back byte.
- 返回:
SD operation result:
SD_OK: Success.
SD_ERROR: Failure.
备注
Out must not be NULL when RWFlag is BUS_READ and may be NULL when RWFlag is BUS_WRITE.
-
SD_RESULT SD_IO_RW_Extended(SD_HdlTypeDef *hsd, u8 RWFlag, u8 Func, u8 OpCode, u32 Addr, u8 *pData, u8 IsBlock, u16 Cnt)
Perform a CMD53 extended read or write on the SDIO card using DMA.
- 参数:
hsd -- Pointer to SD handle.
RWFlag -- Transfer direction: BUS_READ or BUS_WRITE.
Func -- SDIO function number.
OpCode -- Address increment mode: 1 for incrementing address, 0 for fixed address.
Addr -- Access address.
pData -- Pointer to the data buffer.
IsBlock -- 1 for block mode, 0 for byte mode.
Cnt -- Number of bytes or blocks to transfer.
- 返回:
SD operation result:
SD_OK: Success.
SD_ERROR: Failure.
-
SD_RESULT SD_ReadBlocks_DMA(SD_HdlTypeDef *hsd, u8 *pData, u32 BlockAdd, u32 NumberOfBlocks)
Read block(s) from a specified address in a card. The Data transfer is managed in DMA mode.
- 参数:
hsd -- Pointer to SD handle.
pData -- Pointer to the buffer that will contain the received data.
BlockAdd -- Block Address from where data is to be read.
NumberOfBlocks -- Number of blocks to read.
- 返回:
SD operation result:
SD_OK: Success.
Others: Failure.
备注
This API should be followed by a check on the card state through SD_GetCardState().
备注
You could also check the DMA transfer process through the SD Rx interrupt event.
-
SD_RESULT SD_ReadBlocks_IT(SD_HdlTypeDef *hsd, u8 *pData, u32 BlockAdd, u32 NumberOfBlocks)
Read block(s) from a specified address in a card. The Data transfer is managed in interrupt mode.
- 参数:
hsd -- Pointer to SD handle.
pData -- Pointer to the buffer that will contain the received data.
BlockAdd -- Block Address from where data is to be read.
NumberOfBlocks -- Number of blocks to read.
- 返回:
SD operation result:
SD_OK: Success.
Others: Failure.
备注
This API should be followed by a check on the card state through SD_GetCardState().
备注
You could also check the IT transfer process through the SD Rx interrupt event.
-
SD_RESULT SD_ReadBlocks_PIO(SD_HdlTypeDef *hsd, u8 *pData, u32 BlockAdd, u32 NumberOfBlocks, u32 Timeout)
Read block(s) from a specified address in a card. The Data transfer is managed in polling mode.
- 参数:
hsd -- Pointer to SD handle.
pData -- Pointer to the buffer that will contain the received data.
BlockAdd -- Block Address from where data is to be read.
NumberOfBlocks -- Number of SD blocks to read.
Timeout -- Timeout value for the operation.
- 返回:
SD operation result:
SD_OK: Success.
Others: Failure.
备注
This API should be followed by a check on the card state through SD_GetCardState().
-
SD_RESULT SD_WriteBlocks_DMA(SD_HdlTypeDef *hsd, u8 *pData, u32 BlockAdd, u32 NumberOfBlocks)
Write block(s) to a specified address in a card. The Data transfer is managed in DMA mode.
- 参数:
hsd -- Pointer to SD handle.
pData -- Pointer to the buffer that will contain the data to transmit.
BlockAdd -- Block Address where data will be written.
NumberOfBlocks -- Number of blocks to write.
- 返回:
SD operation result:
SD_OK: Success.
Others: Failure.
备注
This API should be followed by a check on the card state through SD_GetCardState().
备注
You could also check the DMA transfer process through the SD Tx interrupt event.
-
SD_RESULT SD_WriteBlocks_IT(SD_HdlTypeDef *hsd, u8 *pData, u32 BlockAdd, u32 NumberOfBlocks)
Write block(s) to a specified address in a card. The Data transfer is managed in interrupt mode.
- 参数:
hsd -- Pointer to SD handle.
pData -- Pointer to the buffer that will contain the data to transmit.
BlockAdd -- Block Address where data will be written.
NumberOfBlocks -- Number of blocks to write.
- 返回:
SD operation result:
SD_OK: Success.
Others: Failure.
备注
This API should be followed by a check on the card state through SD_GetCardState().
备注
You could also check the IT transfer process through the SD Tx interrupt event.
-
SD_RESULT SD_WriteBlocks_PIO(SD_HdlTypeDef *hsd, u8 *pData, u32 BlockAdd, u32 NumberOfBlocks, u32 Timeout)
Write block(s) to a specified address in a card. The Data transfer is managed in polling mode.
- 参数:
hsd -- Pointer to SD handle.
pData -- Pointer to the buffer that will contain the data to transmit.
BlockAdd -- Block Address where data will be written.
NumberOfBlocks -- Number of SD blocks to write.
Timeout -- Timeout value for the operation.
- 返回:
SD operation result:
SD_OK: Success.
Others: Failure.
备注
This API should be followed by a check on the card state through SD_GetCardState().
常见问题排查
文件系统初始化失败
现象 |
运行VFS示例出现 "File System Init Fail" 的提示 |
原因 |
|
解决方法 |
|
备注
格式化将清空卡上的所有内容,因此在格式化之前,请备份您的重要数据。