MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
USDHC: ultra Secured Digital Host Controller Driver

Overview

The MCUXpresso SDK provides a peripheral driver for the ultra Secured Digital Host Controller (USDHC) module of MCUXpresso SDK/i.MX devices.

Typical use case

USDHC Operation

/* Initializes the USDHC. */
usdhcConfig->dataTimeout = 0xFU;
usdhcConfig->endianMode = kUSDHC_EndianModeLittle;
usdhcConfig->readWatermarkLevel = 0x80U;
usdhcConfig->writeWatermarkLevel = 0x80U;
usdhcConfig->readBurstLen = 16U;
usdhcConfig->writeBurstLen = 16U;
USDHC_Init(BOARD_USDHC_BASEADDR, usdhcConfig);
/* Fills state in the card driver. */
card->usdhcBase = BOARD_USDHC_BASEADDR;
card->usdhcSourceClock = CLOCK_GetFreq(BOARD_USDHC_CLKSRC);
card->usdhcTransfer = usdhc_transfer_function;
/* Initializes the card. */
if (SD_Init(card))
{
PRINTF("\r\nSD card init failed.\r\n");
}
PRINTF("\r\nRead/Write/Erase the card continuously until it encounters error......\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);

Data Structures

struct  usdhc_adma2_descriptor_t
 Defines the ADMA2 descriptor structure. More...
 
struct  usdhc_capability_t
 USDHC capability information. More...
 
struct  usdhc_boot_config_t
 Data structure to configure the MMC boot feature. More...
 
struct  usdhc_config_t
 Data structure to initialize the USDHC. More...
 
struct  usdhc_data_t
 Card data descriptor. More...
 
struct  usdhc_command_t
 Card command descriptor. More...
 
struct  usdhc_adma_config_t
 ADMA configuration. More...
 
struct  usdhc_transfer_t
 Transfer state. More...
 
struct  usdhc_transfer_callback_t
 USDHC callback functions. More...
 
struct  usdhc_handle_t
 USDHC handle. More...
 
struct  usdhc_host_t
 USDHC host descriptor. More...
 

Macros

#define USDHC_MAX_BLOCK_COUNT   (USDHC_BLK_ATT_BLKCNT_MASK >> USDHC_BLK_ATT_BLKCNT_SHIFT)
 Maximum block count can be set one time.
 
#define USDHC_ADMA1_ADDRESS_ALIGN   (4096U)
 The alignment size for ADDRESS filed in ADMA1's descriptor.
 
#define USDHC_ADMA1_LENGTH_ALIGN   (4096U)
 The alignment size for LENGTH field in ADMA1's descriptor.
 
#define USDHC_ADMA2_ADDRESS_ALIGN   (4U)
 The alignment size for ADDRESS field in ADMA2's descriptor.
 
#define USDHC_ADMA2_LENGTH_ALIGN   (4U)
 The alignment size for LENGTH filed in ADMA2's descriptor.
 
#define USDHC_ADMA1_DESCRIPTOR_ADDRESS_SHIFT   (12U)
 The bit shift for ADDRESS filed in ADMA1's descriptor.
 
#define USDHC_ADMA1_DESCRIPTOR_ADDRESS_MASK   (0xFFFFFU)
 The bit mask for ADDRESS field in ADMA1's descriptor.
 
#define USDHC_ADMA1_DESCRIPTOR_LENGTH_SHIFT   (12U)
 The bit shift for LENGTH filed in ADMA1's descriptor.
 
#define USDHC_ADMA1_DESCRIPTOR_LENGTH_MASK   (0xFFFFU)
 The mask for LENGTH field in ADMA1's descriptor.
 
#define USDHC_ADMA1_DESCRIPTOR_MAX_LENGTH_PER_ENTRY   (USDHC_ADMA1_DESCRIPTOR_LENGTH_MASK - 3U)
 The maximum value of LENGTH filed in ADMA1's descriptor.
 
#define USDHC_ADMA2_DESCRIPTOR_LENGTH_SHIFT   (16U)
 The bit shift for LENGTH field in ADMA2's descriptor.
 
#define USDHC_ADMA2_DESCRIPTOR_LENGTH_MASK   (0xFFFFU)
 The bit mask for LENGTH field in ADMA2's descriptor.
 
#define USDHC_ADMA2_DESCRIPTOR_MAX_LENGTH_PER_ENTRY   (USDHC_ADMA2_DESCRIPTOR_LENGTH_MASK - 3U)
 The maximum value of LENGTH field in ADMA2's descriptor.
 

Typedefs

typedef uint32_t usdhc_adma1_descriptor_t
 Defines the adma1 descriptor structure. More...
 
typedef status_t(* usdhc_transfer_function_t )(USDHC_Type *base, usdhc_transfer_t *content)
 USDHC transfer function. More...
 

Enumerations

enum  _usdhc_status {
  kStatus_USDHC_BusyTransferring = MAKE_STATUS(kStatusGroup_USDHC, 0U),
  kStatus_USDHC_PrepareAdmaDescriptorFailed = MAKE_STATUS(kStatusGroup_USDHC, 1U),
  kStatus_USDHC_SendCommandFailed = MAKE_STATUS(kStatusGroup_USDHC, 2U),
  kStatus_USDHC_TransferDataFailed = MAKE_STATUS(kStatusGroup_USDHC, 3U),
  kStatus_USDHC_DMADataAddrNotAlign = MAKE_STATUS(kStatusGroup_USDHC, 4U),
  kStatus_USDHC_ReTuningRequest = MAKE_STATUS(kStatusGroup_USDHC, 5U),
  kStatus_USDHC_TuningError = MAKE_STATUS(kStatusGroup_USDHC, 6U)
}
 USDHC status. More...
 
enum  _usdhc_capability_flag {
  kUSDHC_SupportAdmaFlag = USDHC_HOST_CTRL_CAP_ADMAS_MASK,
  kUSDHC_SupportHighSpeedFlag = USDHC_HOST_CTRL_CAP_HSS_MASK,
  kUSDHC_SupportDmaFlag = USDHC_HOST_CTRL_CAP_DMAS_MASK,
  kUSDHC_SupportSuspendResumeFlag = USDHC_HOST_CTRL_CAP_SRS_MASK,
  kUSDHC_SupportV330Flag = USDHC_HOST_CTRL_CAP_VS33_MASK,
  kUSDHC_SupportV300Flag = USDHC_HOST_CTRL_CAP_VS30_MASK,
  kUSDHC_SupportV180Flag = USDHC_HOST_CTRL_CAP_VS18_MASK,
  kUSDHC_Support4BitFlag = (USDHC_HOST_CTRL_CAP_MBL_SHIFT << 0U),
  kUSDHC_Support8BitFlag = (USDHC_HOST_CTRL_CAP_MBL_SHIFT << 1U),
  kUSDHC_SupportDDR50Flag = USDHC_HOST_CTRL_CAP_DDR50_SUPPORT_MASK,
  kUSDHC_SupportSDR104Flag = USDHC_HOST_CTRL_CAP_SDR104_SUPPORT_MASK,
  kUSDHC_SupportSDR50Flag = USDHC_HOST_CTRL_CAP_SDR50_SUPPORT_MASK
}
 Host controller capabilities flag mask. More...
 
enum  _usdhc_wakeup_event {
  kUSDHC_WakeupEventOnCardInt = USDHC_PROT_CTRL_WECINT_MASK,
  kUSDHC_WakeupEventOnCardInsert = USDHC_PROT_CTRL_WECINS_MASK,
  kUSDHC_WakeupEventOnCardRemove = USDHC_PROT_CTRL_WECRM_MASK,
  kUSDHC_WakeupEventsAll
}
 Wakeup event mask. More...
 
enum  _usdhc_reset {
  kUSDHC_ResetAll = USDHC_SYS_CTRL_RSTA_MASK,
  kUSDHC_ResetCommand = USDHC_SYS_CTRL_RSTC_MASK,
  kUSDHC_ResetData = USDHC_SYS_CTRL_RSTD_MASK,
  kUSDHC_ResetTuning = USDHC_SYS_CTRL_RSTT_MASK,
  kUSDHC_ResetsAll
}
 Reset type mask. More...
 
enum  _usdhc_transfer_flag {
  kUSDHC_EnableDmaFlag = USDHC_MIX_CTRL_DMAEN_MASK,
  kUSDHC_CommandTypeSuspendFlag = (USDHC_CMD_XFR_TYP_CMDTYP(1U)),
  kUSDHC_CommandTypeResumeFlag = (USDHC_CMD_XFR_TYP_CMDTYP(2U)),
  kUSDHC_CommandTypeAbortFlag = (USDHC_CMD_XFR_TYP_CMDTYP(3U)),
  kUSDHC_EnableBlockCountFlag = USDHC_MIX_CTRL_BCEN_MASK,
  kUSDHC_EnableAutoCommand12Flag = USDHC_MIX_CTRL_AC12EN_MASK,
  kUSDHC_DataReadFlag = USDHC_MIX_CTRL_DTDSEL_MASK,
  kUSDHC_MultipleBlockFlag = USDHC_MIX_CTRL_MSBSEL_MASK,
  kUSDHC_EnableAutoCommand23Flag = USDHC_MIX_CTRL_AC23EN_MASK,
  kUSDHC_ResponseLength136Flag = USDHC_CMD_XFR_TYP_RSPTYP(1U),
  kUSDHC_ResponseLength48Flag = USDHC_CMD_XFR_TYP_RSPTYP(2U),
  kUSDHC_ResponseLength48BusyFlag = USDHC_CMD_XFR_TYP_RSPTYP(3U),
  kUSDHC_EnableCrcCheckFlag = USDHC_CMD_XFR_TYP_CCCEN_MASK,
  kUSDHC_EnableIndexCheckFlag = USDHC_CMD_XFR_TYP_CICEN_MASK,
  kUSDHC_DataPresentFlag = USDHC_CMD_XFR_TYP_DPSEL_MASK
}
 Transfer flag mask. More...
 
enum  _usdhc_present_status_flag {
  kUSDHC_CommandInhibitFlag = USDHC_PRES_STATE_CIHB_MASK,
  kUSDHC_DataInhibitFlag = USDHC_PRES_STATE_CDIHB_MASK,
  kUSDHC_DataLineActiveFlag = USDHC_PRES_STATE_DLA_MASK,
  kUSDHC_SdClockStableFlag = USDHC_PRES_STATE_SDSTB_MASK,
  kUSDHC_WriteTransferActiveFlag = USDHC_PRES_STATE_WTA_MASK,
  kUSDHC_ReadTransferActiveFlag = USDHC_PRES_STATE_RTA_MASK,
  kUSDHC_BufferWriteEnableFlag = USDHC_PRES_STATE_BWEN_MASK,
  kUSDHC_BufferReadEnableFlag = USDHC_PRES_STATE_BREN_MASK,
  kUSDHC_ReTuningRequestFlag = USDHC_PRES_STATE_RTR_MASK,
  kUSDHC_DelaySettingFinishedFlag = USDHC_PRES_STATE_TSCD_MASK,
  kUSDHC_CardInsertedFlag = USDHC_PRES_STATE_CINST_MASK,
  kUSDHC_CommandLineLevelFlag = USDHC_PRES_STATE_CLSL_MASK,
  kUSDHC_Data0LineLevelFlag = (1U << USDHC_PRES_STATE_DLSL_SHIFT),
  kUSDHC_Data1LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 1U)),
  kUSDHC_Data2LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 2U)),
  kUSDHC_Data3LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 3U)),
  kUSDHC_Data4LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 4U)),
  kUSDHC_Data5LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 5U)),
  kUSDHC_Data6LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 6U)),
  kUSDHC_Data7LineLevelFlag = (1U << (USDHC_PRES_STATE_DLSL_SHIFT + 7U))
}
 Present status flag mask. More...
 
