SD/MMC Reference

Version 1.0


1. Overview

This article mainly introduces how to use SD/EMMC in uboot and user space.


2. Specification

Peripherals Highest clock
One SDIO bus, which can be connected to SD card or eMMC 48Mhz

3. Use SD/MMC in UBOOT


3.1. Enable SD/MMC Driver in UBOOT

The hardware has only one SDIO bus interface, so the SD card and eMMC cannot be connected at the same time.

Enable SD driver in menuconfig:

Device Drivers

-> [*] MStar drivers
    -> [*] MSTAR SDMMC      
    -> [ ] MSTAR eMMC

Enable eMMC driver in menuconfig:

Device Drivers
-> [*] MStar drivers
    -> [ ] MSTAR SDMMC                                  
    -> [*] MSTAR eMMC
        -> [ ] Support eMMC BOOT
        -> [ ] Save environment to eMMC

3.2. Introduce SD/MMC Driver in UBOOT

For SD driver code in uboot, please refer to boot/drivers/mmc/mmc.c and boot/drivers/mstar/sdmmc/ms_sdmmc_ub.c.

Function name Description
mmc_core_init Initialize sdmmc
mmc_bread Read block
mmc_bwrite Write block
mmc_berase Erase block
mmc_send_cmd Send cmd

For eMMC driver code in uboot, please refer to boot/drivers/mstar/emmc/src/api/eMMC_prg.c.

Function name Description
eMMC_mmc_Init Initialize eMMC
eMMC_bread Read block
eMMC_bwrite Write block
eMMC_berase Erase block
eMMC_send_cmd Send cmd

3.3. Test SD/MMC in UBOOT

For SD/eMMC test cmd in ubbot, please refer to boot/common/cmd_mmc.c and boot/common/cmd_mstar.c.

Users can refer to the above files to write application code.

Test SD card:

mmc - MMC sub system

Usage:

mmc info - display info of the current MMC device
mmc read addr blk# cnt
mmc write addr blk# cnt
mmc erase blk# cnt
mmc rescan
mmc part - lists available partition on current mmc device
mmc dev [dev] [part] - show or set current mmc device [partition]
mmc list - lists available devices
mmc setdsr <value> - set DSR register value

Test eMMC:

emmc - EMMC function on NVRAM base partition

Usage:

emmc emmc create [name] [size] - create mmc partition [name]
emmc remove [name] - remove mmc partition [name]
emmc rmgpt - clean all mmc partition table
emmc part - list partitions 
emmc slc size relwr - set slc in the front of user area,  0xffffffff means max slc size
emmc unlzo Src_Address Src_Length Partition_Name [empty_skip:0-disable,1-enable]- decompress lzo file and write to mmc partition 
emmc read.p addr partition_name size
emmc read.p.continue addr partition_name offset size
emmc write.p addr partition_name size [empty_skip:0-disable,1-enable]
emmc write.p.continue addr partition_name offset size [empty_skip:0-disable,1-enable]
emmc erase.p partition_name

Input # mmcinfo in shell to list SD/eMMC info.

The print info when connecting SD card is as follows:

The print info when connecting eMMC is as follows:


4. Use SD/MMC in Userspace

It is recommended to use the following pins and modes as the SDIO bus.

Group Mode CLK CMD DATA0 DATA1 DATA2 DATA3
SDIO 1 PAD_SD_CLK PAD_SD_CMD PAD_SD_D0 PAD_SD_D1 PAD_SD_D2 PAD_SD_D3

4.1. Configure SD/MMC for DTS in Kernel

Configure SD/eMMC device tree attributes in kernel/arch/arm/boot/dts/pioneer3.dtsi.

eMMC adjusts the reset pin according to the actual circuit, or changes the clock to adjust the eMMC speed.


4.2. Configure SDIO PADMUX in Kernel

Configure padmux in Kernel/arch/arm/boot/dts/pioneer3-ssc020a-s01a-demo-padmux.dtsi.

Configure the pin to PINMUX_FOR_SDIO_MODE_1.


4.3. Enable SD/MMC Function in Kernerl

Configured in menuconfig to support SD card.

Device Drivers
    -> <*> MMC/SD/SDIO card support
    -> [*] SStar SoC platform drivers
        -> < > EMMC driver  
        -> <*> SStar SD/MMC Card Interface Support

Configured in menuconfig to support eMMC:

Device Drivers
    -> <*> MMC/SD/SDIO card support
    -> [*] SStar SoC platform drivers
    -> <*> EMMC driver 
        -> [*] UNIFY EMMC DRIVER 
    -> < > SStar SD/MMC Card Interface Support

After kernel runs, use # cat /proc/partitions to check whether the SD/eMMC is loaded successfully. If there is mmcblk0 in the list, the SD/eMMC is loaded successfully.

Use linux cmd to mount mmcblk0, then users can access files in SD/eMMC.

# mount -t vfat -o iocharset=utf8 /dev/mmcblk0 /mnt

4.4. Check PADMUX Configu

Check whether padmux is configured correctly by the register.

Find the SDIO pin in kernel/drivers/sstar/gpio/pioneer3/mhal_pinmux.c.

The register info is as follows when SDIO = PINMUX_FOR_SDIO_MODE_1.

Basic address PADTOP_BANK 0x103C
Offset address REG_SDIO_MODE 0x67
Valid bit BIT8 0x0100

As above, the bank basic address is 0x103C, the offset address is 0x67, and BIT3 is enabled. Run /customer/riu_r 0x103C 0x67 in the demo board to read the value of register, if it is 0x0100, the SDIO PADMUX register configuration is correct.