File System Component  Version 6.16.6
MDK Middleware for Devices with Flash File System
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) From specification 4.3

List of Supported MCI Driver Capabilities

MC Control Layer uses when memory device is connected via MCI. Depending on the , 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_4 Data transfer rate can be increased by using 4-bit data bus
data_width_8 Data 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 .

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.

Health Status (S.M.A.R.T)

Many industrial grade eMMC and SD memory devices support health status monitoring system known as S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology). Health Status monitor data is used to anticipate and detect imminent memory failures.

eMMC and SD memory devices use common command (CMD56) to access vendor specific information about memory health status. In order to retrieve relevant information, function fs_ioc_device_ctrl can be used together with control code fsDevCtrlCodeHealthStatus and structure fsHealthStatus as control code argument.

Health status access command behavior is vendor specific but in general the following rules apply:

  • Variable fsHealthStatus::arg is used to control data direction and to provide vendor specific control info:
    • Bit [0] controls direction: read mode requires setting this bit to 1, write mode requires setting this bit to 0
    • Bits [1-31] are vendor specific and shall be set according to device datasheet
  • Variables fsHealthStatus::buf and fsHealthStatus::buf_sz specify data buffer where health status information will be stored. Data buffer address shall be 4-byte aligned and buffer size shall be equal to or greater than 512 bytes.

When function fs_ioc_device_ctrl is called, general command (CMD56) is executed and variable fsHealthStatus::arg is used as command argument. The transfered data gets copied into or from the buffer specified by fsHealthStatus::buf.

Note
Health Status is usually not available on non-industrial memory devices.

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 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.

Note
Do not implement fs_mc_spi_control_ss when using "SPI Master to Multi-Slave Driver Wrapper". In this case Slave Select line is controlled by Multi-Slave driver function SPI_Control_SlaveSelect.

SPI bus frequency setting

Reliable communication at high frequencies is a common problem when using SPI bus, since maximum bus frequency can be limited by PCB design. To overcome this problem, FileSystem component implements simple bus frequency adaptation algorithm in order to determine the maximum bus frequency at which it is still possible to communicate with the memory card.

FileSystem component will always attempt to set the highest bus frequency supported by the memory card (usually 25MHz) but if after that the memory card is not accessible anymore I will lower the bus frequency. The adaptation is performed only during memory card initialization procedure.