Kinetis SDK v.2.0 API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Secured Digital Card/Embedded MultiMedia Card (CARD)

Overview

The Kinetis SDK provides a driver to access the Secured Digital Card and Embedded MultiMedia Card based on the SDHC driver.

Function groups

This function group implements the SD card functional API.

This function group implements the MMC card functional API.

Typical use case

/* Initialize SDHC. */
sdhcConfig->cardDetectDat3 = false;
sdhcConfig->endianMode = kSDHC_EndianModeLittle;
sdhcConfig->dmaMode = kSDHC_DmaModeAdma2;
sdhcConfig->readWatermarkLevel = 0x80U;
sdhcConfig->writeWatermarkLevel = 0x80U;
SDHC_Init(BOARD_SDHC_BASEADDR, sdhcConfig);
/* Save host information. */
card->host.base = BOARD_SDHC_BASEADDR;
card->host.sourceClock_Hz = CLOCK_GetFreq(BOARD_SDHC_CLKSRC);
card->host.transfer = SDHC_TransferFunction;
/* Init card. */
if (SD_Init(card))
{
PRINTF("\r\nSD card init failed.\r\n");
}
while (true)
{
if (kStatus_Success != SD_WriteBlocks(card, g_dataWrite, DATA_BLOCK_START, DATA_BLOCK_COUNT))
{
PRINTF("Write multiple data blocks failed.\r\n");
}
if (kStatus_Success != SD_ReadBlocks(card, g_dataRead, DATA_BLOCK_START, DATA_BLOCK_COUNT))
{
PRINTF("Read multiple data blocks failed.\r\n");
}
if (kStatus_Success != SD_EraseBlocks(card, DATA_BLOCK_START, DATA_BLOCK_COUNT))
{
PRINTF("Erase multiple data blocks failed.\r\n");
}
}
SD_Deinit(card);
/* Initialize SDHC. */
sdhcConfig->cardDetectDat3 = false;
sdhcConfig->endianMode = kSDHC_EndianModeLittle;
sdhcConfig->dmaMode = kSDHC_DmaModeAdma2;
sdhcConfig->readWatermarkLevel = 0x80U;
sdhcConfig->writeWatermarkLevel = 0x80U;
SDHC_Init(BOARD_SDHC_BASEADDR, sdhcConfig);
/* Save host information. */
card->host.base = BOARD_SDHC_BASEADDR;
card->host.sourceClock_Hz = CLOCK_GetFreq(BOARD_SDHC_CLKSRC);
card->host.transfer = SDHC_TransferFunction;
/* Init card. */
if (MMC_Init(card))
{
PRINTF("\n MMC card init failed \n");
}
while (true)
{
if (kStatus_Success != MMC_WriteBlocks(card, g_dataWrite, DATA_BLOCK_START, DATA_BLOCK_COUNT))
{
PRINTF("Write multiple data blocks failed.\r\n");
}
if (kStatus_Success != MMC_ReadBlocks(card, g_dataRead, DATA_BLOCK_START, DATA_BLOCK_COUNT))
{
PRINTF("Read multiple data blocks failed.\r\n");
}
}
MMC_Deinit(card);

Data Structures

struct  sd_card_t
 SD card state. More...
 
struct  mmc_card_t
 SD card state. More...
 
struct  mmc_boot_config_t
 MMC card boot configuration definition. More...
 

Macros

#define FSL_SDMMC_DRIVER_VERSION   (MAKE_VERSION(2U, 1U, 1U)) /*2.1.1*/
 Driver version. More...
 
#define FSL_SDMMC_DEFAULT_BLOCK_SIZE   (512U)
 Default block size.
 

Enumerations