enum  _usdhc_interrupt_status_flag {
  kUSDHC_CommandCompleteFlag = USDHC_INT_STATUS_CC_MASK,
  kUSDHC_DataCompleteFlag = USDHC_INT_STATUS_TC_MASK,
  kUSDHC_BlockGapEventFlag = USDHC_INT_STATUS_BGE_MASK,
  kUSDHC_DmaCompleteFlag = USDHC_INT_STATUS_DINT_MASK,
  kUSDHC_BufferWriteReadyFlag = USDHC_INT_STATUS_BWR_MASK,
  kUSDHC_BufferReadReadyFlag = USDHC_INT_STATUS_BRR_MASK,
  kUSDHC_CardInsertionFlag = USDHC_INT_STATUS_CINS_MASK,
  kUSDHC_CardRemovalFlag = USDHC_INT_STATUS_CRM_MASK,
  kUSDHC_CardInterruptFlag = USDHC_INT_STATUS_CINT_MASK,
  kUSDHC_ReTuningEventFlag = USDHC_INT_STATUS_RTE_MASK,
  kUSDHC_TuningPassFlag = USDHC_INT_STATUS_TP_MASK,
  kUSDHC_TuningErrorFlag = USDHC_INT_STATUS_TNE_MASK,
  kUSDHC_CommandTimeoutFlag = USDHC_INT_STATUS_CTOE_MASK,
  kUSDHC_CommandCrcErrorFlag = USDHC_INT_STATUS_CCE_MASK,
  kUSDHC_CommandEndBitErrorFlag = USDHC_INT_STATUS_CEBE_MASK,
  kUSDHC_CommandIndexErrorFlag = USDHC_INT_STATUS_CIE_MASK,
  kUSDHC_DataTimeoutFlag = USDHC_INT_STATUS_DTOE_MASK,
  kUSDHC_DataCrcErrorFlag = USDHC_INT_STATUS_DCE_MASK,
  kUSDHC_DataEndBitErrorFlag = USDHC_INT_STATUS_DEBE_MASK,
  kUSDHC_AutoCommand12ErrorFlag = USDHC_INT_STATUS_AC12E_MASK,
  kUSDHC_DmaErrorFlag = USDHC_INT_STATUS_DMAE_MASK,
  kUSDHC_CommandErrorFlag,
  kUSDHC_DataErrorFlag,
  kUSDHC_ErrorFlag = (kUSDHC_CommandErrorFlag | kUSDHC_DataErrorFlag | kUSDHC_DmaErrorFlag),
  kUSDHC_DataFlag,
  kUSDHC_CommandFlag = (kUSDHC_CommandErrorFlag | kUSDHC_CommandCompleteFlag),
  kUSDHC_CardDetectFlag = (kUSDHC_CardInsertionFlag | kUSDHC_CardRemovalFlag) ,
  kUSDHC_AllInterruptFlags
}
 Interrupt status flag mask. More...
 
enum  _usdhc_auto_command12_error_status_flag {
  kUSDHC_AutoCommand12NotExecutedFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12NE_MASK,
  kUSDHC_AutoCommand12TimeoutFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12TOE_MASK,
  kUSDHC_AutoCommand12EndBitErrorFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12EBE_MASK,
  kUSDHC_AutoCommand12CrcErrorFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12CE_MASK,
  kUSDHC_AutoCommand12IndexErrorFlag = USDHC_AUTOCMD12_ERR_STATUS_AC12IE_MASK,
  kUSDHC_AutoCommand12NotIssuedFlag = USDHC_AUTOCMD12_ERR_STATUS_CNIBAC12E_MASK
}
 Auto CMD12 error status flag mask. More...
 
