The MCUXpresso SDK provides a driver to access the Secure Digital Card and Embedded MultiMedia Card based on the SDHC/USDHC/SDIF driver.
Function groups
This function group implements the SD card functional API.
This function group implements the MMC card functional API.
Typical use case
SD CARD Operation
error log support
Lots of error log has been added to sd relate functions, if error occurs during initial/read/write, please enable the error log print functionality with #define SDMMC_ENABLE_LOG_PRINT 1 And rerun the project then user can check what kind of error happened.
User configurable
typedef struct _sd_card
{
SDMMCHOST_CONFIG host;
bool isHostReady;
bool noInteralAlign;
uint32_t busClock_Hz;
uint32_t relativeAddress;
uint32_t version;
uint32_t flags;
uint32_t rawCid[4U];
uint32_t rawCsd[4U];
uint32_t rawScr[2U];
uint32_t ocr;
uint32_t blockCount;
uint32_t blockSize;
sd_timing_mode_t currentTiming;
sd_driver_strength_t driverStrength;
sd_max_current_t maxCurrent;
sdmmc_operation_voltage_t operationVoltage;
Part of The variables above is user configurable,
- SDMMCHOST_CONFIG host Application need to provide host controller base address and the host's source clock frequency.
- sdcard_usr_param_t usrParam Two member in the userParam structure, a. cd-which allow application define the card insert/remove callback function, redefine the card detect timeout ms and also allow application determine how to detect card. b. pwr-which allow application redefine the power on/off function and the power on/off delay ms. However, sdmmc always use the default setting if application not define it in application. The default setting is depend on the macro defined in the board.h.
- bool noInteralAlign Sdmmc include an address align internal buffer(to use host controller internal DMA), to improve read/write performance while application cannot make sure the data address used to read/write is align, set it to true will achieve a better performance.
- sd_timing_mode_t currentTiming It is used to indicate the currentTiming the card is working on, however sdmmc also support preset timing mode, then sdmmc will try to switch to this timing first, if failed, a valid timing will switch to automatically. Generally, user may not set this variable if you don't know what kind of timing the card support, sdmmc will switch to the highest timing which the card support.
- sd_driver_strength_t driverStrength Choose a valid card driver strength if application required and call SD_SetDriverStrength in application.
- sd_max_current_t maxCurrent Choose a valid card current if application required and call SD_SetMaxCurrent in application.
Board dependency
Sdmmc depend on some board specific settings, such as card detect - which is used to detect card, the card active level is determine by the socket you are using, low level is active usually, but some socket use high as active, please set the macro #define BOARD_xxxx_CARD_INSERT_CD_LEVEL (0U) According to your board specific if you cannot detect card even if card is inserted.
power control - Macro for USDHC only, SDHC/SDIF support high speed timing only, so please ignore the power reset pin for SDHC/SDIF. which is used to reset card power for UHS card, to make UHS timing work properly, please make sure the power reset pin is configured properly in board.h. #define BOARD_SD_POWER_RESET_GPIO (GPIO1) #define BOARD_SD_POWER_RESET_GPIO_PIN (5U) #define BOARD_USDHC_SDCARD_POWER_CONTROL_INIT() \
pin configurations - Function for USDHC only. which is used to switch the signal pin configurations include driver strength/speed mode dynamiclly for different timing mode, reference the function defined in board.c void BOARD_SD_Pin_Config(uint32_t speed, uint32_t strength)
Typical use case
card->host.base = BOARD_SDHC_BASEADDR;
card->host.sourceClock_Hz = CLOCK_GetFreq(BOARD_SDHC_CLKSRC);
card->usrParam.cd = &s_sdCardDetect;
card->usrParam.pwr = &s_sdCardPwrCtrl;
{
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");
}
}
MMC CARD Operation
error log support
Not support yet
User configuable
Board dependency
Typical use case
card->host.base = BOARD_SDHC_BASEADDR;
card->host.sourceClock_Hz = CLOCK_GetFreq(BOARD_SDHC_CLKSRC);
card->hostVoltageWindowVCC = BOARD_MMC_VCC_SUPPLY;
{
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");
}
}
SDIO CARD Operation
error log support
Not support yet
User configuable
Board dependency
Typical use case
struct sdmmchost_detect_card_t |
struct sdmmchost_pwr_card_t |
Enumerator |
---|
kSDMMCHOST_EndianModeBig |
Big endian mode.
|
kSDMMCHOST_EndianModeHalfWordBig |
Half word big endian mode.
|
kSDMMCHOST_EndianModeLittle |
Little endian mode.
|
Enumerator |
---|
kSDMMCHOST_DetectCardByGpioCD |
sd card detect by CD pin through GPIO
|
kSDMMCHOST_DetectCardByHostCD |
sd card detect by CD pin through host
|
kSDMMCHOST_DetectCardByHostDATA3 |
sd card detect by DAT3 pin through host
|
static status_t SDMMCHOST_NotSupport |
( |
void * |
parameter | ) |
|
|
inlinestatic |
- Parameters
-
void | parameter ,used to avoid build warning |
- Return values
-
kStatus_Fail,host | do not suppport |
status_t SDMMCHOST_WaitCardDetectStatus |
( |
SDMMCHOST_TYPE * |
hostBase, |
|
|
const sdmmchost_detect_card_t * |
cd, |
|
|
bool |
waitCardStatus |
|
) |
| |
- Parameters
-
base | the pointer to host base address |
cd | card detect configuration |
waitCardStatus | status which user want to wait |
- Return values
-
kStatus_Success | detect card insert |
kStatus_Fail | card insert event fail |
bool SDMMCHOST_IsCardPresent |
( |
void |
| ) |
|
- Return values
-
true | card is present |
false | card is not present |
status_t SDMMCHOST_Init |
( |
SDMMCHOST_CONFIG * |
host, |
|
|
void * |
userData |
|
) |
| |
- Parameters
-
host | the pointer to host structure in card structure. |
userData | specific user data |
- Return values
-
kStatus_Success | host init success |
kStatus_Fail | event fail |
void SDMMCHOST_Reset |
( |
SDMMCHOST_TYPE * |
base | ) |
|
void SDMMCHOST_ErrorRecovery |
( |
SDMMCHOST_TYPE * |
base | ) |
|
void SDMMCHOST_Deinit |
( |
void * |
host | ) |
|
- Parameters
-
host | the pointer to host structure in card structure. |
- Parameters
-
base | host base address. |
pwr | depend on user define power configuration. |
- Parameters
-
base | host base address. |
pwr | depend on user define power configuration. |
void SDMMCHOST_Delay |
( |
uint32_t |
milliseconds | ) |
|
- Parameters
-
milliseconds | delay counter. |