enum  _sdmmc_status {
  kStatus_SDMMC_NotSupportYet = MAKE_STATUS(kStatusGroup_SDMMC, 0U),
  kStatus_SDMMC_TransferFailed = MAKE_STATUS(kStatusGroup_SDMMC, 1U),
  kStatus_SDMMC_SetCardBlockSizeFailed = MAKE_STATUS(kStatusGroup_SDMMC, 2U),
  kStatus_SDMMC_HostNotSupport = MAKE_STATUS(kStatusGroup_SDMMC, 3U),
  kStatus_SDMMC_CardNotSupport = MAKE_STATUS(kStatusGroup_SDMMC, 4U),
  kStatus_SDMMC_AllSendCidFailed = MAKE_STATUS(kStatusGroup_SDMMC, 5U),
  kStatus_SDMMC_SendRelativeAddressFailed = MAKE_STATUS(kStatusGroup_SDMMC, 6U),
  kStatus_SDMMC_SendCsdFailed = MAKE_STATUS(kStatusGroup_SDMMC, 7U),
  kStatus_SDMMC_SelectCardFailed = MAKE_STATUS(kStatusGroup_SDMMC, 8U),
  kStatus_SDMMC_SendScrFailed = MAKE_STATUS(kStatusGroup_SDMMC, 9U),
  kStatus_SDMMC_SetDataBusWidthFailed = MAKE_STATUS(kStatusGroup_SDMMC, 10U),
  kStatus_SDMMC_GoIdleFailed = MAKE_STATUS(kStatusGroup_SDMMC, 11U),
  kStatus_SDMMC_HandShakeOperationConditionFailed,
  kStatus_SDMMC_SendApplicationCommandFailed,
  kStatus_SDMMC_SwitchFailed = MAKE_STATUS(kStatusGroup_SDMMC, 14U),
  kStatus_SDMMC_StopTransmissionFailed = MAKE_STATUS(kStatusGroup_SDMMC, 15U),
  kStatus_SDMMC_WaitWriteCompleteFailed = MAKE_STATUS(kStatusGroup_SDMMC, 16U),
  kStatus_SDMMC_SetBlockCountFailed = MAKE_STATUS(kStatusGroup_SDMMC, 17U),
  kStatus_SDMMC_SetRelativeAddressFailed = MAKE_STATUS(kStatusGroup_SDMMC, 18U),
  kStatus_SDMMC_SwitchHighSpeedFailed = MAKE_STATUS(kStatusGroup_SDMMC, 19U),
  kStatus_SDMMC_SendExtendedCsdFailed = MAKE_STATUS(kStatusGroup_SDMMC, 20U),
  kStatus_SDMMC_ConfigureBootFailed = MAKE_STATUS(kStatusGroup_SDMMC, 21U),
  kStatus_SDMMC_ConfigureExtendedCsdFailed = MAKE_STATUS(kStatusGroup_SDMMC, 22U),
  kStatus_SDMMC_EnableHighCapacityEraseFailed,
  kStatus_SDMMC_SendTestPatternFailed = MAKE_STATUS(kStatusGroup_SDMMC, 24U),
  kStatus_SDMMC_ReceiveTestPatternFailed = MAKE_STATUS(kStatusGroup_SDMMC, 25U)
}
 SD/MMC card API's running status. More...
 
enum  _sd_card_flag {
  kSD_SupportHighCapacityFlag = (1U << 1U),
  kSD_Support4BitWidthFlag = (1U << 2U),
  kSD_SupportSdhcFlag = (1U << 3U),
  kSD_SupportSdxcFlag = (1U << 4U)
}
 SD card flags. More...
 
enum  _mmc_card_flag {
  kMMC_SupportHighCapacityFlag = (1U << 0U),
  kMMC_SupportHighSpeedFlag = (1U << 1U),
  kMMC_SupportHighSpeed52MHZFlag = (1U << 2U),
  kMMC_SupportHighSpeed26MHZFlag = (1U << 3U),
  kMMC_SupportAlternateBootFlag = (1U << 4U)
}
 MMC card flags. More...
 

SDCARD Function

status_t SD_Init (sd_card_t *card)
 Initialize the card on a specific host controller. More...
 
void SD_Deinit (sd_card_t *card)
 Deinitialize the card. More...
 
bool SD_CheckReadOnly (sd_card_t *card)
 Check whether the card is write-protected. More...
 
status_t SD_ReadBlocks (sd_card_t *card, uint8_t *buffer, uint32_t startBlock, uint32_t blockCount)
 Read blocks from the specific card. More...
 
status_t SD_WriteBlocks (sd_card_t *card, const uint8_t *buffer, uint32_t startBlock, uint32_t blockCount)
 Write blocks of data to the specific card. More...
 
status_t SD_EraseBlocks (sd_card_t *card, uint32_t startBlock, uint32_t blockCount)
 Erase blocks of the specific card. More...
 

MMCCARD Function

status_t MMC_Init (mmc_card_t *card)
 Initialize the MMC card. More...
 
void MMC_Deinit (mmc_card_t *card)
 Deinitialize the card. More...
 
bool MMC_CheckReadOnly (mmc_card_t *card)
 Check if the card is read only. More...
 
status_t MMC_ReadBlocks (mmc_card_t *card, uint8_t *buffer, uint32_t startBlock, uint32_t blockCount)
 Read data blocks from the card. More...
 
