MCUXpresso SDK API Reference Manual  Rev 2.15.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

The MMCCARD driver provide card initialization/read/write/erase interface.

MMC CARD Operation

error log support

Not support yet

User configuable

Board dependency

Mutual exclusive access support for RTOS

MMCCARD driver has added mutual exclusive access support for init/deinit/write/read/erase function. Please note that the card init function will create the mutex lock dynamically by default, so to avoid the mutex create redundantly, application must follow bellow sequence for card re-initialization.

MMC_Deinit(card);/* This function will destroy the created mutex */
MMC_Init(card);

Typical use case

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/sdmmc_examples/

Data Structures

struct  _mmc_usr_param
 card user parameter More...
 
struct  _mmc_card
 mmc card state More...
 

Macros

#define FSL_MMC_DRIVER_VERSION   (MAKE_VERSION(2U, 5U, 0U)) /*2.5.0*/
 Middleware mmc version. More...
 

Typedefs

typedef enum _mmc_sleep_awake mmc_sleep_awake_t
 mmccard sleep/awake state
 
typedef void(* mmc_io_strength_t )(uint32_t busFreq)
 card io strength control
 
typedef struct _mmc_usr_param mmc_usr_param_t
 card user parameter
 
typedef struct _mmc_card mmc_card_t
 mmc card state More...
 

Enumerations

enum  {
  kMMC_SupportHighSpeed26MHZFlag = (1U << 0U),
  kMMC_SupportHighSpeed52MHZFlag = (1U << 1U),
  kMMC_SupportHighSpeedDDR52MHZ180V300VFlag = (1 << 2U),
  kMMC_SupportHighSpeedDDR52MHZ120VFlag = (1 << 3U),
  kMMC_SupportHS200200MHZ180VFlag = (1 << 4U),
  kMMC_SupportHS200200MHZ120VFlag = (1 << 5U),
  kMMC_SupportHS400DDR200MHZ180VFlag = (1 << 6U),
  kMMC_SupportHS400DDR200MHZ120VFlag = (1 << 7U),
  kMMC_SupportHighCapacityFlag = (1U << 8U),
  kMMC_SupportAlternateBootFlag = (1U << 9U),
  kMMC_SupportDDRBootFlag = (1U << 10U),
  kMMC_SupportHighSpeedBootFlag = (1U << 11U),
  kMMC_SupportEnhanceHS400StrobeFlag = (1U << 12U)
}
 MMC card flags. More...
 
enum  _mmc_sleep_awake {
  kMMC_Sleep = 1U,
  kMMC_Awake = 0U
}
 mmccard sleep/awake state More...
 

MMCCARD Function

status_t MMC_Init (mmc_card_t *card)
 Initializes the MMC card and host. More...
 
void MMC_Deinit (mmc_card_t *card)
 Deinitializes the card and host. More...
 
status_t MMC_CardInit (mmc_card_t *card)
 Initializes the card. More...
 
void MMC_CardDeinit (mmc_card_t *card)
 Deinitializes the card. More...
 
status_t MMC_HostInit (mmc_card_t *card)
 initialize the host. More...
 
void MMC_HostDeinit (mmc_card_t *card)
 Deinitializes the host. More...
 
void MMC_HostDoReset (mmc_card_t *card)
 Resets the host. More...
 
void MMC_HostReset (SDMMCHOST_CONFIG *host)
 Resets the host. More...
 
void MMC_SetCardPower (mmc_card_t *card, bool enable)
 Sets card power. More...
 
bool MMC_CheckReadOnly (mmc_card_t *card)
 Checks if the card is read-only. More...
 
status_t MMC_ReadBlocks (mmc_card_t *card, uint8_t *buffer, uint32_t startBlock, uint32_t blockCount)
 Reads data blocks from the card. More...
 
status_t MMC_WriteBlocks (mmc_card_t *card, const uint8_t *buffer, uint32_t startBlock, uint32_t blockCount)
 Writes data blocks to the card. More...
 
status_t MMC_EraseGroups (mmc_card_t *card, uint32_t startGroup, uint32_t endGroup)
 Erases groups of the card. More...
 
status_t MMC_SelectPartition (mmc_card_t *card, mmc_access_partition_t partitionNumber)
 Selects the partition to access. More...
 
status_t MMC_SetBootConfig (mmc_card_t *card, const mmc_boot_config_t *config)
 Configures the boot activity of the card. More...
 
status_t MMC_StartBoot (mmc_card_t *card, const mmc_boot_config_t *mmcConfig, uint8_t *buffer, sdmmchost_boot_config_t *hostConfig)
 MMC card start boot. More...
 
