Skip to main content
Version: BSP 7.x.y

SD/MMC Card (Linux)

Introduction

SD (Secure Digital) and MMC (MultiMediaCard) are memory card standards used by a family of small, removable flash memory cards, used for data storage. Both formats share similar electrical interfaces and form factors, and can often be used interchangeably.

This article will guide you on how to handle SD/MMC cards on Toradex System-on-Modules (SoMs). Although both standards are supported, the SD specification is more widely used in practice. Considering this, this article will refer to both SD and MMC cards as SD Cards.

SD/MMC Driver

SD cards are generally mounted automatically on Toradex SoMs after insertion. The mounted SD card appears as a /dev/mmcblk<id> block device, and the kernel normally exports the card partitions with appendix p<x>, where <x> is the partition number (e.g. /dev/mmcblk<id>p<x>).

After inserting an SD Card, you can check whether the kernel correctly detected the insertion by verifying the system logs with dmesg:

# dmesg | egrep "(sdhci|mmc)"

Alternatively, you can check for system interrupts triggered upon the SD Card insertion:

# cat /proc/interrupts | egrep "(mmc|cd)"

In general, the processor on the module provides multiple MMC interfaces, each exposed as a /dev/mmcblk<id> block device. To simplify identifying the block device corresponding to the SD card slot, the Toradex BSP creates a symlink that points to the MMC interface routed to the SoM’s card connector. To determine the correct block device for the inserted card, run the command shown below. Note that the symlink is created only after the SD card is inserted into the board.

# ls -l /dev/verdin-sd*

Running the command above will display the corresponding /dev/mmcblk<id> block device, as shown below. The following examples were extracted from a Verdin iMX8M Plus module, where the SD Card corresponds to the /dev/mmcblk1 block device.

lrwxrwxrwx 1 root root 7 Nov 19 13:15 /dev/verdin-sd -> mmcblk1
lrwxrwxrwx 1 root root 9 Nov 19 13:15 /dev/verdin-sd-part1 -> mmcblk1p1

After identifying your SD Card's corresponding block device, you can check the device specifications through the sysfs interface:

# cat /sys/kernel/debug/mmc1/ios
clock:          50000000 Hz
actual clock: 49500000 Hz
vdd: 21 (3.3 ~ 3.4 V)
bus mode: 2 (push-pull)
chip select: 0 (don't care)
power mode: 2 (on)
bus width: 2 (4 bits)
timing spec: 2 (sd high-speed)
signal voltage: 0 (3.30 V)
driver type: 0 (driver type B)

You can also read your SD Card's CID (Card Identification) and CSD (Card Specific Data) through sysfs:

# cat /sys/bus/mmc/devices/mmc1\:0001/cid
12345641535443000000000c9e013500
# cat /sys/bus/mmc/devices/mmc1\:0001/csd
400e00325b590000752f7f800a400000

Use df to display the total storage and usage of the SD card:

# df -h | grep mmc
/dev/mmcblk2p1 48M 8.9M 39M 19% /boot
/dev/mmcblk1p1 15G 24K 15G 1% /run/media/mmcblk1p1

Use mount to display the mounting status of your card:

# mount | grep mmc
/dev/mmcblk2p2 on / type ext4 (rw,relatime)
/dev/mmcblk2p1 on /run/media/BOOT-mmcblk2p1 type vfat (rw,relatime,gid=6,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/dev/mmcblk2p1 on /boot type vfat (rw,relatime,gid=6,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/dev/mmcblk1p1 on /run/media/mmcblk1p1 type vfat (rw,relatime,gid=6,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

Use hdparm to obtain the data transfer rate of reads from your SD card. Typically, data rate values vary between 10 and 20 MB/sec. If your project requires higher data transfer speeds, refer to the Ultra High Speed (UHS) section.

# hdparm -t /dev/mmcblk1

/dev/mmcblk1:
Timing buffered disk reads: 54 MB in 3.34 seconds = 16.15 MB/sec

UHS-I Support

UHS-I (Ultra High Speed I) is a performance standard for SD memory cards that significantly increases data transfer rates, allowing signaling speeds up to 104 MB/s. UHS-I is usually enabled by default on Toradex SoMs, except on some Apalis and Colibri carrier boards. For further information, refer to UHS-I on Apalis/Colibri Modules.

UHS-I on Apalis/Colibri Modules

The UHS-I standard operates at 1.8V, while the Apalis and Colibri modules operate at a digital voltage of 3.3V. Due to this, the SD signals are pulled down on Apalis and Colibri modules to operate at 1.8V.

When using UHS-I with Apalis/Colibri SoMs, keep in mind the following points:

  • To disable UHS-I, you can add the no-1-8-v property to the Device Tree.

  • Each Apalis and Colibri module adds the no-1-8-v at the module-level device tree include file (such as imx8x-colibri.dtsi). Some carrier board device trees include files (such as imx8x-colibri-iris-v2.dtsi) delete this property, which reenables the UHS-I standard at the carrier board level of the device tree.

  • If you build a custom carrier board for an Apalis or Colibri module, you need to delete the no-1-8-v property, similarly to our boards' device trees, as shown below:

    /* Colibri SD/MMC Card */
    &usdhc2 {
    cap-power-off-card;
    /delete-property/ no-1-8-v;
    vmmc-supply = <&reg_3v3_vmmc>;
    status = "okay";
    };
warning

Make sure your carrier board does not pull up any of the MMC, MMC1, or SD1 signals to 3.3 volts (i.e., remove R46 to R54 for 8-bit or R29 to R32 and R39 for 4-bit SD/MMC slot on our Apalis Evaluation Board V1.1A) before attempting to activate this feature. Refer to the SD/MMC section of your SoM's datasheet for information on what signals are affected by UHS-I.

info

The Apalis iMX8X does not provide the SD1 interface; the MMC1 is four-bit data only.

Test an SD Card with UHS-I

Run the commands below to verify the data transfer rates of your SD Card with UHS-I enabled. These are the same commands referenced in the SD/MMC Driver section. You can compare the results with the ones obtained previously to evaluate the performance gains provided by the UHS-I standard.

warning

Even if UHS-I is enabled on your module, your SD Card itself must also support UHS-I. Otherwise, your board will set the standard transfer speed and voltage to the default ones used by your card.

Read the SD Card specifications through sysfs. The timing spec parameter should specify the UHS standard, and the device should operate at 1.8V.

# cat /sys/kernel/debug/mmc1/ios
clock:          100000000 Hz
vdd: 21 (3.3 ~ 3.4 V)
bus mode: 2 (push-pull)
chip select: 0 (don't care)
power mode: 2 (on)
bus width: 2 (4 bits)
timing spec: 6 (sd uhs SDR104)
signal voltage: 1 (1.80 V)
driver type: 0 (driver type B)

Display the data transfer speed with hdparm. The UHS-I standard allows transfer speeds of up to 104 MB/sec, depending on the specifications of your SD Card.

# hdparm -t /dev/mmcblk1

/dev/mmcblk1:
Timing buffered disk reads: 136 MB in 3.00 seconds = 45.27 MB/sec
Send Feedback!