status_t MMC_WriteBlocks (mmc_card_t *card, const uint8_t *buffer, uint32_t startBlock, uint32_t blockCount)
 Write data blocks to the card. More...
 
status_t MMC_EraseGroups (mmc_card_t *card, uint32_t startGroup, uint32_t endGroup)
 Erase groups of the card. More...
 
status_t MMC_SelectPartition (mmc_card_t *card, mmc_access_partition_t partitionNumber)
 Select the partition to access. More...
 
status_t MMC_SetBootConfig (mmc_card_t *card, const mmc_boot_config_t *config)
 Configure boot activity of the card. More...
 

Data Structure Documentation

struct sd_card_t

Define the card structure including the necessary fields to identify and describe the card.

Data Fields

sdhc_host_t host
 Host information.
 
uint32_t busClock_Hz
 SD bus clock frequency united in Hz.
 
uint32_t relativeAddress
 Relative address of the card.
 
uint32_t version
 Card version.
 
uint32_t flags
 Flags in _sd_card_flag.
 
uint32_t rawCid [4U]
 Raw CID content.
 
uint32_t rawCsd [4U]
 Raw CSD content.
 
uint32_t rawScr [2U]
 Raw CSD content.
 
uint32_t ocr
 Raw OCR content.
 
sd_cid_t cid
 CID.
 
sd_csd_t csd
 CSD.
 
sd_scr_t scr
 SCR.
 
uint32_t blockCount
 Card total block number.
 
uint32_t blockSize
 Card block size.
 
struct mmc_card_t

Define the card structure including the necessary fields to identify and describe the card.

Data Fields

sdhc_host_t host
 Host information.
 
uint32_t busClock_Hz
 MMC bus clock united in Hz.
 
uint32_t relativeAddress
 Relative address of the card.
 
bool enablePreDefinedBlockCount
 Enable PRE-DEFINED block count when read/write.
 
uint32_t flags
 Capability flag in _mmc_card_flag.
 
uint32_t rawCid [4U]
 Raw CID content.
 
uint32_t rawCsd [4U]
 Raw CSD content.
 
uint32_t rawExtendedCsd [MMC_EXTENDED_CSD_BYTES/4U]
 Raw MMC Extended CSD content.
 
uint32_t ocr
 Raw OCR content.
 
mmc_cid_t cid
 CID.
 
mmc_csd_t csd
 CSD.
 
mmc_extended_csd_t extendedCsd
 Extended CSD.
 
uint32_t blockSize
 Card block size.
 
uint32_t userPartitionBlocks
 Card total block number in user partition.
 
uint32_t bootPartitionBlocks
 Boot partition size united as block size.
 
uint32_t eraseGroupBlocks
 Erase group size united as block size.
 
mmc_access_partition_t currentPartition
 Current access partition.
 
mmc_voltage_window_t hostVoltageWindow
 Host voltage window.
 
struct mmc_boot_config_t

Data Fields

bool enableBootAck
 Enable boot ACK.
 
mmc_boot_partition_enable_t bootPartition
 Boot partition.
 
bool retainBootBusWidth
 If retain boot bus width.
 
mmc_data_bus_width_t bootDataBusWidth
 Boot data bus width.
 

Macro Definition Documentation

#define FSL_SDMMC_DRIVER_VERSION   (MAKE_VERSION(2U, 1U, 1U)) /*2.1.1*/

Enumeration Type Documentation

Enumerator
kStatus_SDMMC_NotSupportYet 

Haven't supported.

kStatus_SDMMC_TransferFailed 

Send command failed.

kStatus_SDMMC_SetCardBlockSizeFailed 

Set block size failed.

kStatus_SDMMC_HostNotSupport 

Host doesn't support.

kStatus_SDMMC_CardNotSupport 

Card doesn't support.

kStatus_SDMMC_AllSendCidFailed 

Send CID failed.

kStatus_SDMMC_SendRelativeAddressFailed 

Send relative address failed.

kStatus_SDMMC_SendCsdFailed 

Send CSD failed.

kStatus_SDMMC_SelectCardFailed 

Select card failed.

kStatus_SDMMC_SendScrFailed 

Send SCR failed.

kStatus_SDMMC_SetDataBusWidthFailed 

Set bus width failed.

kStatus_SDMMC_GoIdleFailed 

Go idle failed.

kStatus_SDMMC_HandShakeOperationConditionFailed 

Send Operation Condition failed.

kStatus_SDMMC_SendApplicationCommandFailed 