enum  _usdhc_standard_tuning {
  kUSDHC_ExecuteTuning = USDHC_AUTOCMD12_ERR_STATUS_EXECUTE_TUNING_MASK,
  kUSDHC_TuningSampleClockSel
}
 standard tuning flag More...
 
enum  _usdhc_adma_error_status_flag {
  kUSDHC_AdmaLenghMismatchFlag = USDHC_ADMA_ERR_STATUS_ADMALME_MASK,
  kUSDHC_AdmaDescriptorErrorFlag = USDHC_ADMA_ERR_STATUS_ADMADCE_MASK
}
 ADMA error status flag mask. More...
 
enum  usdhc_adma_error_state_t {
  kUSDHC_AdmaErrorStateStopDma = 0x00U,
  kUSDHC_AdmaErrorStateFetchDescriptor = 0x01U,
  kUSDHC_AdmaErrorStateChangeAddress = 0x02U,
  kUSDHC_AdmaErrorStateTransferData = 0x03U
}
 ADMA error state. More...
 
enum  _usdhc_force_event {
  kUSDHC_ForceEventAutoCommand12NotExecuted = USDHC_FORCE_EVENT_FEVTAC12NE_MASK,
  kUSDHC_ForceEventAutoCommand12Timeout = USDHC_FORCE_EVENT_FEVTAC12TOE_MASK,
  kUSDHC_ForceEventAutoCommand12CrcError = USDHC_FORCE_EVENT_FEVTAC12CE_MASK,
  kUSDHC_ForceEventEndBitError = USDHC_FORCE_EVENT_FEVTAC12EBE_MASK,
  kUSDHC_ForceEventAutoCommand12IndexError = USDHC_FORCE_EVENT_FEVTAC12IE_MASK,
  kUSDHC_ForceEventAutoCommand12NotIssued = USDHC_FORCE_EVENT_FEVTCNIBAC12E_MASK,
  kUSDHC_ForceEventCommandTimeout = USDHC_FORCE_EVENT_FEVTCTOE_MASK,
  kUSDHC_ForceEventCommandCrcError = USDHC_FORCE_EVENT_FEVTCCE_MASK,
  kUSDHC_ForceEventCommandEndBitError = USDHC_FORCE_EVENT_FEVTCEBE_MASK,
  kUSDHC_ForceEventCommandIndexError = USDHC_FORCE_EVENT_FEVTCIE_MASK,
  kUSDHC_ForceEventDataTimeout = USDHC_FORCE_EVENT_FEVTDTOE_MASK,
  kUSDHC_ForceEventDataCrcError = USDHC_FORCE_EVENT_FEVTDCE_MASK,
  kUSDHC_ForceEventDataEndBitError = USDHC_FORCE_EVENT_FEVTDEBE_MASK,
  kUSDHC_ForceEventAutoCommand12Error = USDHC_FORCE_EVENT_FEVTAC12E_MASK,
  kUSDHC_ForceEventCardInt = USDHC_FORCE_EVENT_FEVTCINT_MASK,
  kUSDHC_ForceEventDmaError = USDHC_FORCE_EVENT_FEVTDMAE_MASK,
  kUSDHC_ForceEventTuningError = USDHC_FORCE_EVENT_FEVTTNE_MASK,
  kUSDHC_ForceEventsAll
}
 Force event mask. More...
 
enum  usdhc_data_bus_width_t {
  kUSDHC_DataBusWidth1Bit = 0U,
  kUSDHC_DataBusWidth4Bit = 1U,
  kUSDHC_DataBusWidth8Bit = 2U
}
 Data transfer width. More...
 
enum  usdhc_endian_mode_t {
  kUSDHC_EndianModeBig = 0U,
  kUSDHC_EndianModeHalfWordBig = 1U,
  kUSDHC_EndianModeLittle = 2U
}
 Endian mode. More...
 
enum  usdhc_dma_mode_t {
  kUSDHC_DmaModeSimple = 0U,
  kUSDHC_DmaModeAdma1 = 1U,
  kUSDHC_DmaModeAdma2 = 2U,
  kUSDHC_ExternalDMA = 3U
}
 DMA mode. More...
 
enum  _usdhc_sdio_control_flag {
  kUSDHC_StopAtBlockGapFlag = USDHC_PROT_CTRL_SABGREQ_MASK,
  kUSDHC_ReadWaitControlFlag = USDHC_PROT_CTRL_RWCTL_MASK,
  kUSDHC_InterruptAtBlockGapFlag = USDHC_PROT_CTRL_IABG_MASK,
  kUSDHC_ReadDoneNo8CLK = USDHC_PROT_CTRL_RD_DONE_NO_8CLK_MASK,
  kUSDHC_ExactBlockNumberReadFlag = USDHC_PROT_CTRL_NON_EXACT_BLK_RD_MASK
}
 SDIO control flag mask. More...
 
enum  usdhc_boot_mode_t {
  kUSDHC_BootModeNormal = 0U,
  kUSDHC_BootModeAlternative = 1U
}
 MMC card boot mode. More...
 
enum  usdhc_card_command_type_t {
  kCARD_CommandTypeNormal = 0U,
  kCARD_CommandTypeSuspend = 1U,
  kCARD_CommandTypeResume = 2U,
  kCARD_CommandTypeAbort = 3U
}
 The command type. More...
 
enum  usdhc_card_response_type_t {
  kCARD_ResponseTypeNone = 0U,
  kCARD_ResponseTypeR1 = 1U,
  kCARD_ResponseTypeR1b = 2U,
  kCARD_ResponseTypeR2 = 3U,
  kCARD_ResponseTypeR3 = 4U,
  kCARD_ResponseTypeR4 = 5U,
  kCARD_ResponseTypeR5 = 6U,
  kCARD_ResponseTypeR5b = 7U,
  kCARD_ResponseTypeR6 = 8U,
  kCARD_ResponseTypeR7 = 9U
}
 The command response type. More...
 
enum  _usdhc_adma1_descriptor_flag {
  kUSDHC_Adma1DescriptorValidFlag = (1U << 0U),
  kUSDHC_Adma1DescriptorEndFlag = (1U << 1U),
  kUSDHC_Adma1DescriptorInterrupFlag = (1U << 2U),
  kUSDHC_Adma1DescriptorActivity1Flag = (1U << 4U),
  kUSDHC_Adma1DescriptorActivity2Flag = (1U << 5U),
  kUSDHC_Adma1DescriptorTypeNop = (kUSDHC_Adma1DescriptorValidFlag),
  kUSDHC_Adma1DescriptorTypeTransfer,
  kUSDHC_Adma1DescriptorTypeLink,
  kUSDHC_Adma1DescriptorTypeSetLength
}
 The mask for the control/status field in ADMA1 descriptor. More...
 
enum  _usdhc_adma2_descriptor_flag {
  kUSDHC_Adma2DescriptorValidFlag = (1U << 0U),
  kUSDHC_Adma2DescriptorEndFlag = (1U << 1U),
  kUSDHC_Adma2DescriptorInterruptFlag = (1U << 2U),
  kUSDHC_Adma2DescriptorActivity1Flag = (1U << 4U),
  kUSDHC_Adma2DescriptorActivity2Flag = (1U << 5U),
  kUSDHC_Adma2DescriptorTypeNop = (kUSDHC_Adma2DescriptorValidFlag),
  kUSDHC_Adma2DescriptorTypeReserved,
  kUSDHC_Adma2DescriptorTypeTransfer,
  kUSDHC_Adma2DescriptorTypeLink
}
 ADMA1 descriptor control and status mask. More...
 