status_t MMC_SetBootConfigWP (mmc_card_t *card, uint8_t wp)
 MMC card set boot configuration write protect. More...
 
status_t MMC_ReadBootData (mmc_card_t *card, uint8_t *buffer, sdmmchost_boot_config_t *hostConfig)
 MMC card continuous read boot data. More...
 
status_t MMC_StopBoot (mmc_card_t *card, uint32_t bootMode)
 MMC card stop boot mode. More...
 
status_t MMC_SetBootPartitionWP (mmc_card_t *card, mmc_boot_partition_wp_t bootPartitionWP)
 MMC card set boot partition write protect. More...
 
status_t MMC_EnableCacheControl (mmc_card_t *card, bool enable)
 MMC card cache control function. More...
 
status_t MMC_FlushCache (mmc_card_t *card)
 MMC card cache flush function. More...
 
status_t MMC_SetSleepAwake (mmc_card_t *card, mmc_sleep_awake_t state)
 MMC sets card sleep awake state. More...
 
status_t MMC_PollingCardStatusBusy (mmc_card_t *card, bool checkStatus, uint32_t timeoutMs)
 Polling card idle status. More...
 

Data Structure Documentation

struct _mmc_usr_param

Data Fields

mmc_io_strength_t ioStrength
 switch sd io strength
 
uint32_t maxFreq
 board support maximum frequency
 
uint32_t capability
 board capability flag
 
struct _mmc_card

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

Data Fields

sdmmchost_thost
 Host information.
 
mmc_usr_param_t usrParam
 user parameter
 
bool isHostReady
 Use this flag to indicate if host re-init needed or not.
 
bool noInteralAlign
 Use this flag to disable sdmmc align. More...
 
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.
 
uint8_t internalBuffer [FSL_SDMMC_CARD_INTERNAL_BUFFER_SIZE]
 raw buffer used for mmc driver internal
 
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 hostVoltageWindowVCCQ
 application must set this value according to board specific
 
mmc_voltage_window_t hostVoltageWindowVCC
 application must set this value according to board specific
 
mmc_high_speed_timing_t busTiming
 indicates the current work timing mode
 
mmc_data_bus_width_t busWidth
 indicates the current work bus width
 
sdmmc_osa_mutex_t lock
 card access lock
 

Field Documentation

bool _mmc_card::noInteralAlign

If disabled, sdmmc will not make sure the data buffer address is word align, otherwise all the transfer are aligned to low level driver.

Macro Definition Documentation

#define FSL_MMC_DRIVER_VERSION   (MAKE_VERSION(2U, 5U, 0U)) /*2.5.0*/

Typedef Documentation

typedef struct _mmc_card mmc_card_t

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

Enumeration Type Documentation

anonymous enum

Enumerator
kMMC_SupportHighSpeed26MHZFlag 

Support high speed 26MHZ.

kMMC_SupportHighSpeed52MHZFlag 

Support high speed 52MHZ.

kMMC_SupportHighSpeedDDR52MHZ180V300VFlag 

ddr 52MHZ 1.8V or 3.0V

kMMC_SupportHighSpeedDDR52MHZ120VFlag 

DDR 52MHZ 1.2V.

kMMC_SupportHS200200MHZ180VFlag 

HS200 ,200MHZ,1.8V.

kMMC_SupportHS200200MHZ120VFlag 

HS200, 200MHZ, 1.2V.

kMMC_SupportHS400DDR200MHZ180VFlag 

HS400, DDR, 200MHZ,1.8V.

kMMC_SupportHS400DDR200MHZ120VFlag 

HS400, DDR, 200MHZ,1.2V.

kMMC_SupportHighCapacityFlag 

Support high capacity.

kMMC_SupportAlternateBootFlag 

Support alternate boot.

kMMC_SupportDDRBootFlag 

support DDR boot flag

kMMC_SupportHighSpeedBootFlag 

support high speed boot flag

kMMC_SupportEnhanceHS400StrobeFlag 

support enhance HS400 strobe

Enumerator
kMMC_Sleep 

MMC card sleep.

kMMC_Awake 

MMC card awake.

Function Documentation

status_t MMC_Init ( mmc_card_t card)
Parameters
cardCard descriptor.

Thread safe function, please note that the function will create the mutex lock dynamically by default, so to avoid the mutex to be created redundantly, application must follow bellow sequence for card re-initialization:

MMC_Deinit(card);
MMC_Init(card);
*
Return values
kStatus_SDMMC_HostNotReadyHost is not ready.
kStatus_SDMMC_GoIdleFailedGoing idle failed.
kStatus_SDMMC_HandShakeOperationConditionFailedSending operation condition failed.
kStatus_SDMMC_AllSendCidFailedSending CID failed.
kStatus_SDMMC_SetRelativeAddressFailedSetging relative address failed.
kStatus_SDMMC_SendCsdFailedSending CSD failed.
kStatus_SDMMC_CardNotSupportCard not support.
kStatus_SDMMC_SelectCardFailedSending SELECT_CARD command failed.
kStatus_SDMMC_SendExtendedCsdFailedSending EXT_CSD failed.
kStatus_SDMMC_SetDataBusWidthFailedSetting bus width failed.
kStatus_SDMMC_SwitchBusTimingFailedSwitching high speed failed.
kStatus_SDMMC_SetCardBlockSizeFailedSetting card block size failed.
kStatus_SDMMC_SetPowerClassFailSetting card power class failed.
kStatus_SuccessOperation succeeded.
void MMC_Deinit ( mmc_card_t card)
Note
It is a thread safe function.
Parameters
cardCard descriptor.
status_t MMC_CardInit ( mmc_card_t card)

Thread safe function, please note that the function will create the mutex lock dynamically by default, so to avoid the mutex to be created redundantly, application must follow bellow sequence for card re-initialization:

MMC_CardInit(card);
*
Parameters
cardCard descriptor.
Return values
kStatus_SDMMC_HostNotReadyHost is not ready.
kStatus_SDMMC_GoIdleFailedGoing idle failed.
kStatus_SDMMC_HandShakeOperationConditionFailedSending operation condition failed.
kStatus_SDMMC_AllSendCidFailedSending CID failed.
kStatus_SDMMC_SetRelativeAddressFailedSetting relative address failed.
kStatus_SDMMC_SendCsdFailedSending CSD failed.
kStatus_SDMMC_CardNotSupportCard not support.
kStatus_SDMMC_SelectCardFailedSending SELECT_CARD command failed.
kStatus_SDMMC_SendExtendedCsdFailedSending EXT_CSD failed.
kStatus_SDMMC_SetDataBusWidthFailedSetting bus width failed.
kStatus_SDMMC_SwitchBusTimingFailedSwitching high speed failed.
kStatus_SDMMC_SetCardBlockSizeFailedSetting card block size failed.
kStatus_SDMMC_SetPowerClassFailSetting card power class failed.
kStatus_SuccessOperation succeeded.
void MMC_CardDeinit ( mmc_card_t card)
Note
It is a thread safe function.
Parameters
cardCard descriptor.
status_t MMC_HostInit ( mmc_card_t card)

This function deinitializes the specific host.

Parameters
cardCard descriptor.
void MMC_HostDeinit ( mmc_card_t card)

This function deinitializes the host.

Parameters
cardCard descriptor.
void MMC_HostDoReset ( mmc_card_t card)

This function resets the specific host.

Parameters
cardCard descriptor.
void MMC_HostReset ( SDMMCHOST_CONFIG host)
Deprecated:
Do not use this function. It has been superceded by MMC_HostDoReset. This function resets the specific host.
Parameters
hostHost descriptor.
void MMC_SetCardPower ( mmc_card_t card,
bool  enable 
)
Parameters
cardCard descriptor.
enableTrue is powering on, false is powering off.
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 
)
Note
It is a thread safe function.
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_SetBlockCountFailedSetting block count failed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SDMMC_StopTransmissionFailedStopping transmission failed.
kStatus_SuccessOperation succeeded.
status_t MMC_WriteBlocks ( mmc_card_t card,
const uint8_t *  buffer,
uint32_t  startBlock,
uint32_t  blockCount 
)
Note
  1. It is a thread safe function.
  2. It is an async write function which means that the card status may still be busy after the function returns. Application can call function MMC_PollingCardStatusBusy to wait for the card status to be idle after the write operation.
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_SetBlockCountFailedSetting block count failed.
kStatus_SDMMC_WaitWriteCompleteFailedSending status failed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SDMMC_StopTransmissionFailedStop transmission failed.
kStatus_SuccessOperation succeeded.
status_t MMC_EraseGroups ( mmc_card_t card,
uint32_t  startGroup,
uint32_t  endGroup 
)

The erase command is best used to erase the entire device or a partition. Erase group is the smallest erase unit in MMC card. The erase range is [startGroup, endGroup].

Note
  1. It is a thread safe function.
  2. This function always polls card busy status according to the timeout value defined in the card register after all the erase command sent out.