Send application command failed.

kStatus_SDMMC_SwitchFailed 

Switch command failed.

kStatus_SDMMC_StopTransmissionFailed 

Stop transmission failed.

kStatus_SDMMC_WaitWriteCompleteFailed 

Wait write complete failed.

kStatus_SDMMC_SetBlockCountFailed 

Set block count failed.

kStatus_SDMMC_SetRelativeAddressFailed 

Set relative address failed.

kStatus_SDMMC_SwitchHighSpeedFailed 

Switch high speed failed.

kStatus_SDMMC_SendExtendedCsdFailed 

Send EXT_CSD failed.

kStatus_SDMMC_ConfigureBootFailed 

Configure boot failed.

kStatus_SDMMC_ConfigureExtendedCsdFailed 

Configure EXT_CSD failed.

kStatus_SDMMC_EnableHighCapacityEraseFailed 

Enable high capacity erase failed.

kStatus_SDMMC_SendTestPatternFailed 

Send test pattern failed.

kStatus_SDMMC_ReceiveTestPatternFailed 

Receive test pattern failed.

Enumerator
kSD_SupportHighCapacityFlag 

Support high capacity.

kSD_Support4BitWidthFlag 

Support 4-bit data width.

kSD_SupportSdhcFlag 

Card is SDHC.

kSD_SupportSdxcFlag 

Card is SDXC.

Enumerator
kMMC_SupportHighCapacityFlag 

Support high capacity.

kMMC_SupportHighSpeedFlag 

Support high speed.

kMMC_SupportHighSpeed52MHZFlag 

Support high speed 52MHZ.

kMMC_SupportHighSpeed26MHZFlag 

Support high speed 26MHZ.

kMMC_SupportAlternateBootFlag 

Support alternate boot.

Function Documentation

status_t SD_Init ( sd_card_t card)

This function initializes the card on a specific host controller.

Parameters
cardCard descriptor.
Return values
kStatus_SDMMC_GoIdleFailedGo idle failed.
kStatus_SDMMC_NotSupportYetCard not support.
kStatus_SDMMC_SendOperationConditionFailedSend operation condition failed.
kStatus_SDMMC_AllSendCidFailedSend CID failed.
kStatus_SDMMC_SendRelativeAddressFailedSend relative address failed.
kStatus_SDMMC_SendCsdFailedSend CSD failed.
kStatus_SDMMC_SelectCardFailedSend SELECT_CARD command failed.
kStatus_SDMMC_SendScrFailedSend SCR failed.
kStatus_SDMMC_SetBusWidthFailedSet bus width failed.
kStatus_SDMMC_SwitchHighSpeedFailedSwitch high speed failed.
kStatus_SDMMC_SetCardBlockSizeFailedSet card block size failed.
kStatus_SuccessOperate successfully.
void SD_Deinit ( sd_card_t card)

This function deinitializes the specific card.

Parameters
cardCard descriptor.
bool SD_CheckReadOnly ( sd_card_t card)

This function checks if the card is write-protected via CSD register.

Parameters
cardThe specific card.
Return values
trueCard is read only.
falseCard isn't read only.
status_t SD_ReadBlocks ( sd_card_t card,
uint8_t *  buffer,
uint32_t  startBlock,
uint32_t  blockCount 
)

This function reads blocks from specific card, with default block size defined by SDHC_CARD_DEFAULT_BLOCK_SIZE.

Parameters
cardCard descriptor.
bufferThe buffer to save the data read from card.
startBlockThe start block index.
blockCountThe number of blocks to read.
Return values
kStatus_InvalidArgumentInvalid argument.
kStatus_SDMMC_CardNotSupportCard not support.
kStatus_SDMMC_NotSupportYetNot support now.
kStatus_SDMMC_WaitWriteCompleteFailedSend status failed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SDMMC_StopTransmissionFailedStop transmission failed.
kStatus_SuccessOperate successfully.
status_t SD_WriteBlocks ( sd_card_t card,
const uint8_t *  buffer,
uint32_t  startBlock,
uint32_t  blockCount 
)

This function writes blocks to specific card, with default block size 512 bytes.

Parameters
cardCard descriptor.
bufferThe buffer holding the data to be written to the card.
startBlockThe start block index.
blockCountThe number of blocks to write.
Return values
kStatus_InvalidArgumentInvalid argument.
kStatus_SDMMC_NotSupportYetNot support now.
kStatus_SDMMC_CardNotSupportCard not support.
kStatus_SDMMC_WaitWriteCompleteFailedSend status failed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SDMMC_StopTransmissionFailedStop transmission failed.
kStatus_SuccessOperate successfully.
status_t SD_EraseBlocks ( sd_card_t card,
uint32_t  startBlock,
uint32_t  blockCount 
)

