2.52 High Speed MultiMedia Card Interface (HSMCI)

The HSMCI PLIB provides low level APIs to configure and transfer data using HSMCI. The HSMCI PLIB supports default and high speed data transfer, 1-bit and 4-bit data bus configurations. The PLIB performs the transfers in non-blocking mode. Transfers involving a data stage are performed using ADMA.

Using The Library

The example code demonstrates sending a SD command to read a single block of data from the SD card. This example assumes that the SD card is already initialized by the application and is ready to accept read and write requests. The example application does not show the larger SD protocol required in order to communicate with the SD card.

uint16_t cmd_error;
uint16_t data_error;
bool isCommandCompleted = false;
bool isDataCompleted = false;
uint8_t readBuffer[512];

static void HSMCI_TransferEventHandler(
        HSMCI_XFER_STATUS xferStatus,
        uintptr_t contextHandle
)
{
    if (xferStatus & HSMCI_XFER_STATUS_CMD_COMPLETED)
    {
        // Command transfer complete, read the command error status.
        cmd_error = HSMCI_CommandErrorGet();
        isCommandCompleted = true;
    }
    if (xferStatus & HSMCI_XFER_STATUS_DATA_COMPLETED)
    {
        // Data transfer complete, read the data error status.
        data_error = HSMCI_DataErrorGet();
        isDataCompleted = true;
    }
}

int main ( void )
{
    /* Initialize all modules */
    SYS_Initialize ( NULL );

    // Register event handler with the HSMCI PLIB. This is usually done once.
    HSMCI_CallbackRegister(HSMCI_TransferEventHandler, (uintptr_t) 0);

    HSMCI_DataTransferFlags transferFlags;

    transferFlags.isDataPresent  = true;
    transferFlags.transferDir = HSMCI_DATA_TRANSFER_DIR_READ;
    transferFlags.transferType = HSMCI_DATA_TRANSFER_TYPE_SINGLE;

    // Set the block size to 512 bytes
    HSMCI_BlockSizeSet(512);

    // Set the block count to 1
    HSMCI_BlockCountSet(1);

    // Set up the DMA to read 512 btyes of data
    HSMCI_DmaSetup(readBuffer, 512, HSMCI_DATA_TRANSFER_DIR_READ);

    // Send command to read one block of data from SD card starting at block address 100
    HSMCI_CommandSend(17, 100, HSMCI_CMD_RESP_R1, transferFlags);

    // Check the status of isCommandCompleted and isDataCompleted

    // Other tasks ..
}

Library Interface

High Speed MultiMedia Card Interface peripheral library provides the following interfaces:

Functions

NameDescription
HSMCI_BusWidthSetConfigures the width of the data bus
HSMCI_SpeedModeSetSets the bus speed
HSMCI_BlockSizeSetSets the size of the one data block of transfer
HSMCI_BlockCountSetSets the number of blocks to transfer
HSMCI_IsCmdLineBusyReturns the status of the command line
HSMCI_IsDatLineBusyReturns the status of the data line
HSMCI_ClockSetSets the High Speed MultiMedia Card Interface clock frequency
HSMCI_CommandErrorGetReturns the errors associated with a command transfer
HSMCI_DataErrorGetReturns the errors associated with a data transfer
HSMCI_ResponseReadReads the specified response register
HSMCI_InitializeInitializes the HSMCI peripheral and the internal data structures used by the peripheral library
HSMCI_ModuleInitInitializes the HSMCI peripheral
HSMCI_CallbackRegisterThis function allows a HSMCI PLIB client to set an event handler
HSMCI_CommandSendThis function allows the client to send a SD command on the HSMCI interface
HSMCI_DmaSetupSets up the DMA for data transfers

Data types and constants

NameTypeDescription
HSMCI_DATA_TRANSFER_TYPEEnumThe enumeration lists single or multi block data transfer type
HSMCI_DATA_TRANSFER_DIREnumThe enumeration lists the direction of the data transfer
HSMCI_DataTransferFlagsStructThe data structure is used by the client to provide information about the data transfer to the HSMCI PLIB
HSMCI_ERROR_FLAGSEnumThe enumeration lists the possible error types for a command and data transfer
HSMCI_BUS_WIDTHEnumThe enumeration lists the bus widths for the HSMCI bus
HSMCI_SPEED_MODEEnumThe enumeration lists the bus widths for the HSMCI bus
HSMCI_READ_RESPONSE_REGEnumThe enumeration lists the response registers that can be read for a given command
HSMCI_XFER_STATUSEnumThe enumeration lists the status of the transfer
HSMCI_CALLBACKTypedefThe prototype of the HSMCI callback function
HSMCI_CMD_ERRORMacroThe macro is a bit wise OR of all the possible errors corresponding to a command transfer
Note: Not all APIs maybe implemented. See the specific device family section for available APIs.