enum  usdhc_burst_len_t {
  kUSDHC_EnBurstLenForINCR = 0x01U,
  kUSDHC_EnBurstLenForINCR4816 = 0x02U,
  kUSDHC_EnBurstLenForINCR4816WRAP = 0x04U
}
 dma transfer burst len config. More...
 

Driver version

#define FSL_USDHC_DRIVER_VERSION   (MAKE_VERSION(2U, 1U, 1U))
 Driver version 2.1.1. More...
 

Initialization and deinitialization

void USDHC_Init (USDHC_Type *base, const usdhc_config_t *config)
 USDHC module initialization function. More...
 
void USDHC_Deinit (USDHC_Type *base)
 Deinitializes the USDHC. More...
 
bool USDHC_Reset (USDHC_Type *base, uint32_t mask, uint32_t timeout)
 Resets the USDHC. More...
 

DMA Control

status_t USDHC_SetAdmaTableConfig (USDHC_Type *base, usdhc_adma_config_t *dmaConfig, usdhc_data_t *dataConfig, uint32_t flags)
 Sets the ADMA descriptor table configuration. More...
 

Interrupts

static void USDHC_EnableInterruptStatus (USDHC_Type *base, uint32_t mask)
 Enables the interrupt status. More...
 
static void USDHC_DisableInterruptStatus (USDHC_Type *base, uint32_t mask)
 Disables the interrupt status. More...
 
static void USDHC_EnableInterruptSignal (USDHC_Type *base, uint32_t mask)
 Enables the interrupt signal corresponding to the interrupt status flag. More...
 
static void USDHC_DisableInterruptSignal (USDHC_Type *base, uint32_t mask)
 Disables the interrupt signal corresponding to the interrupt status flag. More...
 

Status

static uint32_t USDHC_GetInterruptStatusFlags (USDHC_Type *base)
 Gets the current interrupt status. More...
 
static void USDHC_ClearInterruptStatusFlags (USDHC_Type *base, uint32_t mask)
 Clears a specified interrupt status. More...
 
static uint32_t USDHC_GetAutoCommand12ErrorStatusFlags (USDHC_Type *base)
 Gets the status of auto command 12 error. More...
 
static uint32_t USDHC_GetAdmaErrorStatusFlags (USDHC_Type *base)
 Gets the status of the ADMA error. More...
 
static uint32_t USDHC_GetPresentStatusFlags (USDHC_Type *base)
 Gets a present status. More...
 

Bus Operations

void USDHC_GetCapability (USDHC_Type *base, usdhc_capability_t *capability)
 Gets the capability information. More...
 
static void USDHC_ForceClockOn (USDHC_Type *base, bool enable)
 force the card clock on. More...
 
uint32_t USDHC_SetSdClock (USDHC_Type *base, uint32_t srcClock_Hz, uint32_t busClock_Hz)
 Sets the SD bus clock frequency. More...
 
bool USDHC_SetCardActive (USDHC_Type *base, uint32_t timeout)
 Sends 80 clocks to the card to set it to the active state. More...
 
static void USDHC_AssertHardwareReset (USDHC_Type *base, bool high)
 trigger a hardware reset. More...
 
static void USDHC_SetDataBusWidth (USDHC_Type *base, usdhc_data_bus_width_t width)
 Sets the data transfer width. More...
 
static void USDHC_WriteData (USDHC_Type *base, uint32_t data)
 Fills the the data port. More...
 
static uint32_t USDHC_ReadData (USDHC_Type *base)
 Retrieves the data from the data port. More...
 
void USDHC_SendCommand (USDHC_Type *base, usdhc_command_t *command)
 send command function More...
 
static void USDHC_EnableWakeupEvent (USDHC_Type *base, uint32_t mask, bool enable)
 Enables or disables a wakeup event in low-power mode. More...
 
static void USDHC_CardDetectByData3 (USDHC_Type *base, bool enable)
 detect card insert status. More...
 
static bool USDHC_DetectCardInsert (USDHC_Type *base)
 detect card insert status. More...
 
static void USDHC_EnableSdioControl (USDHC_Type *base, uint32_t mask, bool enable)
 Enables or disables the SDIO card control. More...
 
static void USDHC_SetContinueRequest (USDHC_Type *base)
 Restarts a transaction which has stopped at the block GAP for the SDIO card. More...
 
void USDHC_SetMmcBootConfig (USDHC_Type *base, const usdhc_boot_config_t *config)
 Configures the MMC boot feature. More...
 
static void USDHC_SetForceEvent (USDHC_Type *base, uint32_t mask)
 Forces generating events according to the given mask. More...
 
static void UDSHC_SelectVoltage (USDHC_Type *base, bool en18v)
 select the usdhc output voltage More...
 
static bool USDHC_RequestTuningForSDR50 (USDHC_Type *base)
 check the SDR50 mode request tuning bit When this bit set, user should call USDHC_StandardTuning function More...
 
static bool USDHC_RequestReTuning (USDHC_Type *base)
 check the request re-tuning bit When this bit is set, user should do manual tuning or standard tuning function More...
 
static void USDHC_EnableAutoTuning (USDHC_Type *base, bool enable)
 the SDR104 mode auto tuning enable and disable This function should call after tuning function execute pass, auto tuning will handle by hardware More...
 
static void USDHC_SetRetuningTimer (USDHC_Type *base, uint32_t counter)
 the config the re-tuning timer for mode 1 and mode 3 This timer is used for standard tuning auto re-tuning, More...
 
void USDHC_EnableAutoTuningForCmdAndData (USDHC_Type *base)
 the auto tuning enbale for CMD/DATA line More...
 
void USDHC_EnableManualTuning (USDHC_Type *base, bool enable)
 manual tuning trigger or abort User should handle the tuning cmd and find the boundary of the delay then calucate a average value which will be config to the CLK_TUNE_CTRL_STATUS This function should called before USDHC_AdjustDelayforSDR104 function More...
 
status_t USDHC_AdjustDelayForManualTuning (USDHC_Type *base, uint32_t delay)
 the SDR104 mode delay setting adjust This function should called after USDHC_ManualTuningForSDR104 More...
 
void USDHC_EnableStandardTuning (USDHC_Type *base, uint32_t tuningStartTap, uint32_t step, bool enable)
 the enable standard tuning function The standard tuning window and tuning counter use the default config tuning cmd is send by the software, user need to check the tuning result can be used for SDR50,SDR104,HS200 mode tuning More...
 
static uint32_t USDHC_GetExecuteStdTuningStatus (USDHC_Type *base)
 Get execute std tuning status. More...
 
static uint32_t USDHC_CheckStdTuningResult (USDHC_Type *base)
 check std tuning result More...
 
static uint32_t USDHC_CheckTuningError (USDHC_Type *base)
 check tuning error More...
 
static void USDHC_EnableDDRMode (USDHC_Type *base, bool enable, uint32_t nibblePos)
 the enable/disable DDR mode More...
 
static void USDHC_EnableHS400Mode (USDHC_Type *base, bool enable)
 the enable/disable HS400 mode More...
 
static void USDHC_ResetStrobeDLL (USDHC_Type *base)
 reset the strobe DLL More...
 
static void USDHC_EnableStrobeDLL (USDHC_Type *base, bool enable)
 enable/disable the strobe DLL More...
 