This function erases blocks of a specific card, with default block size 512 bytes.

Parameters
cardCard descriptor.
startBlockThe start block index.
blockCountThe number of blocks to erase.
Return values
kStatus_InvalidArgumentInvalid argument.
kStatus_SDMMC_WaitWriteCompleteFailedSend status failed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SDMMC_WaitWriteCompleteFailedSend status failed.
kStatus_SuccessOperate successfully.
status_t MMC_Init ( mmc_card_t card)
Parameters
cardCard descriptor.
Return values
kStatus_SDMMC_GoIdleFailedGo idle failed.
kStatus_SDMMC_SendOperationConditionFailedSend operation condition failed.
kStatus_SDMMC_AllSendCidFailedSend CID failed.
kStatus_SDMMC_SetRelativeAddressFailedSet relative address failed.
kStatus_SDMMC_SendCsdFailedSend CSD failed.
kStatus_SDMMC_CardNotSupportCard not support.
kStatus_SDMMC_SelectCardFailedSend SELECT_CARD command failed.
kStatus_SDMMC_SendExtendedCsdFailedSend EXT_CSD failed.
kStatus_SDMMC_SetBusWidthFailedSet bus width failed.
kStatus_SDMMC_SwitchHighSpeedFailedSwitch high speed failed.
kStatus_SDMMC_SetCardBlockSizeFailedSet card block size failed.
kStatus_SuccessOperate successfully.
void MMC_Deinit ( mmc_card_t card)
Parameters
cardCard descriptor.
bool MMC_CheckReadOnly ( mmc_card_t card)
Parameters
cardCard descriptor.
Return values
trueCard is read only.
falseCard isn't read only.
status_t MMC_ReadBlocks ( mmc_card_t card,
uint8_t *  buffer,
uint32_t  startBlock,
uint32_t  blockCount 
)
Parameters
cardCard descriptor.
bufferThe buffer to save data.
startBlockThe start block index.
blockCountThe number of blocks to read.
Return values
kStatus_InvalidArgumentInvalid argument.
kStatus_SDMMC_CardNotSupportCard not support.
kStatus_SDMMC_SetBlockCountFailedSet block count failed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SDMMC_StopTransmissionFailedStop transmission failed.
kStatus_SuccessOperate successfully.
status_t MMC_WriteBlocks ( mmc_card_t card,
const uint8_t *  buffer,
uint32_t  startBlock,
uint32_t  blockCount 
)
Parameters
cardCard descriptor.
bufferThe buffer to save data blocks.
startBlockStart block number to write.
blockCountBlock count.
Return values
kStatus_InvalidArgumentInvalid argument.
kStatus_SDMMC_NotSupportYetNot support now.
kStatus_SDMMC_SetBlockCountFailedSet block count failed.
kStatus_SDMMC_WaitWriteCompleteFailedSend status failed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SDMMC_StopTransmissionFailedStop transmission failed.
kStatus_SuccessOperate successfully.
status_t MMC_EraseGroups ( mmc_card_t card,
uint32_t  startGroup,
uint32_t  endGroup 
)

Erase group is the smallest erase unit in MMC card. The erase range is [startGroup, endGroup].

Parameters
cardCard descriptor.
startGroupStart group number.
endGroupEnd group number.
Return values
kStatus_InvalidArgumentInvalid argument.
kStatus_SDMMC_WaitWriteCompleteFailedSend status failed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SuccessOperate successfully.
status_t MMC_SelectPartition ( mmc_card_t card,
mmc_access_partition_t  partitionNumber 
)
Parameters
cardCard descriptor.
partitionNumberThe partition number.
Return values
kStatus_SDMMC_ConfigureExtendedCsdFailedConfigure EXT_CSD failed.
kStatus_SuccessOperate successfully.
status_t MMC_SetBootConfig ( mmc_card_t card,
const mmc_boot_config_t config 
)
Parameters
cardCard descriptor.
configBoot configuration structure.
Return values
kStatus_SDMMC_NotSupportYetNot support now.
kStatus_SDMMC_ConfigureExtendedCsdFailedConfigure EXT_CSD failed.
kStatus_SDMMC_ConfigureBootFailedConfigure boot failed.
kStatus_SuccessOperate successfully.