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
sdhcConfig->cardDetectDat3 = false;
sdhcConfig->endianMode = kSDHC_EndianModeLittle;
sdhcConfig->dmaMode = kSDHC_DmaModeAdma2;
sdhcConfig->readWatermarkLevel = 0x80U;
sdhcConfig->writeWatermarkLevel = 0x80U;
SDHC_Init(BOARD_SDHC_BASEADDR, sdhcConfig);
card->host.base = BOARD_SDHC_BASEADDR;
card->host.transfer = SDHC_TransferFunction;
{
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");
}
}
sdhcConfig->cardDetectDat3 = false;
sdhcConfig->endianMode = kSDHC_EndianModeLittle;
sdhcConfig->dmaMode = kSDHC_DmaModeAdma2;
sdhcConfig->readWatermarkLevel = 0x80U;
sdhcConfig->writeWatermarkLevel = 0x80U;
SDHC_Init(BOARD_SDHC_BASEADDR, sdhcConfig);
card->host.base = BOARD_SDHC_BASEADDR;
card->host.transfer = SDHC_TransferFunction;
{
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");
}
}
|
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...
|
|
|
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...
|
|
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.
|
|
Define the card structure including the necessary fields to identify and describe the card.
#define FSL_SDMMC_DRIVER_VERSION (MAKE_VERSION(2U, 1U, 1U)) /*2.1.1*/ |
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.
|
This function initializes the card on a specific host controller.
- Parameters
-
- Return values
-
kStatus_SDMMC_GoIdleFailed | Go idle failed. |
kStatus_SDMMC_NotSupportYet | Card not support. |
kStatus_SDMMC_SendOperationConditionFailed | Send operation condition failed. |
kStatus_SDMMC_AllSendCidFailed | Send CID failed. |
kStatus_SDMMC_SendRelativeAddressFailed | Send relative address failed. |
kStatus_SDMMC_SendCsdFailed | Send CSD failed. |
kStatus_SDMMC_SelectCardFailed | Send SELECT_CARD command failed. |
kStatus_SDMMC_SendScrFailed | Send SCR failed. |
kStatus_SDMMC_SetBusWidthFailed | Set bus width failed. |
kStatus_SDMMC_SwitchHighSpeedFailed | Switch high speed failed. |
kStatus_SDMMC_SetCardBlockSizeFailed | Set card block size failed. |
kStatus_Success | Operate successfully. |
This function deinitializes the specific card.
- Parameters
-
This function checks if the card is write-protected via CSD register.
- Parameters
-
- Return values
-
true | Card is read only. |
false | Card 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
-
card | Card descriptor. |
buffer | The buffer to save the data read from card. |
startBlock | The start block index. |
blockCount | The number of blocks to read. |
- Return values
-
kStatus_InvalidArgument | Invalid argument. |
kStatus_SDMMC_CardNotSupport | Card not support. |
kStatus_SDMMC_NotSupportYet | Not support now. |
kStatus_SDMMC_WaitWriteCompleteFailed | Send status failed. |
kStatus_SDMMC_TransferFailed | Transfer failed. |
kStatus_SDMMC_StopTransmissionFailed | Stop transmission failed. |
kStatus_Success | Operate 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
-
card | Card descriptor. |
buffer | The buffer holding the data to be written to the card. |
startBlock | The start block index. |
blockCount | The number of blocks to write. |
- Return values
-
kStatus_InvalidArgument | Invalid argument. |
kStatus_SDMMC_NotSupportYet | Not support now. |
kStatus_SDMMC_CardNotSupport | Card not support. |
kStatus_SDMMC_WaitWriteCompleteFailed | Send status failed. |
kStatus_SDMMC_TransferFailed | Transfer failed. |
kStatus_SDMMC_StopTransmissionFailed | Stop transmission failed. |
kStatus_Success | Operate 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
-
card | Card descriptor. |
startBlock | The start block index. |
blockCount | The number of blocks to erase. |
- Return values
-
kStatus_InvalidArgument | Invalid argument. |
kStatus_SDMMC_WaitWriteCompleteFailed | Send status failed. |
kStatus_SDMMC_TransferFailed | Transfer failed. |
kStatus_SDMMC_WaitWriteCompleteFailed | Send status failed. |
kStatus_Success | Operate successfully. |
- Parameters
-
- Return values
-
kStatus_SDMMC_GoIdleFailed | Go idle failed. |
kStatus_SDMMC_SendOperationConditionFailed | Send operation condition failed. |
kStatus_SDMMC_AllSendCidFailed | Send CID failed. |
kStatus_SDMMC_SetRelativeAddressFailed | Set relative address failed. |
kStatus_SDMMC_SendCsdFailed | Send CSD failed. |
kStatus_SDMMC_CardNotSupport | Card not support. |
kStatus_SDMMC_SelectCardFailed | Send SELECT_CARD command failed. |
kStatus_SDMMC_SendExtendedCsdFailed | Send EXT_CSD failed. |
kStatus_SDMMC_SetBusWidthFailed | Set bus width failed. |
kStatus_SDMMC_SwitchHighSpeedFailed | Switch high speed failed. |
kStatus_SDMMC_SetCardBlockSizeFailed | Set card block size failed. |
kStatus_Success | Operate successfully. |
- Parameters
-
- Return values
-
true | Card is read only. |
false | Card isn't read only. |
status_t MMC_ReadBlocks |
( |
mmc_card_t * |
card, |
|
|
uint8_t * |
buffer, |
|
|
uint32_t |
startBlock, |
|
|
uint32_t |
blockCount |
|
) |
| |
- Parameters
-
card | Card descriptor. |
buffer | The buffer to save data. |
startBlock | The start block index. |
blockCount | The number of blocks to read. |
- Return values
-
kStatus_InvalidArgument | Invalid argument. |
kStatus_SDMMC_CardNotSupport | Card not support. |
kStatus_SDMMC_SetBlockCountFailed | Set block count failed. |
kStatus_SDMMC_TransferFailed | Transfer failed. |
kStatus_SDMMC_StopTransmissionFailed | Stop transmission failed. |
kStatus_Success | Operate successfully. |
status_t MMC_WriteBlocks |
( |
mmc_card_t * |
card, |
|
|
const uint8_t * |
buffer, |
|
|
uint32_t |
startBlock, |
|
|
uint32_t |
blockCount |
|
) |
| |
- Parameters
-
card | Card descriptor. |
buffer | The buffer to save data blocks. |
startBlock | Start block number to write. |
blockCount | Block count. |
- Return values
-
kStatus_InvalidArgument | Invalid argument. |
kStatus_SDMMC_NotSupportYet | Not support now. |
kStatus_SDMMC_SetBlockCountFailed | Set block count failed. |
kStatus_SDMMC_WaitWriteCompleteFailed | Send status failed. |
kStatus_SDMMC_TransferFailed | Transfer failed. |
kStatus_SDMMC_StopTransmissionFailed | Stop transmission failed. |
kStatus_Success | Operate 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
-
card | Card descriptor. |
startGroup | Start group number. |
endGroup | End group number. |
- Return values
-
kStatus_InvalidArgument | Invalid argument. |
kStatus_SDMMC_WaitWriteCompleteFailed | Send status failed. |
kStatus_SDMMC_TransferFailed | Transfer failed. |
kStatus_Success | Operate successfully. |
status_t MMC_SelectPartition |
( |
mmc_card_t * |
card, |
|
|
mmc_access_partition_t |
partitionNumber |
|
) |
| |
- Parameters
-
card | Card descriptor. |
partitionNumber | The partition number. |
- Return values
-
kStatus_SDMMC_ConfigureExtendedCsdFailed | Configure EXT_CSD failed. |
kStatus_Success | Operate successfully. |
- Parameters
-
card | Card descriptor. |
config | Boot configuration structure. |
- Return values
-
kStatus_SDMMC_NotSupportYet | Not support now. |
kStatus_SDMMC_ConfigureExtendedCsdFailed | Configure EXT_CSD failed. |
kStatus_SDMMC_ConfigureBootFailed | Configure boot failed. |
kStatus_Success | Operate successfully. |