LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CHIP: LPC17xx/40xx SDMMC card driver

Detailed Description

Data Structures

struct  SDMMC_EVENT_T
 SDC Event structure. More...
 

Macros

#define SDC_IDENT_CLOCK_RATE   (400000) /* 400KHz */
 
#define SDC_TRAN_CLOCK_RATE   (20000000) /* 20MHz */
 
#define CMDRESP_NONE_TYPE   (SDC_COMMAND_NO_RSP)
 
#define CMDRESP_R1_TYPE   (SDC_COMMAND_SHORT_RSP)
 
#define CMDRESP_R1b_TYPE   (SDC_COMMAND_SHORT_RSP)
 
#define CMDRESP_R2_TYPE   (SDC_COMMAND_LONG_RSP)
 
#define CMDRESP_R3_TYPE   (SDC_COMMAND_SHORT_RSP)
 
#define CMDRESP_R6_TYPE   (SDC_COMMAND_SHORT_RSP)
 
#define CMDRESP_R7_TYPE   (SDC_COMMAND_SHORT_RSP)
 
#define SD_GO_IDLE_STATE   (SDC_COMMAND_INDEX(MMC_GO_IDLE_STATE) | CMDRESP_NONE_TYPE | SDC_COMMAND_INTERRUPT)
 
#define SD_CMD1_SEND_OP_COND   (SDC_COMMAND_INDEX(MMC_SEND_OP_COND) | CMDRESP_R3_TYPE | 0)
 
#define SD_CMD2_ALL_SEND_CID   (SDC_COMMAND_INDEX(MMC_ALL_SEND_CID) | CMDRESP_R2_TYPE | 0)
 
#define SD_CMD3_SET_RELATIVE_ADDR   (SDC_COMMAND_INDEX(MMC_SET_RELATIVE_ADDR) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD3_SEND_RELATIVE_ADDR   (SDC_COMMAND_INDEX(SD_SEND_RELATIVE_ADDR) | CMDRESP_R6_TYPE | 0)
 
#define SD_CMD7_SELECT_CARD   (SDC_COMMAND_INDEX(MMC_SELECT_CARD) | CMDRESP_R1b_TYPE | 0)
 
#define SD_CMD8_SEND_IF_COND   (SDC_COMMAND_INDEX(SD_CMD8) | CMDRESP_R7_TYPE | 0)
 
#define SD_CMD9_SEND_CSD   (SDC_COMMAND_INDEX(MMC_SEND_CSD) | CMDRESP_R2_TYPE | 0)
 
#define SD_CMD12_STOP_TRANSMISSION   (SDC_COMMAND_INDEX(MMC_STOP_TRANSMISSION) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD13_SEND_STATUS   (SDC_COMMAND_INDEX(MMC_SEND_STATUS) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD16_SET_BLOCKLEN   (SDC_COMMAND_INDEX(MMC_SET_BLOCKLEN) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD17_READ_SINGLE_BLOCK   (SDC_COMMAND_INDEX(MMC_READ_SINGLE_BLOCK) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD18_READ_MULTIPLE_BLOCK   (SDC_COMMAND_INDEX(MMC_READ_MULTIPLE_BLOCK) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD24_WRITE_BLOCK   (SDC_COMMAND_INDEX(MMC_WRITE_BLOCK) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD25_WRITE_MULTIPLE_BLOCK   (SDC_COMMAND_INDEX(MMC_WRITE_MULTIPLE_BLOCK) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD32_ERASE_WR_BLK_START   (SDC_COMMAND_INDEX(SD_ERASE_WR_BLK_START) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD33_ERASE_WR_BLK_END   (SDC_COMMAND_INDEX(SD_ERASE_WR_BLK_END) | CMDRESP_R1_TYPE | 0)
 
#define SD_CMD38_ERASE   (SDC_COMMAND_INDEX(SD_ERASE) | CMDRESP_R1b_TYPE | 0)
 
#define SD_CMD55_APP_CMD   (SDC_COMMAND_INDEX(MMC_APP_CMD) | CMDRESP_R1_TYPE | 0)
 
#define SD_ACMD6_SET_BUS_WIDTH   (SDC_COMMAND_INDEX(SD_APP_SET_BUS_WIDTH) | CMDRESP_R1_TYPE | 0)
 
#define SD_ACMD13_SEND_SD_STATUS   (SDC_COMMAND_INDEX(MMC_SEND_STATUS) | CMDRESP_R1_TYPE | 0)
 