static void USDHC_ConfigStrobeDLL (USDHC_Type *base, uint32_t delayTarget, uint32_t updateInterval)
 config the strobe DLL delay target and update interval More...
 
static uint32_t USDHC_GetStrobeDLLStatus (USDHC_Type *base)
 get the strobe DLL status More...
 

Transactional

status_t USDHC_TransferBlocking (USDHC_Type *base, usdhc_adma_config_t *dmaConfig, usdhc_transfer_t *transfer)
 Transfers the command/data using a blocking method. More...
 
void USDHC_TransferCreateHandle (USDHC_Type *base, usdhc_handle_t *handle, const usdhc_transfer_callback_t *callback, void *userData)
 Creates the USDHC handle. More...
 
status_t USDHC_TransferNonBlocking (USDHC_Type *base, usdhc_handle_t *handle, usdhc_adma_config_t *dmaConfig, usdhc_transfer_t *transfer)
 Transfers the command/data using an interrupt and an asynchronous method. More...
 
void USDHC_TransferHandleIRQ (USDHC_Type *base, usdhc_handle_t *handle)
 IRQ handler for the USDHC. More...
 

Data Structure Documentation

struct usdhc_adma2_descriptor_t

Data Fields

uint32_t attribute
 The control and status field.
 
const uint32_t * address
 The address field.
 
struct usdhc_capability_t

Defines a structure to save the capability information of USDHC.

Data Fields

uint32_t sdVersion
 support SD card/sdio version
 
uint32_t mmcVersion
 support emmc card version
 
uint32_t maxBlockLength
 Maximum block length united as byte.
 
uint32_t maxBlockCount
 Maximum block count can be set one time.
 
uint32_t flags
 Capability flags to indicate the support information(_usdhc_capability_flag)
 
struct usdhc_boot_config_t

Data Fields

uint32_t ackTimeoutCount
 Timeout value for the boot ACK. More...
 
usdhc_boot_mode_t bootMode
 Boot mode selection. More...
 
uint32_t blockCount
 Stop at block gap value of automatic mode. More...
 
bool enableBootAck
 Enable or disable boot ACK.
 
bool enableBoot
 Enable or disable fast boot.
 
bool enableAutoStopAtBlockGap
 Enable or disable auto stop at block gap function in boot period.
 

Field Documentation

uint32_t usdhc_boot_config_t::ackTimeoutCount

The available range is 0 ~ 15.

usdhc_boot_mode_t usdhc_boot_config_t::bootMode
uint32_t usdhc_boot_config_t::blockCount

Available range is 0 ~ 65535.

struct usdhc_config_t

Data Fields

uint32_t dataTimeout
 Data timeout value.
 
usdhc_endian_mode_t endianMode
 Endian mode.
 
uint8_t readWatermarkLevel
 Watermark level for DMA read operation. More...
 
uint8_t writeWatermarkLevel
 Watermark level for DMA write operation. More...
 
uint8_t readBurstLen
 Read burst len.
 
uint8_t writeBurstLen
 Write burst len.
 

Field Documentation

uint8_t usdhc_config_t::readWatermarkLevel

Available range is 1 ~ 128.

uint8_t usdhc_config_t::writeWatermarkLevel

Available range is 1 ~ 128.

struct usdhc_data_t

Defines a structure to contain data-related attribute. 'enableIgnoreError' is used for the case that upper card driver want to ignore the error event to read/write all the data not to stop read/write immediately when error event happen for example bus testing procedure for MMC card.

Data Fields

bool enableAutoCommand12
 Enable auto CMD12.
 
bool enableAutoCommand23
 Enable auto CMD23.
 
bool enableIgnoreError
 Enable to ignore error event to read/write all the data.
 
bool executeTuning
 execute tuning flag
 
size_t blockSize
 Block size.
 
uint32_t blockCount
 Block count.
 
uint32_t * rxData
 Buffer to save data read.
 
const uint32_t * txData
 Data buffer to write.
 
struct usdhc_command_t

Define card command-related attribute.

Data Fields

uint32_t index
 Command index.
 
uint32_t argument
 Command argument.
 
usdhc_card_command_type_t type
 Command type.
 
usdhc_card_response_type_t responseType
 Command response type.
 
uint32_t response [4U]
 Response for this command.
 
uint32_t responseErrorFlags
 response error flag, the flag which need to check the command reponse
 
uint32_t flags
 Cmd flags.
 
struct usdhc_adma_config_t

Data Fields

usdhc_dma_mode_t dmaMode
 DMA mode.
 
usdhc_burst_len_t burstLen
 burst len config
 
uint32_t * admaTable
 ADMA table address, can't be null if transfer way is ADMA1/ADMA2.
 
uint32_t admaTableWords
 ADMA table length united as words, can't be 0 if transfer way is ADMA1/ADMA2.
 
struct usdhc_transfer_t

Data Fields

usdhc_data_tdata
 Data to transfer.
 
usdhc_command_tcommand
 Command to send.
 
struct usdhc_transfer_callback_t

Data Fields

void(* CardInserted )(void)
 Card inserted occurs when DAT3/CD pin is for card detect.
 
void(* CardRemoved )(void)
 Card removed occurs.
 
void(* SdioInterrupt )(void)
 SDIO card interrupt occurs.
 
void(* SdioBlockGap )(void)
 SDIO card stopped at block gap occurs.
 
void(* TransferComplete )(USDHC_Type *base, usdhc_handle_t *handle, status_t status, void *userData)
 Transfer complete callback.
 
void(* ReTuning )(void)
 handle the re-tuning
 
struct _usdhc_handle

USDHC handle typedef.

Defines the structure to save the USDHC state information and callback function. The detailed interrupt status when sending a command or transfering data can be obtained from the interruptFlags field by using the mask defined in usdhc_interrupt_flag_t.

Note
All the fields except interruptFlags and transferredWords must be allocated by the user.

Data Fields

usdhc_data_t *volatile data
 Data to transfer.
 
usdhc_command_t *volatile command
 Command to send.
 
volatile uint32_t interruptFlags
 Interrupt flags of last transaction.
 
volatile uint32_t transferredWords
 Words transferred by DATAPORT way.
 
usdhc_transfer_callback_t callback
 Callback function.
 
void * userData
 Parameter for transfer complete callback.
 
struct usdhc_host_t

Data Fields

USDHC_Type * base
 USDHC peripheral base address.
 
uint32_t sourceClock_Hz
 USDHC source clock frequency united in Hz.
 
usdhc_config_t config
 USDHC configuration.
 
usdhc_capability_t capability
 USDHC capability information.
 
usdhc_transfer_function_t transfer
 USDHC transfer function.
 

Macro Definition Documentation

#define FSL_USDHC_DRIVER_VERSION   (MAKE_VERSION(2U, 1U, 1U))

Typedef Documentation

typedef uint32_t usdhc_adma1_descriptor_t
typedef status_t(* usdhc_transfer_function_t)(USDHC_Type *base, usdhc_transfer_t *content)

Enumeration Type Documentation

Enumerator
kStatus_USDHC_BusyTransferring 

Transfer is on-going.

kStatus_USDHC_PrepareAdmaDescriptorFailed 

Set DMA descriptor failed.

kStatus_USDHC_SendCommandFailed 

Send command failed.

kStatus_USDHC_TransferDataFailed 

Transfer data failed.

kStatus_USDHC_DMADataAddrNotAlign 

data address not align

kStatus_USDHC_ReTuningRequest 

re-tuning request

kStatus_USDHC_TuningError 

tuning error

Enumerator
kUSDHC_SupportAdmaFlag 

Support ADMA.

kUSDHC_SupportHighSpeedFlag 