Parameters
cardCard descriptor.
startGroupStart group number.
endGroupEnd group number.
Return values
kStatus_InvalidArgumentInvalid argument.
kStatus_SDMMC_WaitWriteCompleteFailedSend status failed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SuccessOperation succeeded.
status_t MMC_SelectPartition ( mmc_card_t card,
mmc_access_partition_t  partitionNumber 
)
Note
It is a thread safe function.
Parameters
cardCard descriptor.
partitionNumberThe partition number.
Return values
kStatus_SDMMC_ConfigureExtendedCsdFailedConfiguring EXT_CSD failed.
kStatus_SuccessOperation succeeded.
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_ConfigureExtendedCsdFailedConfiguring EXT_CSD failed.
kStatus_SDMMC_ConfigureBootFailedConfiguring boot failed.
kStatus_SuccessOperation succeeded.
status_t MMC_StartBoot ( mmc_card_t card,
const mmc_boot_config_t mmcConfig,
uint8_t *  buffer,
sdmmchost_boot_config_t hostConfig 
)
Parameters
cardCard descriptor.
mmcConfigThe mmc Boot configuration structure.
bufferAddress to receive data.
hostConfigHost boot configurations.
Return values
kStatus_FailFailed.
kStatus_SDMMC_TransferFailedTransfer failed.
kStatus_SDMMC_GoIdleFailedResetting card failed.
kStatus_SuccessOperation succeeded.
status_t MMC_SetBootConfigWP ( mmc_card_t card,
uint8_t  wp 
)
Parameters
cardCard descriptor.
wpWrite protect value.
status_t MMC_ReadBootData ( mmc_card_t card,
uint8_t *  buffer,
sdmmchost_boot_config_t hostConfig 
)
Parameters
cardCard descriptor.
bufferBuffer address.
hostConfigHost boot configurations.
status_t MMC_StopBoot ( mmc_card_t card,
uint32_t  bootMode 
)
Parameters
cardCard descriptor.
bootModeBoot mode.
status_t MMC_SetBootPartitionWP ( mmc_card_t card,
mmc_boot_partition_wp_t  bootPartitionWP 
)
Parameters
cardCard descriptor.
bootPartitionWPBoot partition write protect value.
status_t MMC_EnableCacheControl ( mmc_card_t card,
bool  enable 
)

The mmc device's cache is enabled by the driver by default. The cache should in typical case reduce the access time (compared to an access to the main nonvolatile storage) for both write and read.

Parameters
cardCard descriptor.
enableTrue is enabling the cache, false is disabling the cache.
status_t MMC_FlushCache ( mmc_card_t card)

A Flush operation refers to the requirement, from the host to the device, to write the cached data to the nonvolatile memory. Prior to a flush, the device may autonomously write data to the nonvolatile memory, but after the flush operation all data in the volatile area must be written to nonvolatile memory. There is no requirement for flush due to switching between the partitions. (Note: This also implies that the cache data shall not be lost when switching between partitions). Cached data may be lost in SLEEP state, so host should flush the cache before placing the device into SLEEP state.

Parameters
cardCard descriptor.
status_t MMC_SetSleepAwake ( mmc_card_t card,
mmc_sleep_awake_t  state 
)

The Sleep/Awake command is used to initiate the state transition between Standby state and Sleep state. The memory device indicates the transition phase busy by pulling down the DAT0 line. The Sleep/Standby state is reached when the memory device stops pulling down the DAT0 line, then the function returns.

Parameters
cardCard descriptor.
stateThe sleep/awake command argument, refer to mmc_sleep_awake_t.
Return values
kStatus_SDMMC_NotSupportYetIndicates the memory device doesn't support the Sleep/Awake command.
kStatus_SDMMC_TransferFailedIndicates command transferred fail.
kStatus_SDMMC_PollingCardIdleFailedIndicates polling DAT0 busy timeout.
kStatus_SDMMC_DeselectCardFailedIndicates deselect card command failed.
kStatus_SDMMC_SelectCardFailedIndicates select card command failed.
kStatus_SuccessIndicates the card state switched successfully.
status_t MMC_PollingCardStatusBusy ( mmc_card_t card,
bool  checkStatus,
uint32_t  timeoutMs 
)

This function can be used to poll the status from busy to idle, the function will return with the card status being idle or timeout or command failed.

Parameters
cardCard descriptor.
checkStatusTrue is send CMD and read DAT0 status to check card status, false is read DAT0 status only.
timeoutMsPolling card status timeout value.
Return values
kStatus_SDMMC_CardStatusIdleCard is idle.
kStatus_SDMMC_CardStatusBusyCard is busy.
kStatus_SDMMC_TransferFailedCommand tranfer failed.
kStatus_SDMMC_SwitchFailedStatus command reports switch error.