#define SD_ACMD41_SD_SEND_OP_COND   (SDC_COMMAND_INDEX(SD_APP_OP_COND) | CMDRESP_R3_TYPE | 0)
 

Functions

int32_t Chip_SDMMC_IRQHandler (LPC_SDC_T *pSDC, uint8_t *txBuf, uint32_t *txCnt, uint8_t *rxBuf, uint32_t *rxCnt)
 SD card interrupt service routine.
 
int32_t Chip_SDMMC_Acquire (LPC_SDC_T *pSDC, SDMMC_CARD_T *pCardInfo)
 Function to enumerate the SD/MMC/SDHC/MMC+ cards.
 
SDMMC_STATE_T Chip_SDMMC_GetCardState (LPC_SDC_T *pSDC, SDMMC_CARD_T *pCardInfo)
 Get card's current state (idle, transfer, program, etc.)
 
uint32_t Chip_SDMMC_GetCardStatus (LPC_SDC_T *pSDC, SDMMC_CARD_T *pCardInfo)
 Get 'card status' of SD Memory card.
 
int32_t Chip_SDMMC_GetSDStatus (LPC_SDC_T *pSDC, SDMMC_CARD_T *pCardInfo, uint32_t *pStatus)
 Get 'sd status' of SD Memory card.
 
int32_t Chip_SDMMC_ReadBlocks (LPC_SDC_T *pSDC, SDMMC_CARD_T *pCardInfo, void *buffer, int32_t startblock, int32_t blockNum)
 Performs the read of data from the SD/MMC card.
 
int32_t Chip_SDMMC_WriteBlocks (LPC_SDC_T *pSDC, SDMMC_CARD_T *pCardInfo, void *buffer, int32_t startblock, int32_t blockNum)
 Performs write of data to the SD/MMC card.
 

Macro Definition Documentation

#define CMDRESP_NONE_TYPE   (SDC_COMMAND_NO_RSP)

Definition at line 57 of file sdmmc_17xx_40xx.h.

#define CMDRESP_R1_TYPE   (SDC_COMMAND_SHORT_RSP)

Definition at line 58 of file sdmmc_17xx_40xx.h.

#define CMDRESP_R1b_TYPE   (SDC_COMMAND_SHORT_RSP)

Definition at line 59 of file sdmmc_17xx_40xx.h.

#define CMDRESP_R2_TYPE   (SDC_COMMAND_LONG_RSP)

Definition at line 60 of file sdmmc_17xx_40xx.h.

#define CMDRESP_R3_TYPE   (SDC_COMMAND_SHORT_RSP)

Definition at line 61 of file sdmmc_17xx_40xx.h.

#define CMDRESP_R6_TYPE   (SDC_COMMAND_SHORT_RSP)

Definition at line 62 of file sdmmc_17xx_40xx.h.

#define CMDRESP_R7_TYPE   (SDC_COMMAND_SHORT_RSP)

Definition at line 63 of file sdmmc_17xx_40xx.h.

#define SD_ACMD13_SEND_SD_STATUS   (SDC_COMMAND_INDEX(MMC_SEND_STATUS) | CMDRESP_R1_TYPE | 0)

SEND_SD_STATUS

Definition at line 118 of file sdmmc_17xx_40xx.h.

#define SD_ACMD41_SD_SEND_OP_COND   (SDC_COMMAND_INDEX(SD_APP_OP_COND) | CMDRESP_R3_TYPE | 0)

SD_SEND_OP_COND

Definition at line 119 of file sdmmc_17xx_40xx.h.

#define SD_ACMD6_SET_BUS_WIDTH   (SDC_COMMAND_INDEX(SD_APP_SET_BUS_WIDTH) | CMDRESP_R1_TYPE | 0)

SET_BUS_WIDTH

Definition at line 117 of file sdmmc_17xx_40xx.h.

#define SD_CMD12_STOP_TRANSMISSION   (SDC_COMMAND_INDEX(MMC_STOP_TRANSMISSION) | CMDRESP_R1_TYPE | 0)

STOP_TRANSMISSION

Definition at line 98 of file sdmmc_17xx_40xx.h.

#define SD_CMD13_SEND_STATUS   (SDC_COMMAND_INDEX(MMC_SEND_STATUS) | CMDRESP_R1_TYPE | 0)

SEND_STATUS

Definition at line 99 of file sdmmc_17xx_40xx.h.