Support high-speed.

kUSDHC_SupportDmaFlag 

Support DMA.

kUSDHC_SupportSuspendResumeFlag 

Support suspend/resume.

kUSDHC_SupportV330Flag 

Support voltage 3.3V.

kUSDHC_SupportV300Flag 

Support voltage 3.0V.

kUSDHC_SupportV180Flag 

Support voltage 1.8V.

kUSDHC_Support4BitFlag 

Support 4 bit mode.

kUSDHC_Support8BitFlag 

Support 8 bit mode.

kUSDHC_SupportDDR50Flag 

support DDR50 mode

kUSDHC_SupportSDR104Flag 

support SDR104 mode

kUSDHC_SupportSDR50Flag 

support SDR50 mode

Enumerator
kUSDHC_WakeupEventOnCardInt 

Wakeup on card interrupt.

kUSDHC_WakeupEventOnCardInsert 

Wakeup on card insertion.

kUSDHC_WakeupEventOnCardRemove 

Wakeup on card removal.

kUSDHC_WakeupEventsAll 

All wakeup events.

Enumerator
kUSDHC_ResetAll 

Reset all except card detection.

kUSDHC_ResetCommand 

Reset command line.

kUSDHC_ResetData 

Reset data line.

kUSDHC_ResetTuning 

reset tuning circuit

kUSDHC_ResetsAll 

All reset types.

Enumerator
kUSDHC_EnableDmaFlag 

Enable DMA.

kUSDHC_CommandTypeSuspendFlag 

Suspend command.

kUSDHC_CommandTypeResumeFlag 

Resume command.

kUSDHC_CommandTypeAbortFlag 

Abort command.

kUSDHC_EnableBlockCountFlag 

Enable block count.

kUSDHC_EnableAutoCommand12Flag 

Enable auto CMD12.

kUSDHC_DataReadFlag 

Enable data read.

kUSDHC_MultipleBlockFlag 

Multiple block data read/write.

kUSDHC_EnableAutoCommand23Flag 

Enable auto CMD23.

kUSDHC_ResponseLength136Flag 

136 bit response length

kUSDHC_ResponseLength48Flag 

48 bit response length

kUSDHC_ResponseLength48BusyFlag 

48 bit response length with busy status

kUSDHC_EnableCrcCheckFlag 

Enable CRC check.

kUSDHC_EnableIndexCheckFlag 

Enable index check.

kUSDHC_DataPresentFlag 

Data present flag.

Enumerator
kUSDHC_CommandInhibitFlag 

Command inhibit.

kUSDHC_DataInhibitFlag 

Data inhibit.

kUSDHC_DataLineActiveFlag 

Data line active.

kUSDHC_SdClockStableFlag 

SD bus clock stable.

kUSDHC_WriteTransferActiveFlag 

Write transfer active.

kUSDHC_ReadTransferActiveFlag 

Read transfer active.

kUSDHC_BufferWriteEnableFlag 

Buffer write enable.

kUSDHC_BufferReadEnableFlag 

Buffer read enable.

kUSDHC_ReTuningRequestFlag 

re-tuning request flag ,only used for SDR104 mode

kUSDHC_DelaySettingFinishedFlag 

delay setting finished flag

kUSDHC_CardInsertedFlag 

Card inserted.

kUSDHC_CommandLineLevelFlag 

Command line signal level.

kUSDHC_Data0LineLevelFlag 

Data0 line signal level.

kUSDHC_Data1LineLevelFlag 

Data1 line signal level.

kUSDHC_Data2LineLevelFlag 

Data2 line signal level.

kUSDHC_Data3LineLevelFlag 

Data3 line signal level.

kUSDHC_Data4LineLevelFlag 

Data4 line signal level.

kUSDHC_Data5LineLevelFlag 

Data5 line signal level.

kUSDHC_Data6LineLevelFlag 

Data6 line signal level.

kUSDHC_Data7LineLevelFlag 

Data7 line signal level.

Enumerator
kUSDHC_CommandCompleteFlag 

Command complete.

kUSDHC_DataCompleteFlag 

Data complete.

kUSDHC_BlockGapEventFlag 

Block gap event.

kUSDHC_DmaCompleteFlag 

DMA interrupt.

kUSDHC_BufferWriteReadyFlag 

Buffer write ready.

kUSDHC_BufferReadReadyFlag 

Buffer read ready.

kUSDHC_CardInsertionFlag 

Card inserted.

kUSDHC_CardRemovalFlag 

Card removed.

kUSDHC_CardInterruptFlag 

Card interrupt.

kUSDHC_ReTuningEventFlag 

Re-Tuning event,only for SD3.0 SDR104 mode.

kUSDHC_TuningPassFlag 

SDR104 mode tuning pass flag.

kUSDHC_TuningErrorFlag 

SDR104 tuning error flag.

kUSDHC_CommandTimeoutFlag 

Command timeout error.

kUSDHC_CommandCrcErrorFlag 

Command CRC error.

kUSDHC_CommandEndBitErrorFlag 

Command end bit error.

kUSDHC_CommandIndexErrorFlag 

Command index error.

kUSDHC_DataTimeoutFlag 

Data timeout error.

kUSDHC_DataCrcErrorFlag 

Data CRC error.

kUSDHC_DataEndBitErrorFlag 

Data end bit error.

kUSDHC_AutoCommand12ErrorFlag 

Auto CMD12 error.

kUSDHC_DmaErrorFlag 

DMA error.

kUSDHC_CommandErrorFlag 

Command error.

kUSDHC_DataErrorFlag 

Data error.

kUSDHC_ErrorFlag 

All error.

kUSDHC_DataFlag 

Data interrupts.

kUSDHC_CommandFlag 

Command interrupts.

kUSDHC_CardDetectFlag 

Card detection interrupts.

kUSDHC_AllInterruptFlags 

All flags mask.

Enumerator
kUSDHC_AutoCommand12NotExecutedFlag 

Not executed error.

kUSDHC_AutoCommand12TimeoutFlag 

Timeout error.

kUSDHC_AutoCommand12EndBitErrorFlag 

End bit error.

kUSDHC_AutoCommand12CrcErrorFlag 

CRC error.

kUSDHC_AutoCommand12IndexErrorFlag 

Index error.

kUSDHC_AutoCommand12NotIssuedFlag 

Not issued error.

Enumerator
kUSDHC_ExecuteTuning 

used to start tuning procedure

kUSDHC_TuningSampleClockSel 

when std_tuning_en bit is set, this bit is used select sampleing clock

Enumerator
kUSDHC_AdmaLenghMismatchFlag 

Length mismatch error.

kUSDHC_AdmaDescriptorErrorFlag 

Descriptor error.

This state is the detail state when ADMA error has occurred.

Enumerator
kUSDHC_AdmaErrorStateStopDma 

Stop DMA.

kUSDHC_AdmaErrorStateFetchDescriptor 

Fetch descriptor.

kUSDHC_AdmaErrorStateChangeAddress 

Change address.

kUSDHC_AdmaErrorStateTransferData 

Transfer data.

Enumerator
kUSDHC_ForceEventAutoCommand12NotExecuted 

Auto CMD12 not executed error.

kUSDHC_ForceEventAutoCommand12Timeout 

Auto CMD12 timeout error.

kUSDHC_ForceEventAutoCommand12CrcError 

Auto CMD12 CRC error.

kUSDHC_ForceEventEndBitError 

Auto CMD12 end bit error.

kUSDHC_ForceEventAutoCommand12IndexError 

Auto CMD12 index error.

kUSDHC_ForceEventAutoCommand12NotIssued 

