File System Component  Version 6.6
MDK-Professional Middleware for Devices with Flash File System
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Memory Card Control Layer

The Memory Card (MC) Control Layer is used when connecting to external memory cards or eMMC devices. It supports data transfer via MCI or SPI, but the data rates are much better using MCI.

List of Supported Devices

In general, the following devices are supported by the File System Component:

Memory Card Specification
Standard Capacity SD Memory Card (SDSC) Up to and including 2 GB
High Capacity SD Memory Card (SDHC) More than 2GB and up to and including 32GB
Extended Capacity SD Memory Card (SDXC)More than 32GB and up to and including 2TB
MultiMediaCard (MMC) Up to specification version 4.2
Embedded MultiMediaCard (eMMC) Up to specification 4.41

List of Supported MCI Driver Capabilities

MC Control Layer uses MCI driver when memory device is connected via MCI. Depending on MCI driver capabilities, File System Component can take advantage of certain features. The following table briefly describes how enabled capabilities affect the functionality of the MC Control Layer:

Capability Functionality
cd_state Enables device presence detection by pooling the Card Detect (CD) switch state
cd_event Enables device presence detection using MCI driver events
wp_state Enables write protection detection by pooling Write Protect (WP) switch state
vdd Power consumption can be controlled by turning VDD (VCC) power supply on or off
vccq Power consumption can be controlled by turning VCCQ power supply on or off
data_width_4Data transfer rate can be increased by using 4-bit data bus
data_width_8Data transfer rate can be increased by using 8-bit data bus
high_speed Data transfer rate can be increased by using MCI bus frequencies up to 52MHz
rst_n eMMC device can be reset from software using RST_n pin

Device Specific Features

Power Supply Voltage Control

With appropriately designed hardware and support from the corresponding MCI driver, MC Control Layer can control memory device power supply voltage:

  • VDD (VCC) and VCCQ power supply is turned on when device is mounted
  • VDD (VCC) and VCCQ power supply is turned off when device is unmounted,
  • VCC power supply is turned on/off when eMMC device is switched to/from Sleep state

Data Bus Width

Depending on the memory device type, appropriate data bus width will be selected:

  • 1-bit data bus width is selected by default, since it must be supported by all devices and MCI drivers.
  • 4-bit or 8-bit data bus width selection depends on both, device and MCI driver capabilities. In order to switch either to 4 or 8-bit data bus, both, device and MCI driver must support it.

High Speed Mode

The MC Control Layer is able to automatically switch to high speed mode for SD cards supporting SD specification version 1.10 or higher (3.3V signaling, bus clock frequency up to 50MHz) and MMC/eMMC devices supporting MMCA specification version 4.2 or higher (3.3V signaling, bus clock frequency up to 52MHz). In order to do so, the high speed mode needs to be supported by the corresponding MCI driver.

Note
Improper PCB design can cause reliability problems when in high speed mode.

Password protection

The password protection feature enables the host to lock a card while providing a password, which later will be used for unlocking the card. The password is stored to device internal non-volatile registers and can consist of up to 16 bytes, where each byte can be arbitrary 8-bit value.

Password can be managed by using the function fs_ioc_device_ctrl, with control code fsDevCtrlCodeLockUnlock and structure fsLockUnlock as control code argument. When executing management operation, members of the fsLockUnlock structure must be set as follows:

Setting the password:

  • assign password buffer to member .password
  • define password length by setting member .length
  • define set password operation by setting member .flags to FS_DEVICE_SET_PASSWORD

When operation executes successfully, new password is stored into device registers.

Reset the password:

  • assign password buffer to member .password
  • define password length by setting member .length
  • define clear password operation by setting member .flags to FS_DEVICE_CLR_PASSWORD

When operation executes successfully, password is cleared from device registers.

Lock the card:

  • assign password buffer to member .password
  • define password length by setting member .length
  • define lock operation by setting member .flags to FS_DEVICE_LOCK_UNLOCK

When operation executes successfully, data access protection is activated. All read/write accesses are rejected.

Unlock the card:

  • assign password buffer to member .password
  • define password length by setting member .length
  • define unlock operation by setting member .flags to 0 (zero)

When operation executes successfully, data access protection is deactivated. All read/write accesses are allowed.

Forcing erase:

  • members .password and .length are ignored
  • define force erase operation by setting member .flags to FS_DEVICE_ERASE

When operation executes successfully, all the card data content is erased along with the current password.

Note
It is possible to set password and lock the card in a single step:
SD and MMCA specification also allows to replace the password in a single step. This is not supported by the FileSystem library, since it is known that various devices have issues with the interpretation of this operation. Therefore, when changing the password, old one must be first cleared and then new password can be set.
Is is also recommended to unlock the device before resetting the password.

To successfully mount locked memory card and gain read/write data access, password management information must be provided from the user application:

User application should only implement callback function fs_mc_lock_unlock when support for memory card password management is required. This function will be called only when mounting a memory card with active password protection.

Power Saving Features

File System Component tends to reduce overall power consumption as much as possible, therefore the MC Control Layer will automatically:

  • switch the memory device between Transfer state and Standby state. This way the memory device spends most of the time in Standby state without noticeable effect on the data transfer performance.
  • stop bus clock when there is no communication on the bus

eMMC devices (MMCA specification version 4.3 and higher) support CMD5 (Sleep state). To switch between Sleep state and Standby state, use the function fs_ioc_device_ctrl. While in the Sleep state, VCC power supply may be switched off to further minimize the power consumption.

SPI Mode Support

SD memory cards (up to SD specification version 4.10) and MMC devices (up to MMCA specification version 4.2) also support Serial Peripheral Interface (SPI) bus mode as alternative way of communication. When SPI mode is used, MC Control Layer will use CMSIS-Driver SPI to use the underlying hardware.

The advantage of using the memory card in SPI mode is in simplified hardware requirements, but at the cost of performance loss and limited command set. Since SPI consists of only SCLK, MOSI, MISO and nSS communication lines, File System Component provides following callback routines for interfacing Card Detect (CD) and Write Protect (WP) switches:

Callback functions fs_mc_read_cd and fs_mc_read_wp are optional. If they are not implemented by user application, File System Component will assume that memory device in SPI mode is always present and without write protection.

Since software controlled Slave Select line is not always available an alternative way is provided in such case:

User application should only implement callback function fs_mc_spi_control_ss when SPI driver does not provide software controlled Slave Select line.