SD/MMC Disk Drivers

The Embedded SDK contains two different disk drivers for accessing SD/MMC cards depending upon the physical interface that is available to access the card.

Multimedia Card Interface (MCI)

The multimedia card interface (MCI) disk driver uses an on-chip peripheral of communicating with the card using a 4-wire or 8-wire bus. Although the multimedia card interface provides better performance, it is only supported on MCU's that have a dedicated peripheral for accessing SD/MMC cards.

#include "FS/Disk/disk_mci.h"
#include <assert.h>

static MCIDISK disk;                    /* Allocate the disk driver */

void APP_Function(void)
{
    STATUS status;


    status = MCIDISK_Create(&disk,      /* Create and initialize the disk driver */
                            0);         /* The MCI peripheral port number */

    assert(status == SUCCESS);


    status = DISK_Mount(&disk.base);    /* Mount and initialize the card */
    assert(status == SUCCESS);
}

SPI Interface

The multimedia card SPI disk driver uses a standard SPI port for communicating with a SD/MMC card. The SPI disk driver can be used with any MCU that has an available SPI port.

#include "FS/Disk/disk_mci.h"
#include <assert.h>

static SPI spi;                             /* Allocate the SPI port */
static MCSPIDISK disk;                      /* Allocate the disk driver */

void APP_Function(void)
{
    STATUS status;


    status = SPI_Open(&spi,                 /* Open the SPI port */
                      0,                    /* Port number 0 */
                      10000000,             /* Initial clock frequency of 10Mhz */         
                      SPI_DEFAULT);         /* Default clock polarity and phase */
                      
    status = MCSPIDISK_Create(&disk,        /* Create and initialize the disk driver */
                              &spi,         /* A pointer to the SPI port to be used */
                              P0_3);        /* Use pin P0.3 as the chip-select */

    assert(status == SUCCESS);

    status = DISK_Mount(&disk.base);        /* Mount and initialize the card */
    assert(status == SUCCESS);
}

API Reference

STATUS MCIDISK_Create(MCIDISK* disk, UINT32 port)
Creates and initializes a disk driver that uses a multimedia card interface (MCI) to communicate with an SD/MMC card for storage.
PARAMETERS
disk A pointer to a caller allocated MCI disk instance to be initialized.
port The port number of the multimedia card interface to be used by the driver.
RETURNS
SUCCESS The disk driver has been initialized.
ERR_NULLREFERENCE The argument 'disk' was found to be NULL.
STATUS MCSPIDISK_Create(MCSPIDISK* disk, SPI* port, PIN cs)
Creates and initializes a disk driver that uses a an SPI port to communicate with an SD/MMC card for storage.
PARAMETERS
disk A pointer to a caller allocated MCSPI disk instance to be initialized.
port A pointer to the SPI port to be used for communications with the card.
cs The pin to be used as the chip-select signal for the card.
RETURNS
SUCCESS The disk driver has been initialized.
ERR_NULLREFERENCE The argument 'disk' or 'port' was found to be NULL.