#define SD_CMD16_SET_BLOCKLEN   (SDC_COMMAND_INDEX(MMC_SET_BLOCKLEN) | CMDRESP_R1_TYPE | 0)

SET_BLOCK_LEN

Definition at line 102 of file sdmmc_17xx_40xx.h.

#define SD_CMD17_READ_SINGLE_BLOCK   (SDC_COMMAND_INDEX(MMC_READ_SINGLE_BLOCK) | CMDRESP_R1_TYPE | 0)

READ_SINGLE_BLOCK

Definition at line 103 of file sdmmc_17xx_40xx.h.

#define SD_CMD18_READ_MULTIPLE_BLOCK   (SDC_COMMAND_INDEX(MMC_READ_MULTIPLE_BLOCK) | CMDRESP_R1_TYPE | 0)

READ_MULTIPLE_BLOCK

Definition at line 104 of file sdmmc_17xx_40xx.h.

#define SD_CMD1_SEND_OP_COND   (SDC_COMMAND_INDEX(MMC_SEND_OP_COND) | CMDRESP_R3_TYPE | 0)

SEND_OP_COND(MMC) or ACMD41(SD)

Definition at line 91 of file sdmmc_17xx_40xx.h.

#define SD_CMD24_WRITE_BLOCK   (SDC_COMMAND_INDEX(MMC_WRITE_BLOCK) | CMDRESP_R1_TYPE | 0)

WRITE_BLOCK

Definition at line 107 of file sdmmc_17xx_40xx.h.

#define SD_CMD25_WRITE_MULTIPLE_BLOCK   (SDC_COMMAND_INDEX(MMC_WRITE_MULTIPLE_BLOCK) | CMDRESP_R1_TYPE | 0)

WRITE_MULTIPLE_BLOCK

Definition at line 108 of file sdmmc_17xx_40xx.h.

#define SD_CMD2_ALL_SEND_CID   (SDC_COMMAND_INDEX(MMC_ALL_SEND_CID) | CMDRESP_R2_TYPE | 0)

ALL_SEND_CID

Definition at line 92 of file sdmmc_17xx_40xx.h.

#define SD_CMD32_ERASE_WR_BLK_START   (SDC_COMMAND_INDEX(SD_ERASE_WR_BLK_START) | CMDRESP_R1_TYPE | 0)

ERASE_WR_BLK_START

Definition at line 111 of file sdmmc_17xx_40xx.h.

#define SD_CMD33_ERASE_WR_BLK_END   (SDC_COMMAND_INDEX(SD_ERASE_WR_BLK_END) | CMDRESP_R1_TYPE | 0)

ERASE_WR_BLK_END

Definition at line 112 of file sdmmc_17xx_40xx.h.

#define SD_CMD38_ERASE   (SDC_COMMAND_INDEX(SD_ERASE) | CMDRESP_R1b_TYPE | 0)

ERASE

Definition at line 113 of file sdmmc_17xx_40xx.h.

#define SD_CMD3_SEND_RELATIVE_ADDR   (SDC_COMMAND_INDEX(SD_SEND_RELATIVE_ADDR) | CMDRESP_R6_TYPE | 0)

SEND_RELATE_ADDR

Definition at line 94 of file sdmmc_17xx_40xx.h.

#define SD_CMD3_SET_RELATIVE_ADDR   (SDC_COMMAND_INDEX(MMC_SET_RELATIVE_ADDR) | CMDRESP_R1_TYPE | 0)

SET_RELATE_ADDR

Definition at line 93 of file sdmmc_17xx_40xx.h.

#define SD_CMD55_APP_CMD   (SDC_COMMAND_INDEX(MMC_APP_CMD) | CMDRESP_R1_TYPE | 0)

APP_CMD

Definition at line 116 of file sdmmc_17xx_40xx.h.

#define SD_CMD7_SELECT_CARD   (SDC_COMMAND_INDEX(MMC_SELECT_CARD) | CMDRESP_R1b_TYPE | 0)

SELECT/DESELECT_CARD

Definition at line 95 of file sdmmc_17xx_40xx.h.

#define SD_CMD8_SEND_IF_COND   (SDC_COMMAND_INDEX(SD_CMD8) | CMDRESP_R7_TYPE | 0)

SEND_IF_COND

Definition at line 96 of file sdmmc_17xx_40xx.h.

#define SD_CMD9_SEND_CSD   (SDC_COMMAND_INDEX(MMC_SEND_CSD) | CMDRESP_R2_TYPE | 0)