Auto CMD12 not issued error.

kUSDHC_ForceEventCommandTimeout 

Command timeout error.

kUSDHC_ForceEventCommandCrcError 

Command CRC error.

kUSDHC_ForceEventCommandEndBitError 

Command end bit error.

kUSDHC_ForceEventCommandIndexError 

Command index error.

kUSDHC_ForceEventDataTimeout 

Data timeout error.

kUSDHC_ForceEventDataCrcError 

Data CRC error.

kUSDHC_ForceEventDataEndBitError 

Data end bit error.

kUSDHC_ForceEventAutoCommand12Error 

Auto CMD12 error.

kUSDHC_ForceEventCardInt 

Card interrupt.

kUSDHC_ForceEventDmaError 

Dma error.

kUSDHC_ForceEventTuningError 

Tuning error.

kUSDHC_ForceEventsAll 

All force event flags mask.

Enumerator
kUSDHC_DataBusWidth1Bit 

1-bit mode

kUSDHC_DataBusWidth4Bit 

4-bit mode

kUSDHC_DataBusWidth8Bit 

8-bit mode

Enumerator
kUSDHC_EndianModeBig 

Big endian mode.

kUSDHC_EndianModeHalfWordBig 

Half word big endian mode.

kUSDHC_EndianModeLittle 

Little endian mode.

Enumerator
kUSDHC_DmaModeSimple 

external DMA

kUSDHC_DmaModeAdma1 

ADMA1 is selected.

kUSDHC_DmaModeAdma2 

ADMA2 is selected.

kUSDHC_ExternalDMA 

external dma mode select

Enumerator
kUSDHC_StopAtBlockGapFlag 

Stop at block gap.

kUSDHC_ReadWaitControlFlag 

Read wait control.

kUSDHC_InterruptAtBlockGapFlag 

Interrupt at block gap.

kUSDHC_ReadDoneNo8CLK 

read done without 8 clk for block gap

kUSDHC_ExactBlockNumberReadFlag 

Exact block number read.

Enumerator
kUSDHC_BootModeNormal 

Normal boot.

kUSDHC_BootModeAlternative 

Alternative boot.

Enumerator
kCARD_CommandTypeNormal 

Normal command.

kCARD_CommandTypeSuspend 

Suspend command.

kCARD_CommandTypeResume 

Resume command.

kCARD_CommandTypeAbort 

Abort command.

Define the command response type from card to host controller.

Enumerator
kCARD_ResponseTypeNone 

Response type: none.

kCARD_ResponseTypeR1 

Response type: R1.

kCARD_ResponseTypeR1b 

Response type: R1b.

kCARD_ResponseTypeR2 

Response type: R2.

kCARD_ResponseTypeR3 

Response type: R3.

kCARD_ResponseTypeR4 

Response type: R4.

kCARD_ResponseTypeR5 

Response type: R5.

kCARD_ResponseTypeR5b 

Response type: R5b.

kCARD_ResponseTypeR6 

Response type: R6.

kCARD_ResponseTypeR7 

Response type: R7.

Enumerator
kUSDHC_Adma1DescriptorValidFlag 

Valid flag.

kUSDHC_Adma1DescriptorEndFlag 

End flag.

kUSDHC_Adma1DescriptorInterrupFlag 

Interrupt flag.

kUSDHC_Adma1DescriptorActivity1Flag 

Activity 1 flag.

kUSDHC_Adma1DescriptorActivity2Flag 

Activity 2 flag.

kUSDHC_Adma1DescriptorTypeNop 

No operation.

kUSDHC_Adma1DescriptorTypeTransfer 

Transfer data.

kUSDHC_Adma1DescriptorTypeLink 

Link descriptor.

kUSDHC_Adma1DescriptorTypeSetLength 

Set data length.

Enumerator
kUSDHC_Adma2DescriptorValidFlag 

Valid flag.

kUSDHC_Adma2DescriptorEndFlag 

End flag.

kUSDHC_Adma2DescriptorInterruptFlag 

Interrupt flag.

kUSDHC_Adma2DescriptorActivity1Flag 

Activity 1 mask.

kUSDHC_Adma2DescriptorActivity2Flag 

Activity 2 mask.

kUSDHC_Adma2DescriptorTypeNop 

No operation.

kUSDHC_Adma2DescriptorTypeReserved 

Reserved.

kUSDHC_Adma2DescriptorTypeTransfer 

Transfer type.

kUSDHC_Adma2DescriptorTypeLink 

Link type.

Enumerator
kUSDHC_EnBurstLenForINCR 

enable burst len for INCR

kUSDHC_EnBurstLenForINCR4816 

enable burst len for INCR4/INCR8/INCR16

kUSDHC_EnBurstLenForINCR4816WRAP 

enable burst len for INCR4/8/16 WRAP

Function Documentation

void USDHC_Init ( USDHC_Type *  base,
const usdhc_config_t config 
)

Configures the USDHC according to the user configuration.

Example:

config.cardDetectDat3 = false;
config.dmaMode = kUSDHC_DmaModeAdma2;
config.readWatermarkLevel = 128U;
config.writeWatermarkLevel = 128U;
USDHC_Init(USDHC, &config);
Parameters
baseUSDHC peripheral base address.
configUSDHC configuration information.
Return values
kStatus_SuccessOperate successfully.
void USDHC_Deinit ( USDHC_Type *  base)
Parameters
baseUSDHC peripheral base address.
bool USDHC_Reset ( USDHC_Type *  base,
uint32_t  mask,
uint32_t  timeout 
)
Parameters
baseUSDHC peripheral base address.
maskThe reset type mask(_usdhc_reset).
timeoutTimeout for reset.
Return values
trueReset successfully.
falseReset failed.
status_t USDHC_SetAdmaTableConfig ( USDHC_Type *  base,
usdhc_adma_config_t dmaConfig,
usdhc_data_t dataConfig,
uint32_t  flags 
)
Parameters
baseUSDHC peripheral base address.
admaconfiguration
dataData descriptor
commandflags
Return values
kStatus_OutOfRangeADMA descriptor table length isn't enough to describe data.
kStatus_SuccessOperate successfully.
static void USDHC_EnableInterruptStatus ( USDHC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
maskInterrupt status flags mask(_usdhc_interrupt_status_flag).
static void USDHC_DisableInterruptStatus ( USDHC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
maskThe interrupt status flags mask(_usdhc_interrupt_status_flag).
static void USDHC_EnableInterruptSignal ( USDHC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
maskThe interrupt status flags mask(_usdhc_interrupt_status_flag).
static void USDHC_DisableInterruptSignal ( USDHC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
maskThe interrupt status flags mask(_usdhc_interrupt_status_flag).
static uint32_t USDHC_GetInterruptStatusFlags ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
Returns
Current interrupt status flags mask(_usdhc_interrupt_status_flag).
static void USDHC_ClearInterruptStatusFlags ( USDHC_Type *  base,
uint32_t  mask 
)
inlinestatic

write 1 clears

Parameters
baseUSDHC peripheral base address.
maskThe interrupt status flags mask(_usdhc_interrupt_status_flag).
static uint32_t USDHC_GetAutoCommand12ErrorStatusFlags ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
Returns
Auto command 12 error status flags mask(_usdhc_auto_command12_error_status_flag).
static uint32_t USDHC_GetAdmaErrorStatusFlags ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
Returns
ADMA error status flags mask(_usdhc_adma_error_status_flag).
static uint32_t USDHC_GetPresentStatusFlags ( USDHC_Type *  base)
inlinestatic

This function gets the present USDHC's status except for an interrupt status and an error status.

Parameters
baseUSDHC peripheral base address.
Returns
Present USDHC's status flags mask(_usdhc_present_status_flag).
void USDHC_GetCapability ( USDHC_Type *  base,
usdhc_capability_t capability 
)
Parameters
baseUSDHC peripheral base address.
capabilityStructure to save capability information.
static void USDHC_ForceClockOn ( USDHC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
enable/disableflag.
uint32_t USDHC_SetSdClock ( USDHC_Type *  base,
uint32_t  srcClock_Hz,
uint32_t  busClock_Hz 
)
Parameters
baseUSDHC peripheral base address.
srcClock_HzUSDHC source clock frequency united in Hz.
busClock_HzSD bus clock frequency united in Hz.
Returns
The nearest frequency of busClock_Hz configured to SD bus.
bool USDHC_SetCardActive ( USDHC_Type *  base,
uint32_t  timeout 
)

This function must be called each time the card is inserted to ensure that the card can receive the command correctly.

Parameters
baseUSDHC peripheral base address.
timeoutTimeout to initialize card.
Return values
trueSet card active successfully.
falseSet card active failed.
static void USDHC_AssertHardwareReset ( USDHC_Type *  base,
bool  high 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
1or 0 level
static void USDHC_SetDataBusWidth ( USDHC_Type *  base,
usdhc_data_bus_width_t  width 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
widthData transfer width.
static void USDHC_WriteData ( USDHC_Type *  base,
uint32_t  data 
)
inlinestatic

This function is used to implement the data transfer by Data Port instead of DMA.

Parameters
baseUSDHC peripheral base address.
dataThe data about to be sent.
static uint32_t USDHC_ReadData ( USDHC_Type *  base)
inlinestatic

This function is used to implement the data transfer by Data Port instead of DMA.

Parameters
baseUSDHC peripheral base address.
Returns
The data has been read.
void USDHC_SendCommand ( USDHC_Type *  base,
usdhc_command_t command 
)
Parameters
baseUSDHC peripheral base address.
commandconfiguration
static void USDHC_EnableWakeupEvent ( USDHC_Type *  base,
uint32_t  mask,
bool  enable 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
maskWakeup events mask(_usdhc_wakeup_event).
enableTrue to enable, false to disable.
static void USDHC_CardDetectByData3 ( USDHC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
enable/disableflag
static bool USDHC_DetectCardInsert ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
static void USDHC_EnableSdioControl ( USDHC_Type *  base,
uint32_t  mask,
bool  enable 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
maskSDIO card control flags mask(_usdhc_sdio_control_flag).
enableTrue to enable, false to disable.
static void USDHC_SetContinueRequest ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
void USDHC_SetMmcBootConfig ( USDHC_Type *  base,
const usdhc_boot_config_t config 
)

Example:

config.ackTimeoutCount = 4;
config.blockCount = 5;
config.enableBootAck = true;
config.enableBoot = true;
USDHC_SetMmcBootConfig(USDHC, &config);
Parameters
baseUSDHC peripheral base address.
configThe MMC boot configuration information.
static void USDHC_SetForceEvent ( USDHC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
maskThe force events mask(_usdhc_force_event).
static void UDSHC_SelectVoltage ( USDHC_Type *  base,
bool  en18v 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
true1.8V, false 3.0V
static bool USDHC_RequestTuningForSDR50 ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
static bool USDHC_RequestReTuning ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
static void USDHC_EnableAutoTuning ( USDHC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
enable/disableflag
static void USDHC_SetRetuningTimer ( USDHC_Type *  base,
uint32_t  counter 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
timercounter value
void USDHC_EnableAutoTuningForCmdAndData ( USDHC_Type *  base)
Parameters
baseUSDHC peripheral base address.
void USDHC_EnableManualTuning ( USDHC_Type *  base,
bool  enable 
)
Parameters
baseUSDHC peripheral base address.
tuningenable flag
status_t USDHC_AdjustDelayForManualTuning ( USDHC_Type *  base,
uint32_t  delay 
)
Parameters
baseUSDHC peripheral base address.
delaysetting configuration
Return values
kStatus_Failconfig the delay setting fail
kStatus_Successconfig the delay setting success
void USDHC_EnableStandardTuning ( USDHC_Type *  base,
uint32_t  tuningStartTap,
uint32_t  step,
bool  enable 
)
Parameters
baseUSDHC peripheral base address.
tuningstart tap
tuningstep
enable/disableflag
static uint32_t USDHC_GetExecuteStdTuningStatus ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
static uint32_t USDHC_CheckStdTuningResult ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
static uint32_t USDHC_CheckTuningError ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
static void USDHC_EnableDDRMode ( USDHC_Type *  base,
bool  enable,
uint32_t  nibblePos 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
enable/disableflag
nibbleposition
static void USDHC_EnableHS400Mode ( USDHC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
enable/disableflag
static void USDHC_ResetStrobeDLL ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
static void USDHC_EnableStrobeDLL ( USDHC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
enable/disableflag
static void USDHC_ConfigStrobeDLL ( USDHC_Type *  base,
uint32_t  delayTarget,
uint32_t  updateInterval 
)
inlinestatic
Parameters
baseUSDHC peripheral base address.
delaytarget
updateinterval
static uint32_t USDHC_GetStrobeDLLStatus ( USDHC_Type *  base)
inlinestatic
Parameters
baseUSDHC peripheral base address.
status_t USDHC_TransferBlocking ( USDHC_Type *  base,
usdhc_adma_config_t dmaConfig,
usdhc_transfer_t transfer 
)

This function waits until the command response/data is received or the USDHC encounters an error by polling the status flag. The application must not call this API in multiple threads at the same time. Because of that this API doesn't support the re-entry mechanism.

Note
There is no need to call the API 'USDHC_TransferCreateHandle' when calling this API.
Parameters
baseUSDHC peripheral base address.
admaconfiguration
transferTransfer content.
Return values
kStatus_InvalidArgumentArgument is invalid.
kStatus_USDHC_PrepareAdmaDescriptorFailedPrepare ADMA descriptor failed.
kStatus_USDHC_SendCommandFailedSend command failed.
kStatus_USDHC_TransferDataFailedTransfer data failed.
kStatus_SuccessOperate successfully.
void USDHC_TransferCreateHandle ( USDHC_Type *  base,
usdhc_handle_t *  handle,
const usdhc_transfer_callback_t callback,
void *  userData 
)
Parameters
baseUSDHC peripheral base address.
handleUSDHC handle pointer.
callbackStructure pointer to contain all callback functions.
userDataCallback function parameter.
status_t USDHC_TransferNonBlocking ( USDHC_Type *  base,
usdhc_handle_t *  handle,
usdhc_adma_config_t dmaConfig,
usdhc_transfer_t transfer 
)

This function sends a command and data and returns immediately. It doesn't wait the transfer complete or encounter an error. The application must not call this API in multiple threads at the same time. Because of that this API doesn't support the re-entry mechanism.

Note
Call the API 'USDHC_TransferCreateHandle' when calling this API.
Parameters
baseUSDHC peripheral base address.
handleUSDHC handle.
admaconfiguration.
transferTransfer content.
Return values
kStatus_InvalidArgumentArgument is invalid.
kStatus_USDHC_BusyTransferringBusy transferring.
kStatus_USDHC_PrepareAdmaDescriptorFailedPrepare ADMA descriptor failed.
kStatus_SuccessOperate successfully.
void USDHC_TransferHandleIRQ ( USDHC_Type *  base,
usdhc_handle_t *  handle 
)

This function deals with the IRQs on the given host controller.

Parameters
baseUSDHC peripheral base address.
handleUSDHC handle.