SEND_CSD

Definition at line 97 of file sdmmc_17xx_40xx.h.

GO_IDLE_STATE(MMC) or RESET(SD)

Definition at line 90 of file sdmmc_17xx_40xx.h.

#define SDC_IDENT_CLOCK_RATE   (400000) /* 400KHz */

Card bus clock in Card Identification Mode

Definition at line 50 of file sdmmc_17xx_40xx.h.

#define SDC_TRAN_CLOCK_RATE   (20000000) /* 20MHz */

Card bus clock in Data Transfer Mode

Definition at line 52 of file sdmmc_17xx_40xx.h.

Function Documentation

int32_t Chip_SDMMC_Acquire ( LPC_SDC_T pSDC,
SDMMC_CARD_T pCardInfo 
)

Function to enumerate the SD/MMC/SDHC/MMC+ cards.

Parameters
pSDC: Pointer to SDC peripheral base address
pCardInfo: Pointer to pre-allocated card info structure
Returns
1 if a card is acquired, otherwise 0

Definition at line 844 of file sdmmc_17xx_40xx.c.

SDMMC_STATE_T Chip_SDMMC_GetCardState ( LPC_SDC_T pSDC,
SDMMC_CARD_T pCardInfo 
)

Get card's current state (idle, transfer, program, etc.)

Parameters
pSDC: Pointer to SDC peripheral base address
pCardInfo: Pointer to pre-allocated card info structure
Returns
Current SD card state

Definition at line 751 of file sdmmc_17xx_40xx.c.

uint32_t Chip_SDMMC_GetCardStatus ( LPC_SDC_T pSDC,
SDMMC_CARD_T pCardInfo 
)

Get 'card status' of SD Memory card.

Parameters
pSDC: Pointer to SDC peripheral base address
pCardInfo: Pointer to pre-allocated card info structure
Returns
Current SD card status

Definition at line 764 of file sdmmc_17xx_40xx.c.

int32_t Chip_SDMMC_GetSDStatus ( LPC_SDC_T pSDC,
SDMMC_CARD_T pCardInfo,
uint32_t pStatus 
)

Get 'sd status' of SD Memory card.

Parameters
pSDC: Pointer to SDC peripheral base address
pCardInfo: Pointer to pre-allocated card info structure
pStatus: Pointer to buffer storing status (it must be 64-byte-length)
Returns
Number of bytes read

Definition at line 772 of file sdmmc_17xx_40xx.c.

int32_t Chip_SDMMC_IRQHandler ( LPC_SDC_T pSDC,
uint8_t *  txBuf,
uint32_t txCnt,
uint8_t *  rxBuf,
uint32_t rxCnt 
)

SD card interrupt service routine.

Parameters
pSDC: Pointer to SDC peripheral base address
txBuf: Pointer to TX Buffer (If it is NULL, dont send data to card)
txCnt: Pointer to buffer storing the current transmit index
rxBuf: Pointer to RX Buffer (If it is NULL, dont read data from card)
rxCnt: Pointer to buffer storing the current receive index
Returns
Positive value: Data transfer Negative value: Error in data transfer Zero: Data transfer completed

Definition at line 720 of file sdmmc_17xx_40xx.c.

int32_t Chip_SDMMC_ReadBlocks ( LPC_SDC_T pSDC,
SDMMC_CARD_T pCardInfo,
void *  buffer,
int32_t  startblock,
int32_t  blockNum 
)

Performs the read of data from the SD/MMC card.

Parameters
pSDC: The base of SDC peripheral on the chip
pCardInfo: Pointer to Card information structure
buffer: Pointer to data buffer to copy to
startblock: Start block number
blockNum: Number of block to read
Returns
Bytes read, or 0 on error

Definition at line 945 of file sdmmc_17xx_40xx.c.

int32_t Chip_SDMMC_WriteBlocks ( LPC_SDC_T pSDC,
SDMMC_CARD_T pCardInfo,
void *  buffer,
int32_t  startblock,
int32_t  blockNum 
)

Performs write of data to the SD/MMC card.

Parameters
pSDC: The base of SDC peripheral on the chip
pCardInfo: Pointer to Card information structure
buffer: Pointer to data buffer to copy to
startblock: Start block number
blockNum: Number of block to write
Returns
Number of bytes actually written, or 0 on error

Definition at line 1026 of file sdmmc_17xx_40xx.c.